Commit 1fc8b507 authored by Rafael Espindola's avatar Rafael Espindola
Browse files

Port r292146.

Give priority to linker scripts over preemption.

LLD exports symbols that are also present in used shared libraries to
make sure they are preempted at runtime. That is a reasonable default,
but we must allow for it to be overwritten with linker script. If we
don't, libraries that expect to be able to hide a c++ delete operator
will fail.

This should fix the firebird build.

llvm-svn: 292370
parent 72cd787e
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -426,12 +426,8 @@ void SymbolTable<ELFT>::addShared(SharedFile<ELFT> *F, StringRef Name,
  std::tie(S, WasInserted) =
      insert(Name, Sym.getType(), STV_DEFAULT, /*CanOmitFromDynSym*/ true, F);
  // Make sure we preempt DSO symbols with default visibility.
  if (Sym.getVisibility() == STV_DEFAULT) {
  if (Sym.getVisibility() == STV_DEFAULT)
    S->ExportDynamic = true;
    // Exporting preempting symbols takes precedence over linker scripts.
    if (S->VersionId == VER_NDX_LOCAL)
      S->VersionId = VER_NDX_GLOBAL;
  }
  if (WasInserted || isa<Undefined<ELFT>>(S->body())) {
    replaceBody<SharedSymbol<ELFT>>(S, F, Name, Sym, Verdef);
    if (!S->isWeak())
+2 −1
Original line number Diff line number Diff line
@@ -299,7 +299,8 @@ uint8_t Symbol::computeBinding() const {
    return Binding;
  if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
    return STB_LOCAL;
  if (VersionId == VER_NDX_LOCAL && !body()->isUndefined())
  const SymbolBody *Body = body();
  if (VersionId == VER_NDX_LOCAL && !Body->isUndefined() && !Body->isShared())
    return STB_LOCAL;
  if (Config->NoGnuUnique && Binding == STB_GNU_UNIQUE)
    return STB_GLOBAL;
+0 −9
Original line number Diff line number Diff line
@@ -19,15 +19,6 @@
# CHECK-NEXT:     Section: Undefined (0x0)
# CHECK-NEXT:   }
# CHECK-NEXT:   Symbol {
# CHECK-NEXT:     Name: bar
# CHECK-NEXT:     Value:
# CHECK-NEXT:     Size:
# CHECK-NEXT:     Binding: Global
# CHECK-NEXT:     Type:
# CHECK-NEXT:     Other:
# CHECK-NEXT:     Section: .text
# CHECK-NEXT:   }
# CHECK-NEXT:   Symbol {
# CHECK-NEXT:     Name: bar2
# CHECK-NEXT:     Value:
# CHECK-NEXT:     Size:
+28 −0
Original line number Diff line number Diff line
# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld -shared %t.o -o %t2.so
# RUN: echo "{ local: *; };" > %t.script
# RUN: ld.lld --version-script %t.script -shared %t.o %t2.so -o %t.so
# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck %s

# The symbol foo must be hidden. This matches bfd and gold and is
# required to make it possible for a c++ library to hide its own
# operator delete.

# CHECK:      DynamicSymbols [
# 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: ]

        .global foo
foo:
	nop