1## This is a test to test how SHT_RELR sections are dumped. 2 3# RUN: yaml2obj --docnum=1 %s -o %t1 4# RUN: llvm-readobj --relocations %t1 | \ 5# RUN: FileCheck --match-full-lines --check-prefix=LLVM1 %s 6 7# LLVM1: Section (1) .relr.dyn { 8# LLVM1-NEXT: 0x10D60 R_X86_64_RELATIVE - 9# LLVM1-NEXT: 0x10D68 R_X86_64_RELATIVE - 10# LLVM1-NEXT: 0x10DA0 R_X86_64_RELATIVE - 11# LLVM1-NEXT: 0x20000 R_X86_64_RELATIVE - 12# LLVM1-NEXT: 0x20040 R_X86_64_RELATIVE - 13# LLVM1-NEXT: 0x20050 R_X86_64_RELATIVE - 14# LLVM1-NEXT: 0x20080 R_X86_64_RELATIVE - 15# LLVM1-NEXT: 0x20088 R_X86_64_RELATIVE - 16# LLVM1-NEXT: 0x20090 R_X86_64_RELATIVE - 17# LLVM1-NEXT: 0x20098 R_X86_64_RELATIVE - 18# LLVM1-NEXT: 0x20210 R_X86_64_RELATIVE - 19# LLVM1-NEXT: 0x202A8 R_X86_64_RELATIVE - 20# LLVM1-NEXT: 0x202D8 R_X86_64_RELATIVE - 21# LLVM1-NEXT: 0x202E8 R_X86_64_RELATIVE - 22# LLVM1-NEXT: 0x202F8 R_X86_64_RELATIVE - 23# LLVM1-NEXT: 0x20308 R_X86_64_RELATIVE - 24# LLVM1-NEXT: 0x20358 R_X86_64_RELATIVE - 25# LLVM1-NEXT: 0x20360 R_X86_64_RELATIVE - 26# LLVM1-NEXT: 0x20368 R_X86_64_RELATIVE - 27# LLVM1-NEXT: 0x20380 R_X86_64_RELATIVE - 28# LLVM1-NEXT: 0x20390 R_X86_64_RELATIVE - 29# LLVM1-NEXT: } 30 31# RUN: llvm-readelf --relocations %t1 | FileCheck --check-prefix=GNU1 --match-full-lines --strict-whitespace %s 32# GNU1:Relocation section '.relr.dyn' at offset 0x40 contains 21 entries: 33# GNU1-NEXT:Index: Entry Address Symbolic Address 34# GNU1-NEXT:0000: 0000000000010d60 0000000000010d60 35# GNU1-NEXT:0001: 0000000000000103 0000000000010d68 36# GNU1-NEXT: 0000000000010da0 base + 0x30 37# GNU1-NEXT:0002: 0000000000020000 0000000000020000 foo 38# GNU1-NEXT:0003: 00000000000f0501 0000000000020040 foo + 0x40 39# GNU1-NEXT: 0000000000020050 foo + 0x50 40# GNU1-NEXT: 0000000000020080 foo + 0x80 41# GNU1-NEXT: 0000000000020088 foo + 0x88 42# GNU1-NEXT: 0000000000020090 foo + 0x90 43# GNU1-NEXT: 0000000000020098 foo + 0x98 44# GNU1-NEXT:0004: 000a700550400009 0000000000020210 bar + 0x10 45# GNU1-NEXT: 00000000000202a8 bar + 0xa8 46# GNU1-NEXT: 00000000000202d8 bar + 0xd8 47# GNU1-NEXT: 00000000000202e8 bar + 0xe8 48# GNU1-NEXT: 00000000000202f8 bar + 0xf8 49# GNU1-NEXT: 0000000000020308 bar + 0x108 50# GNU1-NEXT: 0000000000020358 bar + 0x158 51# GNU1-NEXT: 0000000000020360 bar + 0x160 52# GNU1-NEXT: 0000000000020368 bar + 0x168 53# GNU1-NEXT: 0000000000020380 bar + 0x180 54# GNU1-NEXT: 0000000000020390 bar + 0x190 55# GNU1-NOT:{{.}} 56 57## The addresses are not symbolized in the absence of .symtab. 58# RUN: llvm-objcopy --strip-all %t1 %t1.stripped 59# RUN: llvm-readelf --relocations %t1.stripped | FileCheck --check-prefix=GNU1S --match-full-lines --strict-whitespace %s 60# GNU1S:Relocation section '.relr.dyn' at offset 0x40 contains 21 entries: 61# GNU1S-NEXT:Index: Entry Address Symbolic Address 62# GNU1S-NEXT:0000: 0000000000010d60 0000000000010d60 63# GNU1S-NEXT:0001: 0000000000000103 0000000000010d68 64 65--- !ELF 66FileHeader: 67 Class: ELFCLASS64 68 Data: ELFDATA2LSB 69 Type: ET_DYN 70 Machine: EM_X86_64 71Sections: 72 - Name: .relr.dyn 73 Type: SHT_RELR 74 Flags: [ SHF_ALLOC ] 75 Entries: [ 0x0000000000010D60, 0x0000000000000103, 0x0000000000020000, 76 0x00000000000F0501, 0x000A700550400009 ] 77Symbols: 78 - Name: bar 79 Value: 0x20200 80 Section: .relr.dyn 81 - Name: foo 82 Value: 0x20000 83 Section: .relr.dyn 84 - Name: base 85 Value: 0x10d70 86 Section: .relr.dyn 87 - Name: ignored 88 Value: 0x20210 89 90# RUN: yaml2obj --docnum=2 %s -o %t2 91# RUN: llvm-readobj --relocations %t2 | \ 92# RUN: FileCheck --match-full-lines --check-prefix=LLVM2 %s 93 94# LLVM2: Section (1) .relr.dyn { 95# LLVM2-NEXT: 0x10D60 R_386_RELATIVE - 96# LLVM2-NEXT: 0x10D64 R_386_RELATIVE - 97# LLVM2-NEXT: 0x10D80 R_386_RELATIVE - 98# LLVM2-NEXT: 0x20000 R_386_RELATIVE - 99# LLVM2-NEXT: 0x20020 R_386_RELATIVE - 100# LLVM2-NEXT: 0x20028 R_386_RELATIVE - 101# LLVM2-NEXT: 0x20040 R_386_RELATIVE - 102# LLVM2-NEXT: 0x20044 R_386_RELATIVE - 103# LLVM2-NEXT: 0x20048 R_386_RELATIVE - 104# LLVM2-NEXT: 0x2004C R_386_RELATIVE - 105# LLVM2-NEXT: 0x20088 R_386_RELATIVE - 106# LLVM2-NEXT: 0x200D4 R_386_RELATIVE - 107# LLVM2-NEXT: 0x200EC R_386_RELATIVE - 108# LLVM2-NEXT: 0x200F4 R_386_RELATIVE - 109# LLVM2-NEXT: } 110 111# RUN: llvm-readelf --relocations %t2 | FileCheck --check-prefix=GNU2 --match-full-lines --strict-whitespace %s 112# GNU2:Relocation section '.relr.dyn' at offset 0x34 contains 14 entries: 113# GNU2-NEXT:Index: Entry Address Symbolic Address 114# GNU2-NEXT:0000: 00010d60 00010d60 .relr.dyn 115# GNU2-NEXT:0001: 00000103 00010d64 .relr.dyn + 0x4 116# GNU2-NEXT: 00010d80 .relr.dyn + 0x20 117# GNU2-NEXT:0002: 00020000 00020000 .relr.dyn + 0xf2a0 118# GNU2-NEXT:0003: 000f0501 00020020 .relr.dyn + 0xf2c0 119# GNU2-NEXT: 00020028 .relr.dyn + 0xf2c8 120# GNU2-NEXT: 00020040 .relr.dyn + 0xf2e0 121# GNU2-NEXT: 00020044 .relr.dyn + 0xf2e4 122# GNU2-NEXT: 00020048 .relr.dyn + 0xf2e8 123# GNU2-NEXT: 0002004c .relr.dyn + 0xf2ec 124# GNU2-NEXT:0004: 50400009 00020088 .relr.dyn + 0xf328 125# GNU2-NEXT: 000200d4 .relr.dyn + 0xf374 126# GNU2-NEXT: 000200ec .relr.dyn + 0xf38c 127# GNU2-NEXT: 000200f4 .relr.dyn + 0xf394 128# GNU2-NOT:{{.}} 129 130--- !ELF 131FileHeader: 132 Class: ELFCLASS32 133 Data: ELFDATA2LSB 134 Type: ET_DYN 135 Machine: EM_386 136Sections: 137 - Name: .relr.dyn 138 Type: SHT_RELR 139 Flags: [ SHF_ALLOC ] 140 Entries: [ 0x00010D60, 0x00000103, 0x00020000, 141 0x000F0501, 0x50400009 ] 142 EntSize: [[ENTSIZE=<none>]] 143 ShType: [[SHTYPE=<none>]] 144 Link: [[LINK=<none>]] 145Symbols: 146 - Name: .relr.dyn 147 Type: STT_SECTION 148 Value: 0x10D60 149 Section: .relr.dyn 150 151## Check we report a warning when we are unable to dump relocations 152## for a SHT_RELR/SHT_ANDROID_RELR/SHT_AARCH64_AUTH_RELR section. 153 154## Case A: check the case when relocations can't be read from an SHT_RELR section. 155# RUN: yaml2obj --docnum=2 -DENTSIZE=1 %s -o %t2.broken 156# RUN: llvm-readobj --relocations %t2.broken 2>&1 | \ 157# RUN: FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-LLVM %s -DSECNAME=SHT_RELR 158# RUN: llvm-readelf --relocations %t2.broken 2>&1 | \ 159# RUN: FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-GNU %s -DSECNAME=SHT_RELR 160 161# BROKEN-LLVM: Relocations [ 162# BROKEN-LLVM-NEXT: Section (1) .relr.dyn { 163# BROKEN-LLVM-NEXT: warning: '[[FILE]]': unable to read relocations from [[SECNAME]] section with index 1: section [index 1] has invalid sh_entsize: expected 4, but got 1 164# BROKEN-LLVM-NEXT: } 165# BROKEN-LLVM-NEXT: ] 166 167# BROKEN-GNU: warning: '[[FILE]]': unable to get the number of relocations in [[SECNAME]] section with index 1: section [index 1] has invalid sh_entsize: expected 4, but got 1 168# BROKEN-GNU: Relocation section '.relr.dyn' at offset 0x34 contains <?> entries: 169# BROKEN-GNU-NEXT: warning: '[[FILE]]': unable to read relocations from [[SECNAME]] section with index 1: section [index 1] has invalid sh_entsize: expected 4, but got 1 170 171## Case B: check the case when relocations can't be read from an SHT_ANDROID_RELR section. 172## SHT_ANDROID_RELR = 0x6fffff00. 173# RUN: yaml2obj --docnum=2 -DENTSIZE=1 -DSHTYPE=0x6fffff00 %s -o %t2.broken.android 174# RUN: llvm-readobj --relocations %t2.broken.android 2>&1 | \ 175# RUN: FileCheck -DFILE=%t2.broken.android --check-prefix=BROKEN-LLVM %s -DSECNAME=SHT_ANDROID_RELR 176# RUN: llvm-readelf --relocations %t2.broken.android 2>&1 | \ 177# RUN: FileCheck -DFILE=%t2.broken.android --check-prefix=BROKEN-GNU %s -DSECNAME=SHT_ANDROID_RELR 178 179## Case C: check the case when we have an SHT_AARCH64_AUTH_RELR section in non-AArch64 ELF. 180## SHT_AARCH64_AUTH_RELR = 0x70000004. 181# RUN: yaml2obj --docnum=2 -DENTSIZE=1 -DSHTYPE=0x70000004 %s -o %t2.broken.aarch64auth 182# RUN: llvm-readobj --relocations %t2.broken.aarch64auth 2>&1 | \ 183# RUN: FileCheck -DFILE=%t2.broken.aarch64auth --check-prefix=WRONGARCH-LLVM-AARCH64-AUTH %s -DSECNAME=SHT_AARCH64_AUTH_RELR 184# RUN: llvm-readelf --relocations %t2.broken.aarch64auth 2>&1 | \ 185# RUN: FileCheck -DFILE=%t2.broken.aarch64auth --check-prefix=WRONGARCH-GNU-AARCH64-AUTH %s -DSECNAME=SHT_AARCH64_AUTH_RELR 186 187# WRONGARCH-LLVM-AARCH64-AUTH: Relocations [ 188# WRONGARCH-LLVM-AARCH64-AUTH-NEXT: ] 189 190# WRONGARCH-GNU-AARCH64-AUTH-NOT: Relocation section 191 192## Check the behavior when the sh_link field of the SHT_RELR/SHT_ANDROID_RELR/SHT_AARCH64_AUTH_RELR section 193## is set to an arbitrary value. Normally, it is set to 0, because such sections contains 194## only relative relocations and do not have an associated symbol table, like other 195## relocation sections. 196 197## Check we do not report warnings when the sh_link field is set to an arbitrary value 198## and the --relocations option is requested. 199# RUN: yaml2obj --docnum=2 -DLINK=0xff %s -o %t2.has.link 200# RUN: llvm-readobj --relocations %t2.has.link 2>&1 | \ 201# RUN: FileCheck -DFILE=%t2.has.link --check-prefix=LLVM2 %s --implicit-check-not=warning: 202# RUN: llvm-readelf --relocations %t2.has.link 2>&1 | \ 203# RUN: FileCheck -DFILE=%t2.has.link --check-prefix=GNU2 %s --implicit-check-not=warning: 204 205## .symtab is invalid. Check we report a warning and print entries without symbolization. 206# RUN: yaml2obj --docnum=3 -DENTSIZE=1 %s -o %t3.err1 207# RUN: llvm-readelf -r %t3.err1 2>&1 | FileCheck -DFILE=%t3.err1 --check-prefixes=GNU3,GNU3-ERR1 --match-full-lines %s 208# RUN: yaml2obj --docnum=3 -DLINK=0xff %s -o %t3.err2 209# RUN: llvm-readelf -r %t3.err2 2>&1 | FileCheck -DFILE=%t3.err2 --check-prefixes=GNU3,GNU3-ERR2 --match-full-lines %s 210 211# GNU3:Index: Entry Address Symbolic Address 212# GNU3-ERR1-NEXT:{{.*}}warning: '[[FILE]]': unable to read symbols from the SHT_SYMTAB section: section [index 2] has invalid sh_entsize: expected 24, but got 1 213# GNU3-ERR2-NEXT:{{.*}}warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255 214# GNU3-NEXT:0000: 0000000000010d60 0000000000010d60 215# GNU3-NEXT:0001: 0000000000000103 0000000000010d68 216# GNU3-NEXT: 0000000000010da0 217# GNU3-NOT:{{.}} 218 219--- !ELF 220FileHeader: 221 Class: ELFCLASS64 222 Data: ELFDATA2LSB 223 Type: ET_DYN 224 Machine: EM_X86_64 225Sections: 226 - Name: .relr.dyn 227 Type: SHT_RELR 228 Flags: [ SHF_ALLOC ] 229 Entries: [ 0x0000000000010D60, 0x0000000000000103 ] 230 - Name: .symtab 231 Type: SHT_SYMTAB 232 Link: [[LINK=.strtab]] 233 EntSize: [[ENTSIZE=0x18]] 234Symbols: 235 - Name: bar 236 Value: 0x10D60 237