[lld] r246503 - Assign common symbols to the .bss output section.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 15:33:21 PDT 2015
Author: rafael
Date: Mon Aug 31 17:33:21 2015
New Revision: 246503
URL: http://llvm.org/viewvc/llvm-project?rev=246503&view=rev
Log:
Assign common symbols to the .bss output section.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/elf2/common.s
lld/trunk/test/elf2/symbols.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=246503&r1=246502&r2=246503&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug 31 17:33:21 2015
@@ -141,6 +141,8 @@ public:
const SymbolTable &getSymTable() { return Table; }
+ OutputSection<ELFT> *BSSSec = nullptr;
+
private:
SymbolTable &Table;
};
@@ -303,6 +305,7 @@ template <class ELFT> void SymbolTableSe
const SectionChunk<ELFT> *Section = nullptr;
const Elf_Sym *InputSym = nullptr;
+ OutputSection<ELFT> *Out = nullptr;
switch (Body->kind()) {
case SymbolBody::DefinedRegularKind: {
@@ -311,9 +314,12 @@ template <class ELFT> void SymbolTableSe
Section = &Def->Section;
break;
}
+ case SymbolBody::DefinedCommonKind:
+ InputSym = &cast<ELFSymbolBody<ELFT>>(Body)->Sym;
+ Out = BSSSec;
+ break;
case SymbolBody::UndefinedKind:
assert(Body->isWeak() && "Should be defined by now");
- case SymbolBody::DefinedCommonKind:
case SymbolBody::DefinedAbsoluteKind:
InputSym = &cast<ELFSymbolBody<ELFT>>(Body)->Sym;
break;
@@ -330,11 +336,14 @@ template <class ELFT> void SymbolTableSe
}
}
- if (Section) {
- OutputSection<ELFT> *Out = Section->getOutputSection();
+ if (Section)
+ Out = Section->getOutputSection();
+
+ if (Out) {
ESym->st_shndx = Out->getSectionIndex();
uintX_t VA = Out->getVA();
- VA += Section->getOutputSectionOff();
+ if (Section)
+ VA += Section->getOutputSectionOff();
VA += InputSym->st_value;
ESym->st_value = VA;
}
@@ -424,8 +433,8 @@ template <class ELFT> void Writer<ELFT>:
}
}
- OutputSection<ELFT> *BSSSec =
- getSection(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
+ SymTable.BSSSec = getSection(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
+ OutputSection<ELFT> *BSSSec = SymTable.BSSSec;
uintX_t Off = BSSSec->getSize();
// FIXME: Try to avoid the extra walk over all global symbols.
for (auto &P : Symtab.getSymbols()) {
Modified: lld/trunk/test/elf2/common.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/common.s?rev=246503&r1=246502&r2=246503&view=diff
==============================================================================
--- lld/trunk/test/elf2/common.s (original)
+++ lld/trunk/test/elf2/common.s Mon Aug 31 17:33:21 2015
@@ -5,20 +5,20 @@
// REQUIRES: x86
// CHECK: Name: sym2
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x1004
// CHECK-NEXT: Size: 8
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: Section: .bss
// CHECK: Name: sym1
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x1004
// CHECK-NEXT: Size: 8
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Object
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: Section: .bss
.globl _start
Modified: lld/trunk/test/elf2/symbols.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/symbols.s?rev=246503&r1=246502&r2=246503&view=diff
==============================================================================
--- lld/trunk/test/elf2/symbols.s (original)
+++ lld/trunk/test/elf2/symbols.s Mon Aug 31 17:33:21 2015
@@ -106,12 +106,12 @@ abs = 0x123
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: common (34)
-// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Value: 0x1008
// CHECK-NEXT: Size: 4
// CHECK-NEXT: Binding: Global (0x1)
// CHECK-NEXT: Type: Object (0x1)
// CHECK-NEXT: Other: 0
-// CHECK-NEXT: Section: Undefined (0x0)
+// CHECK-NEXT: Section: .bss
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: zed
More information about the llvm-commits
mailing list