[ELF] - Symbols from object files that override symbols in DSO are added to .dynsym table.

Main executable did not export symbols that exist both in the main executable and in DSOs before this patch.
Symbols from object files that override symbols in DSO should be added to .dynsym table.

Differential revision: http://reviews.llvm.org/D16405

llvm-svn: 258672
This commit is contained in:
George Rimar 2016-01-25 08:44:38 +00:00
parent 72b7223ae6
commit 02ca17906d
4 changed files with 71 additions and 2 deletions

View File

@ -53,6 +53,13 @@ template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
if (IsUsedInRegularObj || Other->IsUsedInRegularObj)
IsUsedInRegularObj = Other->IsUsedInRegularObj = true;
// We want to export all symbols that exist both in the executable
// 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))
IsUsedInDynamicReloc = Other->IsUsedInDynamicReloc = true;
if (L != R)
return -1;
if (!std::get<0>(L) || !std::get<1>(L) || !std::get<2>(L))

View File

@ -0,0 +1,16 @@
.text
.globl foo
.type foo,@function
foo:
nop
.globl bar
.type bar,@function
bar:
nop
.globl do
.type do,@function
do:
callq foo@PLT
callq bar@PLT

View File

@ -47,8 +47,8 @@
# EXE-DAG: 0x70000005 MIPS_FLAGS NOTPOT
# EXE-DAG: 0x70000006 MIPS_BASE_ADDRESS
# EXE-DAG: 0x7000000A MIPS_LOCAL_GOTNO 2
# EXE-DAG: 0x70000011 MIPS_SYMTABNO 1
# EXE-DAG: 0x70000013 MIPS_GOTSYM 0x1
# EXE-DAG: 0x70000011 MIPS_SYMTABNO 2
# EXE-DAG: 0x70000013 MIPS_GOTSYM 0x2
# EXE-DAG: 0x70000016 MIPS_RLD_MAP [[RLDMAPADDR]]
# EXE: ]

View File

@ -0,0 +1,46 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/symbol-override.s -o %t2.o
// RUN: ld.lld -shared %t2.o -o %t2.so
// RUN: ld.lld %t1.o %t2.so -o %t
// RUN: llvm-readobj -dyn-symbols %t | FileCheck %s
// CHECK: DynamicSymbols [
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name:
// 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: do
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Function
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: Undefined
// CHECK-NEXT: }
// CHECK-NEXT: Symbol {
// CHECK-NEXT: Name: foo
// CHECK-NEXT: Value: 0x11000
// CHECK-NEXT: Size: 0
// CHECK-NEXT: Binding: Global
// CHECK-NEXT: Type: Function
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text
// CHECK-NEXT: }
// CHECK-NEXT: ]
.text
.globl foo
.type foo,@function
foo:
nop
.text
.globl _start
_start:
callq do