xref: /llvm-project/lld/test/MachO/eh-frame.s (revision e60b30d5e3878e7d91f8872ec4c4dca00d4a2dfc)
1# REQUIRES: x86, aarch64
2# RUN: rm -rf %t; mkdir %t
3
4# RUN: llvm-mc -emit-compact-unwind-non-canonical=true -filetype=obj -triple=x86_64-apple-macos10.15 %s -o %t/eh-frame-x86_64.o
5# RUN: %lld -lSystem -lc++ %t/eh-frame-x86_64.o -o %t/eh-frame-x86_64
6# RUN: llvm-objdump --macho --syms --indirect-symbols --unwind-info \
7# RUN:   --dwarf=frames %t/eh-frame-x86_64 | FileCheck %s -D#BASE=0x100000000 -D#DWARF_ENC=4
8# RUN: llvm-nm -m %t/eh-frame-x86_64 | FileCheck %s --check-prefix NO-EH-SYMS
9# RUN: llvm-readobj --section-headers %t/eh-frame-x86_64 | FileCheck %s --check-prefix=ALIGN -D#ALIGN=3
10
11## Test that we correctly handle the output of `ld -r`, which emits EH frames
12## using subtractor relocations instead of implicitly encoding the offsets.
13## In order to keep this test cross-platform, we check in ld64's output rather
14## than invoking ld64 directly. NOTE: whenever this test is updated, the
15## checked-in copy of `ld -r`'s output should be updated too!
16# COM: ld -r %t/eh-frame-x86_64.o -o %S/Inputs/eh-frame-x86_64-r.o
17# RUN: %lld -lSystem -lc++ %S/Inputs/eh-frame-x86_64-r.o -o %t/eh-frame-x86_64-r
18# RUN: llvm-objdump --macho --syms --indirect-symbols --unwind-info \
19# RUN:   --dwarf=frames %t/eh-frame-x86_64-r | FileCheck %s -D#BASE=0x100000000 -D#DWARF_ENC=4
20# RUN: llvm-nm -m %t/eh-frame-x86_64-r | FileCheck %s --check-prefix NO-EH-SYMS
21# RUN: llvm-readobj --section-headers %t/eh-frame-x86_64-r | FileCheck %s --check-prefix=ALIGN -D#ALIGN=3
22
23# RUN: llvm-mc -filetype=obj -emit-compact-unwind-non-canonical=true -triple=arm64-apple-macos11.0 %s -o %t/eh-frame-arm64.o
24# RUN: %lld -arch arm64 -lSystem -lc++ %t/eh-frame-arm64.o -o %t/eh-frame-arm64
25# RUN: llvm-objdump --macho --syms --indirect-symbols --unwind-info \
26# RUN:   --dwarf=frames %t/eh-frame-arm64 | FileCheck %s -D#BASE=0x100000000 -D#DWARF_ENC=3
27# RUN: llvm-nm -m %t/eh-frame-arm64 | FileCheck %s --check-prefix NO-EH-SYMS
28
29# COM: ld -r %t/eh-frame-arm64.o -o %S/Inputs/eh-frame-arm64-r.o
30# RUN: %lld -arch arm64 -lSystem -lc++ %S/Inputs/eh-frame-arm64-r.o -o %t/eh-frame-arm64-r
31# RUN: llvm-objdump --macho --syms --indirect-symbols --unwind-info \
32# RUN:   --dwarf=frames %t/eh-frame-arm64-r | FileCheck %s -D#BASE=0x100000000 -D#DWARF_ENC=3
33# RUN: llvm-nm -m %t/eh-frame-arm64-r | FileCheck %s --check-prefix NO-EH-SYMS
34
35# ALIGN:      Name: __eh_frame
36# ALIGN-NEXT: Segment: __TEXT
37# ALIGN-NEXT: Address:
38# ALIGN-NEXT: Size:
39# ALIGN-NEXT: Offset:
40# ALIGN-NEXT: Alignment: [[#ALIGN]]
41
42# NO-EH-SYMS-NOT: __eh_frame
43
44# CHECK: Indirect symbols for (__DATA_CONST,__got) 2 entries
45# CHECK: address                         index  name
46# CHECK: 0x[[#%x,GXX_PERSONALITY_GOT:]]  {{.*}}  ___gxx_personality_v0
47# CHECK: 0x[[#%x,MY_PERSONALITY_GOT:]]
48# CHECK: SYMBOL TABLE:
49# CHECK-DAG: [[#%x,F:]]              l   F __TEXT,__text _f
50# CHECK-DAG: [[#%x,NO_UNWIND:]]      l   F __TEXT,__text _no_unwind
51# CHECK-DAG: [[#%x,G:]]              l   F __TEXT,__text _g
52# CHECK-DAG: [[#%x,H:]]              l   F __TEXT,__text _h
53# CHECK-DAG: [[#%x,EXCEPT0:]]        l   O __TEXT,__gcc_except_tab GCC_except_table0
54# CHECK-DAG: [[#%x,EXCEPT1:]]        l   O __TEXT,__gcc_except_tab GCC_except_table1
55# CHECK-DAG: [[#%x,EXCEPT2:]]        l   O __TEXT,custom_except custom_except_table2
56# CHECK-DAG: [[#%x,MY_PERSONALITY:]] g   F __TEXT,__text _my_personality
57# CHECK: Contents of __unwind_info section:
58# CHECK:   Version:                                   0x1
59# CHECK:   Number of personality functions in array:  0x1
60# CHECK:   Number of indices in array:                0x2
61# CHECK:   Personality functions: (count = 1)
62# CHECK:     personality[1]: 0x[[#%.8x,GXX_PERSONALITY_GOT - BASE]]
63# CHECK:   LSDA descriptors:
64# CHECK:     [0]: function offset=0x[[#%.8x,F - BASE]], LSDA offset=0x[[#%.8x,EXCEPT0 - BASE]]
65# CHECK:     [1]: function offset=0x[[#%.8x,G - BASE]], LSDA offset=0x[[#%.8x,EXCEPT1 - BASE]]
66# CHECK:     [2]: function offset=0x[[#%.8x,H - BASE]], LSDA offset=0x[[#%.8x,EXCEPT2 - BASE]]
67# CHECK:   Second level indices:
68# CHECK:     Second level index[0]:
69# CHECK       [0]: function offset=0x[[#%.8x,F - BASE]],              encoding[{{.*}}]=0x52{{.*}}
70# CHECK       [1]: function offset=0x[[#%.8x,NO_UNWIND - BASE]],      encoding[{{.*}}]=0x00000000
71# CHECK:      [2]: function offset=0x[[#%.8x,G - BASE]],              encoding[{{.*}}]=0x0[[#%x,DWARF_ENC]][[#%.6x, G_DWARF_OFF:]]
72# CHECK:      [3]: function offset=0x[[#%.8x,H - BASE]],              encoding[{{.*}}]=0x0[[#%x,DWARF_ENC]][[#%.6x, H_DWARF_OFF:]]
73# CHECK:      [4]: function offset=0x[[#%.8x,MY_PERSONALITY - BASE]], encoding[{{.*}}]=0x00000000
74
75# CHECK: .debug_frame contents:
76# CHECK: .eh_frame contents:
77
78# CHECK: [[#%.8x,CIE1_OFF:]] {{.*}} CIE
79# CHECK:   Format:                DWARF32
80# CHECK:   Version:               1
81# CHECK:   Augmentation:          "zPLR"
82# CHECK:   Code alignment factor: 1
83# CHECK:   Data alignment factor: -8
84# CHECK:   Return address column:
85# CHECK:   Personality Address:   [[#%.16x,GXX_PERSONALITY_GOT]]
86# CHECK:   Augmentation data:     9B {{(([[:xdigit:]]{2} ){4})}}10 10
87
88# CHECK: [[#%.8x,G_DWARF_OFF]] {{.*}} [[#%.8x,G_DWARF_OFF + 4 - CIE1_OFF]] FDE cie=[[#CIE1_OFF]] pc=[[#%x,G]]
89# CHECK:   Format:       DWARF32
90# CHECK:   LSDA Address: [[#%.16x,EXCEPT1]]
91# CHECK:   DW_CFA_def_cfa_offset: +8
92# CHECK:   0x[[#%x,G]]:
93
94# CHECK: [[#%.8x,CIE2_OFF:]] {{.*}} CIE
95# CHECK:   Format:                DWARF32
96# CHECK:   Version:               1
97# CHECK:   Augmentation:          "zPLR"
98# CHECK:   Code alignment factor: 1
99# CHECK:   Data alignment factor: -8
100# CHECK:   Return address column:
101# CHECK:   Personality Address:   [[#%.16x,MY_PERSONALITY_GOT]]
102# CHECK:   Augmentation data:     9B {{(([[:xdigit:]]{2} ){4})}}10 10
103
104# CHECK: [[#%.8x,H_DWARF_OFF]] {{.*}} [[#%.8x,H_DWARF_OFF + 4 - CIE2_OFF]] FDE cie=[[#CIE2_OFF]] pc=[[#%x,H]]
105# CHECK:   Format:       DWARF32
106# CHECK:   LSDA Address: [[#%.16x,EXCEPT2]]
107# CHECK:   DW_CFA_def_cfa_offset: +8
108# CHECK:   0x[[#%x,H]]:
109
110.globl _my_personality, _main
111
112.text
113## _f's unwind info can be encoded with compact unwind, so we shouldn't see an
114## FDE entry for it in the output file.
115.p2align 2
116_f:
117  .cfi_startproc
118  .cfi_personality 155, ___gxx_personality_v0
119  .cfi_lsda 16, Lexception0
120  .cfi_def_cfa_offset 8
121  ret
122  .cfi_endproc
123
124.p2align 2
125_no_unwind:
126  ret
127
128.p2align 2
129_g:
130  .cfi_startproc
131  .cfi_personality 155, ___gxx_personality_v0
132  .cfi_lsda 16, Lexception1
133  .cfi_def_cfa_offset 8
134  ## cfi_escape cannot be encoded in compact unwind, so we must keep _g's FDE
135  .cfi_escape 0x2e, 0x10
136  ret
137  .cfi_endproc
138
139.p2align 2
140_h:
141  .cfi_startproc
142  .cfi_personality 155, _my_personality
143  .cfi_lsda 16, Lexception2
144  .cfi_def_cfa_offset 8
145  ## cfi_escape cannot be encoded in compact unwind, so we must keep _h's FDE
146  .cfi_escape 0x2e, 0x10
147  ret
148  .cfi_endproc
149
150.p2align 2
151_my_personality:
152  ret
153
154.p2align 2
155_main:
156  ret
157
158.section __TEXT,__gcc_except_tab
159GCC_except_table0:
160Lexception0:
161  .byte 255
162
163GCC_except_table1:
164Lexception1:
165  .byte 255
166
167.section __TEXT,custom_except
168custom_except_table2:
169Lexception2:
170  .byte 255
171
172.subsections_via_symbols
173