llvm-project
184 строки · 8.2 Кб
1# REQUIRES: x86, aarch64
2# RUN: rm -rf %t; split-file %s %t
3# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 -emit-compact-unwind-non-canonical=true %t/my-personality.s -o %t/x86_64-my-personality.o
4# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 -emit-compact-unwind-non-canonical=true %t/main.s -o %t/x86_64-main.o
5# RUN: %lld -arch x86_64 -lSystem -lc++ %t/x86_64-my-personality.o %t/x86_64-main.o -o %t/x86_64-personality-first
6# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/x86_64-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK -D#%x,BASE=0x100000000 -DSEG=__TEXT
7# RUN: %lld -dead_strip -arch x86_64 -lSystem -lc++ %t/x86_64-main.o %t/x86_64-my-personality.o -o %t/x86_64-personality-second
8# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/x86_64-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK -D#%x,BASE=0x100000000 -DSEG=__TEXT
9
10# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin19.0.0 -emit-compact-unwind-non-canonical=true %t/my-personality.s -o %t/arm64-my-personality.o
11# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin19.0.0 -emit-compact-unwind-non-canonical=true %t/main.s -o %t/arm64-main.o
12# RUN: %lld -arch arm64 -lSystem -lc++ %t/arm64-my-personality.o %t/arm64-main.o -o %t/arm64-personality-first
13# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK -D#%x,BASE=0x100000000 -DSEG=__TEXT
14# RUN: %lld -dead_strip -arch arm64 -lSystem -lc++ %t/arm64-main.o %t/arm64-my-personality.o -o %t/arm64-personality-second
15# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK -D#%x,BASE=0x100000000 -DSEG=__TEXT
16
17# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos -emit-compact-unwind-non-canonical=true %t/my-personality.s -o %t/arm64-32-my-personality.o
18# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-watchos -emit-compact-unwind-non-canonical=true %t/main.s -o %t/arm64-32-main.o
19# RUN: %lld-watchos -lSystem -lc++ %t/arm64-32-my-personality.o %t/arm64-32-main.o -o %t/arm64-32-personality-first
20# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-32-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK -D#%x,BASE=0x4000 -DSEG=__TEXT
21# RUN: %lld-watchos -dead_strip -lSystem -lc++ %t/arm64-32-main.o %t/arm64-32-my-personality.o -o %t/arm64-32-personality-second
22# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/arm64-32-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK -D#%x,BASE=0x4000 -DSEG=__TEXT
23
24# RUN: %lld -arch x86_64 -rename_section __TEXT __gcc_except_tab __RODATA __gcc_except_tab -lSystem -lc++ %t/x86_64-my-personality.o %t/x86_64-main.o -o %t/x86_64-personality-first
25# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/x86_64-personality-first | FileCheck %s --check-prefixes=FIRST,CHECK -D#%x,BASE=0x100000000 -DSEG=__RODATA
26# RUN: %lld -dead_strip -arch x86_64 -rename_section __TEXT __gcc_except_tab __RODATA __gcc_except_tab -lSystem -lc++ %t/x86_64-main.o %t/x86_64-my-personality.o -o %t/x86_64-personality-second
27# RUN: llvm-objdump --macho --unwind-info --syms --indirect-symbols --rebase %t/x86_64-personality-second | FileCheck %s --check-prefixes=SECOND,CHECK -D#%x,BASE=0x100000000 -DSEG=__RODATA
28
29# FIRST: Indirect symbols for (__DATA_CONST,__got)
30# FIRST-NEXT: address index name
31# FIRST-DAG: 0x[[#%x,GXX_PERSONALITY:]] [[#]] ___gxx_personality_v0
32# FIRST-DAG: 0x[[#%x,MY_PERSONALITY:]] LOCAL
33
34# SECOND: Indirect symbols for (__DATA_CONST,__got)
35# SECOND-NEXT: address index name
36# SECOND-DAG: 0x[[#%x,GXX_PERSONALITY:]] [[#]] ___gxx_personality_v0
37# SECOND-DAG: 0x[[#%x,MY_PERSONALITY:]] LOCAL
38
39# CHECK: SYMBOL TABLE:
40# CHECK-DAG: [[#%x,MAIN:]] g F __TEXT,__text _main
41# CHECK-DAG: [[#%x,QUUX:]] g F __TEXT,__text _quux
42# CHECK-DAG: [[#%x,FOO:]] l F __TEXT,__text _foo
43# CHECK-DAG: [[#%x,BAZ:]] l F __TEXT,__text _baz
44# CHECK-DAG: [[#%x,EXCEPTION0:]] g O [[SEG]],__gcc_except_tab _exception0
45# CHECK-DAG: [[#%x,EXCEPTION1:]] g O [[SEG]],__gcc_except_tab _exception1
46
47# CHECK: Contents of __unwind_info section:
48# CHECK: Personality functions: (count = 2)
49# CHECK-DAG: personality[{{[0-9]+}}]: 0x{{0*}}[[#MY_PERSONALITY-BASE]]
50# CHECK-DAG: personality[{{[0-9]+}}]: 0x{{0*}}[[#GXX_PERSONALITY-BASE]]
51# CHECK: Top level indices: (count = 2)
52# CHECK-DAG: [0]: function offset={{.*}}, 2nd level page offset=0x[[#%x,PAGEOFF:]],
53# CHECK-DAG: [1]: function offset={{.*}}, 2nd level page offset=0x00000000,
54# CHECK: LSDA descriptors:
55# CHECK-DAG: function offset=0x[[#%.8x,FOO-BASE]], LSDA offset=0x[[#%.8x,EXCEPTION0-BASE]]
56# CHECK-DAG: function offset=0x[[#%.8x,MAIN-BASE]], LSDA offset=0x[[#%.8x,EXCEPTION1-BASE]]
57# CHECK: Second level indices:
58# CHECK-NEXT: Second level index[0]: offset in section=0x[[#%.8x,PAGEOFF]]
59# CHECK-DAG: function offset=0x[[#%.8x,MAIN-BASE]], encoding
60# CHECK-DAG: function offset=0x[[#%.8x,FOO-BASE]], encoding
61# CHECK-DAG: function offset=0x[[#%.8x,BAZ-BASE]], encoding
62# CHECK-DAG: function offset=0x[[#%.8x,QUUX-BASE]], encoding{{.*}}=0x00000000
63
64## Check that we do not add rebase opcodes to the compact unwind section.
65# CHECK: Rebase table:
66# CHECK-NEXT: segment section address type
67# CHECK-NEXT: __DATA_CONST __got 0x{{[0-9A-F]*}} pointer
68# CHECK-NOT: __TEXT
69
70## Check that we don't create an __unwind_info section if no unwind info
71## remains after dead-stripping.
72# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 \
73# RUN: %t/empty-after-dead-strip.s -o %t/x86_64-empty-after-dead-strip.o
74# RUN: %lld -dylib -dead_strip -arch x86_64 -lSystem \
75# RUN: %t/x86_64-empty-after-dead-strip.o -o %t/x86_64-empty-after-strip.dylib
76# RUN: llvm-objdump --macho --unwind-info %t/x86_64-empty-after-strip.dylib | \
77# RUN: FileCheck %s --check-prefixes=NOUNWIND --allow-empty
78# NOUNWIND-NOT: Contents of __unwind_info section:
79
80#--- my-personality.s
81.globl _my_personality, _exception0
82.text
83.p2align 2
84.no_dead_strip _foo
85_foo:
86.cfi_startproc
87## This will generate a section relocation.
88.cfi_personality 155, _my_personality
89.cfi_lsda 16, _exception0
90.cfi_def_cfa_offset 16
91ret
92.cfi_endproc
93
94.p2align 2
95.no_dead_strip _bar
96_bar:
97.cfi_startproc
98## Check that we dedup references to the same statically-linked personality.
99.cfi_personality 155, _my_personality
100.cfi_lsda 16, _exception0
101.cfi_def_cfa_offset 16
102ret
103.cfi_endproc
104
105.data
106.p2align 2
107## We put this personality in `__data` to test if we correctly handle
108## personality symbols whose output addresses occur after that of the
109## `__unwind_info` section.
110_my_personality:
111ret
112
113.section __TEXT,__gcc_except_tab
114_exception0:
115.space 1
116
117.subsections_via_symbols
118
119#--- main.s
120.globl _main, _quux, _my_personality, _exception1
121
122.text
123.p2align 2
124_main:
125.cfi_startproc
126.cfi_personality 155, ___gxx_personality_v0
127.cfi_lsda 16, _exception1
128.cfi_def_cfa_offset 16
129ret
130.cfi_endproc
131
132## _quux has no unwind information.
133## (In real life, it'd be part of a separate TU that was built with
134## -fno-exceptions, while the previous and next TU might be Objective-C++
135## which has unwind info for Objective-C).
136.p2align 2
137.no_dead_strip _quux
138_quux:
139ret
140
141.globl _abs
142.no_dead_strip _abs
143_abs = 4
144
145.p2align 2
146.no_dead_strip _baz
147_baz:
148.cfi_startproc
149## This will generate a symbol relocation. Check that we reuse the personality
150## referenced by the section relocation in my_personality.s.
151.cfi_personality 155, _my_personality
152.cfi_lsda 16, _exception1
153.cfi_def_cfa_offset 16
154ret
155.cfi_endproc
156
157.globl _stripped
158_stripped:
159.cfi_startproc
160.cfi_personality 155, ___gxx_personality_v0
161.cfi_lsda 16, _exception1
162.cfi_def_cfa_offset 16
163ret
164.cfi_endproc
165
166
167.section __TEXT,__gcc_except_tab
168_exception1:
169.space 1
170
171.subsections_via_symbols
172
173#--- empty-after-dead-strip.s
174.text
175
176## Local symbol with unwind info.
177## The symbol is removed by -dead_strip.
178_foo :
179.cfi_startproc
180.cfi_def_cfa_offset 16
181retq
182.cfi_endproc
183
184.subsections_via_symbols
185