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 0x17e7e7e8b0: 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 0x17e7e7e8b0: offset goes past the end of file
11# LLVM-NEXT:     0x2 R_X86_64_NONE - 0x0
12# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_REL section with index 3: invalid section index: 255
13# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 5 in SHT_REL section with index 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
14# LLVM-NEXT:   }
15# LLVM-NEXT:   Section (4) .rela.text {
16# 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
17# LLVM-NEXT:   }
18# LLVM-NEXT: ]
19
20# GNU:       Relocation section '.rel.text' at offset 0x41 contains 5 entries:
21# GNU-NEXT:      Offset             Info             Type               Symbol's Value  Symbol's Name
22# GNU-NEXT:  warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
23# GNU-NEXT:  warning: '[[FILE]]': unable to print relocation 2 in SHT_REL section with index 3: unable to access section [index 6] data at 0x17e7e7e8b0: offset goes past the end of file
24# GNU-NEXT:  0000000000000002  0000000000000000 R_X86_64_NONE
25# GNU-NEXT:  warning: '[[FILE]]': unable to print relocation 4 in SHT_REL section with index 3: invalid section index: 255
26# GNU-NEXT:  warning: '[[FILE]]': unable to print relocation 5 in SHT_REL section with index 3: a section [index 2] has an invalid sh_name (0xfefefefe) offset which goes past the end of the section name string table
27# GNU-EMPTY:
28# GNU-NEXT:  Relocation section '.rela.text' at offset 0x91 contains 1 entries:
29# GNU-NEXT:      Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
30# 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
31
32--- !ELF
33FileHeader:
34  Class:   ELFCLASS64
35  Data:    ELFDATA2LSB
36  Type:    ET_REL
37  Machine: EM_X86_64
38Sections:
39  - Name:    .text
40    Type:    SHT_PROGBITS
41    Content: '00'
42  - Name:   .foo
43    Type:   SHT_PROGBITS
44    ShName: 0xFEFEFEFE
45  - Name: .rel.text
46    Type: SHT_REL
47    Info: .text
48    Relocations:
49## Case 1: There is no symbol with index 0xFEFEFEFE.
50      - Symbol: 0xFEFEFEFE
51        Type:   R_X86_64_NONE
52      - Symbol: 0xFEFEFEFE
53        Type:   R_X86_64_NONE
54## Case 2: Test that no warning is reported for a relocation against a symbol with index 0.
55      - Offset: 0x2
56        Symbol: 0
57        Type:   R_X86_64_NONE
58## Case 3: Test a relocation against a section symbol that has an invalid
59##         section index (larger than the number of sections).
60      - Offset: 0x3
61        Symbol: .sec.symbol1
62        Type:   R_X86_64_NONE
63## Case 4: Test a relocation against a section symbol that has an invalid
64##         sh_name offset that goes past the end of the section name string table.
65      - Offset: 0x4
66        Symbol: .sec.symbol2
67        Type:   R_X86_64_NONE
68## Case 5: Test a relocation in a section that is linked to a symbol table that
69##         has a section type that is neither SHT_SYMTAB nor SHT_DYNSYM.
70##         In this case the code fails to find a corresponding symbol string table.
71  - Name: .rela.text
72    Type: SHT_RELA
73    Info: .text
74    Link: .fake.symtab
75    Relocations:
76      - Offset: 0x5
77        Symbol: symbol
78        Type:   R_X86_64_NONE
79  - Name:    .fake.symtab
80    Type:    SHT_PROGBITS
81    EntSize: 24
82    Size:    48
83Symbols:
84  - Name:    symbol
85    Section: .text
86    Value:   0
87  - Name:  .sec.symbol1
88    Type:  STT_SECTION
89    Index: 0xFF
90  - Name:  .sec.symbol2
91    Type:  STT_SECTION
92    Index: 0x2
93