1// REQUIRES: x86
2// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3
4// RUN: ld.lld %t.o -o %t
5// RUN: llvm-readobj --file-headers -S --section-data -l --symbols %t \
6// RUN:   | FileCheck %s --check-prefix=NOHDR
7
8// RUN: ld.lld -eh-frame-hdr -no-eh-frame-hdr %t.o -o %t
9// RUN: llvm-readobj --file-headers -S --section-data -l --symbols %t \
10// RUN:   | FileCheck %s --check-prefix=NOHDR
11
12// RUN: ld.lld --eh-frame-hdr %t.o -o %t
13// RUN: llvm-readobj --file-headers -S --section-data -l --symbols %t \
14// RUN:   | FileCheck %s --check-prefix=HDR
15// RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=HDRDISASM
16
17.section foo,"ax",@progbits
18.cfi_startproc
19 nop
20.cfi_endproc
21
22.section bar,"ax",@progbits
23.cfi_startproc
24 nop
25.cfi_endproc
26
27.section dah,"ax",@progbits
28.cfi_startproc
29 nop
30.cfi_endproc
31
32.text
33.globl _start
34_start:
35
36// NOHDR:       Sections [
37// NOHDR-NOT:    Name: .eh_frame_hdr
38// NOHDR:      ProgramHeaders [
39// NOHDR-NOT:   PT_GNU_EH_FRAME
40
41// HDRDISASM:      Disassembly of section foo:
42// HDRDISASM-EMPTY:
43// HDRDISASM-NEXT: <foo>:
44// HDRDISASM-NEXT:    2011e4: 90 nop
45// HDRDISASM-EMPTY:
46// HDRDISASM-NEXT: Disassembly of section bar:
47// HDRDISASM-EMPTY:
48// HDRDISASM-NEXT: <bar>:
49// HDRDISASM-NEXT:    2011e5: 90 nop
50// HDRDISASM-EMPTY:
51// HDRDISASM-NEXT: Disassembly of section dah:
52// HDRDISASM-EMPTY:
53// HDRDISASM-NEXT: <dah>:
54// HDRDISASM-NEXT:    2011e6: 90 nop
55
56// HDR:       Section {
57// HDR:         Index:
58// HDR:         Name: .eh_frame_hdr
59// HDR-NEXT:    Type: SHT_PROGBITS
60// HDR-NEXT:    Flags [
61// HDR-NEXT:      SHF_ALLOC
62// HDR-NEXT:    ]
63// HDR-NEXT:    Address: 0x200158
64// HDR-NEXT:    Offset: 0x158
65// HDR-NEXT:    Size: 36
66// HDR-NEXT:    Link: 0
67// HDR-NEXT:    Info: 0
68// HDR-NEXT:    AddressAlignment: 4
69// HDR-NEXT:    EntrySize: 0
70// HDR-NEXT:    SectionData (
71// HDR-NEXT:      0000: 011B033B 24000000 03000000 8C100000
72// HDR-NEXT:      0010: 40000000 8D100000 58000000 8E100000
73// HDR-NEXT:      0020: 70000000
74// HDR-NEXT:    )
75//              Header (always 4 bytes): 0x011B033B
76//                 24000000 = .eh_frame(0x200180) - .eh_frame_hdr(0x200158) - 4
77//                 03000000 = 3 = the number of FDE pointers in the table.
78//              Entry(1): 8C100000 40000000
79//                 480E0000 = 0x2011e4 - .eh_frame_hdr(0x200158) = 0x108C
80//                 40000000 = address of FDE(1) - .eh_frame_hdr(0x200158) =
81//                    = .eh_frame(0x200180) + 24 - 0x200158 = 0x40
82//              Entry(2): 8D100000 58000000
83//                 A90E0000 = 0x2011e5 - .eh_frame_hdr(0x200158) = 0x108D
84//                 58000000 = address of FDE(2) - .eh_frame_hdr(0x200158) =
85//                    = .eh_frame(0x200180) + 24 + 24 - 0x200158 = 0x58
86//              Entry(3): 8E100000 70000000
87//                 AA0E0000 = 0x2011e6 - .eh_frame_hdr(0x200158) = 0x108E
88//                 70000000 = address of FDE(3) - .eh_frame_hdr(0x200158) =
89//                    = .eh_frame(0x200180) + 24 + 24 + 24 - 0x200158 = 0x70
90// HDR-NEXT:  }
91// HDR-NEXT:  Section {
92// HDR-NEXT:    Index:
93// HDR-NEXT:    Name: .eh_frame
94// HDR-NEXT:    Type: SHT_PROGBITS
95// HDR-NEXT:    Flags [
96// HDR-NEXT:      SHF_ALLOC
97// HDR-NEXT:    ]
98// HDR-NEXT:    Address: 0x200180
99// HDR-NEXT:    Offset: 0x180
100// HDR-NEXT:    Size: 100
101// HDR-NEXT:    Link: 0
102// HDR-NEXT:    Info: 0
103// HDR-NEXT:    AddressAlignment: 8
104// HDR-NEXT:    EntrySize: 0
105// HDR-NEXT:    SectionData (
106// HDR-NEXT:      0000: 14000000 00000000 017A5200 01781001
107// HDR-NEXT:      0010: 1B0C0708 90010000 14000000 1C000000
108// HDR-NEXT:      0020: 44100000 01000000 00000000 00000000
109// HDR-NEXT:      0030: 14000000 34000000 2D100000 01000000
110// HDR-NEXT:      0040: 00000000 00000000 14000000 4C000000
111// HDR-NEXT:      0050: 16100000 01000000 00000000 00000000
112// HDR-NEXT:      0060: 00000000
113// HDR-NEXT:    )
114//            CIE: 14000000 00000000 017A5200 01781001 1B0C0708 90010000
115//            FDE(1): 14000000 1C000000 600E0000 01000000 00000000 00000000
116//                    address of data (starts with 0x600E0000) = 0x200180 + 0x0020 = 0x2001A0
117//                    The starting address to which this FDE applies = 0xE60 + 0x2001A0 = 0x201000
118//                    The number of bytes after the start address to which this FDE applies = 0x01000000 = 1
119//            FDE(2): 14000000 34000000 490E0000 01000000 00000000 00000000
120//                    address of data (starts with 0x490E0000) = 0x200180 + 0x0038 = 0x2001B8
121//                    The starting address to which this FDE applies = 0xE49 + 0x2001B8 = 0x201001
122//                    The number of bytes after the start address to which this FDE applies = 0x01000000 = 1
123//            FDE(3): 14000000 4C000000 320E0000 01000000 00000000 00000000
124//                    address of data (starts with 0x320E0000) = 0x200180 + 0x0050 = 0x2001D0
125//                    The starting address to which this FDE applies = 0xE5A + 0x2001D0 = 0x201002
126//                    The number of bytes after the start address to which this FDE applies = 0x01000000 = 1
127// HDR-NEXT:  }
128// HDR:     ProgramHeaders [
129// HDR:      ProgramHeader {
130// HDR:       Type: PT_GNU_EH_FRAME
131// HDR-NEXT:   Offset: 0x158
132// HDR-NEXT:   VirtualAddress: 0x200158
133// HDR-NEXT:   PhysicalAddress: 0x200158
134// HDR-NEXT:   FileSize: 36
135// HDR-NEXT:   MemSize: 36
136// HDR-NEXT:   Flags [
137// HDR-NEXT:     PF_R
138// HDR-NEXT:   ]
139// HDR-NEXT:   Alignment: 4
140// HDR-NEXT: }
141