1*2b2f4ae0SEleanor Bonnici## This test tests the behavior of --change-section-address option. 2*2b2f4ae0SEleanor Bonnici 3*2b2f4ae0SEleanor Bonnici# RUN: yaml2obj -DTYPE=REL %s -o %ti1 4*2b2f4ae0SEleanor Bonnici 5*2b2f4ae0SEleanor Bonnici## Basic check that the option processes wildcards and changes the address as expected. 6*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address *+0x20 %ti1 %to1 7*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to1 | FileCheck %s --check-prefix=CHECK-ADD-ALL 8*2b2f4ae0SEleanor Bonnici 9*2b2f4ae0SEleanor Bonnici## Check that --change-section-address alias --adjust-section-vma produces the same output as the test above. 10*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --adjust-section-vma *+0x20 %ti1 %to2 11*2b2f4ae0SEleanor Bonnici# RUN: cmp %to1 %to2 12*2b2f4ae0SEleanor Bonnici 13*2b2f4ae0SEleanor Bonnici## Check that negative adjustment reduces the address by the specified value. 14*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .anotherone-0x30 %ti1 %to3 15*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to3 | FileCheck %s --check-prefix=CHECK-SUB-SECTION 16*2b2f4ae0SEleanor Bonnici 17*2b2f4ae0SEleanor Bonnici## Check that a wildcard pattern works and only the specified sections are updated. 18*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text*+0x20 %ti1 %to4 19*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to4 | FileCheck %s --check-prefix=CHECK-ADD-PATTERN 20*2b2f4ae0SEleanor Bonnici 21*2b2f4ae0SEleanor Bonnici## Check that regex pattern can be used with --change-section-address. 22*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --regex --change-section-address .text.+0x20 %ti1 %to5 23*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to5 | FileCheck %s --check-prefix=CHECK-ADD-PATTERN 24*2b2f4ae0SEleanor Bonnici 25*2b2f4ae0SEleanor Bonnici## Check that a section address can be set to a specific value. 26*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text*=0x10 %ti1 %to6 27*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to6 | FileCheck %s --check-prefix=CHECK-SET-PATTERN 28*2b2f4ae0SEleanor Bonnici 29*2b2f4ae0SEleanor Bonnici## Check setting that a section address can be set to the maximum possible value (UINT64_MAX). 30*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text2=0xffffffffffffffff %ti1 %to7 31*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to7 | FileCheck %s --check-prefix=CHECK-MAX 32*2b2f4ae0SEleanor Bonnici 33*2b2f4ae0SEleanor Bonnici## Check that a section address can be adjusted to the maximum possible value (UINT64_MAX). 34*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text2+0xfffffffffffffdff %ti1 %to8 35*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to8 | FileCheck %s --check-prefix=CHECK-MAX 36*2b2f4ae0SEleanor Bonnici 37*2b2f4ae0SEleanor Bonnici## Check that the section address can be adjusted to the minimum possible value (0). 38*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text2-0x200 %ti1 %to9 39*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to9 | FileCheck %s --check-prefix=CHECK-ZERO 40*2b2f4ae0SEleanor Bonnici 41*2b2f4ae0SEleanor Bonnici## Check that a section address can be adjusted by a maximum possible positive offset (UINT64_MAX). 42*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text2=0 %ti1 %to10 43*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text2+0xffffffffffffffff %to10 %to11 44*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to11 | FileCheck %s --check-prefix=CHECK-MAX 45*2b2f4ae0SEleanor Bonnici 46*2b2f4ae0SEleanor Bonnici## Check that a section address can be adjusted by a maximum possible negative offset (UINT64_MIN). 47*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text2=0xffffffffffffffff %ti1 %to12 48*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text2-0xffffffffffffffff %to12 %to13 49*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to13 | FileCheck %s --check-prefix=CHECK-ZERO 50*2b2f4ae0SEleanor Bonnici 51*2b2f4ae0SEleanor Bonnici## Check two independent changes. 52*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .text1=0x110 --change-section-address .text2=0x210 %ti1 %to14 53*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to14 | FileCheck %s --check-prefix=CHECK-INDEPENDENT 54*2b2f4ae0SEleanor Bonnici 55*2b2f4ae0SEleanor Bonnici## Check two overlapping changes. 56*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .anotherone-0x30 --change-section-address .anotherone+0x20 %ti1 %to15 57*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to15 | FileCheck %s --check-prefix=CHECK-USE-LAST 58*2b2f4ae0SEleanor Bonnici 59*2b2f4ae0SEleanor Bonnici## Check unused option. 60*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address .anotherone=0x455 --change-section-address *+0x20 %ti1 %to16 61*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to16 | FileCheck %s --check-prefix=CHECK-NOTSUPERSET-SET 62*2b2f4ae0SEleanor Bonnici 63*2b2f4ae0SEleanor Bonnici## Check partial overlap (.anotherone overlaps). 64*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --change-section-address *+0x20 --change-section-address .anotherone=0x455 %ti1 %to17 65*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to17 | FileCheck %s --check-prefix=CHECK-SUPERSET-SET 66*2b2f4ae0SEleanor Bonnici 67*2b2f4ae0SEleanor Bonnici## Check more complex partial overlap (P1: .anotherone, .text2, P2: .text1, text2) (.text2 overlaps). 68*2b2f4ae0SEleanor Bonnici# RUN: llvm-objcopy --regex --change-section-address ".(text2|anotherone)+0x20" --change-section-address .text.*+0x30 %ti1 %to18 69*2b2f4ae0SEleanor Bonnici# RUN: llvm-readelf --section-headers %to18 | FileCheck %s --check-prefix=CHECK-PARTIAL-OVERLAP 70*2b2f4ae0SEleanor Bonnici 71*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL: [Nr] Name Type Address 72*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL: .text1 73*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL-SAME: 0000000000000120 74*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL: .text2 75*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL-SAME: 0000000000000220 76*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL: .anotherone 77*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL-SAME: 0000000000000320 78*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL: =a-b+c++d 79*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL-SAME: 0000000000000420 80*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL: .strtab 81*2b2f4ae0SEleanor Bonnici# CHECK-ADD_ALL-SAME: 0000000000000020 82*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL: .shstrtab 83*2b2f4ae0SEleanor Bonnici# CHECK-ADD-ALL-SAME: 0000000000000020 84*2b2f4ae0SEleanor Bonnici 85*2b2f4ae0SEleanor Bonnici# CHECK-SUB-SECTION: .text1 86*2b2f4ae0SEleanor Bonnici# CHECK-SUB-SECTION-SAME: 0000000000000100 87*2b2f4ae0SEleanor Bonnici# CHECK-SUB-SECTION: .text2 88*2b2f4ae0SEleanor Bonnici# CHECK-SUB-SECTION-SAME: 0000000000000200 89*2b2f4ae0SEleanor Bonnici# CHECK-SUB-SECTION: .anotherone 90*2b2f4ae0SEleanor Bonnici# CHECK-SUB-SECTION-SAME: 00000000000002d0 91*2b2f4ae0SEleanor Bonnici 92*2b2f4ae0SEleanor Bonnici# CHECK-ADD-PATTERN: .text1 93*2b2f4ae0SEleanor Bonnici# CHECK-ADD-PATTERN-SAME: 0000000000000120 94*2b2f4ae0SEleanor Bonnici# CHECK-ADD-PATTERN: .text2 95*2b2f4ae0SEleanor Bonnici# CHECK-ADD-PATTERN-SAME: 0000000000000220 96*2b2f4ae0SEleanor Bonnici# CHECK-ADD-PATTERN: .anotherone 97*2b2f4ae0SEleanor Bonnici# CHECK-ADD-PATTERN-SAME: 0000000000000300 98*2b2f4ae0SEleanor Bonnici 99*2b2f4ae0SEleanor Bonnici# CHECK-SET-PATTERN: .text1 100*2b2f4ae0SEleanor Bonnici# CHECK-SET-PATTERN-SAME: 0000000000000010 101*2b2f4ae0SEleanor Bonnici# CHECK-SET-PATTERN: .text2 102*2b2f4ae0SEleanor Bonnici# CHECK-SET-PATTERN-SAME: 0000000000000010 103*2b2f4ae0SEleanor Bonnici# CHECK-SET-PATTERN: .anotherone 104*2b2f4ae0SEleanor Bonnici# CHECK-SET-PATTERN-SAME: 0000000000000300 105*2b2f4ae0SEleanor Bonnici 106*2b2f4ae0SEleanor Bonnici# CHECK-MAX: .text2 107*2b2f4ae0SEleanor Bonnici# CHECK-MAX-SAME: ffffffffffffffff 108*2b2f4ae0SEleanor Bonnici# CHECK-ZERO: .text2 109*2b2f4ae0SEleanor Bonnici# CHECK-ZERO-SAME: 0000000000000000 110*2b2f4ae0SEleanor Bonnici 111*2b2f4ae0SEleanor Bonnici# CHECK-INDEPENDENT: .text1 112*2b2f4ae0SEleanor Bonnici# CHECK-INDEPENDENT-SAME: 0000000000000110 113*2b2f4ae0SEleanor Bonnici# CHECK-INDEPENDENT: .text2 114*2b2f4ae0SEleanor Bonnici# CHECK-INDEPENDENT-SAME: 0000000000000210 115*2b2f4ae0SEleanor Bonnici 116*2b2f4ae0SEleanor Bonnici# CHECK-USE-LAST: .anotherone 117*2b2f4ae0SEleanor Bonnici# CHECK-USE-LAST-SAME: 0000000000000320 118*2b2f4ae0SEleanor Bonnici 119*2b2f4ae0SEleanor Bonnici# CHECK-NOTSUPERSET-SET: .text1 120*2b2f4ae0SEleanor Bonnici# CHECK-NOTSUPERSET-SET-SAME: 0000000000000120 121*2b2f4ae0SEleanor Bonnici# CHECK-NOTSUPERSET-SET: .text2 122*2b2f4ae0SEleanor Bonnici# CHECK-NOTSUPERSET-SET-SAME: 0000000000000220 123*2b2f4ae0SEleanor Bonnici# CHECK-NOTSUPERSET-SET: .anotherone 124*2b2f4ae0SEleanor Bonnici# CHECK-NOTSUPERSET-SET-SAME: 0000000000000320 125*2b2f4ae0SEleanor Bonnici 126*2b2f4ae0SEleanor Bonnici# CHECK-SUPERSET-SET: .text1 127*2b2f4ae0SEleanor Bonnici# CHECK-SUPERSET-SET-SAME: 0000000000000120 128*2b2f4ae0SEleanor Bonnici# CHECK-SUPERSET-SET: .text2 129*2b2f4ae0SEleanor Bonnici# CHECK-SUPERSET-SET-SAME: 0000000000000220 130*2b2f4ae0SEleanor Bonnici# CHECK-SUPERSET-SET: .anotherone 131*2b2f4ae0SEleanor Bonnici# CHECK-SUPERSET-SET-SAME: 0000000000000455 132*2b2f4ae0SEleanor Bonnici 133*2b2f4ae0SEleanor Bonnici# CHECK-PARTIAL-OVERLAP: .text1 134*2b2f4ae0SEleanor Bonnici# CHECK-PARTIAL-OVERLAP-SAME: 0000000000000130 135*2b2f4ae0SEleanor Bonnici# CHECK-PARTIAL-OVERLAP: .text2 136*2b2f4ae0SEleanor Bonnici# CHECK-PARTIAL-OVERLAP-SAME: 0000000000000230 137*2b2f4ae0SEleanor Bonnici# CHECK-PARTIAL-OVERLAP: .anotherone 138*2b2f4ae0SEleanor Bonnici# CHECK-PARTIAL-OVERLAP-SAME: 0000000000000320 139*2b2f4ae0SEleanor Bonnici 140*2b2f4ae0SEleanor Bonnici## Check overflow by 1. 141*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address .anotherone+0xfffffffffffffd00 %ti1 2>&1 | FileCheck %s --check-prefix=ERR-OVERFLOW 142*2b2f4ae0SEleanor Bonnici## Check underflow by 1. 143*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address .text2-0x201 %ti1 2>&1 | FileCheck %s --check-prefix=ERR-UNDERFLOW 144*2b2f4ae0SEleanor Bonnici## Check error when argument value is invalid as a whole. 145*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address 0 %ti1 2>&1 | FileCheck %s --check-prefix=ERR-IVALID-VAL 146*2b2f4ae0SEleanor Bonnici## Check error when the value is invalid in the argument value. 147*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address .anotherone+0c50 %ti1 2>&1 | FileCheck %s --check-prefix=ERR-NOT-INTEGER 148*2b2f4ae0SEleanor Bonnici## Check error when the value does not fit in uint64_t. 149*2b2f4ae0SEleanor Bonnici# RUN not llvm-objcopy --change-section-address .text1=0x10000000000000000 %ti1 %to 2>&1 | FileCheck %s --chack-prefix=ERR-NOT-INTEGER 150*2b2f4ae0SEleanor Bonnici## Check error when the section pattern is missing. 151*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address =0x10 %ti1 2>&1 | FileCheck %s --check-prefix=ERR-MISSING-SECTION 152*2b2f4ae0SEleanor Bonnici## Check error when the negative adjustment value is missing. 153*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address .text1- %ti1 2>&1 | FileCheck %s --check-prefix=ERR-MISSING-VALUE-MINUS 154*2b2f4ae0SEleanor Bonnici## Check error when the positive adjustment value is missing. 155*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address .text1+ %ti1 2>&1 | FileCheck %s --check-prefix=ERR-MISSING-VALUE-PLUS 156*2b2f4ae0SEleanor Bonnici## Check error when the value to set the address to is missing. 157*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address .text1= %ti1 2>&1 | FileCheck %s --check-prefix=ERR-MISSING-VALUE-EQUAL 158*2b2f4ae0SEleanor Bonnici## Check error when the provided regex is invalid. 159*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --regex --change-section-address "ab**-0x20" %ti1 2>&1 | FileCheck %s --check-prefix=ERR-MATCHER-FAILURE 160*2b2f4ae0SEleanor Bonnici 161*2b2f4ae0SEleanor Bonnici# ERR-OVERFLOW: address 0x300 cannot be increased by 0xfffffffffffffd00. The result would overflow 162*2b2f4ae0SEleanor Bonnici# ERR-UNDERFLOW: address 0x200 cannot be decreased by 0x201. The result would underflow 163*2b2f4ae0SEleanor Bonnici# ERR-IVALID-VAL: error: bad format for --change-section-address: argument value 0 is invalid. See --help 164*2b2f4ae0SEleanor Bonnici# ERR-NOT-INTEGER: error: bad format for --change-section-address: value after + is 0c50 when it should be a 64-bit integer 165*2b2f4ae0SEleanor Bonnici# ERR-MISSING-SECTION: error: bad format for --change-section-address: missing section pattern to apply address change to 166*2b2f4ae0SEleanor Bonnici# ERR-MISSING-VALUE-MINUS: error: bad format for --change-section-address: missing value of offset after '-' 167*2b2f4ae0SEleanor Bonnici# ERR-MISSING-VALUE-PLUS: error: bad format for --change-section-address: missing value of offset after '+' 168*2b2f4ae0SEleanor Bonnici# ERR-MISSING-VALUE-EQUAL: error: bad format for --change-section-address: missing address value after '=' 169*2b2f4ae0SEleanor Bonnici# ERR-MATCHER-FAILURE: error: cannot compile regular expression 'ab**': repetition-operator operand invalid 170*2b2f4ae0SEleanor Bonnici 171*2b2f4ae0SEleanor Bonnici--- !ELF 172*2b2f4ae0SEleanor BonniciFileHeader: 173*2b2f4ae0SEleanor Bonnici Class: ELFCLASS64 174*2b2f4ae0SEleanor Bonnici Data: ELFDATA2LSB 175*2b2f4ae0SEleanor Bonnici Type: ET_[[TYPE]] 176*2b2f4ae0SEleanor BonniciSections: 177*2b2f4ae0SEleanor Bonnici - Name: .text1 178*2b2f4ae0SEleanor Bonnici Type: SHT_PROGBITS 179*2b2f4ae0SEleanor Bonnici Size: 0x100 180*2b2f4ae0SEleanor Bonnici Address: 0x100 181*2b2f4ae0SEleanor Bonnici - Name: .text2 182*2b2f4ae0SEleanor Bonnici Type: SHT_PROGBITS 183*2b2f4ae0SEleanor Bonnici Size: 0x100 184*2b2f4ae0SEleanor Bonnici Address: 0x200 185*2b2f4ae0SEleanor Bonnici - Name: .anotherone 186*2b2f4ae0SEleanor Bonnici Type: SHT_PROGBITS 187*2b2f4ae0SEleanor Bonnici Size: 0x100 188*2b2f4ae0SEleanor Bonnici Address: 0x300 189*2b2f4ae0SEleanor Bonnici - Name: =a-b+c++d 190*2b2f4ae0SEleanor Bonnici Type: SHT_PROGBITS 191*2b2f4ae0SEleanor Bonnici Size: 0x100 192*2b2f4ae0SEleanor Bonnici Address: 0x400 193*2b2f4ae0SEleanor Bonnici 194*2b2f4ae0SEleanor Bonnici# RUN: yaml2obj -DTYPE=EXEC %s -o %ti2 195*2b2f4ae0SEleanor Bonnici 196*2b2f4ae0SEleanor Bonnici## Input file is not ET_REL 197*2b2f4ae0SEleanor Bonnici# RUN: not llvm-objcopy --change-section-address *+0x20 %ti2 2>&1 | FileCheck %s --check-prefix=ERR-FILE-TYPE 198*2b2f4ae0SEleanor Bonnici 199*2b2f4ae0SEleanor Bonnici# ERR-FILE-TYPE: cannot change section address in a non-relocatable file 200