diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-01-25 08:44:38 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-01-25 08:44:38 +0000 |
commit | 02ca17906d51a1766c21482123e0d412240d4f21 (patch) | |
tree | 0d09eff54de73c0fc4d358894be9b6db904b25d4 | |
parent | 72b7223ae61191fc146e50c0a019bae39e2ca593 (diff) | |
download | bcm5719-llvm-02ca17906d51a1766c21482123e0d412240d4f21.tar.gz bcm5719-llvm-02ca17906d51a1766c21482123e0d412240d4f21.zip |
[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
-rw-r--r-- | lld/ELF/Symbols.cpp | 7 | ||||
-rw-r--r-- | lld/test/ELF/Inputs/symbol-override.s | 16 | ||||
-rw-r--r-- | lld/test/ELF/mips-dynamic.s | 4 | ||||
-rw-r--r-- | lld/test/ELF/symbol-override.s | 46 |
4 files changed, 71 insertions, 2 deletions
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index bc0db8aa575..ad6423f5e93 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -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)) diff --git a/lld/test/ELF/Inputs/symbol-override.s b/lld/test/ELF/Inputs/symbol-override.s new file mode 100644 index 00000000000..21f3ae244c7 --- /dev/null +++ b/lld/test/ELF/Inputs/symbol-override.s @@ -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 diff --git a/lld/test/ELF/mips-dynamic.s b/lld/test/ELF/mips-dynamic.s index 148249e36f7..7dcc247e536 100644 --- a/lld/test/ELF/mips-dynamic.s +++ b/lld/test/ELF/mips-dynamic.s @@ -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: ] diff --git a/lld/test/ELF/symbol-override.s b/lld/test/ELF/symbol-override.s new file mode 100644 index 00000000000..ae2114914ab --- /dev/null +++ b/lld/test/ELF/symbol-override.s @@ -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 |