Index: lld/trunk/ELF/Symbols.cpp =================================================================== --- lld/trunk/ELF/Symbols.cpp +++ lld/trunk/ELF/Symbols.cpp @@ -53,6 +53,13 @@ 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>(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)) Index: lld/trunk/test/ELF/Inputs/symbol-override.s =================================================================== --- lld/trunk/test/ELF/Inputs/symbol-override.s +++ lld/trunk/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 Index: lld/trunk/test/ELF/mips-dynamic.s =================================================================== --- lld/trunk/test/ELF/mips-dynamic.s +++ lld/trunk/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: ] Index: lld/trunk/test/ELF/symbol-override.s =================================================================== --- lld/trunk/test/ELF/symbol-override.s +++ lld/trunk/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