[lld] r296448 - Add a comment.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 00:32:56 PST 2017


Author: silvas
Date: Tue Feb 28 02:32:56 2017
New Revision: 296448

URL: http://llvm.org/viewvc/llvm-project?rev=296448&view=rev
Log:
Add a comment.

Naively it seemed at first like getVA had the responsibility of adding
the addend, and getSymVA had the responsibility of getting the symbol
VA.
So it was not obvious to me at first why getVA passes Addend to
getSymVA. In fact, it passes it as a mutable reference.

It turns out that it only matters for SHF_MERGE sections, and in
particular only for STT_SECTION symbols that are used as a hack for
reducing the number of local symbols (e.g. to avoid a local symbol for
each string in the string table).

Modified:
    lld/trunk/ELF/Symbols.cpp

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=296448&r1=296447&r2=296448&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Feb 28 02:32:56 2017
@@ -58,10 +58,21 @@ static typename ELFT::uint getSymVA(cons
       return D.Value;
 
     uintX_t Offset = D.Value;
+
+    // An object in an SHF_MERGE section might be referenced via a
+    // section symbol (as a hack for reducing the number of local
+    // symbols).
+    // We must incorporate the addend into the section offset (and
+    // zero out the addend for later processing) so that we find the
+    // right object in the section.
+    // Note that for an ordinary symbol we do not perform this
+    // adjustment and thus effectively assume that the addend cannot
+    // cross the boundaries of mergeable objects.
     if (D.isSection()) {
       Offset += Addend;
       Addend = 0;
     }
+
     const OutputSection *OutSec = IS->getOutputSection<ELFT>();
     uintX_t VA = (OutSec ? OutSec->Addr : 0) + IS->getOffset<ELFT>(Offset);
     if (D.isTls() && !Config->Relocatable) {




More information about the llvm-commits mailing list