diff --git a/lld/test/ELF/symver.s b/lld/test/ELF/symver.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/symver.s @@ -0,0 +1,145 @@ +# REQUIRES: x86 +# RUN: split-file %s %t +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/ref.s -o %t/ref.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/ref1.s -o %t/ref1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/ref1p.s -o %t/ref1p.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/def1.s -o %t/def1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/def1w.s -o %t/def1w.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/hid1.s -o %t/hid1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/hid1w.s -o %t/hid1w.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/def2.s -o %t/def2.o +# RUN: llvm-mc -filetype=obj -triple=x86_64 %t/wrap.s -o %t/wrap.o +# RUN: ld.lld -shared --soname=def1.so --version-script=%t/ver %t/def1.o -o %t/def1.so +# RUN: ld.lld -shared --soname=hid1.so --version-script=%t/ver %t/hid1.o -o %t/hid1.so + +# TODO Report an duplicate definition error for foo@v1 and foo@@v1. +# RUN: ld.lld -shared --version-script=%t/ver %t/def1.o %t/hid1.o -o /dev/null + +# RUN: ld.lld -shared --version-script=%t/ver %t/def1w.o %t/hid1.o -o /dev/null +# RUN: ld.lld -shared --version-script=%t/ver %t/def1.o %t/hid1w.o -o /dev/null +# RUN: ld.lld -shared --version-script=%t/ver %t/def1w.o %t/hid1w.o -o /dev/null + +# TODO foo@@v1 should resolve undefined foo@v1. +# RUN: not ld.lld -shared --version-script=%t/ver %t/ref1p.o %t/def1.o -o /dev/null + +## TODO +## foo@@v1 resolves both undefined foo and foo@v1. There is one single definition. +## Note, set soname so that the name string referenced by .gnu.version_d is fixed. +# RUN: ld.lld -shared --soname=t1 --version-script=%t/ver %t/ref.o %t/ref1.o %t/def1.o -o %t1 +# RUN: llvm-readelf -r --dyn-syms %t1 | FileCheck %s + +# CHECK: Relocation section '.rela.plt' at offset {{.*}} contains 2 entries: +# CHECK-NEXT: {{.*}} Type {{.*}} +# CHECK-NEXT: {{.*}} R_X86_64_JUMP_SLOT {{.*}} foo@@v1 + 0 +# CHECK-NEXT: {{.*}} R_X86_64_JUMP_SLOT {{.*}} foo + 0 + +# CHECK: 1: {{.*}} NOTYPE GLOBAL DEFAULT UND foo{{$}} +# CHECK-NEXT: 2: {{.*}} NOTYPE GLOBAL DEFAULT {{[1-9]}} foo@@v1 +# CHECK-EMPTY: + +## foo@@v2 does not resolve undefined foo@v1. +## TODO Undefined 'foo@v1' should be errored. +# RUN: ld.lld -shared --soname=t2 --version-script=%t/ver %t/ref.o %t/ref1.o %t/def2.o -o %t2 +# RUN: llvm-readelf --dyn-syms %t2 | FileCheck %s --check-prefix=CHECK2 + +# CHECK2: 1: {{.*}} NOTYPE GLOBAL DEFAULT UND foo{{$}} +# CHECK2-NEXT: 2: {{.*}} NOTYPE GLOBAL DEFAULT {{[1-9]}} foo@@v2 +# CHECK2-EMPTY: + +## foo@@v2 resolves undefined foo while foo@v1 resolves undefined foo@v1. +# RUN: ld.lld -shared --soname=t3 --version-script=%t/ver %t/ref.o %t/ref1.o %t/hid1.o %t/def2.o -o %t3 +# RUN: llvm-readelf -r --dyn-syms %t3 | FileCheck %s --check-prefix=CHECK3 +# RUN: llvm-objdump -d --no-show-raw-insn %t3 | FileCheck %s --check-prefix=DIS3 + +# CHECK3: 00000000000034b8 {{.*}} R_X86_64_JUMP_SLOT {{.*}} foo@@v2 + 0 +# CHECK3-NEXT: 00000000000034c0 {{.*}} R_X86_64_JUMP_SLOT {{.*}} foo@v1 + 0 + +# CHECK3: 1: {{.*}} NOTYPE GLOBAL DEFAULT {{[1-9]}} foo@@v2 +# CHECK3-NEXT: 2: {{.*}} NOTYPE GLOBAL DEFAULT {{[1-9]}} foo@v1 +# CHECK3-NEXT: 3: {{.*}} NOTYPE GLOBAL DEFAULT {{[1-9]}} foo_v1 +# CHECK3-EMPTY: + +# DIS3-LABEL: <.text>: +# DIS3-NEXT: callq 0x1390 +# DIS3-COUNT-3: int3 +# DIS3-NEXT: callq 0x13a0 +# DIS3-LABEL: : +# DIS3-NEXT: jmpq *{{.*}}(%rip) # 34b8 +# DIS3-LABEL: : +# DIS3-NEXT: jmpq *{{.*}}(%rip) # 34c0 + +## Then, test versioned definitions in shared objects. + +## TODO Both foo and foo@v1 are undefined. Ideally we should not create two .dynsym entries. +# RUN: ld.lld -shared --soname=t4 --version-script=%t/ver %t/ref.o %t/ref1.o %t/def1.so -o %t4 +# RUN: llvm-readelf --dyn-syms %t4 | FileCheck %s --check-prefix=CHECK4 + +# CHECK4: 1: {{.*}} NOTYPE GLOBAL DEFAULT UND foo@v1 +# CHECK4-NEXT: 2: {{.*}} NOTYPE GLOBAL DEFAULT UND foo@v1 +# CHECK4-EMPTY: + +## hid1.so resolves undefined foo@v1. foo is undefined. +# RUN: ld.lld -shared --soname=t5 --version-script=%t/ver %t/ref.o %t/ref1.o %t/hid1.so -o %t5 +# RUN: llvm-readelf --dyn-syms %t5 | FileCheck %s --check-prefix=CHECK5 + +# CHECK5: 1: {{.*}} NOTYPE GLOBAL DEFAULT UND foo{{$}} +# CHECK5-NEXT: 2: {{.*}} NOTYPE GLOBAL DEFAULT UND foo@v1 +# CHECK5-EMPTY: + +## Unversioned foo is redirected. foo@v1 is not. +# RUN: ld.lld -shared --soname=t6 --version-script=%t/ver --wrap=foo %t/ref.o %t/ref1.o %t/def1.so %t/wrap.o -o %t6 +# RUN: llvm-objdump -d --no-show-raw-insn %t6 | FileCheck %s --check-prefix=DIS6 + +# DIS6-LABEL: <.text>: +# DIS6-NEXT: callq {{.*}} <__wrap_foo@plt> +# DIS6-COUNT-3: int3 +# DIS6-NEXT: callq {{.*}} + +#--- ver +v1 {}; +v2 {}; + +#--- ref.s +call foo + +#--- ref1.s +.symver foo, foo@@@v1 +call foo + +#--- ref1p.s +.protected foo +.symver foo, foo@@@v1 +call foo + +#--- def1.s +.globl foo +.symver foo, foo@@@v1 +foo: + +#--- def1w.s +.weak foo +.symver foo, foo@@@v1 +foo: + +#--- hid1.s +.globl foo_v1 +.symver foo_v1, foo@v1 +foo_v1: + ret + +#--- hid1w.s +.weak foo_v1 +.symver foo_v1, foo@v1 +foo_v1: + ret + +#--- def2.s +.globl foo +.symver foo, foo@@@v2 +foo: + ret + +#--- wrap.s +.globl __wrap_foo +__wrap_foo: + nop