xref: /llvm-project/lld/test/MachO/eh-frame-sdata4.s (revision 6c9f6812523a706c11a12e6cb4119b0cf67bbb21)
1# REQUIRES: x86
2# RUN: rm -rf %t; split-file %s %t
3
4## Test that we correctly handle the sdata4 DWARF pointer encoding. llvm-mc's
5## CFI directives always generate EH frames using the absptr (i.e. system
6## pointer size) encoding, but it is possible to hand-roll your own EH frames
7## that use the sdata4 encoding. For instance, libffi does this.
8
9# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos10.15 %t/sdata4.s -o %t/sdata4.o
10# RUN: %lld -lSystem %t/sdata4.o -o %t/sdata4
11# RUN: llvm-objdump --macho --syms --dwarf=frames %t/sdata4 | FileCheck %s
12
13# CHECK: SYMBOL TABLE:
14# CHECK: [[#%.16x,MAIN:]] g     F __TEXT,__text _main
15
16# CHECK: .eh_frame contents:
17# CHECK: 00000000 00000010 00000000 CIE
18# CHECK:   Format:                DWARF32
19# CHECK:   Version:               1
20# CHECK:   Augmentation:          "zR"
21# CHECK:   Code alignment factor: 1
22# CHECK:   Data alignment factor: 1
23# CHECK:   Return address column: 1
24# CHECK:   Augmentation data:     1B
25# CHECK:   DW_CFA_def_cfa: reg7 +8
26# CHECK:   CFA=reg7+8
27
28# CHECK: 00000014 00000010 00000018 FDE cie=00000000 pc=[[#%x,MAIN]]...[[#%x,MAIN+1]]
29# CHECK:   Format:       DWARF32
30# CHECK:   DW_CFA_GNU_args_size: +16
31# CHECK:   DW_CFA_nop:
32# CHECK:   0x[[#%x,MAIN]]: CFA=reg7+8
33
34#--- sdata4.s
35.globl  _main
36_main:
37  retq
38LmainEnd:
39
40.balign 4
41.section __TEXT,__eh_frame
42# Although we don't reference this EhFrame symbol directly, we must have at
43# least one non-local symbol in this section, otherwise llvm-mc generates bogus
44# subtractor relocations.
45EhFrame:
46LCieHdr:
47  .long LCieEnd - LCieStart
48LCieStart:
49  .long 0           # CIE ID
50  .byte 1           # CIE version
51  .ascii "zR\0"
52  .byte 1           # Code alignment
53  .byte 1           # Data alignment
54  .byte 1           # RA column
55  .byte 1           # Augmentation size
56  .byte 0x1b        # FDE pointer encoding (pcrel | sdata4)
57  .byte 0xc, 7, 8   # DW_CFA_def_cfa reg7 +8
58  .balign 4
59LCieEnd:
60
61LFdeHdr:
62  .long LFdeEnd - LFdeStart
63LFdeStart:
64  .long LFdeStart - LCieHdr
65  # The next two fields are longs instead of quads because of the sdata4
66  # encoding.
67  .long _main - .        # Function address
68  .long LmainEnd - _main # Function length
69  .byte 0
70  ## Insert DW_CFA_GNU_args_size to prevent ld64 from creating a compact unwind
71  ## entry to replace this FDE. Makes it easier for us to cross-check behavior
72  ## across the two linkers (LLD never bothers trying to synthesize compact
73  ## unwind if it is not already present).
74  .byte 0x2e, 0x10       # DW_CFA_GNU_args_size
75  .balign 4
76LFdeEnd:
77
78  .long 0 # terminator
79
80.subsections_via_symbols
81