blob: 823e573a297696fbcb55a81c8df94e3a6d823f8d [file] [log] [blame]
## Show that the value field is omitted when a relocation does not reference a symbol.
## In other cases, particularly when a symbol has a zero value or when it has an empty
## name, we print it. Test for both static and dynamic relocation printing.
# RUN: yaml2obj %s -o %t
# RUN: llvm-readelf --relocations --dyn-relocations %t 2>&1 | FileCheck %s -DFILE=%t
# RUN: llvm-readobj --relocations %t 2>&1 | FileCheck %s -DFILE=%t --check-prefix=LLVM
# CHECK: Relocation section '.rela.text' at offset {{.*}} contains 5 entries:
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 <null> + 456
# CHECK-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 <?> + 678
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 <null> + 2
# CHECK: Relocation section '.rela.dyn' at offset {{.*}} contains 5 entries:
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 <null> + 456
# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 <?> + 678
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 <null> + 2
# CHECK: 'RELA' relocation section at offset {{.*}} contains 120 bytes:
# CHECK-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend
# CHECK-NEXT: 0000000000000000 0000000000000000 R_X86_64_NONE 1
# CHECK-NEXT: 0000000000000000 0000000100000000 R_X86_64_NONE 0000000000000000 sym + 1
# CHECK-NEXT: 0000000000000000 0000000200000000 R_X86_64_NONE 0000000000000123 <null> + 456
# CHECK-NEXT: 0000000000000000 0000000300000000 R_X86_64_NONE 0000000000000000 <null> + 678
# CHECK-NEXT: 0000000000000000 0000000400000000 R_X86_64_NONE 0000000000000000 <null> + 2
# LLVM: Relocations [
# LLVM-NEXT: Section (2) .rela.text {
# LLVM-NEXT: 0x0 R_X86_64_NONE - 0x1
# LLVM-NEXT: 0x0 R_X86_64_NONE sym 0x1
# LLVM-NEXT: 0x0 R_X86_64_NONE <null> 0x456
# LLVM-NEXT: warning: '[[FILE]]': unable to get section index for symbol with st_shndx = 0x0 (SHN_UNDEF)
# LLVM-NEXT: 0x0 R_X86_64_NONE <?> 0x678
# LLVM-NEXT: 0x0 R_X86_64_NONE <null> 0x2
# LLVM-NEXT: }
# LLVM-NEXT: Section (4) .rela.dyn {
# LLVM-NEXT: 0x0 R_X86_64_NONE - 0x1
# LLVM-NEXT: 0x0 R_X86_64_NONE sym 0x1
# LLVM-NEXT: 0x0 R_X86_64_NONE <null> 0x456
# LLVM-NEXT: 0x0 R_X86_64_NONE <?> 0x678
# LLVM-NEXT: 0x0 R_X86_64_NONE <null> 0x2
# LLVM-NEXT: }
# LLVM-NEXT: ]
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Size: 0x10
- Name: .rela.text
Type: SHT_RELA
Link: .symtab
Info: .text
Relocations:
- Offset: 0
Type: R_X86_64_NONE
Addend: 1
- Offset: 0
Type: R_X86_64_NONE
Addend: 1
Symbol: sym
- Offset: 0
Type: R_X86_64_NONE
Addend: 0x456
Symbol: 2
- Offset: 0
Addend: 0x678
Type: R_X86_64_NONE
Symbol: 3
## References a symbol with a zero value and an empty name.
- Offset: 0
Type: R_X86_64_NONE
Addend: 2
Symbol: 4
- Name: .dynamic
Type: SHT_DYNAMIC
Flags: [SHF_ALLOC]
Address: 0x1000
AddressAlign: 0x1000
Entries:
- Tag: DT_RELA
Value: 0x1100
- Tag: DT_RELASZ
Value: 120
- Tag: DT_RELAENT
Value: 24
- Tag: DT_NULL
Value: 0
- Name: .rela.dyn
Type: SHT_RELA
Flags: [SHF_ALLOC]
Info: .text
Address: 0x1100
AddressAlign: 0x100
Relocations:
- Offset: 0
Type: R_X86_64_NONE
Addend: 1
- Offset: 0
Type: R_X86_64_NONE
Addend: 1
Symbol: sym
- Offset: 0
Type: R_X86_64_NONE
Addend: 0x456
Symbol: 2
- Offset: 0
Addend: 0x678
Type: R_X86_64_NONE
Symbol: 3
## References a symbol with a zero value and an empty name.
- Offset: 0
Type: R_X86_64_NONE
Addend: 2
Symbol: 4
Symbols:
- Name: sym
Value: 0
Section: .text
Binding: STB_GLOBAL
- Value: 0x123
Section: .text
Binding: STB_GLOBAL
- Type: STT_SECTION
Index: 0
- Value: 0x0
Section: .text
Binding: STB_GLOBAL
DynamicSymbols:
- Name: sym
Value: 0
Section: .text
Binding: STB_GLOBAL
- Value: 0x123
Section: .text
Binding: STB_GLOBAL
- Type: STT_SECTION
Index: 0
- Value: 0x0
Section: .text
Binding: STB_GLOBAL
ProgramHeaders:
- Type: PT_LOAD
VAddr: 0x1000
FirstSec: .dynamic
LastSec: .rela.dyn
- Type: PT_DYNAMIC
VAddr: 0x1000
FirstSec: .dynamic
LastSec: .dynamic