Files
clang-p2996/llvm/test/tools/llvm-readobj/ELF/relocation-errors.test
Fangrui Song 1b704e889f [MC,llvm-readobj,yaml2obj] Support CREL relocation format
CREL is a compact relocation format for the ELF object file format.

This patch adds integrated assembler support (using the RELA form)
available with `llvm-mc -filetype=obj -crel a.s -o a.o`.
A dependent patch will add `clang -c -Wa,--crel,--allow-experimental-crel`.

Also add llvm-readobj support (for both REL and RELA forms) to
facilitate testing the assembler. Additionally, yaml2obj gains support
for the RELA form to aid testing with llvm-readobj.

We temporarily assign the section type code 0x40000020 from the generic
range to `SHT_CREL`. We avoided using `SHT_LLVM_` or `SHT_GNU_` to
avoid code churn and maintain broader applicability for interested psABIs.
Similarly, `DT_CREL` is temporarily 0x40000026.

LLVM will change the code and break compatibility. This is not an issue
if all relocatable files using CREL are regenerated (aka no prebuilt
relocatable files).

Link: https://discourse.llvm.org/t/rfc-crel-a-compact-relocation-format-for-elf/77600

Pull Request: https://github.com/llvm/llvm-project/pull/91280
2024-07-01 10:32:02 -07:00

132 lines
7.8 KiB
Plaintext

## Check how we report warnings when dumping an object with broken relocations.
# RUN: yaml2obj %s -o %t64
# RUN: llvm-readobj --relocations %t64 2>&1 | FileCheck %s -DFILE=%t64 --check-prefix=LLVM
# RUN: llvm-readelf --relocations %t64 2>&1 | FileCheck %s -DFILE=%t64 --check-prefix=GNU
# LLVM: Relocations [
# LLVM-NEXT: Section (3) .rel.text {
# 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)
# 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)
# LLVM-NEXT: 0x2 R_X86_64_NONE -{{$}}
# LLVM-NEXT: 0x3 R_X86_64_NONE .sec.symbol1{{$}}
# LLVM-NEXT: warning: '[[FILE]]': invalid section index: 255
# LLVM-NEXT: 0x4 R_X86_64_NONE <section 255>{{$}}
# LLVM-NEXT: 0x5 R_X86_64_NONE .sec.symbol2{{$}}
# 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
# LLVM-NEXT: 0x6 R_X86_64_NONE <section 2>{{$}}
# LLVM-NEXT: }
# LLVM-NEXT: Section (4) .rela.text {
# 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
# LLVM-NEXT: }
# LLVM-NEXT: ]
# GNU: Relocation section '.rel.text' at offset 0x41 contains 7 entries:
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name
# 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)
# 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)
# GNU-NEXT: 0000000000000002 0000000000000000 R_X86_64_NONE
# GNU-NEXT: 0000000000000003 0000000200000000 R_X86_64_NONE 0000000000000000 .sec.symbol1
# GNU-NEXT: warning: '[[FILE]]': invalid section index: 255
# GNU-NEXT: 0000000000000004 0000000400000000 R_X86_64_NONE 0000000000000000 <section 255>
# GNU-NEXT: 0000000000000005 0000000300000000 R_X86_64_NONE 0000000000000000 .sec.symbol2
# 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
# GNU-NEXT: 0000000000000006 0000000500000000 R_X86_64_NONE 0000000000000000 <section 2>
# GNU-EMPTY:
# GNU-NEXT: Relocation section '.rela.text' at offset 0xb1 contains 1 entries:
# GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# 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
# RUN: yaml2obj -DTYPE=SHT_CREL %s -o %t64.crel
# RUN: llvm-readelf --relocations %t64.crel 2>&1 | FileCheck %s -DFILE=%t64.crel --check-prefix=CREL-GNU
# CREL-GNU: Relocation section '.rel.text' at offset 0x41 contains 7 entries:
# CREL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# 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
# 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
# CREL-GNU-NEXT: 0000000000000002 0000000000000000 R_X86_64_NONE 0
# 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
# 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
# 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
# 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
# CREL-GNU-EMPTY:
# CREL-GNU-NEXT: Relocation section '.rela.text' at offset 0x5a contains 1 entries:
# CREL-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# 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
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Content: '00'
- Name: .foo
Type: SHT_PROGBITS
ShName: 0xFEFEFEFE
- Name: .rel.text
Type: [[TYPE=SHT_REL]]
Info: .text
Relocations:
## Case 1: There is no symbol with index 0xFEFEFEFE.
- Symbol: 0xFEFEFEFE
Type: R_X86_64_NONE
- Symbol: 0xFEFEFEFE
Type: R_X86_64_NONE
## Case 2: Test that no warning is reported for a relocation against a symbol with index 0.
- Offset: 0x2
Symbol: 0
Type: R_X86_64_NONE
## Case 3: Test a relocation against a named section symbol that has an invalid
## section index (larger than the number of sections).
- Offset: 0x3
Symbol: .sec.symbol1
Type: R_X86_64_NONE
## Case 4: Test a relocation against an unnamed section symbol that has an invalid
## section index (larger than the number of sections).
- Offset: 0x4
Symbol: 4
Type: R_X86_64_NONE
## Case 4: Test a relocation against a named section symbol with a section with an invalid
## sh_name offset that goes past the end of the section name string table.
- Offset: 0x5
Symbol: .sec.symbol2
Type: R_X86_64_NONE
## Case 5: Test a relocation against an unnamed section symbol with a section with an invalid
## sh_name offset that goes past the end of the section name string table.
- Offset: 0x6
Symbol: 5
Type: R_X86_64_NONE
## Case 6: Test a relocation in a section that is linked to a symbol table that
## has a section type that is neither SHT_SYMTAB nor SHT_DYNSYM.
## In this case the code fails to find a corresponding symbol string table.
- Name: .rela.text
Type: SHT_RELA
Info: .text
Link: .fake.symtab
Relocations:
- Offset: 0x7
Symbol: symbol
Type: R_X86_64_NONE
- Name: .fake.symtab
Type: SHT_PROGBITS
EntSize: 24
Size: 48
Symbols:
- Name: symbol
Section: .text
Value: 0
- Name: .sec.symbol1
Type: STT_SECTION
Index: 0xFF
- Name: .sec.symbol2
Type: STT_SECTION
Index: 0x2
- Type: STT_SECTION
Index: 0xFF
- Type: STT_SECTION
Index: 0x2