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 0 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90) 10# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90) 11# LLVM-NEXT: 0x2 R_X86_64_NONE -{{$}} 12# LLVM-NEXT: 0x3 R_X86_64_NONE .sec.symbol1{{$}} 13# LLVM-NEXT: warning: '[[FILE]]': invalid section index: 255 14# LLVM-NEXT: 0x4 R_X86_64_NONE <section 255>{{$}} 15# LLVM-NEXT: 0x5 R_X86_64_NONE .sec.symbol2{{$}} 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>{{$}} 18# LLVM-NEXT: } 19# LLVM-NEXT: Section (4) .rela.text { 20# LLVM-NEXT: warning: '[[FILE]]': unable to print relocation 0 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 0 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90) 27# GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_REL section with index 3: unable to read an entry with index 4278124286 from SHT_SYMTAB section with index 6: can't read an entry at 0x17e7e7e7d0: it goes past the end of the section (0x90) 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 0 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM 39 40# RUN: yaml2obj -DTYPE=SHT_CREL %s -o %t64.crel 41# RUN: llvm-readelf --relocations %t64.crel 2>&1 | FileCheck %s -DFILE=%t64.crel --check-prefix=CREL-GNU 42 43# CREL-GNU: Relocation section '.rel.text' at offset 0x41 contains 7 entries: 44# CREL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend 45# CREL-GNU-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_CREL section with index 3: unable to read an entry with index 4278124286 from SHT_NULL section with index 0: section [index 0] has invalid sh_entsize: expected 24, but got 0 46# CREL-GNU-NEXT: warning: '[[FILE]]': unable to print relocation 1 in SHT_CREL section with index 3: unable to read an entry with index 4278124286 from SHT_NULL section with index 0: section [index 0] has invalid sh_entsize: expected 24, but got 0 47# CREL-GNU-NEXT: 0000000000000002 0000000000000000 R_X86_64_NONE 0 48# CREL-GNU-NEXT: warning: '[[FILE]]': unable to print relocation 3 in SHT_CREL section with index 3: unable to read an entry with index 2 from SHT_NULL section with index 0: section [index 0] has invalid sh_entsize: expected 24, but got 0 49# CREL-GNU-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_CREL section with index 3: unable to read an entry with index 4 from SHT_NULL section with index 0: section [index 0] has invalid sh_entsize: expected 24, but got 0 50# CREL-GNU-NEXT: warning: '[[FILE]]': unable to print relocation 5 in SHT_CREL section with index 3: unable to read an entry with index 3 from SHT_NULL section with index 0: section [index 0] has invalid sh_entsize: expected 24, but got 0 51# CREL-GNU-NEXT: warning: '[[FILE]]': unable to print relocation 6 in SHT_CREL section with index 3: unable to read an entry with index 5 from SHT_NULL section with index 0: section [index 0] has invalid sh_entsize: expected 24, but got 0 52# CREL-GNU-EMPTY: 53# CREL-GNU-NEXT: Relocation section '.rela.text' at offset 0x5a contains 1 entries: 54# CREL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend 55# CREL-GNU-NEXT: warning: '[[FILE]]': unable to print relocation 0 in SHT_RELA section with index 4: invalid sh_type for symbol table, expected SHT_SYMTAB or SHT_DYNSYM 56 57--- !ELF 58FileHeader: 59 Class: ELFCLASS64 60 Data: ELFDATA2LSB 61 Type: ET_REL 62 Machine: EM_X86_64 63Sections: 64 - Name: .text 65 Type: SHT_PROGBITS 66 Content: '00' 67 - Name: .foo 68 Type: SHT_PROGBITS 69 ShName: 0xFEFEFEFE 70 - Name: .rel.text 71 Type: [[TYPE=SHT_REL]] 72 Info: .text 73 Relocations: 74## Case 1: There is no symbol with index 0xFEFEFEFE. 75 - Symbol: 0xFEFEFEFE 76 Type: R_X86_64_NONE 77 - Symbol: 0xFEFEFEFE 78 Type: R_X86_64_NONE 79## Case 2: Test that no warning is reported for a relocation against a symbol with index 0. 80 - Offset: 0x2 81 Symbol: 0 82 Type: R_X86_64_NONE 83## Case 3: Test a relocation against a named section symbol that has an invalid 84## section index (larger than the number of sections). 85 - Offset: 0x3 86 Symbol: .sec.symbol1 87 Type: R_X86_64_NONE 88## Case 4: Test a relocation against an unnamed section symbol that has an invalid 89## section index (larger than the number of sections). 90 - Offset: 0x4 91 Symbol: 4 92 Type: R_X86_64_NONE 93## Case 4: Test a relocation against a named section symbol with a section with an invalid 94## sh_name offset that goes past the end of the section name string table. 95 - Offset: 0x5 96 Symbol: .sec.symbol2 97 Type: R_X86_64_NONE 98## Case 5: Test a relocation against an unnamed section symbol with a section with an invalid 99## sh_name offset that goes past the end of the section name string table. 100 - Offset: 0x6 101 Symbol: 5 102 Type: R_X86_64_NONE 103## Case 6: Test a relocation in a section that is linked to a symbol table that 104## has a section type that is neither SHT_SYMTAB nor SHT_DYNSYM. 105## In this case the code fails to find a corresponding symbol string table. 106 - Name: .rela.text 107 Type: SHT_RELA 108 Info: .text 109 Link: .fake.symtab 110 Relocations: 111 - Offset: 0x7 112 Symbol: symbol 113 Type: R_X86_64_NONE 114 - Name: .fake.symtab 115 Type: SHT_PROGBITS 116 EntSize: 24 117 Size: 48 118Symbols: 119 - Name: symbol 120 Section: .text 121 Value: 0 122 - Name: .sec.symbol1 123 Type: STT_SECTION 124 Index: 0xFF 125 - Name: .sec.symbol2 126 Type: STT_SECTION 127 Index: 0x2 128 - Type: STT_SECTION 129 Index: 0xFF 130 - Type: STT_SECTION 131 Index: 0x2 132