File: wrap-unreferenced-before-codegen.test

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (91 lines) | stat: -rw-r--r-- 3,509 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# REQUIRES: x86
## Verify that we can correctly wrap symbols produced only during LTO codegen
## and unreferenced before then.

# RUN: rm -rf %t && split-file %s %t
# RUN: llvm-mc -triple x86_64-elf --filetype=obj -o %t/unwind.o %t/unwind.s
# RUN: ld.lld -shared -o %t/libunwind.so -soname libunwind.so %t/unwind.o
# RUN: llvm-as -o %t/resume.bc %t/resume.ll
# RUN: ld.lld -shared -o %t/libresume.so -soname libresume.so %t/resume.bc \
# RUN:   %t/libunwind.so --wrap _Unwind_Resume
# RUN: llvm-objdump --no-print-imm-hex --dynamic-reloc --disassemble %t/libresume.so | \
# RUN:   FileCheck --check-prefix=UNWIND-DISASM %s
# RUN: llvm-readelf --dyn-syms %t/libresume.so | \
# RUN:   FileCheck --check-prefix=UNWIND-DYNSYM %s

# UNWIND-DISASM:       [[#%x,RELOC:]] R_X86_64_JUMP_SLOT __wrap__Unwind_Resume
# UNWIND-DISASM-LABEL: <_Z1fv>:
# UNWIND-DISASM:       callq {{.*}}<__wrap__Unwind_Resume@plt>
# UNWIND-DISASM-LABEL: <__wrap__Unwind_Resume@plt>:
# UNWIND-DISASM-NEXT:  jmpq *[[#]](%rip) # [[#%#x,RELOC]]

# UNWIND-DYNSYM:      Symbol table '.dynsym' contains 4 entries:
# UNWIND-DYNSYM:      NOTYPE  LOCAL  DEFAULT   UND
# UNWIND-DYNSYM-NEXT: NOTYPE  GLOBAL DEFAULT   UND throw
# UNWIND-DYNSYM-NEXT: NOTYPE  GLOBAL DEFAULT   UND __wrap__Unwind_Resume
# UNWIND-DYNSYM-NEXT: FUNC    GLOBAL DEFAULT     9 _Z1fv

# RUN: llvm-mc -triple x86_64-elf -filetype=obj -o %t/malloc.o %t/malloc.s
# RUN: ld.lld -shared -o %t/libmalloc.so -soname libmalloc.so %t/malloc.o
# RUN: llvm-mc -triple x86_64-elf -filetype=obj -o %t/emutls.o %t/emutls.s
# RUN: llvm-as -o %t/usetls.bc %t/usetls.ll
# RUN: ld.lld -shared -o %t/libusetls.so \
# RUN:   %t/usetls.bc %t/libmalloc.so \
# RUN:   --start-lib %t/emutls.o -mllvm -emulated-tls --wrap malloc
# RUN: llvm-objdump --no-print-imm-hex --dynamic-reloc --disassemble %t/libusetls.so | \
# RUN:   FileCheck --check-prefix=USETLS-DISASM %s
# RUN: llvm-readelf --dyn-syms %t/libusetls.so | \
# RUN:   FileCheck --check-prefix=USETLS-DYNSYM %s

# USETLS-DISASM:       [[#%x,RELOC:]] R_X86_64_JUMP_SLOT __wrap_malloc
# USETLS-DISASM-LABEL: <__emutls_get_address>:
# USETLS-DISASM-NEXT:  jmp{{.*}}<__wrap_malloc@plt>
# USETLS-DISASM-LABEL: <__wrap_malloc@plt>:
# USETLS-DISASM-NEXT:  jmpq *[[#]](%rip) # [[#%#x,RELOC]]

# USETLS-DYNSYM:      Symbol table '.dynsym' contains 5 entries:
# USETLS-DYNSYM:      NOTYPE  LOCAL  DEFAULT   UND
# USETLS-DYNSYM-NEXT: NOTYPE  GLOBAL DEFAULT   UND __wrap_malloc
# USETLS-DYNSYM-NEXT: FUNC    GLOBAL DEFAULT     6 f
# USETLS-DYNSYM-NEXT: NOTYPE  GLOBAL DEFAULT     6 __emutls_get_address

#--- unwind.s
.globl _Unwind_Resume
.globl __wrap__Unwind_Resume
_Unwind_Resume:
__wrap__Unwind_Resume:
	retq

#--- resume.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define dso_local void @_Z1fv() optnone noinline personality ptr @throw {
  invoke void @throw()
          to label %unreachable unwind label %lpad
lpad:
  %1 = landingpad { ptr, i32 }
          cleanup
  resume { ptr, i32 } %1
unreachable:
  unreachable
}
declare void @throw()

#--- malloc.s
.globl malloc
malloc:
	retq

#--- emutls.s
.globl __emutls_get_address
__emutls_get_address:
	jmp	malloc@plt

#--- usetls.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@x = dso_local thread_local global i32 0, align 4
define dso_local i32 @f() {
  %loaded = load i32, ptr @x, align 4
  ret i32 %loaded
}