brintos

brintos / llvm-project-archived public Read only

0
0
Text · 12.7 KiB · 1c5c3cc Raw
275 lines · plain
1DEFINE: %{local1a_386} = 0x30002DEFINE: %{sym1_386} = 0x20B03DEFINE: %{sym3_386} = 0x20BC4DEFINE: %{local1a_x64} = 0x30005DEFINE: %{sym1_x64} = 0x20E86DEFINE: %{sym3_x64} = 0x20D87DEFINE: %{relocbegin} = 88DEFINE: %{relocend} = 809DEFINE: %{rdatasize} = 25410 11RUN: yaml2obj  -o %t.exe-x86_64 %p/Inputs/pseudoreloc.x86_64.yaml12RUN: llvm-readobj %t.exe-x86_64 --coff-pseudoreloc 2>&1 | \13RUN:   FileCheck %s --check-prefixes=CHECK,CHECK-X64 --match-full-lines --implicit-check-not=warning \14RUN:     -D#WORD=8 -D#SYM1=%{sym1_x64} -D#SYM3=%{sym3_x64} -D#LOCAL1A=%{local1a_x64} -DPREFIX=15 16RUN: yaml2obj   -o %t.exe-i386  %p/Inputs/pseudoreloc.i386.yaml17RUN: llvm-readobj  %t.exe-i386  --coff-pseudoreloc 2>&1 | \18RUN:   FileCheck %s --check-prefixes=CHECK,CHECK-386 --match-full-lines --implicit-check-not=warning \19RUN:     -D#WORD=4 -D#SYM1=%{sym1_386} -D#SYM3=%{sym3_386} -D#LOCAL1A=%{local1a_386} -DPREFIX=_20 21CHECK-X64:      Format: COFF-x86-6422CHECK-X64-NEXT: Arch: x86_6423CHECK-386:      Format: COFF-i38624CHECK-386-NEXT: Arch: i38625CHECK-NEXT: AddressSize: [[#%u,BW:mul(WORD,8)]]bit26CHECK-NEXT: PseudoReloc [27CHECK-NEXT:  Entry {28CHECK-NEXT:   Symbol: 0x[[#%X,SYM1]]29CHECK-NEXT:   SymbolName: sym130CHECK-NEXT:   Target: 0x[[#%X,LOCAL1A]]31CHECK-NEXT:   TargetSymbol: .data+0x032CHECK-NEXT:   BitWidth: [[#BW]]33CHECK-NEXT:  }34CHECK-NEXT:  Entry {35CHECK-NEXT:   Symbol: 0x[[#%X,SYM1+mul(1,WORD)]]36CHECK-NEXT:   SymbolName: sym237CHECK-NEXT:   Target: 0x[[#%X,LOCAL1A+mul(1,WORD)]]38CHECK-NEXT:   TargetSymbol: [[PREFIX]]local2a39CHECK-NEXT:   BitWidth: [[#BW]]40CHECK-NEXT:  }41CHECK-NEXT:  Entry {42CHECK-NEXT:   Symbol: 0x[[#%X,SYM3]]43CHECK-NEXT:   SymbolName: sym344CHECK-NEXT:   Target: 0x[[#%X,LOCAL1A+mul(2,WORD)]]45CHECK-NEXT:   TargetSymbol: [[PREFIX]]local3a46CHECK-NEXT:   BitWidth: [[#BW]]47CHECK-NEXT:  }48CHECK-NEXT:  Entry {49CHECK-NEXT:   Symbol: 0x[[#%X,SYM3]]50CHECK-NEXT:   SymbolName: sym351CHECK-NEXT:   Target: 0x[[#%X,LOCAL1A+mul(3,WORD)]]52CHECK-NEXT:   TargetSymbol: [[PREFIX]]local3a+0x[[#%X,mul(1,WORD)]]53CHECK-NEXT:   BitWidth: [[#BW]]54CHECK-NEXT:  }55CHECK-NEXT:  Entry {56CHECK-NEXT:   Symbol: 0x[[#%X,SYM1]]57CHECK-NEXT:   SymbolName: sym158CHECK-NEXT:   Target: 0x[[#%X,LOCAL1A+mul(4,WORD)]]59CHECK-NEXT:   TargetSymbol: [[PREFIX]]local3a+0x[[#%X,mul(2,WORD)]]60CHECK-NEXT:   BitWidth: [[#BW]]61CHECK-NEXT:  }62CHECK-NEXT: ]63 64; Test that llvm-readobj warns about missing imported symbol names.65RUN: yaml2obj  -o %t.corrupted-iat.exe-i386 %p/Inputs/pseudoreloc.i386.yaml \66RUN:   -DSYMBOL0=30000000 -DSYMBOL1=B2200000 -DSYMBOL2=00FFFF0067RUN: llvm-readobj %t.corrupted-iat.exe-i386 --coff-pseudoreloc 2>&1 | \68RUN:   FileCheck %s --check-prefix=INVALIDSYMBOL --match-full-lines -D#LOCAL1A=%{local1a_386} --implicit-check-not=warning69 70INVALIDSYMBOL:      Symbol: 0x[[#%X,ADDR:0x0030]]71INVALIDSYMBOL-NEXT: {{.*}}warning: {{.*}}: the address referenced by pseudo-relocation is not a valid import entry: 0x[[#%x,ADDR]]72INVALIDSYMBOL-NEXT: SymbolName: (missing)73INVALIDSYMBOL-NEXT: Target: 0x[[#%X,LOCAL1A]]74INVALIDSYMBOL:      Symbol: 0x[[#%X,ADDR:0x20B2]]75INVALIDSYMBOL-NEXT: {{.*}}warning: {{.*}}: the address referenced by pseudo-relocation is not a valid import entry: 0x[[#%x,ADDR]]76INVALIDSYMBOL-NEXT: SymbolName: (missing)77INVALIDSYMBOL-NEXT: Target: 0x[[#%X,LOCAL1A+4]]78INVALIDSYMBOL:      Symbol: 0x[[#%X,ADDR:0xFFFF00]]79INVALIDSYMBOL-NEXT: {{.*}}warning: {{.*}}: the address referenced by pseudo-relocation is not a valid import entry: 0x[[#%x,ADDR]]80INVALIDSYMBOL-NEXT: SymbolName: (missing)81INVALIDSYMBOL-NEXT: Target: 0x[[#%X,LOCAL1A+8]]82 83; Assume the position of the section and the relocation list for further tests.84RUN: FileCheck --input-file=%p/Inputs/pseudoreloc.i386.yaml %s --check-prefix=RELOCPOS --match-full-lines \85RUN:   -D#RDATASIZE=%{rdatasize} -DTHEBEGIN=%{relocbegin} -DTHEEND=%{relocend}86 87RELOCPOS:     sections:88RELOCPOS-NOT:   - Name:89RELOCPOS:       - Name:            .text90RELOCPOS-NOT:   - Name:91RELOCPOS:       - Name:            .rdata92RELOCPOS-NEXT:    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]93RELOCPOS-NEXT:    VirtualAddress:  819294RELOCPOS-NEXT:    VirtualSize:     [[#%d,RDATASIZE]]95RELOCPOS:       - Name:            .data96RELOCPOS-NEXT:    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]97RELOCPOS-NEXT:    VirtualAddress:  1228898RELOCPOS:       - Name: ___RUNTIME_PSEUDO_RELOC_LIST_END__99RELOCPOS-NEXT:    Value: [{{\[}}END=[[THEEND]]{{]}}]100RELOCPOS:       - Name: ___RUNTIME_PSEUDO_RELOC_LIST__101RELOCPOS-NEXT:    Value: [{{\[}}BEGIN=[[THEBEGIN]]{{]}}]102RELOCPOS-NEXT:    SectionNumber: {{\[\[SECTION_OF_BEGIN=2\]\]}}103 104; Test that llvm-readobj warns if a symbol belongs to a nonexistent section.105RUN: yaml2obj  -o %t.nosection.exe-i386 %p/Inputs/pseudoreloc.i386.yaml -DSECTION_OF_LOCAL2A=999106RUN: llvm-readobj %t.nosection.exe-i386 --coff-pseudoreloc 2>&1 | \107RUN:   FileCheck %s --check-prefixes=WARN-NOSECTION --match-full-lines108 109WARN-NOSECTION: {{.*}} warning:{{.*}}: section index out of bounds110 111; Test that llvm-readobj shows an empty list if the relocation list has no contents.112RUN: yaml2obj  -o %t.empty-list.exe-i386 %p/Inputs/pseudoreloc.i386.yaml -DEND=20113RUN: llvm-readobj %t.empty-list.exe-i386 --coff-pseudoreloc 2>&1 | \114RUN:   FileCheck %s --check-prefix=EMPTY --match-full-lines --implicit-check-not=warning115 116; Test that llvm-readobj shows an empty list if the relocation list has no header.117RUN: yaml2obj  -o %t.no-header.exe-i386 %p/Inputs/pseudoreloc.i386.yaml -DEND=%{relocbegin}118RUN: llvm-readobj %t.no-header.exe-i386 --coff-pseudoreloc 2>&1 | \119RUN:   FileCheck %s --check-prefix=EMPTY --match-full-lines --implicit-check-not=warning120 121; Test that llvm-readobj shows an empty list if the image is stripped.122RUN: llvm-readobj --coff-pseudoreloc %p/Inputs/imports.exe.coff-i386 2>&1 | \123RUN:   FileCheck %s --check-prefix=EMPTY --match-full-lines --implicit-check-not=warning124 125; Test that llvm-readobj warns if the marker symbol of the relocation list is absent from the symbol table.126RUN: sed -e 's/__RUNTIME//' %p/Inputs/pseudoreloc.i386.yaml | \127RUN:   yaml2obj -o %t.nosymbol.exe-i386128RUN: llvm-readobj  %t.nosymbol.exe-i386 --coff-pseudoreloc 2>&1 | \129RUN:   FileCheck %s --check-prefixes=EMPTY,WARN-MISSINGMARKER --match-full-lines130 131; Test that llvm-readobj shows an empty list if a .obj is specified.132RUN: llvm-readobj --coff-pseudoreloc %p/Inputs/trivial.obj.coff-i386 2>&1 | \133RUN:   FileCheck %s --check-prefix=EMPTY --match-full-lines --implicit-check-not=warning134 135; Test that llvm-readobj warns if the header of the relocation list is broken.136RUN: yaml2obj  -o %t.broken-header.exe-i386 %p/Inputs/pseudoreloc.i386.yaml -DBEGIN=1%{relocbegin}137RUN: llvm-readobj %t.broken-header.exe-i386 --coff-pseudoreloc 2>&1 | \138RUN:   FileCheck %s --check-prefixes=EMPTY,WARN-INVALIDHEADER --match-full-lines139 140; Test that llvm-readobj warns if end < start.141RUN: yaml2obj  -o %t.negative-size.exe-i386 %p/Inputs/pseudoreloc.i386.yaml -DBEGIN=%{relocend} -DEND=%{relocbegin}142RUN: llvm-readobj %t.negative-size.exe-i386 --coff-pseudoreloc 2>&1 | \143RUN:   FileCheck %s --check-prefixes=EMPTY,WARN-LOWEREND -D#BEGIN=%{relocend} -D#END=%{relocbegin} --match-full-lines144 145; Test that llvm-readobj warns if the marker symbol points out of the section space.146RUN: yaml2obj  -o %t.outofrange-both.exe-i386 %p/Inputs/pseudoreloc.i386.yaml -DBEGIN=8888 -DEND=9999147RUN: llvm-readobj %t.outofrange-both.exe-i386 --coff-pseudoreloc 2>&1 | \148RUN:   FileCheck %s --check-prefixes=EMPTY,WARN-OUTOFRANGE --match-full-lines -D#RDATASIZE=%{rdatasize}149 150RUN: yaml2obj  -o %t.outofrange-end.exe-i386 %p/Inputs/pseudoreloc.i386.yaml -DEND=8888151RUN: llvm-readobj %t.outofrange-end.exe-i386 --coff-pseudoreloc 2>&1 | \152RUN:   FileCheck %s --check-prefixes=EMPTY,WARN-OUTOFRANGE --match-full-lines -D#RDATASIZE=%{rdatasize}153 154; Test that llvm-readobj warns if the marker symbols point different sections.155RUN: yaml2obj  -o %t.section-differs.exe-i386 %p/Inputs/pseudoreloc.i386.yaml -DSECTION_OF_BEGIN=1156RUN: llvm-readobj %t.section-differs.exe-i386 --coff-pseudoreloc 2>&1 | \157RUN:   FileCheck %s --check-prefixes=EMPTY,WARN-SECTIONDIFFERS --match-full-lines158 159EMPTY:      Format: COFF-i386160EMPTY-NEXT: Arch: i386161EMPTY-NEXT: AddressSize: 32bit162EMPTY-NEXT: PseudoReloc [163WARN-MISSINGMARKER-NEXT:  {{.*}}warning: {{.*}}: the marker symbols for runtime pseudo-relocation were not found164WARN-INVALIDHEADER-NEXT:  {{.*}}warning: {{.*}}: invalid runtime pseudo-relocation records165WARN-LOWEREND-NEXT:       {{.*}}warning: {{.*}}: the end marker symbol for runtime pseudo-relocation must point to a higher address than where the begin marker points to: expected >=0x[[#%x,BEGIN]], but got 0x[[#%x,END]]166WARN-OUTOFRANGE-NEXT:     {{.*}}warning: {{.*}}: the marker symbol of runtime pseudo-relocation points past the end of the section 0x[[#%x,RDATASIZE]]: got 0x[[#%x,8888]]167WARN-SECTIONDIFFERS-NEXT: {{.*}}warning: {{.*}}: the end marker symbol for runtime pseudo-relocation must point to the same section where the begin marker points to: expected 1, but got {{[2-9]}}168EMPTY-NEXT: ]169 170;;171;; To regenerate Inputs/pseudoreloc.*.yaml, run following one-liner and review actual address map:172;;173;; $ split-file pseudoreloc.test /tmp/pseudoreloc && bash /tmp/pseudoreloc/generate.sh && cp /tmp/pseudoreloc/*.yaml Inputs/174;;175 176#--- generate.sh177cd "$(dirname $0)"178set -e179 180generate() {181  LANG=C182  local arch=$1183  local emul=$2184 185  llc -mtriple $arch-mingw32 -filetype obj export1.ll -o export1.$arch.o186  ld.lld -m $emul --dll export1.$arch.o -o export1.$arch.dll -entry=187  llc -mtriple $arch-mingw32 -filetype obj export2.ll -o export2.$arch.o188  ld.lld -m $emul --dll export2.$arch.o -o export2.$arch.dll -entry=189  llc -mtriple $arch-mingw32 -filetype obj import.ll -o import.$arch.o190  ld.lld -m $emul -S import.$arch.o export1.$arch.dll export2.$arch.dll -o pseudoreloc.$arch.exe -entry=start \191    --disable-dynamicbase --disable-reloc-section192 193  obj2yaml pseudoreloc.$arch.exe -o pseudoreloc.$arch.yaml.orig194 195  llvm-readobj --coff-imports --syms --section-headers pseudoreloc.$arch.exe > dump.$arch.txt196  local begin=$(sed -n -e '/__RUNTIME_PSEUDO_RELOC_LIST__/,/Value:/{/Value:/{s/ *Value: *//p;q}}' dump.$arch.txt)197 198  # Make these parameterizable:199  #  - the referenced symbol in 1st, 2nd, and 3rd relocation entry200  #  - the marker symbols' value201  #  - a section which the marker symbol belongs to202  #  - a section which the symbol of the relocation target belongs to203  sed -E -f - pseudoreloc.$arch.yaml.orig <<EOT > pseudoreloc.$arch.yaml204/- Name: *\\.rdata/,/SectionData:/{205  s/( *SectionData: *[0-9A-F]{$(($begin * 2 + 24))})(.{8})(.{16})(.{8})(.{16})(.{8})/\\1[[SYMBOL0=\\2]]\\3[[SYMBOL1=\\4]]\\5[[SYMBOL2=\\6]]/206}207/__RUNTIME_PSEUDO_RELOC_LIST_END__/,/Value:/{208  /Value:/s/([0-9]+)/[[END=\1]]/209}210/__RUNTIME_PSEUDO_RELOC_LIST__/,/Value:/{211  /Value:/s/([0-9]+)/[[BEGIN=\1]]/212}213/__RUNTIME_PSEUDO_RELOC_LIST__/,/SectionNumber:/{214  /SectionNumber:/s/([0-9]+)/[[SECTION_OF_BEGIN=\1]]/215}216/local2a/,/SectionNumber:/{217  /SectionNumber:/s/([0-9]+)/[[SECTION_OF_LOCAL2A=\1]]/218}219EOT220 221  # Ensure the binaries generated from the parameterized yaml and original one are exactly the same.222  diff <(yaml2obj pseudoreloc.$arch.yaml.orig -o -) <(yaml2obj pseudoreloc.$arch.yaml -o -)223}224 225generate i386 i386pe226generate x86_64 i386pep227 228#--- export1.ll229@sym1 = dso_local dllexport global [4 x i8] c"\11\22\33\44"230@sym2 = dso_local dllexport global [4 x i8] c"\55\66\77\88"231 232#--- export2.ll233@sym3 = dso_local dllexport global [4 x i8] c"\AA\BB\CC\DD"234 235#--- import.ll236@__RUNTIME_PSEUDO_RELOC_LIST__ = external dso_local constant ptr237@__RUNTIME_PSEUDO_RELOC_LIST_END__ = external dso_local constant ptr238@sym1 = external dso_local global [4 x i8]239@sym2 = external dso_local global [4 x i8]240@sym3 = external dso_local global [4 x i8]241@dummy_to_bump_address = private constant i64 u0x4488226655117733242@local1a = private global ptr getelementptr (i8, ptr @sym1, i32 1)243@local2a = dso_local global ptr getelementptr (i8, ptr @sym2, i32 2)244@local3a = dso_local global [2 x ptr] [ptr getelementptr (i8, ptr @sym3, i32 1), ptr getelementptr (i8, ptr @sym3, i32 1)]245@local1b = private global ptr getelementptr (i8, ptr @sym1, i32 2)246 247define dso_local i32 @start() noinline nounwind {248  %p1a = load ptr, ptr @local1a249  %v1a = load i8, ptr %p1a250  %x1a = sext i8 %v1a to i32251  %p2a = load ptr, ptr @local2a252  %v2a = load i8, ptr %p2a253  %x2a = sext i8 %v2a to i32254  %p3a = load ptr, ptr @local3a255  %v3a = load i8, ptr %p3a256  %x3a = sext i8 %v3a to i32257  %p1b = load ptr, ptr @local1b258  %v1b = load i8, ptr %p1b259  %x1b = sext i8 %v1b to i32260  %1 = add nsw i32 %x1a, %x2a261  %2 = add nsw i32 %x3a, %x1b262  %3 = add nsw i32 %1, %2263  ret i32 %3264}265 266define dso_local i32 @_pei386_runtime_relocator() noinline nounwind {267  %1 = load ptr, ptr @__RUNTIME_PSEUDO_RELOC_LIST_END__268  %2 = load ptr, ptr @__RUNTIME_PSEUDO_RELOC_LIST__269  %3 = ptrtoint ptr %1 to i64270  %4 = ptrtoint ptr %2 to i64271  %5 = sub i64 %3, %4272  %6 = trunc i64 %5 to i32273  ret i32 %6274}275