|
| 1 | +# REQUIRES: x86 |
| 2 | +## Verify that we can correctly wrap symbols produced only during LTO codegen |
| 3 | +## and unreferenced before then. |
| 4 | + |
| 5 | +# RUN: rm -rf %t && split-file %s %t |
| 6 | +# RUN: llvm-mc -triple x86_64-elf --filetype=obj -o %t/unwind.o %t/unwind.s |
| 7 | +# RUN: ld.lld -shared -o %t/libunwind.so -soname libunwind.so %t/unwind.o |
| 8 | +# RUN: llvm-as -o %t/resume.bc %t/resume.ll |
| 9 | +# RUN: ld.lld -shared -o %t/libresume.so -soname libresume.so %t/resume.bc \ |
| 10 | +# RUN: %t/libunwind.so --wrap _Unwind_Resume |
| 11 | +# RUN: llvm-objdump --dynamic-reloc --disassemble %t/libresume.so | \ |
| 12 | +# RUN: FileCheck --check-prefix=UNWIND-DISASM %s |
| 13 | +# RUN: llvm-readelf --dyn-syms %t/libresume.so | \ |
| 14 | +# RUN: FileCheck --check-prefix=UNWIND-DYNSYM %s |
| 15 | + |
| 16 | +# UNWIND-DISASM: [[#%x,RELOC:]] R_X86_64_JUMP_SLOT __wrap__Unwind_Resume |
| 17 | +# UNWIND-DISASM-LABEL: <_Z1fv>: |
| 18 | +# UNWIND-DISASM: callq {{.*}}<__wrap__Unwind_Resume@plt> |
| 19 | +# UNWIND-DISASM-LABEL: <__wrap__Unwind_Resume@plt>: |
| 20 | +# UNWIND-DISASM-NEXT: jmpq *[[#]](%rip) # [[#%#x,RELOC]] |
| 21 | + |
| 22 | +# UNWIND-DYNSYM: Symbol table '.dynsym' contains 5 entries: |
| 23 | +# UNWIND-DYNSYM: NOTYPE LOCAL DEFAULT UND |
| 24 | +# UNWIND-DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND throw |
| 25 | +# UNWIND-DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND _Unwind_Resume |
| 26 | +# UNWIND-DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND __wrap__Unwind_Resume |
| 27 | +# UNWIND-DYNSYM-NEXT: FUNC GLOBAL DEFAULT 9 _Z1fv |
| 28 | + |
| 29 | +# RUN: llvm-mc -triple x86_64-elf -filetype=obj -o %t/malloc.o %t/malloc.s |
| 30 | +# RUN: ld.lld -shared -o %t/libmalloc.so -soname libmalloc.so %t/malloc.o |
| 31 | +# RUN: llvm-mc -triple x86_64-elf -filetype=obj -o %t/emutls.o %t/emutls.s |
| 32 | +# RUN: llvm-as -o %t/usetls.bc %t/usetls.ll |
| 33 | +# RUN: ld.lld -shared -o %t/libusetls.so %t/usetls.bc %t/libmalloc.so \ |
| 34 | +# RUN: --start-lib %t/emutls.o -mllvm -emulated-tls --wrap malloc |
| 35 | +# RUN: llvm-objdump --dynamic-reloc --disassemble %t/libusetls.so | \ |
| 36 | +# RUN: FileCheck --check-prefix=USETLS-DISASM %s |
| 37 | +# RUN: llvm-readelf --dyn-syms %t/libusetls.so | \ |
| 38 | +# RUN: FileCheck --check-prefix=USETLS-DYNSYM %s |
| 39 | + |
| 40 | +# USETLS-DISASM: [[#%x,RELOC:]] R_X86_64_JUMP_SLOT __wrap_malloc |
| 41 | +# USETLS-DISASM-LABEL: <__emutls_get_address>: |
| 42 | +# USETLS-DISASM-NEXT: jmp{{.*}}<__wrap_malloc@plt> |
| 43 | +# USETLS-DISASM-LABEL: <__wrap_malloc@plt>: |
| 44 | +# USETLS-DISASM-NEXT: jmpq *[[#]](%rip) # [[#%#x,RELOC]] |
| 45 | + |
| 46 | +# USETLS-DYNSYM: Symbol table '.dynsym' contains 6 entries: |
| 47 | +# USETLS-DYNSYM: NOTYPE LOCAL DEFAULT UND |
| 48 | +# USETLS-DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND malloc |
| 49 | +# USETLS-DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT UND __wrap_malloc |
| 50 | +# USETLS-DYNSYM-NEXT: FUNC GLOBAL DEFAULT 6 f |
| 51 | +# USETLS-DYNSYM-NEXT: NOTYPE GLOBAL DEFAULT 6 __emutls_get_address |
| 52 | + |
| 53 | +#--- unwind.s |
| 54 | +.globl _Unwind_Resume |
| 55 | +.globl __wrap__Unwind_Resume |
| 56 | +_Unwind_Resume: |
| 57 | +__wrap__Unwind_Resume: |
| 58 | + retq |
| 59 | + |
| 60 | +#--- resume.ll |
| 61 | +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" |
| 62 | +target triple = "x86_64-unknown-linux-gnu" |
| 63 | +define dso_local void @_Z1fv() optnone noinline personality i8* bitcast (void ()* @throw to i8*) { |
| 64 | + invoke void @throw() |
| 65 | + to label %unreachable unwind label %lpad |
| 66 | +lpad: |
| 67 | + %1 = landingpad { i8*, i32 } |
| 68 | + cleanup |
| 69 | + resume { i8*, i32 } %1 |
| 70 | +unreachable: |
| 71 | + unreachable |
| 72 | +} |
| 73 | +declare void @throw() |
| 74 | + |
| 75 | +#--- malloc.s |
| 76 | +.globl malloc |
| 77 | +malloc: |
| 78 | + retq |
| 79 | + |
| 80 | +#--- emutls.s |
| 81 | +.globl __emutls_get_address |
| 82 | +__emutls_get_address: |
| 83 | + jmp malloc@plt |
| 84 | + |
| 85 | +#--- usetls.ll |
| 86 | +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" |
| 87 | +target triple = "x86_64-unknown-linux-gnu" |
| 88 | +@x = dso_local thread_local global i32 0, align 4 |
| 89 | +define dso_local i32 @f() { |
| 90 | + %loaded = load i32, ptr @x, align 4 |
| 91 | + ret i32 %loaded |
| 92 | +} |
0 commit comments