forked from OSchip/llvm-project
Discard local symbols from SHF_MERGE sections.
This matches the behavior of both gold and bfd ld. llvm-svn: 255355
This commit is contained in:
parent
d7634fc91d
commit
a6763e8386
|
@ -1168,15 +1168,26 @@ bool lld::elf2::shouldKeepInSymtab(const ObjectFile<ELFT> &File,
|
||||||
if (Sym.getType() == STT_SECTION)
|
if (Sym.getType() == STT_SECTION)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
InputSectionBase<ELFT> *Sec = File.getSection(Sym);
|
||||||
// If sym references a section in a discarded group, don't keep it.
|
// If sym references a section in a discarded group, don't keep it.
|
||||||
if (File.getSection(Sym) == &InputSection<ELFT>::Discarded)
|
if (Sec == &InputSection<ELFT>::Discarded)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Config->DiscardNone)
|
if (Config->DiscardNone)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// ELF defines dynamic locals as symbols which name starts with ".L".
|
// In ELF assembly .L symbols are normally discarded by the assembler.
|
||||||
return !(Config->DiscardLocals && SymName.startswith(".L"));
|
// If the assembler fails to do so, the linker discards them if
|
||||||
|
// * --discard-locals is used.
|
||||||
|
// * The symbol is in a SHF_MERGE section, which is normally the reason for
|
||||||
|
// the assembler keeping the .L symbol.
|
||||||
|
if (!SymName.startswith(".L"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (Config->DiscardLocals)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return !(Sec->getSectionHdr()->sh_flags & SHF_MERGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
|
||||||
|
// RUN: ld.lld %t -o %t2 -shared
|
||||||
|
// RUN: llvm-readobj -t %t2 | FileCheck %s
|
||||||
|
// REQUIRES: x86
|
||||||
|
|
||||||
|
leaq .L.str(%rip), %rdi
|
||||||
|
|
||||||
|
.section .rodata.str1.1,"aMS",@progbits,1
|
||||||
|
.L.str:
|
||||||
|
.asciz "foobar"
|
||||||
|
|
||||||
|
// Test that the .L symbol is omitted
|
||||||
|
|
||||||
|
// CHECK: Symbols [
|
||||||
|
// CHECK-NEXT: Symbol {
|
||||||
|
// CHECK-NEXT: Name: (0)
|
||||||
|
// CHECK-NEXT: Value: 0x0
|
||||||
|
// CHECK-NEXT: Size: 0
|
||||||
|
// CHECK-NEXT: Binding: Local
|
||||||
|
// CHECK-NEXT: Type: None
|
||||||
|
// CHECK-NEXT: Other: 0
|
||||||
|
// CHECK-NEXT: Section: Undefined
|
||||||
|
// CHECK-NEXT: }
|
||||||
|
// CHECK-NEXT: ]
|
Loading…
Reference in New Issue