diff options
| -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 |

