[PATCH] D18780: ELF: Preserve MustBeInDynSym for bitcode symbols.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 4 17:43:05 PDT 2016


pcc created this revision.
pcc added reviewers: ruiu, rafael.
pcc added a subscriber: llvm-commits.
Herald added a subscriber: joker.eph.

Make sure to copy the MustBeInDynSym field when replacing shared symbols with
bitcode symbols, and when replacing bitcode symbols with regular symbols
in addCombinedLtoObject. Fixes interposition of DSO symbols with bitcode
symbols in the main executable.

http://reviews.llvm.org/D18780

Files:
  ELF/SymbolTable.cpp
  ELF/Symbols.cpp
  test/ELF/lto/Inputs/dynsym.s
  test/ELF/lto/dynsym.ll

Index: test/ELF/lto/dynsym.ll
===================================================================
--- /dev/null
+++ test/ELF/lto/dynsym.ll
@@ -0,0 +1,25 @@
+; REQUIRES: x86
+; RUN: llvm-mc -filetype=obj -o %t.o %p/Inputs/dynsym.s
+; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -shared
+; RUN: llvm-as %s -o %t2.o
+; RUN: ld.lld -m elf_x86_64 %t2.o %t.so -o %t
+; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @_start() {
+  call void @foo()
+  ret void
+}
+
+; CHECK:      Name: foo
+; CHECK-NEXT: Value:
+; CHECK-NEXT: Size:
+; CHECK-NEXT: Binding:
+; CHECK-NEXT: Type:
+; CHECK-NEXT: Other:
+; CHECK-NEXT: Section: .text
+define void @foo() {
+  ret void
+}
Index: test/ELF/lto/Inputs/dynsym.s
===================================================================
--- /dev/null
+++ test/ELF/lto/Inputs/dynsym.s
@@ -0,0 +1,3 @@
+.globl foo
+foo:
+ret
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -205,8 +205,10 @@
   // and in DSOs, so that the symbols in the executable can interrupt
   // symbols in the DSO at runtime.
   if (isShared() != Other->isShared())
-    if (isa<DefinedRegular<ELFT>>(isShared() ? Other : this))
+    if (isa<Defined>(isShared() ? Other : this)) {
+      IsUsedInRegularObj = Other->IsUsedInRegularObj = true;
       MustBeInDynSym = Other->MustBeInDynSym = true;
+    }
 
   if (L != R)
     return -1;
Index: ELF/SymbolTable.cpp
===================================================================
--- ELF/SymbolTable.cpp
+++ ELF/SymbolTable.cpp
@@ -112,6 +112,8 @@
     Sym->Body->setUsedInRegularObj();
     if (!Sym->Body->isUndefined() && Body->isUndefined())
       continue;
+    if (Sym->Body->MustBeInDynSym)
+      Body->MustBeInDynSym = true;
     Sym->Body = Body;
   }
   ObjectFiles.emplace_back(Obj);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18780.52646.patch
Type: text/x-patch
Size: 1954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160405/da5ca764/attachment.bin>


More information about the llvm-commits mailing list