[ELF] --wrap: set isUsedInRegularObj of __wrap_ if it is defined or shared

Fixes PR47017 (a regression when fixing PR46169): if __wrap_ is shared,
it is not exported.
This commit is contained in:
Fangrui Song 2020-08-08 09:24:08 -07:00
parent f22ac1d15b
commit 99cd56906a
2 changed files with 24 additions and 2 deletions

View File

@ -1862,7 +1862,7 @@ static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &args) {
// Tell LTO not to eliminate these symbols.
sym->isUsedInRegularObj = true;
if (wrap->isDefined())
if (!wrap->isUndefined())
wrap->isUsedInRegularObj = true;
}
return v;

View File

@ -1,6 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
# RUN: split-file %s %t.dir
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/main.s -o %t.o
# RUN: echo '.globl bar; bar: call __real_foo' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
# RUN: ld.lld -shared -soname=t.so %t1.o -o %t.so
@ -19,7 +20,28 @@
# CHECK-NEXT: NOTYPE GLOBAL DEFAULT UND bar
# CHECK-NEXT: NOTYPE GLOBAL DEFAULT 6 foo
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/wrap.s -o %twrap.o
# RUN: ld.lld -shared --soname=fixed %twrap.o -o %twrap.so
# RUN: ld.lld %t.o %twrap.so --wrap bar -o %t1
# RUN: llvm-readelf --dyn-syms %t1 | FileCheck %s --check-prefix=DYNSYM
# RUN: llvm-objdump -d %t1 | FileCheck %s --check-prefix=ASM
## FIXME GNU ld does not export bar
# DYNSYM: Symbol table '.dynsym' contains 3 entries:
# DYNSYM: NOTYPE LOCAL DEFAULT UND
# DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND bar
# DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND __wrap_bar
# ASM: <_start>:
# ASM-NEXT: callq {{.*}} <__wrap_bar@plt>
#--- main.s
.globl _start, foo
_start:
call bar
foo:
#--- wrap.s
.globl __wrap_bar
__wrap_bar:
retq