1## Check how we report warnings when dumping an object with broken relocations.
2
3# RUN: yaml2obj %s -o %t64
4# RUN: llvm-readobj --relocations %t64 2>&1 | FileCheck %s -DFILE=%t64 --check-prefix=LLVM
5# RUN: llvm-readelf --relocations %t64 2>&1 | FileCheck %s -DFILE=%t64 --check-prefix=GNU
6
7# LLVM:      Relocations [
8# LLVM-NEXT:   Section (3) .rel.text {
9# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8d0: offset goes past the end of file
10# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8d0: offset goes past the end of file
11# LLVM-NEXT:     0x2 R_X86_64_NONE - 0x0
12# LLVM-NEXT:     0x3 R_X86_64_NONE .sec.symbol1 0x0
13# LLVM-NEXT: warning: '[[FILE]]': invalid section index: 255
14# LLVM-NEXT:     0x4 R_X86_64_NONE <section 255> 0x0
15# LLVM-NEXT:     0x5 R_X86_64_NONE .sec.symbol2 0x0
16# LLVM-NEXT: warning: '[[FILE]]': a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
17# LLVM-NEXT:     0x6 R_X86_64_NONE <section 2> 0x0
18# LLVM-NEXT:   }
19# LLVM-NEXT:   Section (4) .rela.text {
20# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
21# LLVM-NEXT:   }
22# LLVM-NEXT: ]
23
24# GNU:       Relocation section '.rel.text' at offset 0x41 contains 7 entries:
25# GNU-NEXT:      Offset             Info             Type               Symbol's Value  Symbol's Name
26# GNU-NEXT:  warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8d0: offset goes past the end of file
27# GNU-NEXT:  warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8d0: offset goes past the end of file
28# GNU-NEXT:  0000000000000002  0000000000000000 R_X86_64_NONE
29# GNU-NEXT:  0000000000000003  0000000200000000 R_X86_64_NONE 0000000000000000 .sec.symbol1
30# GNU-NEXT:  warning: '[[FILE]]': invalid section index: 255
31# GNU-NEXT:  0000000000000004  0000000400000000 R_X86_64_NONE 0000000000000000 <section 255>
32# GNU-NEXT:  0000000000000005  0000000300000000 R_X86_64_NONE 0000000000000000 .sec.symbol2
33# GNU-NEXT:  warning: '[[FILE]]': a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
34# GNU-NEXT:  0000000000000006  0000000500000000 R_X86_64_NONE 0000000000000000 <section 2>
35# GNU-EMPTY:
36# GNU-NEXT:  Relocation section '.rela.text' at offset 0xb1 contains 1 entries:
37# GNU-NEXT:      Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
38# GNU-NEXT:  warning: '[[FILE]]': unable to print relocation 1 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM
39
40--- !ELF
41FileHeader:
42  Class:   ELFCLASS64
43  Data:    ELFDATA2LSB
44  Type:    ET_REL
45  Machine: EM_X86_64
46Sections:
47  - Name:    .text
48    Type:    SHT_PROGBITS
49    Content: '00'
50  - Name:   .foo
51    Type:   SHT_PROGBITS
52    ShName: 0xFEFEFEFE
53  - Name: .rel.text
54    Type: SHT_REL
55    Info: .text
56    Relocations:
57## Case 1: There is no symbol with index 0xFEFEFEFE.
58      - Symbol: 0xFEFEFEFE
59        Type:   R_X86_64_NONE
60      - Symbol: 0xFEFEFEFE
61        Type:   R_X86_64_NONE
62## Case 2: Test that no warning is reported for a relocation against a symbol with index 0.
63      - Offset: 0x2
64        Symbol: 0
65        Type:   R_X86_64_NONE
66## Case 3: Test a relocation against a named section symbol that has an invalid
67##         section index (larger than the number of sections).
68      - Offset: 0x3
69        Symbol: .sec.symbol1
70        Type:   R_X86_64_NONE
71## Case 4: Test a relocation against an unnamed section symbol that has an invalid
72##         section index (larger than the number of sections).
73      - Offset: 0x4
74        Symbol: 4
75        Type:   R_X86_64_NONE
76## Case 4: Test a relocation against a named section symbol with a section with an invalid
77##         sh_name offset that goes past the end of the section name string table.
78      - Offset: 0x5
79        Symbol: .sec.symbol2
80        Type:   R_X86_64_NONE
81## Case 5: Test a relocation against an unnamed section symbol with a section with an invalid
82##         sh_name offset that goes past the end of the section name string table.
83      - Offset: 0x6
84        Symbol: 5
85        Type:   R_X86_64_NONE
86## Case 6: Test a relocation in a section that is linked to a symbol table that
87##         has a section type that is neither SHT_SYMTAB nor SHT_DYNSYM.
88##         In this case the code fails to find a corresponding symbol string table.
89  - Name: .rela.text
90    Type: SHT_RELA
91    Info: .text
92    Link: .fake.symtab
93    Relocations:
94      - Offset: 0x7
95        Symbol: symbol
96        Type:   R_X86_64_NONE
97  - Name:    .fake.symtab
98    Type:    SHT_PROGBITS
99    EntSize: 24
100    Size:    48
101Symbols:
102  - Name:    symbol
103    Section: .text
104    Value:   0
105  - Name:  .sec.symbol1
106    Type:  STT_SECTION
107    Index: 0xFF
108  - Name:  .sec.symbol2
109    Type:  STT_SECTION
110    Index: 0x2
111  - Type:  STT_SECTION
112    Index: 0xFF
113  - Type:  STT_SECTION
114    Index: 0x2
115