[lld] r246505 - Set the correct value for the common symbols.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 15:55:21 PDT 2015


Author: rafael
Date: Mon Aug 31 17:55:21 2015
New Revision: 246505

URL: http://llvm.org/viewvc/llvm-project?rev=246505&view=rev
Log:
Set the correct value for the common symbols.

In the relocatable object it is the alignment, but in the linked file it is
a regular address.

Modified:
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/elf2/common.s
    lld/trunk/test/elf2/symbols.s

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=246505&r1=246504&r2=246505&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Mon Aug 31 17:55:21 2015
@@ -138,12 +138,18 @@ template <class ELFT> class DefinedCommo
   typedef typename Base::Elf_Sym Elf_Sym;
 
 public:
+  typedef typename std::conditional<ELFT::Is64Bits, uint64_t, uint32_t>::type
+      uintX_t;
   explicit DefinedCommon(StringRef N, const Elf_Sym &Sym)
       : Defined<ELFT>(Base::DefinedCommonKind, N, Sym) {}
 
   static bool classof(const SymbolBody *S) {
     return S->kind() == Base::DefinedCommonKind;
   }
+
+  // The output offset of this common symbol in the output bss. Computed by the
+  // writer.
+  uintX_t OffsetInBSS;
 };
 
 // Regular defined symbols read from object file symbol tables.

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=246505&r1=246504&r2=246505&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug 31 17:55:21 2015
@@ -344,7 +344,10 @@ template <class ELFT> void SymbolTableSe
       uintX_t VA = Out->getVA();
       if (Section)
         VA += Section->getOutputSectionOff();
-      VA += InputSym->st_value;
+      if (auto *C = dyn_cast<DefinedCommon<ELFT>>(Body))
+        VA += C->OffsetInBSS;
+      else
+        VA += InputSym->st_value;
       ESym->st_value = VA;
     }
 
@@ -445,6 +448,7 @@ template <class ELFT> void Writer<ELFT>:
     const Elf_Sym &Sym = C->Sym;
     uintX_t Align = Sym.st_value;
     Off = RoundUpToAlignment(Off, Align);
+    C->OffsetInBSS = Off;
     Off += Sym.st_size;
   }
   BSSSec->setSize(Off);

Modified: lld/trunk/test/elf2/common.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/common.s?rev=246505&r1=246504&r2=246505&view=diff
==============================================================================
--- lld/trunk/test/elf2/common.s (original)
+++ lld/trunk/test/elf2/common.s Mon Aug 31 17:55:21 2015
@@ -1,11 +1,20 @@
 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/common.s -o %t2
 // RUN: lld -flavor gnu2 %t %t2 -o %t3
-// RUN: llvm-readobj -t %t3 | FileCheck %s
+// RUN: llvm-readobj -t -s %t3 | FileCheck %s
 // REQUIRES: x86
 
+// CHECK:      Name: .bss
+// CHECK-NEXT: Type: SHT_NOBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT:   SHF_ALLOC
+// CHECK-NEXT:   SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address: 0x1000
+
+
 // CHECK:      Name: sym2
-// CHECK-NEXT: Value: 0x1004
+// CHECK-NEXT: Value: 0x1008
 // CHECK-NEXT: Size: 8
 // CHECK-NEXT: Binding: Global
 // CHECK-NEXT: Type: Object
@@ -13,7 +22,7 @@
 // CHECK-NEXT: Section: .bss
 
 // CHECK:      Name: sym1
-// CHECK-NEXT: Value: 0x1004
+// CHECK-NEXT: Value: 0x1000
 // CHECK-NEXT: Size: 8
 // CHECK-NEXT: Binding: Global
 // CHECK-NEXT: Type: Object

Modified: lld/trunk/test/elf2/symbols.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/symbols.s?rev=246505&r1=246504&r2=246505&view=diff
==============================================================================
--- lld/trunk/test/elf2/symbols.s (original)
+++ lld/trunk/test/elf2/symbols.s Mon Aug 31 17:55:21 2015
@@ -106,7 +106,7 @@ abs = 0x123
 // CHECK-NEXT:   }
 // CHECK-NEXT:   Symbol {
 // CHECK-NEXT:     Name: common (34)
-// CHECK-NEXT:     Value: 0x1008
+// CHECK-NEXT:     Value: 0x1004
 // CHECK-NEXT:     Size: 4
 // CHECK-NEXT:     Binding: Global (0x1)
 // CHECK-NEXT:     Type: Object (0x1)




More information about the llvm-commits mailing list