llvm-project/lld/test/ELF/wrap-weak.s
Alexander Qi 1b3e376ec0
[lld][ELF] --wrap: Make X weak when __real_X is to avoid undefined symbol errors (#98297)
Fix #98294.

When you specify --wrap=foo, sometimes foo is undefined in any context.
If you declare __real_foo as weak, GNU ld will not attempt to find the
strong symbol foo, instead, it generates a weak undefined symbol.

This pull request imitates this behavior by copying the binding
attribute from __real_foo to foo.
2024-07-10 18:38:52 -07:00

24 lines
584 B
ArmAsm

# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
# RUN: ld.lld -shared -o %t.so %t.o -wrap foo
# RUN: llvm-readelf --dyn-syms %t.so | FileCheck %s
# CHECK: Symbol table '.dynsym' contains 4 entries:
# CHECK: NOTYPE LOCAL DEFAULT UND
# CHECK-NEXT: NOTYPE WEAK DEFAULT UND foo
# CHECK-NEXT: NOTYPE GLOBAL DEFAULT [[#]] __wrap_foo
# CHECK-NEXT: NOTYPE GLOBAL DEFAULT [[#]] _start
.global foo
.weak __real_foo
.global __wrap_foo
__wrap_foo:
movq __real_foo@gotpcrel(%rip), %rax
call __real_foo@plt
.global _start
_start:
call foo@plt