185 lines · plain
1## Test that we are able to print dynamic relocations with --dyn-relocations.2 3## Check what we print when there are no dynamic relocations in an object.4# RUN: yaml2obj --docnum=1 %s -o %t15# RUN: llvm-readobj --dyn-relocations %t1 2>&1 | FileCheck %s --check-prefix=LLVM-NONE6# RUN: llvm-readelf --dyn-relocations %t1 2>&1 | FileCheck %s --implicit-check-not={{.}} --allow-empty7 8# LLVM-NONE: Dynamic Relocations {9# LLVM-NONE-NEXT: }10# LLVM-NONE-NOT: {{.}}11 12--- !ELF13FileHeader:14 Class: ELFCLASS6415 Data: ELFDATA2LSB16 Type: ET_DYN17 18## Check that we dump all possbile dynamic relocation sections.19# RUN: yaml2obj --docnum=2 %s -o %t2.120# RUN: llvm-readobj --dyn-relocations %t2.1 2>&1 | \21# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix=LLVM-RELOCS22# RUN: llvm-readelf --dyn-relocations %t2.1 2>&1 | \23# RUN: FileCheck %s --implicit-check-not=warning: --strict-whitespace \24# RUN: --match-full-lines --check-prefixes=GNU-RELOCS,GNU-PLTREL25 26## 7 == DT_RELA.27# RUN: yaml2obj --docnum=2 %s -DDTPLTREL=7 -DPLTTYPE=SHT_RELA -DPLTRELSZ=0x18 -o %t2.228# RUN: llvm-readobj --dyn-relocations %t2.2 2>&1 | \29# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix=LLVM-RELOCS30# RUN: llvm-readelf --dyn-relocations %t2.2 2>&1 | \31# RUN: FileCheck %s --implicit-check-not=warning: --strict-whitespace \32# RUN: --match-full-lines --check-prefixes=GNU-RELOCS,GNU-PLTRELA33 34# LLVM-RELOCS: Dynamic Relocations {35# LLVM-RELOCS-NEXT: 0x8 R_X86_64_64 foo 0x036# LLVM-RELOCS-NEXT: 0x1 R_X86_64_NONE foo 0x037# LLVM-RELOCS-NEXT: 0x2 R_X86_64_NONE foo38# LLVM-RELOCS-NEXT: 0x4 R_X86_64_RELATIVE -39# LLVM-RELOCS-NEXT: 0x8 R_X86_64_NONE foo40# LLVM-RELOCS-NEXT: }41 42# GNU-RELOCS:'CREL' relocation section at offset 0xa8:43# GNU-RELOCS-NEXT: Offset Info Type Symbol's Value Symbol's Name44# GNU-RELOCS-NEXT:0000000000000008 0000000100000001 R_X86_64_64 0000000000000000 foo + 045# GNU-RELOCS-EMPTY:46# GNU-RELOCS:'RELA' relocation section at offset 0x78 contains 24 bytes:47# GNU-RELOCS-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend48# GNU-RELOCS-NEXT:0000000000000001 0000000100000000 R_X86_64_NONE 0000000000000000 foo + 049# GNU-RELOCS-EMPTY:50# GNU-RELOCS-NEXT:'REL' relocation section at offset 0x90 contains 16 bytes:51# GNU-RELOCS-NEXT: Offset Info Type Symbol's Value Symbol's Name52# GNU-RELOCS-NEXT:0000000000000002 0000000100000000 R_X86_64_NONE 0000000000000000 foo53# GNU-RELOCS-EMPTY:54# GNU-RELOCS-NEXT:'RELR' relocation section at offset 0xa0 contains 8 bytes:55# GNU-RELOCS-NEXT: Offset Info Type Symbol's Value Symbol's Name56# GNU-RELOCS-NEXT:0000000000000004 0000000000000008 R_X86_64_RELATIVE {{$}}57# GNU-RELOCS-EMPTY:58# GNU-PLTREL-NEXT:'PLT' relocation section at offset 0xac contains 16 bytes:59# GNU-PLTREL-NEXT: Offset Info Type Symbol's Value Symbol's Name60# GNU-PLTREL-NEXT:0000000000000008 0000000100000000 R_X86_64_NONE 0000000000000000 foo61# GNU-PLTRELA-NEXT:'PLT' relocation section at offset 0xac contains 24 bytes:62# GNU-PLTRELA-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend63# GNU-PLTRELA-NEXT:0000000000000008 0000000100000000 R_X86_64_NONE 0000000000000000 foo + 064# GNU-RELOCS-EMPTY:65# GNU-RELOCS-NOT:{{.}}66 67--- !ELF68FileHeader:69 Class: ELFCLASS6470 Data: ELFDATA2LSB71 Type: ET_DYN72 Machine: EM_X86_6473Sections:74 - Name: .rela.dyn75 Type: SHT_RELA76 Relocations:77 - Type: R_X86_64_NONE78 Offset: 0x179 Symbol: foo80 - Name: .rel.dyn81 Type: SHT_REL82 Relocations:83 - Type: R_X86_64_NONE84 Offset: 0x285 Symbol: foo86 - Name: .relr.dyn87 Type: SHT_RELR88 Flags: [ SHF_ALLOC ]89 Entries: [ 0x0000000000000004 ]90 - Name: .crel.dyn91 Type: SHT_CREL92 Relocations:93 - Type: R_X86_64_6494 Offset: 0x895 Symbol: foo96 - Name: .plt97 Type: [[PLTTYPE=SHT_REL]]98 Relocations:99 - Type: R_X86_64_NONE100 Offset: 0x8101 Symbol: foo102 - Name: .dynamic103 Type: SHT_DYNAMIC104 Entries:105 - Tag: DT_RELA106 Value: 0x0107 - Tag: DT_RELASZ108 Value: 0x18109 - Tag: DT_RELAENT110 Value: 0x18111## 0x18 == offset of .rel.dyn in the segment.112 - Tag: DT_REL113 Value: 0x18114 - Tag: DT_RELSZ115 Value: 0x10116 - Tag: DT_RELENT117 Value: 0x10118## 0x28 == offset of .relr.dyn section in the segment.119 - Tag: DT_RELR120 Value: 0x28121 - Tag: DT_RELRSZ122 Value: 0x8123 - Tag: DT_RELRENT124 Value: 0x8125## 0x30 == offset of .crel.dyn section in the segment.126 - Tag: DT_CREL127 Value: 0x30128## 0x34 == offset of .plt section in the segment.129 - Tag: DT_JMPREL130 Value: 0x34131 - Tag: DT_PLTREL132 Value: [[DTPLTREL=17]] ## 17 == DT_REL133 - Tag: DT_PLTRELSZ134 Value: [[PLTRELSZ=0x10]]135 - Tag: DT_NULL136 Value: 0x0137Symbols:138 - Name: foo139DynamicSymbols:140 - Name: foo141ProgramHeaders:142 - Type: PT_LOAD143 FirstSec: .rela.dyn144 LastSec: .dynamic145 146## Check we report a warning when the value of the DT_PLTREL dynamic tag is invalid.147## We currently accept DT_RELA(7) and DT_REL(17) values. This test case uses 0xff.148 149# RUN: yaml2obj --docnum=2 %s -DDTPLTREL=0xFF -o %t3150# RUN: llvm-readobj --dyn-relocations %t3 2>&1 | \151# RUN: FileCheck %s -DFILE=%t3 --implicit-check-not=warning: --check-prefix=PLTRELUNKNOWN-LLVM152# RUN: llvm-readelf --dyn-relocations %t3 2>&1 | \153# RUN: FileCheck %s -DFILE=%t3 --implicit-check-not=warning: --check-prefix=PLTRELUNKNOWN-GNU154 155# PLTRELUNKNOWN-LLVM: warning: '[[FILE]]': unknown DT_PLTREL value of 255156# PLTRELUNKNOWN-LLVM: Dynamic Relocations {157# PLTRELUNKNOWN-LLVM-NEXT: 0x8 R_X86_64_64 foo 0x0158# PLTRELUNKNOWN-LLVM-NEXT: 0x1 R_X86_64_NONE foo 0x0159# PLTRELUNKNOWN-LLVM-NEXT: 0x2 R_X86_64_NONE foo{{$}}160# PLTRELUNKNOWN-LLVM-NEXT: 0x4 R_X86_64_RELATIVE -{{$}}161# PLTRELUNKNOWN-LLVM-NEXT: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0x10) or PLTREL entry size (0x0)162# PLTRELUNKNOWN-LLVM-NEXT: }163 164# PLTRELUNKNOWN-GNU: warning: '[[FILE]]': unknown DT_PLTREL value of 255165# PLTRELUNKNOWN-GNU-EMPTY:166# PLTRELUNKNOWN-GNU-NEXT: 'CREL' relocation section at offset 0xa8:167# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name168# PLTRELUNKNOWN-GNU-NEXT: 0000000000000008 0000000100000001 R_X86_64_64 0000000000000000 foo + 0169# PLTRELUNKNOWN-GNU-EMPTY:170# PLTRELUNKNOWN-GNU-NEXT: 'RELA' relocation section at offset 0x78 contains 24 bytes:171# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name + Addend172# PLTRELUNKNOWN-GNU-NEXT: 0000000000000001 0000000100000000 R_X86_64_NONE 0000000000000000 foo + 0173# PLTRELUNKNOWN-GNU-EMPTY:174# PLTRELUNKNOWN-GNU-NEXT: 'REL' relocation section at offset 0x90 contains 16 bytes:175# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name176# PLTRELUNKNOWN-GNU-NEXT: 0000000000000002 0000000100000000 R_X86_64_NONE 0000000000000000 foo177# PLTRELUNKNOWN-GNU-EMPTY:178# PLTRELUNKNOWN-GNU-NEXT: 'RELR' relocation section at offset 0xa0 contains 8 bytes:179# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name180# PLTRELUNKNOWN-GNU-NEXT: 0000000000000004 0000000000000008 R_X86_64_RELATIVE181# PLTRELUNKNOWN-GNU-EMPTY:182# PLTRELUNKNOWN-GNU-NEXT: 'PLT' relocation section at offset 0xac contains 16 bytes:183# PLTRELUNKNOWN-GNU-NEXT: Offset Info Type Symbol's Value Symbol's Name184# PLTRELUNKNOWN-GNU-NEXT: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0x10) or PLTREL entry size (0x0)185