2020-06-02 13:57:43 +08:00
|
|
|
# REQUIRES: x86
|
|
|
|
|
2021-01-20 13:05:16 +08:00
|
|
|
# RUN: rm -rf %t && split-file %s %t
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/main.s -o %t/main.o
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/call-foo.s -o %t/call-foo.o
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/bar.s -o %t/bar.o
|
|
|
|
# RUN: ld.lld -shared -soname=t.so %t/bar.o -o %t/bar.so
|
|
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/wrap.s -o %t/wrap.o
|
|
|
|
# RUN: ld.lld -shared --soname=fixed %t/wrap.o -o %t/wrap.so
|
|
|
|
|
2021-01-20 13:23:57 +08:00
|
|
|
## foo is defined, then referenced in another object file.
|
2021-01-20 13:05:16 +08:00
|
|
|
# RUN: ld.lld -shared %t/main.o %t/call-foo.o --wrap foo -o %t1.so
|
|
|
|
# RUN: llvm-readelf -r %t1.so | FileCheck %s --check-prefix=CHECK1
|
|
|
|
|
|
|
|
# CHECK1: R_X86_64_JUMP_SLOT 0000000000000000 bar + 0
|
2021-01-20 13:23:57 +08:00
|
|
|
# CHECK1-NEXT: R_X86_64_JUMP_SLOT 0000000000000000 __wrap_foo + 0
|
2020-06-02 13:57:43 +08:00
|
|
|
|
|
|
|
## --no-allow-shlib-undefined errors because __real_foo is not defined.
|
2021-01-20 13:05:16 +08:00
|
|
|
# RUN: not ld.lld %t/main.o %t/bar.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.
|
2021-01-20 13:05:16 +08:00
|
|
|
# RUN: ld.lld %t/main.o %t/bar.so --wrap=foo -o %t2
|
|
|
|
# RUN: llvm-readelf --dyn-syms %t2 | FileCheck %s --check-prefix=CHECK2
|
2020-06-02 13:57:43 +08:00
|
|
|
|
2021-01-20 13:05:16 +08:00
|
|
|
## The reference __real_foo from %t/bar.so causes foo to be exported.
|
2020-08-02 09:19:14 +08:00
|
|
|
## __wrap_foo is not used, thus not exported.
|
2021-01-20 13:05:16 +08:00
|
|
|
# CHECK2: Symbol table '.dynsym' contains 3 entries:
|
|
|
|
# CHECK2: NOTYPE LOCAL DEFAULT UND
|
|
|
|
# CHECK2-NEXT: NOTYPE GLOBAL DEFAULT UND bar
|
|
|
|
# CHECK2-NEXT: NOTYPE GLOBAL DEFAULT 6 foo
|
|
|
|
|
|
|
|
## __wrap_bar is undefined.
|
2021-01-20 19:43:27 +08:00
|
|
|
# RUN: ld.lld -shared %t/main.o --wrap=bar -o %t3.so
|
2021-01-20 13:05:16 +08:00
|
|
|
# RUN: llvm-readelf -r --dyn-syms %t3.so | FileCheck %s --check-prefix=CHECK3
|
2021-01-20 13:23:57 +08:00
|
|
|
# CHECK3: R_X86_64_JUMP_SLOT 0000000000000000 __wrap_bar + 0
|
|
|
|
# CHECK3: Symbol table '.dynsym' contains 4 entries:
|
2021-01-20 13:05:16 +08:00
|
|
|
# CHECK3: NOTYPE LOCAL DEFAULT UND
|
2021-01-20 13:23:57 +08:00
|
|
|
# CHECK3-NEXT: NOTYPE GLOBAL DEFAULT UND __wrap_bar
|
2021-01-20 13:05:16 +08:00
|
|
|
# CHECK3-NEXT: NOTYPE GLOBAL DEFAULT 6 _start
|
|
|
|
# CHECK3-NEXT: NOTYPE GLOBAL DEFAULT 6 foo
|
|
|
|
|
|
|
|
## __wrap_bar is defined in %t/wrap.so.
|
2021-01-20 19:43:27 +08:00
|
|
|
# RUN: ld.lld -shared %t/main.o %t/wrap.so --wrap=bar -o %t4.so
|
2021-01-20 13:05:16 +08:00
|
|
|
# RUN: llvm-readelf -r --dyn-syms %t4.so | FileCheck %s --check-prefix=CHECK4
|
|
|
|
# CHECK4: R_X86_64_JUMP_SLOT {{.*}} __wrap_bar + 0
|
|
|
|
# CHECK4: Symbol table '.dynsym' contains 4 entries:
|
|
|
|
# CHECK4: NOTYPE LOCAL DEFAULT UND
|
|
|
|
# CHECK4-NEXT: NOTYPE GLOBAL DEFAULT UND __wrap_bar
|
|
|
|
# CHECK4-NEXT: NOTYPE GLOBAL DEFAULT 6 _start
|
|
|
|
# CHECK4-NEXT: NOTYPE GLOBAL DEFAULT 6 foo
|
|
|
|
|
2021-01-20 19:43:27 +08:00
|
|
|
# RUN: ld.lld %t/main.o %t/wrap.so --wrap bar -o %t1
|
2020-08-09 00:24:08 +08:00
|
|
|
# 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
|
|
|
|
2021-01-20 13:05:16 +08:00
|
|
|
#--- call-foo.s
|
|
|
|
call foo
|
|
|
|
|
|
|
|
#--- bar.s
|
|
|
|
.globl bar
|
|
|
|
bar:
|
|
|
|
call __real_foo
|
|
|
|
|
2020-08-09 00:24:08 +08:00
|
|
|
#--- wrap.s
|
|
|
|
.globl __wrap_bar
|
|
|
|
__wrap_bar:
|
|
|
|
retq
|