ELF: Always include undefined DSO symbols in the symbol table.

Fixes check-llvm when bootstrapping.

Also remove mostly dead and most likely incorrect logic regarding preemption
of weak undefined symbols.

llvm-svn: 267314
This commit is contained in:
Peter Collingbourne 2016-04-24 02:31:02 +00:00
parent 0da2076ba1
commit d869a040ee
2 changed files with 41 additions and 7 deletions

View File

@ -123,13 +123,9 @@ bool SymbolBody::isPreemptible() const {
if (!Config->Shared)
return false;
// Undefined symbols in DSOs can only be preempted if they are strong.
// Weak symbols just resolve to zero.
if (isUndefined())
return !isWeak();
// -Bsymbolic means that not even default visibility symbols can be preempted.
if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc()))
if ((Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc())) &&
isDefined())
return false;
// Only default visibility symbols that appear in the dynamic symbol table can
@ -323,7 +319,8 @@ std::string elf::demangle(StringRef Name) {
bool Symbol::includeInDynsym() const {
if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
return false;
return (ExportDynamic && VersionScriptGlobal) || Body->isShared();
return (ExportDynamic && VersionScriptGlobal) || Body->isShared() ||
Body->isUndefined();
}
template uint32_t SymbolBody::template getVA<ELF32LE>(uint32_t) const;

View File

@ -0,0 +1,37 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: echo "{ local: *; };" > %t.script
# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so
# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s
# CHECK: DynamicSymbols [
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: @ (0)
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Binding: Local (0x0)
# CHECK-NEXT: Type: None (0x0)
# CHECK-NEXT: Other: 0
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: bar@ (1)
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Binding: Weak (0x2)
# CHECK-NEXT: Type: None (0x0)
# CHECK-NEXT: Other: 0
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: foo@ (5)
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Binding: Global (0x1)
# CHECK-NEXT: Type: None (0x0)
# CHECK-NEXT: Other: 0
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: }
# CHECK-NEXT: ]
.global foo
.weak bar