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, between
3 # sections in a segment, and after all sections in a segment.
4 # To create inputs with arbitrary data in segments, not covered by sections, we
5 # use yaml2obj to create segments with sections covering all areas, then remove
6 # some sections in those segments, and finally write over the areas of the
7 # removed sections using python.
9 # blob* sections are the sections that will be removed to create unlabelled
10 # areas and then overwritten with data to show we preserve the data.
12 # RUN: yaml2obj %s -o %t.base
13 # RUN: llvm-objcopy %t.base %t.stripped --regex -R blob.*
14 # Show that the removal leaves the bytes as zeroes, as desired, for all our
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"
24 # RUN: cp %t.stripped %t.in
25 # RUN: echo "with open('%/t.in', 'rb+') as input:" > %t.py
26 # RUN: echo " for offset in [" >> %t.py
27 # RUN: echo " 0x2000, 0x2008, 0x200C, 0x2018, 0x2104, 0x2300," >> %t.py
28 # RUN: echo " 0x3008, 0x3010, 0x3018, 0x3020, 0x3028, 0x302C, 0x3034, 0x303C," >> %t.py
29 # RUN: echo " 0x4000, 0x4008, 0x4010, 0x4014, 0x401C, 0x4024, 0x4034," >> %t.py
30 # RUN: echo " 0x5000, 0x5008, 0x5010, 0x501C, 0x5024, 0x502C, 0x5030, 0x5038]:" >> %t.py
31 # RUN: echo " input.seek(offset)" >> %t.py
32 # RUN: echo " input.write(bytearray.fromhex('DEADBEEF'))" >> %t.py
34 # RUN: llvm-objcopy %t.in %t.out
35 # 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"
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 ff
47 # CHECK4: [[PATTERN]] 00 00 00 00 00 00 00 00
48 # CHECK5: ff ff ee ee dd dd cc cc [[PATTERN]] bb bb aa aa
49 # CHECK5-NEXT: [[PATTERN]] 00 00 99 99 [[PATTERN]] 88 88 77 77
50 # 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 33
53 # CHECK6: [[PATTERN]] 44 55 66 77 [[PATTERN]] 88 99 aa bb
54 # CHECK6-NEXT: [[PATTERN]] [[PATTERN]] cc dd ee ff [[PATTERN]]
55 # CHECK6-NEXT: ff ee dd cc [[PATTERN]] bb aa 99 88 77 66 55 44
56 # CHECK6-NEXT: 33 22 11 00 [[PATTERN]] 11 11 11 11
57 # CHECK7: [[PATTERN]] 12 34 56 78 [[PATTERN]] 90 ab cd ef
58 # 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]]
313 # First segment has unlabelled space at start and end.
314 - Type: 0x6ABCDEF0 # Non-specific segment type.
319 # Second segment has sections at start and end.
325 # Third segment is all covered by a section.
331 # Fourth segment has no sections (after removing blob headers).
337 # Fifth segment is empty.
341 # The next few segments test behaviour of fully nested segments.
342 # Sixth segment is the "parent" segment.
348 # Seventh segment is empty and nested.
352 # Eighth segment contains only a section and is nested.
357 # Ninth segment contains only unlabelled space and is nested.
362 # Tenth segment contains two sections with space between and is nested.
367 # Eleventh segment contains two sections with space between and at ends and is nested.
372 # Twelfth segment contains one section with space at ends adjacent to space in parent segment.
379 # Thirteenth segment contains overlaps sections at either end in parent segment.
387 # The next batch of segments are segments that only partially overlap other segments.
389 # Segment14: |-unlabelled-|-Sec-|
390 # Segment15: |--|-Sec-|-unlabelled-|
401 # Segment16: |-Sec-|--|
402 # Segment17: |--|----unlabelled---|
414 # Segment18: |-unlabelled-|-Sec-|
415 # Segment19: |-Sec-|-unlabelled-|
426 # Segment21: |--|-unlabelled-|-Sec-|
439 # Segment23: |--|-Sec-|
450 # Segment24: |-unlabelled-|--|
451 # Segment25: |--Sec--|
462 # The next batch of segments represent groups of three nested/overlapping segments,
463 # with one parent segment containing two overlapping segments.
465 # Segment26: |-unlabelled-|-Sec-|-unlabelled-|
466 # Segment27: |------------|--|
467 # Segment28: |-Sec-|------------|
483 # Segment29: |-Sec-|-unlabelled-|-Sec-|
484 # Segment30: |-Sec-|--------|
485 # Segment31: |---------|-Sec-|
501 # Segment32: |-Sec-|-unlabelled-|-Sec-|
502 # Segment33: |-Sec-|------------|
503 # Segment34: |------------|-Sec-|
517 # Segment35: |-unlabelled-|-Sec-|-unlabelled-|
518 # Segment36: |------------|-Sec-|
519 # Segment37: |-Sec-|------------|
533 # Segment38: |-unlabelled-|-Sec-|-unlabelled-|
534 # Segment39: |------------|---|
535 # Segment40: |---|------------|