10b511c23SGeorgii Rymar## Check how we report warnings when dumping an object with broken relocations.
20b511c23SGeorgii Rymar
30b511c23SGeorgii Rymar# RUN: yaml2obj %s -o %t64
40b511c23SGeorgii Rymar# RUN: llvm-readobj --relocations %t64 2>&1 | FileCheck %s -DFILE=%t64 --check-prefix=LLVM
50b511c23SGeorgii Rymar# RUN: llvm-readelf --relocations %t64 2>&1 | FileCheck %s -DFILE=%t64 --check-prefix=GNU
60b511c23SGeorgii Rymar
70b511c23SGeorgii Rymar# LLVM:      Relocations [
80b511c23SGeorgii Rymar# LLVM-NEXT:   Section (3) .rel.text {
9*a6db7cf1SGeorgii Rymar# 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)
108590b5ccSGeorgii Rymar# 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)
1198a42898SGeorgii Rymar# LLVM-NEXT:     0x2 R_X86_64_NONE -{{$}}
1298a42898SGeorgii Rymar# LLVM-NEXT:     0x3 R_X86_64_NONE .sec.symbol1{{$}}
13d4035af2SGeorgii Rymar# LLVM-NEXT: warning: '[[FILE]]': invalid section index: 255
1498a42898SGeorgii Rymar# LLVM-NEXT:     0x4 R_X86_64_NONE <section 255>{{$}}
1598a42898SGeorgii Rymar# LLVM-NEXT:     0x5 R_X86_64_NONE .sec.symbol2{{$}}
16d4035af2SGeorgii Rymar# 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
1798a42898SGeorgii Rymar# LLVM-NEXT:     0x6 R_X86_64_NONE <section 2>{{$}}
180b511c23SGeorgii Rymar# LLVM-NEXT:   }
190b511c23SGeorgii Rymar# LLVM-NEXT:   Section (4) .rela.text {
20*a6db7cf1SGeorgii Rymar# 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
210b511c23SGeorgii Rymar# LLVM-NEXT:   }
220b511c23SGeorgii Rymar# LLVM-NEXT: ]
230b511c23SGeorgii Rymar
24d4035af2SGeorgii Rymar# GNU:       Relocation section '.rel.text' at offset 0x41 contains 7 entries:
250b511c23SGeorgii Rymar# GNU-NEXT:      Offset             Info             Type               Symbol's Value  Symbol's Name
26*a6db7cf1SGeorgii Rymar# 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)
278590b5ccSGeorgii Rymar# 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)
280b511c23SGeorgii Rymar# GNU-NEXT:  0000000000000002  0000000000000000 R_X86_64_NONE
29d4035af2SGeorgii Rymar# GNU-NEXT:  0000000000000003  0000000200000000 R_X86_64_NONE 0000000000000000 .sec.symbol1
30d4035af2SGeorgii Rymar# GNU-NEXT:  warning: '[[FILE]]': invalid section index: 255
31d4035af2SGeorgii Rymar# GNU-NEXT:  0000000000000004  0000000400000000 R_X86_64_NONE 0000000000000000 <section 255>
32d4035af2SGeorgii Rymar# GNU-NEXT:  0000000000000005  0000000300000000 R_X86_64_NONE 0000000000000000 .sec.symbol2
33d4035af2SGeorgii Rymar# 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
34d4035af2SGeorgii Rymar# GNU-NEXT:  0000000000000006  0000000500000000 R_X86_64_NONE 0000000000000000 <section 2>
350b511c23SGeorgii Rymar# GNU-EMPTY:
36d4035af2SGeorgii Rymar# GNU-NEXT:  Relocation section '.rela.text' at offset 0xb1 contains 1 entries:
370b511c23SGeorgii Rymar# GNU-NEXT:      Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
38*a6db7cf1SGeorgii Rymar# 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
390b511c23SGeorgii Rymar
400b511c23SGeorgii Rymar--- !ELF
410b511c23SGeorgii RymarFileHeader:
420b511c23SGeorgii Rymar  Class:   ELFCLASS64
430b511c23SGeorgii Rymar  Data:    ELFDATA2LSB
440b511c23SGeorgii Rymar  Type:    ET_REL
450b511c23SGeorgii Rymar  Machine: EM_X86_64
460b511c23SGeorgii RymarSections:
470b511c23SGeorgii Rymar  - Name:    .text
480b511c23SGeorgii Rymar    Type:    SHT_PROGBITS
490b511c23SGeorgii Rymar    Content: '00'
500b511c23SGeorgii Rymar  - Name:   .foo
510b511c23SGeorgii Rymar    Type:   SHT_PROGBITS
520b511c23SGeorgii Rymar    ShName: 0xFEFEFEFE
530b511c23SGeorgii Rymar  - Name: .rel.text
540b511c23SGeorgii Rymar    Type: SHT_REL
550b511c23SGeorgii Rymar    Info: .text
560b511c23SGeorgii Rymar    Relocations:
570b511c23SGeorgii Rymar## Case 1: There is no symbol with index 0xFEFEFEFE.
58e4ceb8f4SGeorgii Rymar      - Symbol: 0xFEFEFEFE
590b511c23SGeorgii Rymar        Type:   R_X86_64_NONE
60e4ceb8f4SGeorgii Rymar      - Symbol: 0xFEFEFEFE
610b511c23SGeorgii Rymar        Type:   R_X86_64_NONE
620b511c23SGeorgii Rymar## Case 2: Test that no warning is reported for a relocation against a symbol with index 0.
630b511c23SGeorgii Rymar      - Offset: 0x2
640b511c23SGeorgii Rymar        Symbol: 0
650b511c23SGeorgii Rymar        Type:   R_X86_64_NONE
66d4035af2SGeorgii Rymar## Case 3: Test a relocation against a named section symbol that has an invalid
670b511c23SGeorgii Rymar##         section index (larger than the number of sections).
680b511c23SGeorgii Rymar      - Offset: 0x3
690b511c23SGeorgii Rymar        Symbol: .sec.symbol1
700b511c23SGeorgii Rymar        Type:   R_X86_64_NONE
71d4035af2SGeorgii Rymar## Case 4: Test a relocation against an unnamed section symbol that has an invalid
72d4035af2SGeorgii Rymar##         section index (larger than the number of sections).
730b511c23SGeorgii Rymar      - Offset: 0x4
74d4035af2SGeorgii Rymar        Symbol: 4
75d4035af2SGeorgii Rymar        Type:   R_X86_64_NONE
76d4035af2SGeorgii Rymar## Case 4: Test a relocation against a named section symbol with a section with an invalid
77d4035af2SGeorgii Rymar##         sh_name offset that goes past the end of the section name string table.
78d4035af2SGeorgii Rymar      - Offset: 0x5
790b511c23SGeorgii Rymar        Symbol: .sec.symbol2
800b511c23SGeorgii Rymar        Type:   R_X86_64_NONE
81d4035af2SGeorgii Rymar## Case 5: Test a relocation against an unnamed section symbol with a section with an invalid
82d4035af2SGeorgii Rymar##         sh_name offset that goes past the end of the section name string table.
83d4035af2SGeorgii Rymar      - Offset: 0x6
84d4035af2SGeorgii Rymar        Symbol: 5
85d4035af2SGeorgii Rymar        Type:   R_X86_64_NONE
86d4035af2SGeorgii Rymar## Case 6: Test a relocation in a section that is linked to a symbol table that
870b511c23SGeorgii Rymar##         has a section type that is neither SHT_SYMTAB nor SHT_DYNSYM.
880b511c23SGeorgii Rymar##         In this case the code fails to find a corresponding symbol string table.
890b511c23SGeorgii Rymar  - Name: .rela.text
900b511c23SGeorgii Rymar    Type: SHT_RELA
910b511c23SGeorgii Rymar    Info: .text
920b511c23SGeorgii Rymar    Link: .fake.symtab
930b511c23SGeorgii Rymar    Relocations:
94d4035af2SGeorgii Rymar      - Offset: 0x7
950b511c23SGeorgii Rymar        Symbol: symbol
960b511c23SGeorgii Rymar        Type:   R_X86_64_NONE
970b511c23SGeorgii Rymar  - Name:    .fake.symtab
980b511c23SGeorgii Rymar    Type:    SHT_PROGBITS
990b511c23SGeorgii Rymar    EntSize: 24
1000b511c23SGeorgii Rymar    Size:    48
1010b511c23SGeorgii RymarSymbols:
1020b511c23SGeorgii Rymar  - Name:    symbol
1030b511c23SGeorgii Rymar    Section: .text
1040b511c23SGeorgii Rymar    Value:   0
1050b511c23SGeorgii Rymar  - Name:  .sec.symbol1
1060b511c23SGeorgii Rymar    Type:  STT_SECTION
1070b511c23SGeorgii Rymar    Index: 0xFF
1080b511c23SGeorgii Rymar  - Name:  .sec.symbol2
1090b511c23SGeorgii Rymar    Type:  STT_SECTION
1100b511c23SGeorgii Rymar    Index: 0x2
111d4035af2SGeorgii Rymar  - Type:  STT_SECTION
112d4035af2SGeorgii Rymar    Index: 0xFF
113d4035af2SGeorgii Rymar  - Type:  STT_SECTION
114d4035af2SGeorgii Rymar    Index: 0x2
115