[lld] r296507 - Make it obvious that st_value for common symbols has a different meaning.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 11:22:09 PST 2017


Author: ruiu
Date: Tue Feb 28 13:22:09 2017
New Revision: 296507

URL: http://llvm.org/viewvc/llvm-project?rev=296507&view=rev
Log:
Make it obvious that st_value for common symbols has a different meaning.

Modified:
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=296507&r1=296506&r2=296507&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Feb 28 13:22:09 2017
@@ -1363,6 +1363,7 @@ template <class ELFT> void SymbolTableSe
   for (SymbolTableEntry &Ent : Symbols) {
     SymbolBody *Body = Ent.Symbol;
 
+    // Set st_info and st_other.
     if (Body->isLocal()) {
       ESym->setBindingAndType(STB_LOCAL, Body->Type);
     } else {
@@ -1372,16 +1373,23 @@ template <class ELFT> void SymbolTableSe
 
     ESym->st_name = Ent.StrTabOffset;
     ESym->st_size = Body->getSize<ELFT>();
-    ESym->st_value = Body->getVA<ELFT>();
 
-    if (const OutputSection *OutSec = Body->getOutputSection<ELFT>()) {
+    // Set a section index.
+    if (const OutputSection *OutSec = Body->getOutputSection<ELFT>())
       ESym->st_shndx = OutSec->SectionIndex;
-    } else if (isa<DefinedRegular<ELFT>>(Body)) {
+    else if (isa<DefinedRegular<ELFT>>(Body))
       ESym->st_shndx = SHN_ABS;
-    } else if (isa<DefinedCommon>(Body)) {
+    else if (isa<DefinedCommon>(Body))
       ESym->st_shndx = SHN_COMMON;
+
+    // st_value is usually an address of a symbol, but that has a
+    // special meaining for uninstantiated common symbols (this can
+    // occur if -r is given).
+    if (!Config->DefineCommon && isa<DefinedCommon>(Body))
       ESym->st_value = cast<DefinedCommon>(Body)->Alignment;
-    }
+    else
+      ESym->st_value = Body->getVA<ELFT>();
+
     ++ESym;
   }
 




More information about the llvm-commits mailing list