[lld] r268644 - Reuse logic for deciding whether to keep a local symbol or not.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu May 5 09:38:47 PDT 2016
Author: rafael
Date: Thu May 5 11:38:46 2016
New Revision: 268644
URL: http://llvm.org/viewvc/llvm-project?rev=268644&view=rev
Log:
Reuse logic for deciding whether to keep a local symbol or not.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/string-gc.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=268644&r1=268643&r2=268644&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu May 5 11:38:46 2016
@@ -832,6 +832,8 @@ static bool shouldKeepInSymtab(InputSect
return !(Sec->getSectionHdr()->sh_flags & SHF_MERGE);
}
+template <class ELFT> static bool includeInSymtab(const SymbolBody &B);
+
// Local symbols are not in the linker's symbol table. This function scans
// each object file's symbol table to copy local symbols to the output.
template <class ELFT> void Writer<ELFT>::copyLocalSymbols() {
@@ -845,23 +847,12 @@ template <class ELFT> void Writer<ELFT>:
// No reason to keep local undefined symbol in symtab.
if (!DR)
continue;
+ if (!includeInSymtab<ELFT>(*B))
+ continue;
StringRef SymName(StrTab + B->getNameOffset());
InputSectionBase<ELFT> *Sec = DR->Section;
if (!shouldKeepInSymtab<ELFT>(Sec, SymName, *B))
continue;
- if (Sec) {
- if (!Sec->Live)
- continue;
-
- // Garbage collection is normally able to remove local symbols if they
- // point to gced sections. In the case of SHF_MERGE sections, we want it
- // to also be able to drop them if part of the section is gced.
- // We could look at the section offset map to keep some of these
- // symbols, but almost all local symbols are .L* symbols, so it
- // is probably not worth the complexity.
- if (Config->GcSections && isa<MergeInputSection<ELFT>>(Sec))
- continue;
- }
++Out<ELFT>::SymTab->NumLocals;
if (Config->Relocatable)
B->DynsymIndex = Out<ELFT>::SymTab->NumLocals;
@@ -1114,7 +1105,7 @@ template <class ELFT> void Writer<ELFT>:
}
template <class ELFT> static bool includeInSymtab(const SymbolBody &B) {
- if (!B.symbol()->IsUsedInRegularObj)
+ if (!B.isLocal() && !B.symbol()->IsUsedInRegularObj)
return false;
if (auto *D = dyn_cast<DefinedRegular<ELFT>>(&B)) {
Modified: lld/trunk/test/ELF/string-gc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/string-gc.s?rev=268644&r1=268643&r2=268644&view=diff
==============================================================================
--- lld/trunk/test/ELF/string-gc.s (original)
+++ lld/trunk/test/ELF/string-gc.s Thu May 5 11:38:46 2016
@@ -13,7 +13,16 @@
// CHECK-NEXT: Section: Undefined (0x0)
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: s1 (8)
+// CHECK-NEXT: Name: s3
+// CHECK-NEXT: Value: 0x10125
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Local (0x0)
+// CHECK-NEXT: Type: Object (0x1)
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: .rodata (0x1)
+// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: s1
// CHECK-NEXT: Value: 0x10120
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Local (0x0)
@@ -24,7 +33,7 @@
// CHECK-NEXT: Section: .rodata (0x1)
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
-// CHECK-NEXT: Name: _start (1)
+// CHECK-NEXT: Name: _start
// CHECK-NEXT: Value: 0x11000
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Global (0x1)
@@ -39,6 +48,7 @@
.type _start, at function
_start:
movl $s1, %eax
+movl $s3, %eax
.hidden s1
.type s1, at object
@@ -52,3 +62,12 @@ s1:
.globl s2
s2:
.asciz "efgh"
+
+.type s3, at object
+s3:
+.asciz "ijkl"
+
+.type s4, at object
+.globl s4
+s4:
+.asciz "mnop"
More information about the llvm-commits
mailing list