237 lines · plain
1## This is a test to test how SHT_RELR sections are dumped.2 3# RUN: yaml2obj --docnum=1 %s -o %t14# RUN: llvm-readobj --relocations %t1 | \5# RUN: FileCheck --match-full-lines --check-prefix=LLVM1 %s6 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 %s32# GNU1:Relocation section '.relr.dyn' at offset 0x40 contains 21 entries:33# GNU1-NEXT:Index: Entry Address Symbolic Address34# GNU1-NEXT:0000: 0000000000010d60 0000000000010d6035# GNU1-NEXT:0001: 0000000000000103 0000000000010d6836# GNU1-NEXT: 0000000000010da0 base + 0x3037# GNU1-NEXT:0002: 0000000000020000 0000000000020000 foo38# GNU1-NEXT:0003: 00000000000f0501 0000000000020040 foo + 0x4039# GNU1-NEXT: 0000000000020050 foo + 0x5040# GNU1-NEXT: 0000000000020080 foo + 0x8041# GNU1-NEXT: 0000000000020088 foo + 0x8842# GNU1-NEXT: 0000000000020090 foo + 0x9043# GNU1-NEXT: 0000000000020098 foo + 0x9844# GNU1-NEXT:0004: 000a700550400009 0000000000020210 bar + 0x1045# GNU1-NEXT: 00000000000202a8 bar + 0xa846# GNU1-NEXT: 00000000000202d8 bar + 0xd847# GNU1-NEXT: 00000000000202e8 bar + 0xe848# GNU1-NEXT: 00000000000202f8 bar + 0xf849# GNU1-NEXT: 0000000000020308 bar + 0x10850# GNU1-NEXT: 0000000000020358 bar + 0x15851# GNU1-NEXT: 0000000000020360 bar + 0x16052# GNU1-NEXT: 0000000000020368 bar + 0x16853# GNU1-NEXT: 0000000000020380 bar + 0x18054# GNU1-NEXT: 0000000000020390 bar + 0x19055# GNU1-NOT:{{.}}56 57## The addresses are not symbolized in the absence of .symtab.58# RUN: llvm-objcopy --strip-all %t1 %t1.stripped59# RUN: llvm-readelf --relocations %t1.stripped | FileCheck --check-prefix=GNU1S --match-full-lines --strict-whitespace %s60# GNU1S:Relocation section '.relr.dyn' at offset 0x40 contains 21 entries:61# GNU1S-NEXT:Index: Entry Address Symbolic Address62# GNU1S-NEXT:0000: 0000000000010d60 0000000000010d6063# GNU1S-NEXT:0001: 0000000000000103 0000000000010d6864 65--- !ELF66FileHeader:67 Class: ELFCLASS6468 Data: ELFDATA2LSB69 Type: ET_DYN70 Machine: EM_X86_6471Sections:72 - Name: .relr.dyn73 Type: SHT_RELR74 Flags: [ SHF_ALLOC ]75 Entries: [ 0x0000000000010D60, 0x0000000000000103, 0x0000000000020000,76 0x00000000000F0501, 0x000A700550400009 ]77Symbols:78 - Name: bar79 Value: 0x2020080 Section: .relr.dyn81 - Name: foo82 Value: 0x2000083 Section: .relr.dyn84 - Name: base85 Value: 0x10d7086 Section: .relr.dyn87 - Name: ignored88 Value: 0x2021089 90# RUN: yaml2obj --docnum=2 %s -o %t291# RUN: llvm-readobj --relocations %t2 | \92# RUN: FileCheck --match-full-lines --check-prefix=LLVM2 %s93 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 %s112# GNU2:Relocation section '.relr.dyn' at offset 0x34 contains 14 entries:113# GNU2-NEXT:Index: Entry Address Symbolic Address114# GNU2-NEXT:0000: 00010d60 00010d60 .relr.dyn115# GNU2-NEXT:0001: 00000103 00010d64 .relr.dyn + 0x4116# GNU2-NEXT: 00010d80 .relr.dyn + 0x20117# GNU2-NEXT:0002: 00020000 00020000 .relr.dyn + 0xf2a0118# GNU2-NEXT:0003: 000f0501 00020020 .relr.dyn + 0xf2c0119# GNU2-NEXT: 00020028 .relr.dyn + 0xf2c8120# GNU2-NEXT: 00020040 .relr.dyn + 0xf2e0121# GNU2-NEXT: 00020044 .relr.dyn + 0xf2e4122# GNU2-NEXT: 00020048 .relr.dyn + 0xf2e8123# GNU2-NEXT: 0002004c .relr.dyn + 0xf2ec124# GNU2-NEXT:0004: 50400009 00020088 .relr.dyn + 0xf328125# GNU2-NEXT: 000200d4 .relr.dyn + 0xf374126# GNU2-NEXT: 000200ec .relr.dyn + 0xf38c127# GNU2-NEXT: 000200f4 .relr.dyn + 0xf394128# GNU2-NOT:{{.}}129 130--- !ELF131FileHeader:132 Class: ELFCLASS32133 Data: ELFDATA2LSB134 Type: ET_DYN135 Machine: EM_386136Sections:137 - Name: .relr.dyn138 Type: SHT_RELR139 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.dyn147 Type: STT_SECTION148 Value: 0x10D60149 Section: .relr.dyn150 151## Check we report a warning when we are unable to dump relocations152## 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.broken156# RUN: llvm-readobj --relocations %t2.broken 2>&1 | \157# RUN: FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-LLVM %s -DSECNAME=SHT_RELR158# RUN: llvm-readelf --relocations %t2.broken 2>&1 | \159# RUN: FileCheck -DFILE=%t2.broken --check-prefix=BROKEN-GNU %s -DSECNAME=SHT_RELR160 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 1164# 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 1168# 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 1170 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.android174# RUN: llvm-readobj --relocations %t2.broken.android 2>&1 | \175# RUN: FileCheck -DFILE=%t2.broken.android --check-prefix=BROKEN-LLVM %s -DSECNAME=SHT_ANDROID_RELR176# RUN: llvm-readelf --relocations %t2.broken.android 2>&1 | \177# RUN: FileCheck -DFILE=%t2.broken.android --check-prefix=BROKEN-GNU %s -DSECNAME=SHT_ANDROID_RELR178 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.aarch64auth182# 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_RELR184# 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_RELR186 187# WRONGARCH-LLVM-AARCH64-AUTH: Relocations [188# WRONGARCH-LLVM-AARCH64-AUTH-NEXT: ]189 190# WRONGARCH-GNU-AARCH64-AUTH-NOT: Relocation section191 192## Check the behavior when the sh_link field of the SHT_RELR/SHT_ANDROID_RELR/SHT_AARCH64_AUTH_RELR section193## is set to an arbitrary value. Normally, it is set to 0, because such sections contains194## only relative relocations and do not have an associated symbol table, like other195## relocation sections.196 197## Check we do not report warnings when the sh_link field is set to an arbitrary value198## and the --relocations option is requested.199# RUN: yaml2obj --docnum=2 -DLINK=0xff %s -o %t2.has.link200# 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.err1207# RUN: llvm-readelf -r %t3.err1 2>&1 | FileCheck -DFILE=%t3.err1 --check-prefixes=GNU3,GNU3-ERR1 --match-full-lines %s208# RUN: yaml2obj --docnum=3 -DLINK=0xff %s -o %t3.err2209# RUN: llvm-readelf -r %t3.err2 2>&1 | FileCheck -DFILE=%t3.err2 --check-prefixes=GNU3,GNU3-ERR2 --match-full-lines %s210 211# GNU3:Index: Entry Address Symbolic Address212# 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 1213# GNU3-ERR2-NEXT:{{.*}}warning: '[[FILE]]': unable to get the string table for the SHT_SYMTAB section: invalid section index: 255214# GNU3-NEXT:0000: 0000000000010d60 0000000000010d60215# GNU3-NEXT:0001: 0000000000000103 0000000000010d68216# GNU3-NEXT: 0000000000010da0217# GNU3-NOT:{{.}}218 219--- !ELF220FileHeader:221 Class: ELFCLASS64222 Data: ELFDATA2LSB223 Type: ET_DYN224 Machine: EM_X86_64225Sections:226 - Name: .relr.dyn227 Type: SHT_RELR228 Flags: [ SHF_ALLOC ]229 Entries: [ 0x0000000000010D60, 0x0000000000000103 ]230 - Name: .symtab231 Type: SHT_SYMTAB232 Link: [[LINK=.strtab]]233 EntSize: [[ENTSIZE=0x18]]234Symbols:235 - Name: bar236 Value: 0x10D60237