xref: /llvm-project/llvm/test/tools/llvm-objdump/ELF/crel.test (revision 2f37a22f10a1128c695bc469871a9101edce853e)
1# RUN: yaml2obj --docnum=1 %s -o %t
2# RUN: llvm-objdump -r %t | FileCheck %s --strict-whitespace --match-full-lines
3
4#      CHECK:RELOCATION RECORDS FOR [.text]:
5# CHECK-NEXT:OFFSET           TYPE                     VALUE
6# CHECK-NEXT:0000000000000001 R_X86_64_32              g1+0x1
7# CHECK-NEXT:0000000000000002 R_X86_64_64              l1+0x2
8# CHECK-NEXT:0000000000000000 R_X86_64_32S             g1-0x1
9# CHECK-NEXT:0000000000000004 R_X86_64_32S             .text-0x8000000000000000
10#CHECK-EMPTY:
11# CHECK-NEXT:RELOCATION RECORDS FOR [nonalloc]:
12# CHECK-NEXT:OFFSET           TYPE                     VALUE
13# CHECK-NEXT:0000000000000010 R_X86_64_64              g1+0x1
14# CHECK-NEXT:0000000000000020 R_X86_64_64              g2+0x2
15# CHECK-NEXT:0000000000000030 R_X86_64_64              *ABS*
16#  CHECK-NOT:{{.}}
17
18--- !ELF
19FileHeader: !FileHeader
20  Class: ELFCLASS64
21  Data: ELFDATA2LSB
22  Type: ET_REL
23  Machine: EM_X86_64
24
25Sections:
26- Name: .text
27  Type: SHT_PROGBITS
28  Content: "0000000000000000"
29  Flags: [SHF_ALLOC]
30- Name: .crel.text
31  Type: SHT_CREL
32  Info: .text
33  Link: .symtab
34  Relocations:
35    - Offset: 0x1
36      Symbol: g1
37      Type:   R_X86_64_32
38      Addend: 1
39    - Offset: 0x2
40      Symbol: l1
41      Type:   R_X86_64_64
42      Addend: 2
43    - Offset: 0x0
44      Symbol: g1
45      Type:   R_X86_64_32S
46      Addend: 0xffffffffffffffff
47    - Offset: 0x4
48      Symbol: .text
49      Type:   R_X86_64_32S
50      Addend: 0x8000000000000000
51- Name: nonalloc
52  Type: SHT_PROGBITS
53  Size: 0x30
54- Name: .crelnonalloc
55  Type: SHT_CREL
56  Info: nonalloc
57  Link: .symtab
58  Relocations:
59    - Offset: 0x10
60      Symbol: g1
61      Type:   R_X86_64_64
62      Addend: 1
63    - Offset: 0x20
64      Symbol: g2
65      Type:   R_X86_64_64
66      Addend: 2
67    - Offset: 0x30
68      Symbol: 0
69      Type:   R_X86_64_64
70
71Symbols:
72  - Name: .text
73    Type: STT_SECTION
74    Section: .text
75  - Name:    l1
76  - Name:    g1
77    Section: .text
78    Value:   0x0
79    Size:    4
80    Binding: STB_GLOBAL
81  - Name:    g2
82    Binding: STB_GLOBAL
83
84## Check relocation formatting on ELFCLASS32 as well.
85# RUN: yaml2obj --docnum=2 %s > %t2
86# RUN: llvm-objdump -r %t2 | FileCheck %s --check-prefix=ELF32 --strict-whitespace --match-full-lines
87
88#      ELF32:RELOCATION RECORDS FOR [.text]:
89# ELF32-NEXT:OFFSET   TYPE                     VALUE
90# ELF32-NEXT:00000008 R_ARM_REL32              l1+0x1
91# ELF32-NEXT:00000004 R_ARM_ABS32              g1
92
93--- !ELF
94FileHeader:
95  Class:   ELFCLASS32
96  Data:    ELFDATA2MSB
97  Type:    ET_REL
98  Machine: EM_ARM
99Sections:
100- Name: .text
101  Type: SHT_PROGBITS
102  Size: 0x10
103- Name: .crel.text
104  Type: SHT_CREL
105  Info: .text
106  Link: .symtab
107  Relocations:
108    - Offset: 0x8
109      Symbol: l1
110      Type:   R_ARM_REL32
111      Addend: 1
112    - Offset: 0x4
113      Symbol: g1
114      Type:   R_ARM_ABS32
115Symbols:
116  - Name:    l1
117  - Name:    g1
118    Binding: STB_GLOBAL
119
120## Check CREL with implicit addends.
121# RUN: yaml2obj --docnum=3 %s -o %t3
122# RUN: llvm-objdump -r %t3 | FileCheck %s --check-prefix=IMPLICIT --strict-whitespace --match-full-lines
123#      IMPLICIT:RELOCATION RECORDS FOR [.data]:
124# IMPLICIT-NEXT:OFFSET           TYPE                     VALUE
125# IMPLICIT-NEXT:000000000000001f R_X86_64_32              g1
126# IMPLICIT-NEXT:000000000000003f R_X86_64_64              g1
127# IMPLICIT-NEXT:0000000000000000 R_X86_64_32S             l1
128--- !ELF
129FileHeader:
130  Class:     ELFCLASS64
131  Data:      ELFDATA2LSB
132  Type:      ET_REL
133  Machine:   EM_X86_64
134Sections:
135  - Name:    .text
136    Type:    SHT_PROGBITS
137  - Name:    .data
138    Type:    SHT_PROGBITS
139  - Name:    .crel.data
140    Type:    SHT_CREL
141    Flags:   [ SHF_INFO_LINK ]
142    Link:    .symtab
143    Info:    .data
144    Content: 187f030a82017787feffffffffffffff077f0a
145Symbols:
146  - Name:    .text
147    Type:    STT_SECTION
148    Section: .text
149  - Name:    l1
150    Section: .text
151  - Name:    g1
152    Section: .text
153    Binding: STB_GLOBAL
154
155## Test errors.
156# RUN: yaml2obj --docnum=4 %s -o %t.err
157# RUN: llvm-objdump -r %t.err 2>&1 | FileCheck %s --check-prefix=ERR -DFILE=%t.err
158
159#      ERR:RELOCATION RECORDS FOR [.data]:
160# ERR-NEXT:OFFSET           TYPE                     VALUE
161# ERR-NEXT:warning: '[[FILE]]': unable to decode LEB128 at offset 0x00000000: malformed uleb128, extends past end
162#  ERR-NOT:{{.}}
163
164--- !ELF
165FileHeader:
166  Class:     ELFCLASS64
167  Data:      ELFDATA2LSB
168  Type:      ET_REL
169  Machine:   EM_X86_64
170Sections:
171  - Name:    .text
172    Type:    SHT_PROGBITS
173  - Name:    .data
174    Type:    SHT_PROGBITS
175  - Name:    .crel.data
176    Type:    SHT_CREL
177    Flags:   []
178    Link:    .symtab
179    Info:    .data
180Symbols:
181  - Name:    .text
182    Type:    STT_SECTION
183    Section: .text
184
185# RUN: yaml2obj --docnum=5 %s -o %t.err2
186# RUN: llvm-objdump -r %t.err2 2>&1 | FileCheck %s --check-prefix=ERR2 -DFILE=%t.err2
187
188#      ERR2:RELOCATION RECORDS FOR [.data]:
189# ERR2-NEXT:OFFSET           TYPE                     VALUE
190# ERR2-NEXT:warning: '[[FILE]]': unexpected end of data at offset 0x1 while reading [0x1, 0x2)
191# ERR2-NOT:{{.}}
192
193--- !ELF
194FileHeader:
195  Class:     ELFCLASS32
196  Data:      ELFDATA2MSB
197  Type:      ET_REL
198  Machine:   EM_ARM
199Sections:
200  - Name:    .text
201    Type:    SHT_PROGBITS
202  - Name:    .data
203    Type:    SHT_PROGBITS
204  - Name:    .crel.data
205    Type:    SHT_CREL
206    Flags:   []
207    Link:    .symtab
208    Info:    .data
209    Content: 08
210Symbols:
211  - Name:    .text
212    Type:    STT_SECTION
213    Section: .text
214