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