550 lines · plain
1# We want to preserve areas in segments that are not covered by section headers.2# This test shows that we do this for areas at the start of a segment, between3# sections in a segment, and after all sections in a segment.4# To create inputs with arbitrary data in segments, not covered by sections, we5# use yaml2obj to create segments with sections covering all areas, then remove6# some sections in those segments, and finally write over the areas of the7# removed sections using python.8 9# blob* sections are the sections that will be removed to create unlabelled10# areas and then overwritten with data to show we preserve the data.11 12# RUN: yaml2obj %s -o %t.base13# RUN: llvm-objcopy %t.base %t.stripped --regex -R blob.*14# Show that the removal leaves the bytes as zeroes, as desired, for all our15# test cases.16# RUN: od -t x1 -j 0x2000 -N 28 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK1 -DPATTERN="00 00 00 00"17# RUN: od -t x1 -j 0x2100 -N 12 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK2 -DPATTERN="00 00 00 00"18# RUN: od -t x1 -j 0x2200 -N 4 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK3 -DPATTERN="00 00 00 00"19# RUN: od -t x1 -j 0x2300 -N 12 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK4 -DPATTERN="00 00 00 00"20# RUN: od -t x1 -j 0x3000 -N 68 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK5 -DPATTERN="00 00 00 00"21# RUN: od -t x1 -j 0x4000 -N 60 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK6 -DPATTERN="00 00 00 00"22# RUN: od -t x1 -j 0x5000 -N 60 %t.stripped | FileCheck %s --ignore-case --check-prefix=CHECK7 -DPATTERN="00 00 00 00"23 24# RUN: cp %t.stripped %t.in25# RUN: echo "with open('%/t.in', 'rb+') as input:" > %t.py26# RUN: echo " for offset in [" >> %t.py27# RUN: echo " 0x2000, 0x2008, 0x200C, 0x2018, 0x2104, 0x2300," >> %t.py28# RUN: echo " 0x3008, 0x3010, 0x3018, 0x3020, 0x3028, 0x302C, 0x3034, 0x303C," >> %t.py29# RUN: echo " 0x4000, 0x4008, 0x4010, 0x4014, 0x401C, 0x4024, 0x4034," >> %t.py30# RUN: echo " 0x5000, 0x5008, 0x5010, 0x501C, 0x5024, 0x502C, 0x5030, 0x5038]:" >> %t.py31# RUN: echo " input.seek(offset)" >> %t.py32# RUN: echo " input.write(bytearray.fromhex('DEADBEEF'))" >> %t.py33# RUN: %python %t.py34# RUN: llvm-objcopy %t.in %t.out35# RUN: od -t x1 -j 0x2000 -N 28 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK1 -DPATTERN="de ad be ef"36# RUN: od -t x1 -j 0x2100 -N 12 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK2 -DPATTERN="de ad be ef"37# RUN: od -t x1 -j 0x2200 -N 4 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK3 -DPATTERN="de ad be ef"38# RUN: od -t x1 -j 0x2300 -N 12 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK4 -DPATTERN="de ad be ef"39# RUN: od -t x1 -j 0x3000 -N 68 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK5 -DPATTERN="de ad be ef"40# RUN: od -t x1 -j 0x4000 -N 60 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK6 -DPATTERN="de ad be ef"41# RUN: od -t x1 -j 0x5000 -N 60 %t.out | FileCheck %s --ignore-case --check-prefix=CHECK7 -DPATTERN="de ad be ef"42 43# CHECK1: [[PATTERN]] 11 22 33 44 [[PATTERN]] [[PATTERN]]44# CHECK1-NEXT: 00 00 00 00 55 66 77 88 [[PATTERN]]45# CHECK2: 99 00 aa bb [[PATTERN]] cc dd ee ff46# CHECK3: fe fe fe fe47# CHECK4: [[PATTERN]] 00 00 00 00 00 00 00 0048# CHECK5: ff ff ee ee dd dd cc cc [[PATTERN]] bb bb aa aa49# CHECK5-NEXT: [[PATTERN]] 00 00 99 99 [[PATTERN]] 88 88 77 7750# CHECK5-NEXT: [[PATTERN]] 66 66 55 55 [[PATTERN]] [[PATTERN]]51# CHECK5-NEXT: 44 44 33 33 [[PATTERN]] 22 22 11 11 [[PATTERN]]52# CHECK5-NEXT: 00 11 22 3353# CHECK6: [[PATTERN]] 44 55 66 77 [[PATTERN]] 88 99 aa bb54# CHECK6-NEXT: [[PATTERN]] [[PATTERN]] cc dd ee ff [[PATTERN]]55# CHECK6-NEXT: ff ee dd cc [[PATTERN]] bb aa 99 88 77 66 55 4456# CHECK6-NEXT: 33 22 11 00 [[PATTERN]] 11 11 11 1157# CHECK7: [[PATTERN]] 12 34 56 78 [[PATTERN]] 90 ab cd ef58# CHECK7-NEXT: [[PATTERN]] fe dc ba 09 87 65 43 21 [[PATTERN]]59# CHECK7-NEXT: 22 22 22 22 [[PATTERN]] 33 33 33 33 [[PATTERN]]60# CHECK7-NEXT: [[PATTERN]] 44 44 44 44 [[PATTERN]]61 62--- !ELF63FileHeader:64 Class: ELFCLASS6465 Data: ELFDATA2LSB66 Type: ET_EXEC67 Machine: EM_X86_6468Sections:69 - Name: blob170 Type: SHT_PROGBITS71 Content: 'abbababa'72 Address: 0x200073 AddressAlign: 0x200074 - Name: section175 Type: SHT_PROGBITS76 Address: 0x200477 Content: '11223344'78 - Name: blob279 Type: SHT_PROGBITS80 Content: 'abbababa'81 Address: 0x200882 - Name: section283 Type: SHT_NOBITS84 Size: 485 Address: 0x200C86 - Name: blob387 Type: SHT_PROGBITS88 Content: 'abbababa'89 Address: 0x201090 - Name: section391 Type: SHT_PROGBITS92 Content: '55667788'93 Address: 0x201494 - Name: blob495 Type: SHT_PROGBITS96 Content: 'abbababa'97 Address: 0x201898 - Name: section499 Type: SHT_PROGBITS100 Content: '9900aabb'101 Address: 0x2100102 AddressAlign: 0x100103 - Name: blob5104 Type: SHT_PROGBITS105 Content: 'abbababa'106 Address: 0x2104107 - Name: section5108 Type: SHT_PROGBITS109 Address: 0x2108110 Content: 'ccddeeff'111 - Name: section6112 Type: SHT_PROGBITS113 Content: 'fefefefe'114 Address: 0x2200115 AddressAlign: 0x100116 - Name: blob6117 Type: SHT_PROGBITS118 Content: 'abbababa'119 Address: 0x2300120 AddressAlign: 0x100121 - Name: sectionA122 Type: SHT_PROGBITS123 Content: 'ffffeeee'124 Address: 0x3000125 AddressAlign: 0x1000126 - Name: sectionB127 Type: SHT_PROGBITS128 Content: 'ddddcccc'129 Address: 0x3004130 - Name: blobA131 Type: SHT_PROGBITS132 Content: 'abbababa'133 Address: 0x3008134 - Name: sectionC135 Type: SHT_PROGBITS136 Content: 'bbbbaaaa'137 Address: 0x300C138 - Name: blobB139 Type: SHT_PROGBITS140 Content: 'abbababa'141 Address: 0x3010142 - Name: sectionD143 Type: SHT_PROGBITS144 Content: '00009999'145 Address: 0x3014146 - Name: blobC147 Type: SHT_PROGBITS148 Content: 'abbababa'149 Address: 0x3018150 - Name: sectionE151 Type: SHT_PROGBITS152 Content: '88887777'153 Address: 0x301C154 - Name: blobD155 Type: SHT_PROGBITS156 Content: 'abbababa'157 Address: 0x3020158 - Name: sectionF159 Type: SHT_PROGBITS160 Content: '66665555'161 Address: 0x3024162 - Name: blobE163 Type: SHT_PROGBITS164 Content: 'abbababa'165 Address: 0x3028166 - Name: blobF167 Type: SHT_PROGBITS168 Content: 'abbababa'169 Address: 0x302C170 - Name: sectionG171 Type: SHT_PROGBITS172 Content: '44443333'173 Address: 0x3030174 - Name: blobG175 Type: SHT_PROGBITS176 Content: 'abbababa'177 Address: 0x3034178 - Name: sectionH179 Type: SHT_PROGBITS180 Content: '22221111'181 Address: 0x3038182 - Name: blobH183 Type: SHT_PROGBITS184 Content: 'abbababa'185 Address: 0x303C186 - Name: sectionI187 Type: SHT_PROGBITS188 Content: '00112233'189 Address: 0x3040190 - Name: blobz191 Type: SHT_PROGBITS192 Content: 'abbababa'193 Address: 0x4000194 AddressAlign: 0x1000195 - Name: sectionz196 Type: SHT_PROGBITS197 Content: '44556677'198 Address: 0x4004199 - Name: bloby200 Type: SHT_PROGBITS201 Content: 'abbababa'202 Address: 0x4008203 - Name: sectiony204 Type: SHT_PROGBITS205 Content: '8899aabb'206 Address: 0x400C207 - Name: blobx208 Type: SHT_PROGBITS209 Content: 'abbababa'210 Address: 0x4010211 - Name: blobw212 Type: SHT_PROGBITS213 Content: 'abbababa'214 Address: 0x4014215 - Name: sectionx216 Type: SHT_PROGBITS217 Content: 'ccddeeff'218 Address: 0x4018219 - Name: blobv220 Type: SHT_PROGBITS221 Content: 'abbababa'222 Address: 0x401C223 - Name: sectionw224 Type: SHT_PROGBITS225 Content: 'ffeeddcc'226 Address: 0x4020227 - Name: blobu228 Type: SHT_PROGBITS229 Content: 'abbababa'230 Address: 0x4024231 - Name: sectionv232 Type: SHT_PROGBITS233 Content: 'bbaa9988'234 Address: 0x4028235 - Name: sectionu236 Type: SHT_PROGBITS237 Content: '77665544'238 Address: 0x402C239 - Name: sectiont240 Type: SHT_PROGBITS241 Content: '33221100'242 Address: 0x4030243 - Name: blobt244 Type: SHT_PROGBITS245 Content: 'abbababa'246 Address: 0x4034247 - Name: sections248 Type: SHT_PROGBITS249 Content: '11111111'250 Address: 0x4038251 - Name: bloba252 Type: SHT_PROGBITS253 Content: 'abbababa'254 Address: 0x5000255 AddressAlign: 0x1000256 - Name: sectiona257 Type: SHT_PROGBITS258 Content: '12345678'259 Address: 0x5004260 - Name: blobb261 Type: SHT_PROGBITS262 Content: 'abbababa'263 Address: 0x5008264 - Name: sectionb265 Type: SHT_PROGBITS266 Content: '90abcdef'267 Address: 0x500C268 - Name: blobc269 Type: SHT_PROGBITS270 Content: 'abbababa'271 Address: 0x5010272 - Name: sectionc273 Type: SHT_PROGBITS274 Content: 'fedcba09'275 Address: 0x5014276 - Name: sectiond277 Type: SHT_PROGBITS278 Content: '87654321'279 Address: 0x5018280 - Name: blobd281 Type: SHT_PROGBITS282 Content: 'abbababa'283 Address: 0x501C284 - Name: sectione285 Type: SHT_PROGBITS286 Content: '22222222'287 Address: 0x5020288 - Name: blobe289 Type: SHT_PROGBITS290 Content: 'abbababa'291 Address: 0x5024292 - Name: sectionf293 Type: SHT_PROGBITS294 Content: '33333333'295 Address: 0x5028296 - Name: blobf297 Type: SHT_PROGBITS298 Content: 'abbababa'299 Address: 0x502C300 - Name: blobg301 Type: SHT_PROGBITS302 Content: 'abbababa'303 Address: 0x5030304 - Name: sectiong305 Type: SHT_PROGBITS306 Content: '44444444'307 Address: 0x5034308 - Name: blobh309 Type: SHT_PROGBITS310 Content: 'abbababa'311 Address: 0x5038312ProgramHeaders:313 # First segment has unlabelled space at start and end.314 - Type: 0x6ABCDEF0 # Non-specific segment type.315 VAddr: 0x2000316 Align: 0x2000317 FirstSec: blob1318 LastSec: blob4319 # Second segment has sections at start and end.320 - Type: 0x6ABCDEF0321 VAddr: 0x2100322 Align: 0x100323 FirstSec: section4324 LastSec: section5325 # Third segment is all covered by a section.326 - Type: 0x6ABCDEF0327 VAddr: 0x2200328 Align: 0x100329 FirstSec: section6330 LastSec: section6331 # Fourth segment has no sections (after removing blob headers).332 - Type: 0x6ABCDEF0333 VAddr: 0x2300334 Align: 0x100335 FirstSec: blob6336 LastSec: blob6337 # Fifth segment is empty.338 - Type: 0x6ABCDEF0339 VAddr: 0x2308340 Offset: 0x2308341 # The next few segments test behaviour of fully nested segments.342 # Sixth segment is the "parent" segment.343 - Type: 0x6ABCDEF0344 VAddr: 0x3000345 Align: 0x1000346 FirstSec: sectionA347 LastSec: sectionI348 # Seventh segment is empty and nested.349 - Type: 0x6ABCDEF0350 VAddr: 0x3002351 Offset: 0x3002352 # Eighth segment contains only a section and is nested.353 - Type: 0x6ABCDEF0354 VAddr: 0x3004355 FirstSec: sectionB356 LastSec: sectionB357 # Ninth segment contains only unlabelled space and is nested.358 - Type: 0x6ABCDEF0359 VAddr: 0x3008360 FirstSec: blobA361 LastSec: blobA362 # Tenth segment contains two sections with space between and is nested.363 - Type: 0x6ABCDEF0364 VAddr: 0x300C365 FirstSec: sectionC366 LastSec: sectionD367 # Eleventh segment contains two sections with space between and at ends and is nested.368 - Type: 0x6ABCDEF0369 VAddr: 0x3018370 FirstSec: blobC371 LastSec: blobE372 # Twelfth segment contains one section with space at ends adjacent to space in parent segment.373 - Type: 0x6ABCDEF0374 VAddr: 0x302E375 Offset: 0x302E376 FileSize: 8377 FirstSec: sectionG378 LastSec: sectionG379 # Thirteenth segment contains overlaps sections at either end in parent segment.380 - Type: 0x6ABCDEF0381 VAddr: 0x303A382 Offset: 0x303A383 FileSize: 0x8384 FirstSec: blobH385 LastSec: blobH386 387 # The next batch of segments are segments that only partially overlap other segments.388 389 # Segment14: |-unlabelled-|-Sec-|390 # Segment15: |--|-Sec-|-unlabelled-|391 - Type: 0x6ABCDEF0392 VAddr: 0x4000393 FirstSec: blobz394 LastSec: sectionz395 - Type: 0x6ABCDEF0396 VAddr: 0x4002397 Offset: 0x4002398 FirstSec: sectionz399 LastSec: bloby400 401 # Segment16: |-Sec-|--|402 # Segment17: |--|----unlabelled---|403 - Type: 0x6ABCDEF0404 VAddr: 0x400C405 FileSize: 6406 FirstSec: sectiony407 LastSec: sectiony408 - Type: 0x6ABCDEF0409 VAddr: 0x400E410 Offset: 0x400E411 FirstSec: blobx412 LastSec: blobx413 414 # Segment18: |-unlabelled-|-Sec-|415 # Segment19: |-Sec-|-unlabelled-|416 - Type: 0x6ABCDEF0417 VAddr: 0x4014418 FirstSec: blobw419 LastSec: sectionx420 - Type: 0x6ABCDEF0421 VAddr: 0x4018422 FirstSec: sectionx423 LastSec: blobv424 425 # Segment20: |-Sec-|426 # Segment21: |--|-unlabelled-|-Sec-|427 - Type: 0x6ABCDEF0428 VAddr: 0x4020429 FirstSec: sectionw430 LastSec: sectionw431 432 - Type: 0x6ABCDEF0433 VAddr: 0x4022434 Offset: 0x4022435 FirstSec: blobu436 LastSec: sectionv437 438 # Segment22: |-Sec-|439 # Segment23: |--|-Sec-|440 - Type: 0x6ABCDEF0441 VAddr: 0x402C442 FirstSec: sectionu443 LastSec: sectionu444 - Type: 0x6ABCDEF0445 VAddr: 0x402E446 Offset: 0x402E447 FirstSec: sectiont448 LastSec: sectiont449 450 # Segment24: |-unlabelled-|--|451 # Segment25: |--Sec--|452 - Type: 0x6ABCDEF0453 VAddr: 0x4034454 FileSize: 6455 FirstSec: blobt456 LastSec: blobt457 - Type: 0x6ABCDEF0458 VAddr: 0x4038459 FirstSec: sections460 LastSec: sections461 462 # The next batch of segments represent groups of three nested/overlapping segments,463 # with one parent segment containing two overlapping segments.464 465 # Segment26: |-unlabelled-|-Sec-|-unlabelled-|466 # Segment27: |------------|--|467 # Segment28: |-Sec-|------------|468 - Type: 0x6ABCDEF0469 VAddr: 0x5000470 Align: 0x1000471 FirstSec: bloba472 LastSec: blobb473 - Type: 0x6ABCDEF0474 VAddr: 0x5000475 FileSize: 6476 FirstSec: bloba477 LastSec: bloba478 - Type: 0x6ABCDEF0479 VAddr: 0x5004480 FirstSec: sectiona481 LastSec: blobb482 483 # Segment29: |-Sec-|-unlabelled-|-Sec-|484 # Segment30: |-Sec-|--------|485 # Segment31: |---------|-Sec-|486 - Type: 0x6ABCDEF0487 VAddr: 0x500C488 FirstSec: sectionb489 LastSec: sectionc490 - Type: 0x6ABCDEF0491 VAddr: 0x500C492 FileSize: 7493 FirstSec: sectionb494 LastSec: sectionb495 - Type: 0x6ABCDEF0496 VAddr: 0x5011497 Offset: 0x5011498 FirstSec: sectionc499 LastSec: sectionc500 501 # Segment32: |-Sec-|-unlabelled-|-Sec-|502 # Segment33: |-Sec-|------------|503 # Segment34: |------------|-Sec-|504 - Type: 0x6ABCDEF0505 VAddr: 0x5018506 FirstSec: sectiond507 LastSec: sectione508 - Type: 0x6ABCDEF0509 VAddr: 0x5018510 FirstSec: sectiond511 LastSec: blobd512 - Type: 0x6ABCDEF0513 VAddr: 0x501C514 FirstSec: blobd515 LastSec: sectione516 517 # Segment35: |-unlabelled-|-Sec-|-unlabelled-|518 # Segment36: |------------|-Sec-|519 # Segment37: |-Sec-|------------|520 - Type: 0x6ABCDEF0521 VAddr: 0x5024522 FirstSec: blobe523 LastSec: blobf524 - Type: 0x6ABCDEF0525 VAddr: 0x5024526 FirstSec: blobe527 LastSec: sectionf528 - Type: 0x6ABCDEF0529 VAddr: 0x5028530 FirstSec: sectionf531 LastSec: blobf532 533 # Segment38: |-unlabelled-|-Sec-|-unlabelled-|534 # Segment39: |------------|---|535 # Segment40: |---|------------|536 - Type: 0x6ABCDEF0537 VAddr: 0x5030538 FirstSec: blobg539 LastSec: blobh540 - Type: 0x6ABCDEF0541 VAddr: 0x5030542 FileSize: 7543 FirstSec: blobg544 LastSec: blobg545 - Type: 0x6ABCDEF0546 VAddr: 0x5035547 Offset: 0x5035548 FirstSec: blobh549 LastSec: blobh550