xref: /llvm-project/llvm/test/tools/llvm-readobj/ELF/broken-dynamic-reloc.test (revision fdd1da3f36e2a6911c0beea1d69c62bc77d8cb98)
1## Test how we handle cases when dynamic relocations or corresponding dynamic tags are broken.
2
3## Check that llvm-readobj/llvm-readelf reports an error when dumping relocations if a dynamic
4## symbol name offset is broken (goes past the end of the dynamic symbol string table).
5
6# RUN: yaml2obj --docnum=1 %s -o %t1
7# RUN: llvm-readobj --dyn-relocations %t1 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=LLVM
8# RUN: llvm-readelf --dyn-relocations %t1 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=GNU
9
10# LLVM:      Dynamic Relocations {
11# LLVM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 1: st_name (0x1234) is past the end of the string table of size 0x1
12# LLVM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
13# LLVM-NEXT: }
14
15# GNU:      'RELA' relocation section at offset {{.+}} contains 24 bytes:
16# GNU-NEXT: Offset           Info             Type          Symbol's Value   Symbol's Name + Addend
17# GNU-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 1: st_name (0x1234) is past the end of the string table of size 0x1
18# GNU-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 <corrupt> + 0
19
20--- !ELF
21FileHeader:
22  Class:   ELFCLASS64
23  Data:    ELFDATA2LSB
24  Type:    ET_DYN
25  Machine: EM_X86_64
26Sections:
27  - Name:    .rela.dyn
28    Type:    SHT_RELA
29    Link:    .dynsym
30    Relocations:
31      - Symbol: 1 ## Index of a dynamic symbol with a broken st_name.
32        Type:   R_X86_64_NONE
33  - Name: .dynamic
34    Type: SHT_DYNAMIC
35    Entries:
36      - Tag:   DT_RELA
37        Value: 0x0000000000000000
38      - Tag:   DT_RELASZ
39        Value: 0x0000000000000018
40      - Tag:   DT_RELAENT
41        Value: 0x0000000000000018
42      - Tag:   DT_NULL
43        Value: 0x0000000000000000
44DynamicSymbols:
45  - StName: 0x1234
46ProgramHeaders:
47  - Type:     PT_LOAD
48    FirstSec: .rela.dyn
49    LastSec:  .dynamic
50
51## Show we print a warning for an invalid relocation table size stored in a DT_RELASZ entry.
52
53## Case A: the size of a single relocation entry is 0x18. In this case 0xFF % 0x18 != 0 and we report a warning
54
55# RUN: yaml2obj --docnum=2 -DRELTYPE=RELA -DTAG1=DT_RELASZ -DTAG1VAL=0xFF -DTAG2=DT_RELAENT %s -o %t2a
56# RUN: llvm-readobj --dyn-relocations %t2a 2>&1 | \
57# RUN:   FileCheck %s -DFILE=%t2a --check-prefix=INVALID-DT-RELASZ1 --implicit-check-not=warning:
58# RUN: llvm-readelf --dyn-relocations %t2a 2>&1 | \
59# RUN:   FileCheck %s -DFILE=%t2a --check-prefix=INVALID-DT-RELASZ1 --implicit-check-not=warning:
60
61# INVALID-DT-RELASZ1: warning: '[[FILE]]': invalid DT_RELASZ value (0xff) or DT_RELAENT value (0x18)
62
63--- !ELF
64FileHeader:
65  Class: ELFCLASS64
66  Data:  ELFDATA2LSB
67  Type:  ET_DYN
68Sections:
69  - Name:  .relx.dyn
70    Type:  SHT_[[RELTYPE]]
71  - Name: .dynamic
72    Type: SHT_DYNAMIC
73    Entries:
74      - Tag:   DT_[[RELTYPE]]
75        Value: 0x0
76      - Tag:   [[TAG1]]
77        Value: [[TAG1VAL=0x18]]
78      - Tag:   [[TAG2]]
79        Value: [[TAG2VAL=0x18]]
80      - Tag:   DT_NULL
81        Value: 0x0
82DynamicSymbols: []
83ProgramHeaders:
84  - Type:     PT_LOAD
85    FirstSec: .relx.dyn
86    LastSec:  .dynamic
87
88## Case B: the DT_RELASZ has value of 0x251, what is too large, because the relocation table goes past the EOF.
89
90# RUN: yaml2obj --docnum=2 -DRELTYPE=RELA -DTAG1=DT_RELASZ -DTAG1VAL=0x251 -DTAG2=DT_RELAENT %s -o %t2b
91# RUN: llvm-readobj --dyn-relocations %t2b 2>&1 | \
92# RUN:   FileCheck %s -DFILE=%t2b --check-prefix=INVALID-DT-RELASZ2 --implicit-check-not=warning:
93# RUN: llvm-readelf --dyn-relocations %t2b 2>&1 | \
94# RUN:   FileCheck %s -DFILE=%t2b --check-prefix=INVALID-DT-RELASZ2 --implicit-check-not=warning:
95
96# INVALID-DT-RELASZ2: warning: '[[FILE]]': unable to read data at 0x78 of size 0x251 (DT_RELASZ value): it goes past the end of the file of size 0x2c8
97
98## Show we print a warning for an invalid relocation table entry size stored in a DT_RELAENT entry.
99# RUN: yaml2obj --docnum=2 -DRELTYPE=RELA -DTAG1=DT_RELASZ -DTAG2=DT_RELAENT -DTAG2VAL=0xFF %s -o %t3
100# RUN: llvm-readobj --dyn-relocations %t3 2>&1 | \
101# RUN:   FileCheck %s -DFILE=%t3 --check-prefix=INVALID-DT-RELAENT --implicit-check-not=warning:
102# RUN: llvm-readelf --dyn-relocations %t3 2>&1 | \
103# RUN:   FileCheck %s -DFILE=%t3 --check-prefix=INVALID-DT-RELAENT --implicit-check-not=warning:
104
105# INVALID-DT-RELAENT: warning: '[[FILE]]': invalid DT_RELASZ value (0x18) or DT_RELAENT value (0xff)
106
107## Show we print a warning for an invalid relocation table size stored in a DT_RELSZ entry.
108
109## Case A: the size of a single relocation entry is 0x18. In this case 0xFF % 0x18 != 0 and we report a warning.
110
111# RUN: yaml2obj --docnum=2 -DRELTYPE=REL -DTAG1=DT_RELSZ -DTAG1VAL=0xFF -DTAG2=DT_RELENT %s -o %t4a
112# RUN: llvm-readobj --dyn-relocations %t4a 2>&1 | FileCheck %s -DFILE=%t4a --check-prefix=INVALID-DT-RELSZ1
113# RUN: llvm-readelf --dyn-relocations %t4a 2>&1 | FileCheck %s -DFILE=%t4a --check-prefix=INVALID-DT-RELSZ1
114
115# INVALID-DT-RELSZ1: warning: '[[FILE]]': invalid DT_RELSZ value (0xff) or DT_RELENT value (0x18)
116
117## Case B: the DT_RELSZ has value of 0x251, what is too large, because the relocation table goes past the EOF.
118
119# RUN: yaml2obj --docnum=2 -DRELTYPE=REL -DTAG1=DT_RELSZ -DTAG1VAL=0x251 -DTAG2=DT_RELENT %s -o %t4b
120# RUN: llvm-readobj --dyn-relocations %t4b 2>&1 | FileCheck %s -DFILE=%t4b --check-prefix=INVALID-DT-RELSZ2
121# RUN: llvm-readelf --dyn-relocations %t4b 2>&1 | FileCheck %s -DFILE=%t4b --check-prefix=INVALID-DT-RELSZ2
122
123# INVALID-DT-RELSZ2: warning: '[[FILE]]': unable to read data at 0x78 of size 0x251 (DT_RELSZ value): it goes past the end of the file of size 0x2c8
124
125## Show we print a warning for an invalid relocation table entry size stored in a DT_RELENT entry.
126# RUN: yaml2obj --docnum=2 -DRELTYPE=REL -DTAG1=DT_RELSZ -DTAG2=DT_RELENT -DTAG2VAL=0xFF %s -o %t5
127# RUN: llvm-readobj --dyn-relocations %t5 2>&1 | FileCheck %s -DFILE=%t5 --check-prefix=INVALID-DT-RELENT
128# RUN: llvm-readelf --dyn-relocations %t5 2>&1 | FileCheck %s -DFILE=%t5 --check-prefix=INVALID-DT-RELENT
129
130# INVALID-DT-RELENT: warning: '[[FILE]]': invalid DT_RELSZ value (0x18) or DT_RELENT value (0xff)
131
132## Show we print a warning for an invalid relocation table size stored in a DT_RELRSZ/DT_ANDROID_RELRSZ entry.
133# RUN: yaml2obj --docnum=2 -DRELTYPE=RELR -DTAG1=DT_RELRSZ -DTAG1VAL=0xFF -DTAG2=DT_RELRENT %s -o %t6
134# RUN: llvm-readobj --dyn-relocations %t6 2>&1 | FileCheck %s -DFILE=%t6 --check-prefix=INVALID-DT-RELRSZ
135# RUN: llvm-readelf --dyn-relocations %t6 2>&1 | FileCheck %s -DFILE=%t6 --check-prefix=INVALID-DT-RELRSZ
136
137# RUN: yaml2obj --docnum=2 -DRELTYPE=RELR -DTAG1=DT_ANDROID_RELRSZ -DTAG1VAL=0xFF -DTAG2=DT_ANDROID_RELRENT %s -o %t7
138# RUN: llvm-readobj --dyn-relocations %t7 2>&1 | FileCheck %s -DFILE=%t7 --check-prefix=INVALID-DT-ANDROID-RELRSZ
139# RUN: llvm-readelf --dyn-relocations %t7 2>&1 | FileCheck %s -DFILE=%t7 --check-prefix=INVALID-DT-ANDROID-RELRSZ
140
141# INVALID-DT-RELRSZ:         warning: '[[FILE]]': invalid DT_RELRSZ value (0xff) or DT_RELRENT value (0x18)
142# INVALID-DT-ANDROID-RELRSZ: warning: '[[FILE]]': invalid DT_ANDROID_RELRSZ value (0xff) or DT_ANDROID_RELRENT value (0x18)
143
144## Show we print a warning for an invalid relocation table entry size stored in a DT_RELRENT/DT_ANDROID_RELRENT entry.
145# RUN: yaml2obj --docnum=2 -DRELTYPE=RELR -DTAG1=DT_RELRSZ -DTAG2=DT_RELRENT -DTAG2VAL=0xFF %s -o %t8
146# RUN: llvm-readobj --dyn-relocations %t8 2>&1 | FileCheck %s -DFILE=%t8 --check-prefix=INVALID-DT-RELRENT
147# RUN: llvm-readelf --dyn-relocations %t8 2>&1 | FileCheck %s -DFILE=%t8 --check-prefix=INVALID-DT-RELRENT
148# RUN: yaml2obj --docnum=2 -DRELTYPE=RELR -DTAG1=DT_ANDROID_RELRSZ -DTAG2=DT_ANDROID_RELRENT -DTAG2VAL=0xFF %s -o %t9
149# RUN: llvm-readobj --dyn-relocations %t9 2>&1 | FileCheck %s -DFILE=%t9 --check-prefix=INVALID-DT-ANDROID-RELRENT
150# RUN: llvm-readelf --dyn-relocations %t9 2>&1 | FileCheck %s -DFILE=%t9 --check-prefix=INVALID-DT-ANDROID-RELRENT
151
152# INVALID-DT-RELRENT:         invalid DT_RELRSZ value (0x18) or DT_RELRENT value (0xff)
153# INVALID-DT-ANDROID-RELRENT: invalid DT_ANDROID_RELRSZ value (0x18) or DT_ANDROID_RELRENT value (0xff)
154
155## Show we print a warning for an invalid value of DT_PLTRELSZ, which describes the total size
156## of the relocation entries associated with the procedure linkage table.
157
158## Case A: the size of a single relocation entry is 0x18. In this case 0xFF % 0x18 != 0 and we report a warning.
159
160# RUN: yaml2obj --docnum=3 -DVAL=0xFF %s -o %t10a
161# RUN: llvm-readobj --dyn-relocations %t10a 2>&1 | \
162# RUN:   FileCheck %s -DFILE=%t10a --check-prefix=INVALID-DT-PLTRELSZ1 --implicit-check-not=warning:
163# RUN: llvm-readelf --dyn-relocations %t10a 2>&1 | \
164# RUN:   FileCheck %s -DFILE=%t10a --check-prefix=INVALID-DT-PLTRELSZ1 --implicit-check-not=warning:
165
166# INVALID-DT-PLTRELSZ1: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0xff) or PLTREL entry size (0x18){{$}}
167
168--- !ELF
169FileHeader:
170  Class:   ELFCLASS64
171  Data:    ELFDATA2LSB
172  Type:    ET_EXEC
173  Machine: EM_X86_64
174Sections:
175  - Name:  .rela.plt
176    Type:  SHT_RELA
177    Relocations:
178      - Type:   R_X86_64_NONE
179  - Name:  .dynamic
180    Type:  SHT_DYNAMIC
181    Entries:
182      - Tag:   DT_JMPREL
183        Value: 0x0
184      - Tag:   DT_PLTRELSZ
185        Value: [[VAL]] ## The valid value would be 0x18.
186      - Tag:   DT_PLTREL
187        Value: 0x7 ## DT_RELA
188      - Tag:   DT_NULL
189        Value: 0x0
190DynamicSymbols: []
191ProgramHeaders:
192  - Type:     PT_LOAD
193    FirstSec: .rela.plt
194    LastSec:  .dynamic
195
196## Case B: the DT_PLTRELSZ (PLT size) has value of 0x269, what is too large, because PLT goes past the EOF.
197
198# RUN: yaml2obj --docnum=3 -DVAL=0x269 %s -o %t10b
199# RUN: llvm-readobj --dyn-relocations %t10b 2>&1 | \
200# RUN:   FileCheck %s -DFILE=%t10b --check-prefix=INVALID-DT-PLTRELSZ2-LLVM --implicit-check-not=warning:
201# RUN: llvm-readelf --dyn-relocations %t10b 2>&1 | \
202# RUN:   FileCheck %s -DFILE=%t10b --check-prefix=INVALID-DT-PLTRELSZ2-GNU --implicit-check-not=warning:
203
204# INVALID-DT-PLTRELSZ2-LLVM:      Dynamic Relocations {
205# INVALID-DT-PLTRELSZ2-LLVM-NEXT: warning: '[[FILE]]': unable to read data at 0x78 of size 0x269 (DT_PLTRELSZ value): it goes past the end of the file of size 0x2e0
206# INVALID-DT-PLTRELSZ2-LLVM-NEXT: }
207
208# INVALID-DT-PLTRELSZ2-GNU:      'PLT' relocation section at offset 0x78 contains 617 bytes:
209# INVALID-DT-PLTRELSZ2-GNU-NEXT:     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
210# INVALID-DT-PLTRELSZ2-GNU-NEXT: warning: '[[FILE]]': unable to read data at 0x78 of size 0x269 (DT_PLTRELSZ value): it goes past the end of the file of size 0x2e0
211
212## Show we print a warning when dumping dynamic relocations if there is no dynamic symbol table.
213# RUN: yaml2obj --docnum=4 %s -o %t11
214# RUN: llvm-readobj --dyn-relocations %t11 2>&1 | FileCheck %s -DFILE=%t11 --check-prefix=LLVM-NO-DYNSYM
215# RUN: llvm-readelf --dyn-relocations %t11 2>&1 | FileCheck %s -DFILE=%t11 --check-prefix=GNU-NO-DYNSYM
216
217# LLVM-NO-DYNSYM:      Dynamic Relocations {
218# LLVM-NO-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 0: no dynamic symbol table found
219# LLVM-NO-DYNSYM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
220# LLVM-NO-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 1: no dynamic symbol table found
221# LLVM-NO-DYNSYM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
222# LLVM-NO-DYNSYM-NEXT: }
223
224# GNU-NO-DYNSYM:      'RELA' relocation section at offset 0x78 contains 48 bytes:
225# GNU-NO-DYNSYM-NEXT: Offset            Info             Type             Symbol's Value   Symbol's Name + Addend
226# GNU-NO-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 0: no dynamic symbol table found
227# GNU-NO-DYNSYM-NEXT: 0000000000000000  0000000000000000 R_X86_64_NONE                     <corrupt> + 0
228# GNU-NO-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 1: no dynamic symbol table found
229# GNU-NO-DYNSYM-NEXT: 0000000000000000  0000000100000000 R_X86_64_NONE                     <corrupt> + 0
230
231--- !ELF
232FileHeader:
233  Class:   ELFCLASS64
234  Data:    ELFDATA2LSB
235  Type:    ET_DYN
236  Machine: EM_X86_64
237Sections:
238  - Name:    .rela.dyn
239    Type:    SHT_RELA
240    Relocations:
241      - Type:   R_X86_64_NONE
242      - Type:   R_X86_64_NONE
243        Symbol: 0x1
244  - Name: .dynamic
245    Type: SHT_DYNAMIC
246    Entries:
247      - Tag:   DT_RELA
248        Value: 0x0
249      - Tag:   DT_RELASZ
250        Value: 0x30
251      - Tag:   DT_RELAENT
252        Value: 0x18
253      - Tag:   DT_NULL
254        Value: 0x0
255ProgramHeaders:
256  - Type:     PT_LOAD
257    FirstSec: .rela.dyn
258    LastSec:  .dynamic
259
260## Show we print a warning when the symbol index of a dynamic relocation is too
261## large (goes past the end of the dynamic symbol table).
262# RUN: yaml2obj --docnum=5 %s -o %t12
263# RUN: llvm-readobj --dyn-relocations %t12 2>&1 | \
264# RUN:   FileCheck %s -DFILE=%t12 --implicit-check-not=warning: --check-prefix=LLVM-INVALID-DYNSYM
265# RUN: llvm-readelf --dyn-relocations %t12 2>&1 | \
266# RUN:   FileCheck %s -DFILE=%t12 --implicit-check-not=warning: --check-prefix=GNU-INVALID-DYNSYM
267
268# LLVM-INVALID-DYNSYM:      Dynamic Relocations {
269# LLVM-INVALID-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 2: index is greater than or equal to the number of dynamic symbols (2)
270# LLVM-INVALID-DYNSYM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
271# LLVM-INVALID-DYNSYM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
272# LLVM-INVALID-DYNSYM-NEXT: }
273
274# GNU-INVALID-DYNSYM:      'RELA' relocation section at offset 0x78 contains 48 bytes:
275# GNU-INVALID-DYNSYM-NEXT: Offset            Info             Type             Symbol's Value   Symbol's Name + Addend
276# GNU-INVALID-DYNSYM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 2: index is greater than or equal to the number of dynamic symbols (2)
277# GNU-INVALID-DYNSYM-NEXT: 0000000000000000  0000000200000000 R_X86_64_NONE                     <corrupt> + 0
278# GNU-INVALID-DYNSYM-NEXT: 0000000000000000  0000000200000000 R_X86_64_NONE                     <corrupt> + 0
279
280--- !ELF
281FileHeader:
282  Class:   ELFCLASS64
283  Data:    ELFDATA2LSB
284  Type:    ET_DYN
285  Machine: EM_X86_64
286Sections:
287  - Name:    .rela.dyn
288    Type:    SHT_RELA
289    Relocations:
290      - Type:   R_X86_64_NONE
291        Symbol: 0x2
292      - Type:   R_X86_64_NONE
293        Symbol: 0x2
294  - Name: .dynamic
295    Type: SHT_DYNAMIC
296    Entries:
297      - Tag:   DT_RELA
298        Value: 0x0
299      - Tag:   DT_RELASZ
300        Value: 0x30
301      - Tag:   DT_RELAENT
302        Value: 0x18
303      - Tag:   DT_NULL
304        Value: 0x0
305DynamicSymbols:
306  - Name: foo
307ProgramHeaders:
308  - Type:     PT_LOAD
309    FirstSec: .rela.dyn
310    LastSec:  .dynamic
311
312## Show that when we have both REL and RELA relocations, we dump both sets.
313# RUN: yaml2obj --docnum=6 %s -o %t13
314# RUN: llvm-readobj --dyn-relocations %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=BOTH-RELA-REL-LLVM
315# RUN: llvm-readelf --dyn-relocations %t13 2>&1 | FileCheck %s -DFILE=%t13 --check-prefix=BOTH-RELA-REL-GNU
316
317# BOTH-RELA-REL-LLVM:      Dynamic Relocations {
318# BOTH-RELA-REL-LLVM-NEXT:   0x1 R_X86_64_NONE - 0x0{{$}}
319# BOTH-RELA-REL-LLVM-NEXT:   0x2 R_X86_64_NONE -{{$}}
320# BOTH-RELA-REL-LLVM-NEXT: }
321
322# BOTH-RELA-REL-GNU:       'RELA' relocation section at offset 0x78 contains 24 bytes:
323# BOTH-RELA-REL-GNU-NEXT:    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
324# BOTH-RELA-REL-GNU-NEXT:  0000000000000001  0000000000000000 R_X86_64_NONE                     0
325# BOTH-RELA-REL-GNU-EMPTY:
326# BOTH-RELA-REL-GNU:       'REL' relocation section at offset 0x90 contains 16 bytes:
327# BOTH-RELA-REL-GNU-NEXT:    Offset             Info             Type               Symbol's Value  Symbol's Name
328# BOTH-RELA-REL-GNU-NEXT:  0000000000000002  0000000000000000 R_X86_64_NONE
329
330--- !ELF
331FileHeader:
332  Class:   ELFCLASS64
333  Data:    ELFDATA2LSB
334  Type:    ET_DYN
335  Machine: EM_X86_64
336Sections:
337  - Name: .rela.dyn
338    Type: SHT_RELA
339    Relocations:
340      - Type:   R_X86_64_NONE
341        Offset: 0x1
342  - Name: .rel.dyn
343    Type: SHT_REL
344    Relocations:
345      - Type:   R_X86_64_NONE
346        Offset: 0x2
347  - Name: .dynamic
348    Type: SHT_DYNAMIC
349    Entries:
350      - Tag:   DT_RELA
351        Value: 0x0
352      - Tag:   DT_RELASZ
353        Value: 0x18
354      - Tag:   DT_RELAENT
355        Value: 0x18
356## 0x18 == offset of .rel.dyn == size of .rela.dyn section.
357      - Tag:   DT_REL
358        Value: 0x18
359      - Tag:   DT_RELSZ
360        Value: 0x10
361      - Tag:   DT_RELENT
362        Value: 0x10
363      - Tag:   DT_NULL
364        Value: 0x0
365DynamicSymbols: []
366ProgramHeaders:
367  - Type:     PT_LOAD
368    FirstSec: .rela.dyn
369    LastSec:  .dynamic
370
371## Check that llvm-readobj/llvm-readelf reports a warning when dumping a relocation
372## which refers to a symbol past the end of the file.
373
374# RUN: yaml2obj --docnum=7 %s -o %t7
375# RUN: llvm-readobj --dyn-relocations %t7 2>&1 | \
376# RUN:   FileCheck %s -DFILE=%t7 --check-prefix=PAST-EOF-LLVM
377# RUN: llvm-readelf --dyn-relocations %t7 2>&1 | \
378# RUN:   FileCheck %s -DFILE=%t7 --check-prefix=PAST-EOF-GNU
379
380# PAST-EOF-LLVM:      Dynamic Relocations {
381# PAST-EOF-LLVM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 1: st_name (0x1) is past the end of the string table of size 0x0
382# PAST-EOF-LLVM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
383# PAST-EOF-LLVM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 2: symbol at 0x330 goes past the end of the file (0x330)
384# PAST-EOF-LLVM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
385# PAST-EOF-LLVM-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 4294967295: symbol at 0x18000002e8 goes past the end of the file (0x330)
386# PAST-EOF-LLVM-NEXT:   0x0 R_X86_64_NONE <corrupt> 0x0
387# PAST-EOF-LLVM-NEXT: }
388
389# PAST-EOF-GNU:      'RELA' relocation section at offset 0x200 contains 72 bytes:
390# PAST-EOF-GNU-NEXT:     Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
391# PAST-EOF-GNU-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 1: st_name (0x1) is past the end of the string table of size 0x0
392# PAST-EOF-GNU-NEXT: 0000000000000000  0000000100000000 R_X86_64_NONE          0000000000000000 <corrupt> + 0
393# PAST-EOF-GNU-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 2: symbol at 0x330 goes past the end of the file (0x330)
394# PAST-EOF-GNU-NEXT: 0000000000000000  0000000200000000 R_X86_64_NONE                           <corrupt> + 0
395# PAST-EOF-GNU-NEXT: warning: '[[FILE]]': unable to get name of the dynamic symbol with index 4294967295: symbol at 0x18000002e8 goes past the end of the file (0x330)
396# PAST-EOF-GNU-NEXT: 0000000000000000  ffffffff00000000 R_X86_64_NONE                           <corrupt> + 0
397
398--- !ELF
399FileHeader:
400  Class:   ELFCLASS64
401  Data:    ELFDATA2LSB
402  Type:    ET_DYN
403  Machine: EM_X86_64
404Sections:
405  - Name:    .dynamic
406    Type:    SHT_DYNAMIC
407    Flags:   [ SHF_ALLOC ]
408    Address: 0x100
409    Offset:  0x100
410    Entries:
411      - Tag:   DT_RELA
412        Value: 0x200
413      - Tag:   DT_SYMTAB
414        Value: 0x300
415      - Tag:   DT_RELASZ
416        Value: 0x48
417      - Tag:   DT_RELAENT
418        Value: 0x18
419      - Tag:   DT_NULL
420        Value: 0x0
421  - Name:    .rela.dyn
422    Type:    SHT_RELA
423    Flags:   [ SHF_ALLOC ]
424    Address: 0x200
425    Offset:  0x200
426    Relocations:
427## This symbol is located right before the EOF, so we can dump it.
428      - Symbol: 0x1
429        Type:   R_X86_64_NONE
430## The next symbol, which goes past the EOF.
431      - Symbol: 0x2
432        Type:   R_X86_64_NONE
433## One more symbol that goes past the EOF
434## with the maximal possible index.
435      - Symbol: 0xFFFFFFFF
436        Type:   R_X86_64_NONE
437## Place all implicit sections here to make the .dynsym section to be the
438## last in the file. This makes the task of validating offsets a bit easier.
439  - Name: .dynstr
440    Type: SHT_STRTAB
441  - Name: .strtab
442    Type: SHT_STRTAB
443  - Name: .shstrtab
444    Type: SHT_STRTAB
445  - Name:    .dynsym
446    Type:    SHT_DYNSYM
447    Flags:   [ SHF_ALLOC ]
448    Address: 0x300
449    Offset:  0x300
450  - Type: SectionHeaderTable
451    NoHeaders: true
452DynamicSymbols:
453  - Name: foo
454ProgramHeaders:
455  - Type:     PT_LOAD
456    Offset:   0x0
457    FirstSec: .dynamic
458    LastSec:  .dynsym
459  - Type:     PT_DYNAMIC
460    FirstSec: .dynamic
461    LastSec:  .dynamic
462
463## Show we print a warning for an invalid relocation table size stored in a DT_AARCH64_AUTH_RELRSZ entry.
464# RUN: yaml2obj --docnum=8 -DRELTYPE=RELR -DTAG1=DT_AARCH64_AUTH_RELRSZ -DTAG1VAL=0xFF -DTAG2=DT_AARCH64_AUTH_RELRENT %s -o %t14
465# RUN: llvm-readobj --dyn-relocations %t14 2>&1 | FileCheck %s -DFILE=%t14 --check-prefix=INVALID-DT-AARCH64-AUTH-RELRSZ
466# RUN: llvm-readelf --dyn-relocations %t14 2>&1 | FileCheck %s -DFILE=%t14 --check-prefix=INVALID-DT-AARCH64-AUTH-RELRSZ
467
468# INVALID-DT-AARCH64-AUTH-RELRSZ: warning: '[[FILE]]': invalid DT_AARCH64_AUTH_RELRSZ value (0xff) or DT_AARCH64_AUTH_RELRENT value (0x18)
469
470## Show we print a warning for an invalid relocation table entry size stored in a DT_AARCH64_AUTH_RELRENT entry.
471# RUN: yaml2obj --docnum=8 -DRELTYPE=RELR -DTAG1=DT_AARCH64_AUTH_RELRSZ -DTAG2=DT_AARCH64_AUTH_RELRENT -DTAG2VAL=0xFF %s -o %t15
472# RUN: llvm-readobj --dyn-relocations %t15 2>&1 | FileCheck %s -DFILE=%t15 --check-prefix=INVALID-DT-AARCH64-AUTH-RELRENT
473# RUN: llvm-readelf --dyn-relocations %t15 2>&1 | FileCheck %s -DFILE=%t15 --check-prefix=INVALID-DT-AARCH64-AUTH-RELRENT
474
475# INVALID-DT-AARCH64-AUTH-RELRENT: invalid DT_AARCH64_AUTH_RELRSZ value (0x18) or DT_AARCH64_AUTH_RELRENT value (0xff)
476
477--- !ELF
478FileHeader:
479  Class: ELFCLASS64
480  Data:  ELFDATA2LSB
481  Type:  ET_DYN
482  Machine: EM_AARCH64
483Sections:
484  - Name:  .relx.dyn
485    Type:  SHT_[[RELTYPE]]
486  - Name: .dynamic
487    Type: SHT_DYNAMIC
488    Entries:
489      - Tag:   DT_[[RELTYPE]]
490        Value: 0x0
491      - Tag:   [[TAG1]]
492        Value: [[TAG1VAL=0x18]]
493      - Tag:   [[TAG2]]
494        Value: [[TAG2VAL=0x18]]
495      - Tag:   DT_NULL
496        Value: 0x0
497DynamicSymbols: []
498ProgramHeaders:
499  - Type:     PT_LOAD
500    FirstSec: .relx.dyn
501    LastSec:  .dynamic
502