2020-06-02 13:57:43 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
|
2020-08-09 00:24:08 +08:00
|
|
|
# RUN: split-file %s %t.dir
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.dir/main.s -o %t.o
|
2020-06-02 13:57:43 +08:00
|
|
|
# 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
|
|
|
|
|
|
|
|
## --no-allow-shlib-undefined errors because __real_foo is not defined.
|
|
|
|
# RUN: not ld.lld %t.o %t.so -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
|
2020-06-03 22:59:28 +08:00
|
|
|
# ERR: {{.*}}.so: undefined reference to __real_foo [--no-allow-shlib-undefined]
|
2020-06-02 13:57:43 +08:00
|
|
|
|
|
|
|
## --wrap=foo defines __real_foo.
|
|
|
|
# RUN: ld.lld %t.o %t.so --wrap=foo -o %t
|
|
|
|
# RUN: llvm-readelf --dyn-syms %t | FileCheck %s
|
|
|
|
|
|
|
|
## The reference __real_foo from %t.so causes foo to be exported.
|
2020-08-02 09:19:14 +08:00
|
|
|
## __wrap_foo is not used, thus not exported.
|
|
|
|
# CHECK: Symbol table '.dynsym' contains 3 entries:
|
2020-06-02 13:57:43 +08:00
|
|
|
# CHECK: NOTYPE LOCAL DEFAULT UND
|
|
|
|
# CHECK-NEXT: NOTYPE GLOBAL DEFAULT UND bar
|
|
|
|
# CHECK-NEXT: NOTYPE GLOBAL DEFAULT 6 foo
|
|
|
|
|
2020-08-09 00:24:08 +08:00
|
|
|
# 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
|
|
|
|
|
2020-08-09 09:17:38 +08:00
|
|
|
# DYNSYM: Symbol table '.dynsym' contains 2 entries:
|
2020-08-09 00:24:08 +08:00
|
|
|
# DYNSYM: NOTYPE LOCAL DEFAULT UND
|
|
|
|
# DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND __wrap_bar
|
|
|
|
|
|
|
|
# ASM: <_start>:
|
|
|
|
# ASM-NEXT: callq {{.*}} <__wrap_bar@plt>
|
|
|
|
|
|
|
|
#--- main.s
|
2020-06-02 13:57:43 +08:00
|
|
|
.globl _start, foo
|
|
|
|
_start:
|
|
|
|
call bar
|
|
|
|
foo:
|
2020-08-09 00:24:08 +08:00
|
|
|
|
|
|
|
#--- wrap.s
|
|
|
|
.globl __wrap_bar
|
|
|
|
__wrap_bar:
|
|
|
|
retq
|