mirror of
https://github.com/intel/llvm.git
synced 2026-02-06 15:18:53 +08:00
Don't copy STT_SECTION from the inputs.
This matches the behavior of gold and bfd ld. llvm-svn: 249326
This commit is contained in:
@@ -407,7 +407,12 @@ bool lld::elf2::includeInDynamicSymtab(const SymbolBody &B) {
|
||||
return B.isUsedInDynamicReloc();
|
||||
}
|
||||
|
||||
bool lld::elf2::shouldKeepInSymtab(StringRef SymName) {
|
||||
template <class ELFT>
|
||||
bool lld::elf2::shouldKeepInSymtab(StringRef SymName,
|
||||
const typename ELFFile<ELFT>::Elf_Sym &Sym) {
|
||||
if (Sym.getType() == STT_SECTION)
|
||||
return false;
|
||||
|
||||
if (Config->DiscardNone)
|
||||
return true;
|
||||
|
||||
@@ -451,7 +456,7 @@ void SymbolTableSection<ELFT>::writeLocalSymbols(uint8_t *&Buf) {
|
||||
Elf_Sym_Range Syms = File.getLocalSymbols();
|
||||
for (const Elf_Sym &Sym : Syms) {
|
||||
ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());
|
||||
if (SymName && !shouldKeepInSymtab(*SymName))
|
||||
if (SymName && !shouldKeepInSymtab<ELFT>(*SymName, Sym))
|
||||
continue;
|
||||
auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
|
||||
Buf += sizeof(*ESym);
|
||||
@@ -630,5 +635,14 @@ template bool includeInSymtab<ELF32LE>(const SymbolBody &);
|
||||
template bool includeInSymtab<ELF32BE>(const SymbolBody &);
|
||||
template bool includeInSymtab<ELF64LE>(const SymbolBody &);
|
||||
template bool includeInSymtab<ELF64BE>(const SymbolBody &);
|
||||
|
||||
template bool shouldKeepInSymtab<ELF32LE>(StringRef,
|
||||
const ELFFile<ELF32LE>::Elf_Sym &);
|
||||
template bool shouldKeepInSymtab<ELF32BE>(StringRef,
|
||||
const ELFFile<ELF32BE>::Elf_Sym &);
|
||||
template bool shouldKeepInSymtab<ELF64LE>(StringRef,
|
||||
const ELFFile<ELF64LE>::Elf_Sym &);
|
||||
template bool shouldKeepInSymtab<ELF64BE>(StringRef,
|
||||
const ELFFile<ELF64BE>::Elf_Sym &);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,10 @@ getLocalSymVA(const typename llvm::object::ELFFile<ELFT>::Elf_Sym *Sym,
|
||||
template <class ELFT> bool includeInSymtab(const SymbolBody &B);
|
||||
|
||||
bool includeInDynamicSymtab(const SymbolBody &B);
|
||||
bool shouldKeepInSymtab(StringRef SymName);
|
||||
|
||||
template <class ELFT>
|
||||
bool shouldKeepInSymtab(
|
||||
StringRef Name, const typename llvm::object::ELFFile<ELFT>::Elf_Sym &Sym);
|
||||
|
||||
// This represents a section in an output file.
|
||||
// Different sub classes represent different types of sections. Some contain
|
||||
|
||||
@@ -293,7 +293,7 @@ template <class ELFT> void Writer<ELFT>::createSections() {
|
||||
Elf_Sym_Range Syms = File.getLocalSymbols();
|
||||
for (const Elf_Sym &Sym : Syms) {
|
||||
ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());
|
||||
if (SymName && shouldKeepInSymtab(*SymName))
|
||||
if (SymName && shouldKeepInSymtab<ELFT>(*SymName, Sym))
|
||||
SymTabSec.addSymbol(*SymName, true);
|
||||
}
|
||||
}
|
||||
|
||||
29
lld/test/elf2/section-symbol.s
Normal file
29
lld/test/elf2/section-symbol.s
Normal file
@@ -0,0 +1,29 @@
|
||||
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
|
||||
// RUN: ld.lld2 %t -o %t.so -shared -discard-none
|
||||
// RUN: llvm-readobj -t %t.so | FileCheck %s
|
||||
|
||||
// Test that we don't include the section symbols from the .o in the .so
|
||||
|
||||
// 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: Symbol {
|
||||
// CHECK-NEXT: Name: foo
|
||||
// CHECK-NEXT: Value:
|
||||
// CHECK-NEXT: Size: 0
|
||||
// CHECK-NEXT: Binding: Local
|
||||
// CHECK-NEXT: Type: None
|
||||
// CHECK-NEXT: Other: 0
|
||||
// CHECK-NEXT: Section: .text
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: ]
|
||||
|
||||
foo:
|
||||
.quad foo
|
||||
Reference in New Issue
Block a user