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 %t1 5# RUN: llvm-readobj --dyn-relocations %t1 2>&1 | FileCheck %s --check-prefix=LLVM-NONE 6# RUN: llvm-readelf --dyn-relocations %t1 2>&1 | FileCheck %s --implicit-check-not={{.}} --allow-empty 7 8# LLVM-NONE: Dynamic Relocations { 9# LLVM-NONE-NEXT: } 10# LLVM-NONE-NOT: {{.}} 11 12--- !ELF 13FileHeader: 14 Class: ELFCLASS64 15 Data: ELFDATA2LSB 16 Type: ET_DYN 17 18## Check that we dump all possbile dynamic relocation sections. 19# RUN: yaml2obj --docnum=2 %s -o %t2.1 20# RUN: llvm-readobj --dyn-relocations %t2.1 2>&1 | \ 21# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix=LLVM-RELOCS 22# 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-PLTREL 25 26## 7 == DT_RELA. 27# RUN: yaml2obj --docnum=2 %s -DDTPLTREL=7 -DPLTTYPE=SHT_RELA -DPLTRELSZ=0x18 -o %t2.2 28# RUN: llvm-readobj --dyn-relocations %t2.2 2>&1 | \ 29# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix=LLVM-RELOCS 30# 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-PLTRELA 33 34# LLVM-RELOCS: Dynamic Relocations { 35# LLVM-RELOCS-NEXT: 0x8 R_X86_64_64 foo 0x0 36# LLVM-RELOCS-NEXT: 0x1 R_X86_64_NONE foo 0x0 37# LLVM-RELOCS-NEXT: 0x2 R_X86_64_NONE foo 38# LLVM-RELOCS-NEXT: 0x4 R_X86_64_RELATIVE - 39# LLVM-RELOCS-NEXT: 0x8 R_X86_64_NONE foo 40# 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 Name 44# GNU-RELOCS-NEXT:0000000000000008 0000000100000001 R_X86_64_64 0000000000000000 foo + 0 45# 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 + Addend 48# GNU-RELOCS-NEXT:0000000000000001 0000000100000000 R_X86_64_NONE 0000000000000000 foo + 0 49# 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 Name 52# GNU-RELOCS-NEXT:0000000000000002 0000000100000000 R_X86_64_NONE 0000000000000000 foo 53# 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 Name 56# 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 Name 60# GNU-PLTREL-NEXT:0000000000000008 0000000100000000 R_X86_64_NONE 0000000000000000 foo 61# 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 + Addend 63# GNU-PLTRELA-NEXT:0000000000000008 0000000100000000 R_X86_64_NONE 0000000000000000 foo + 0 64# GNU-RELOCS-EMPTY: 65# GNU-RELOCS-NOT:{{.}} 66 67--- !ELF 68FileHeader: 69 Class: ELFCLASS64 70 Data: ELFDATA2LSB 71 Type: ET_DYN 72 Machine: EM_X86_64 73Sections: 74 - Name: .rela.dyn 75 Type: SHT_RELA 76 Relocations: 77 - Type: R_X86_64_NONE 78 Offset: 0x1 79 Symbol: foo 80 - Name: .rel.dyn 81 Type: SHT_REL 82 Relocations: 83 - Type: R_X86_64_NONE 84 Offset: 0x2 85 Symbol: foo 86 - Name: .relr.dyn 87 Type: SHT_RELR 88 Flags: [ SHF_ALLOC ] 89 Entries: [ 0x0000000000000004 ] 90 - Name: .crel.dyn 91 Type: SHT_CREL 92 Relocations: 93 - Type: R_X86_64_64 94 Offset: 0x8 95 Symbol: foo 96 - Name: .plt 97 Type: [[PLTTYPE=SHT_REL]] 98 Relocations: 99 - Type: R_X86_64_NONE 100 Offset: 0x8 101 Symbol: foo 102 - Name: .dynamic 103 Type: SHT_DYNAMIC 104 Entries: 105 - Tag: DT_RELA 106 Value: 0x0 107 - Tag: DT_RELASZ 108 Value: 0x18 109 - Tag: DT_RELAENT 110 Value: 0x18 111## 0x18 == offset of .rel.dyn in the segment. 112 - Tag: DT_REL 113 Value: 0x18 114 - Tag: DT_RELSZ 115 Value: 0x10 116 - Tag: DT_RELENT 117 Value: 0x10 118## 0x28 == offset of .relr.dyn section in the segment. 119 - Tag: DT_RELR 120 Value: 0x28 121 - Tag: DT_RELRSZ 122 Value: 0x8 123 - Tag: DT_RELRENT 124 Value: 0x8 125## 0x30 == offset of .crel.dyn section in the segment. 126 - Tag: DT_CREL 127 Value: 0x30 128## 0x34 == offset of .plt section in the segment. 129 - Tag: DT_JMPREL 130 Value: 0x34 131 - Tag: DT_PLTREL 132 Value: [[DTPLTREL=17]] ## 17 == DT_REL 133 - Tag: DT_PLTRELSZ 134 Value: [[PLTRELSZ=0x10]] 135 - Tag: DT_NULL 136 Value: 0x0 137Symbols: 138 - Name: foo 139DynamicSymbols: 140 - Name: foo 141ProgramHeaders: 142 - Type: PT_LOAD 143 FirstSec: .rela.dyn 144 LastSec: .dynamic 145 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 %t3 150# RUN: llvm-readobj --dyn-relocations %t3 2>&1 | \ 151# RUN: FileCheck %s -DFILE=%t3 --implicit-check-not=warning: --check-prefix=PLTRELUNKNOWN-LLVM 152# RUN: llvm-readelf --dyn-relocations %t3 2>&1 | \ 153# RUN: FileCheck %s -DFILE=%t3 --implicit-check-not=warning: --check-prefix=PLTRELUNKNOWN-GNU 154 155# PLTRELUNKNOWN-LLVM: warning: '[[FILE]]': unknown DT_PLTREL value of 255 156# PLTRELUNKNOWN-LLVM: Dynamic Relocations { 157# PLTRELUNKNOWN-LLVM-NEXT: 0x8 R_X86_64_64 foo 0x0 158# PLTRELUNKNOWN-LLVM-NEXT: 0x1 R_X86_64_NONE foo 0x0 159# 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 255 165# 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 Name 168# PLTRELUNKNOWN-GNU-NEXT: 0000000000000008 0000000100000001 R_X86_64_64 0000000000000000 foo + 0 169# 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 + Addend 172# PLTRELUNKNOWN-GNU-NEXT: 0000000000000001 0000000100000000 R_X86_64_NONE 0000000000000000 foo + 0 173# 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 Name 176# PLTRELUNKNOWN-GNU-NEXT: 0000000000000002 0000000100000000 R_X86_64_NONE 0000000000000000 foo 177# 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 Name 180# PLTRELUNKNOWN-GNU-NEXT: 0000000000000004 0000000000000008 R_X86_64_RELATIVE 181# 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 Name 184# PLTRELUNKNOWN-GNU-NEXT: warning: '[[FILE]]': invalid DT_PLTRELSZ value (0x10) or PLTREL entry size (0x0) 185