ELF: Preserve MustBeInDynSym for bitcode symbols.

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.

Differential Revision: http://reviews.llvm.org/D18780

llvm-svn: 265371
This commit is contained in:
Peter Collingbourne 2016-04-05 00:47:55 +00:00
parent fb7c764496
commit e8afa4971c
4 changed files with 33 additions and 1 deletions

View File

@ -112,6 +112,8 @@ template <class ELFT> void SymbolTable<ELFT>::addCombinedLtoObject() {
Sym->Body->setUsedInRegularObj();
if (!Sym->Body->isUndefined() && Body->isUndefined())
continue;
if (Sym->Body->MustBeInDynSym)
Body->MustBeInDynSym = true;
Sym->Body = Body;
}
ObjectFiles.emplace_back(Obj);

View File

@ -205,8 +205,10 @@ template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
// 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;

View File

@ -0,0 +1,3 @@
.globl foo
foo:
ret

View File

@ -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
}