xref: /llvm-project/lld/test/ELF/eh-frame-negative-pcrel-sdata4.s (revision b2559f2f5ca950e917253b156bfd08ede5577cd5)
1# REQUIRES: x86
2
3# Test handling of FDE pc negative relative addressing with DW_EH_PE_sdata4.
4# This situation can arise when .eh_frame is placed after .text.
5
6# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
7# RUN: echo "SECTIONS { .text : { *(.text) } .eh_frame : { *(.eh_frame) } }" > %t.script
8# RUN: ld.lld --eh-frame-hdr --script %t.script --section-start .text=0x1000 %t.o -o %t
9# RUN: llvm-readobj -S --section-data %t | FileCheck %s
10
11# CHECK:      Section {
12# CHECK:        Index:
13# CHECK:        Name: .eh_frame
14# CHECK-NEXT:   Type: SHT_PROGBITS
15# CHECK-NEXT:   Flags [
16# CHECK-NEXT:     SHF_ALLOC
17# CHECK-NEXT:   ]
18# CHECK-NEXT:   Address: 0x1001
19# CHECK-NEXT:   Offset: 0x1001
20# CHECK-NEXT:   Size:
21# CHECK-NEXT:   Link:
22# CHECK-NEXT:   Info:
23# CHECK-NEXT:   AddressAlignment:
24# CHECK-NEXT:   EntrySize:
25# CHECK-NEXT:   SectionData (
26# CHECK-NEXT:     0000: 10000000 00000000 017A5200 01010101
27# CHECK-NEXT:     0010: 1B000000 0C000000 18000000 E3FFFFFF
28# CHECK-NEXT:     0020: 00000000 00000000
29
30# CHECK:      Section {
31# CHECK:        Index:
32# CHECK:        Name: .eh_frame_hdr
33# CHECK-NEXT:   Type: SHT_PROGBITS
34# CHECK-NEXT:   Flags [
35# CHECK-NEXT:     SHF_ALLOC
36# CHECK-NEXT:   ]
37# CHECK-NEXT:   Address: 0x102C
38# CHECK-NEXT:   Offset: 0x102C
39# CHECK-NEXT:   Size: 20
40# CHECK-NEXT:   Link: 0
41# CHECK-NEXT:   Info: 0
42# CHECK-NEXT:   AddressAlignment: 4
43# CHECK-NEXT:   EntrySize: 0
44# CHECK-NEXT:   SectionData (
45# CHECK-NEXT:     0000: 011B033B D1FFFFFF 01000000 D4FFFFFF
46# CHECK-NEXT:     0010: E9FFFFFF
47#   Header (always 4 bytes): 011B033B
48#   D1FFFFFF = .eh_frame(0x1001) - .eh_frame_hdr(0x102C) - 4
49#   01000000 = 1 = the number of FDE pointers in the table.
50#   D4FFFFFF = _start(0x1000) - .eh_frame_hdr(0x102C)
51#   E9FFFFFF = FDE(.eh_frame(0x1001) + 0x18) - .eh_frame_hdr(0x102C)
52
53.text
54.global _start
55_start:
56 nop
57
58.section .eh_frame,"a",@unwind
59  .long 16   # Size
60  .long 0x00 # ID
61  .byte 0x01 # Version.
62
63  .byte 0x7A # Augmentation string: "zR"
64  .byte 0x52
65  .byte 0x00
66
67  .byte 0x01
68
69  .byte 0x01 # LEB128
70  .byte 0x01 # LEB128
71
72  .byte 0x01 # LEB128
73  .byte 0x1B # DW_EH_PE_pcrel | DW_EH_PE_sdata4
74
75  .byte 0x00
76  .byte 0x00
77  .byte 0x00
78
79  .long 12   # Size
80  .long 24   # ID
81fde:
82  .long _start - fde
83  .long 0
84