1 ## In this test we check that we allocate file space for SHT_NOBITS sections when
2 ## there are non-nobits sections in the same segment after them. When an object has
3 ## multiple segments, we check each and allocate the space if at least one matches the
4 ## condition mentioned.
6 ## Case A. In this case there are no non-nobits sections after SHT_NOBITS sections in segments.
7 ## Because of this the file space for SHT_NOBITS sections is not allocated.
8 # RUN: yaml2obj %s -D SEC1=.data.before -D SEC2=.nobits.1 -o %t1
9 # RUN: llvm-readelf --sections --segments %t1 | FileCheck %s --check-prefix=NO-ALLOC
11 # NO-ALLOC: [Nr] Name Type Address Off Size
12 # NO-ALLOC: [ 1] .data.before PROGBITS 0000000000000000 0000b0 000001
13 # NO-ALLOC-NEXT: [ 2] .nobits.1 NOBITS 0000000000000001 0000b1 000002
14 # NO-ALLOC-NEXT: [ 3] .data.after PROGBITS 0000000000000003 0000b1 000003
15 # NO-ALLOC-NEXT: [ 4] .nobits.2 NOBITS 0000000000000006 0000b4 000004
16 ## .fill of size 0x5 is placed here.
17 # NO-ALLOC-NEXT: [ 5] .data.last PROGBITS 000000000000000f 0000b9 000006
19 # NO-ALLOC: Type Offset VirtAddr PhysAddr FileSiz MemSiz
20 # NO-ALLOC-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003
21 # NO-ALLOC-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003
23 ## Case B. We have a segment that has a non-nobits section after the SHT_NOBITS section ".nobits.1".
24 ## The file space is allocated for it, but not for ".nobits.2",
25 ## which does not belong to any segment.
26 # RUN: yaml2obj %s -D SEC1=.nobits.1 -D SEC2=.data.after -o %t2
27 # RUN: llvm-readelf --sections --segments %t2 | FileCheck %s --check-prefix=ALLOC-FIRST
29 # ALLOC-FIRST: [Nr] Name Type Address Off Size
30 # ALLOC-FIRST: [ 1] .data.before PROGBITS 0000000000000000 0000b0 000001
31 # ALLOC-FIRST-NEXT: [ 2] .nobits.1 NOBITS 0000000000000001 0000b1 000002
32 # ALLOC-FIRST-NEXT: [ 3] .data.after PROGBITS 0000000000000003 0000b3 000003
33 # ALLOC-FIRST-NEXT: [ 4] .nobits.2 NOBITS 0000000000000006 0000b6 000004
34 ## .fill of size 0x5 is placed here.
35 # ALLOC-FIRST-NEXT: [ 5] .data.last PROGBITS 000000000000000f 0000bb 000006
37 # ALLOC-FIRST: Type Offset VirtAddr PhysAddr FileSiz MemSiz
38 # ALLOC-FIRST-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003
39 # ALLOC-FIRST-NEXT: LOAD 0x0000b1 0x0000000000000000 0x0000000000000000 0x000005 0x000005
41 ## Case C. We have a Fill after the ".nobits.2" section. In this case the file space is
42 ## allocated for it, because fills are handled just like any other non-nobits sections.
43 # RUN: yaml2obj %s -D SEC1=.nobits.2 -D SEC2=.fill -o %t3
44 # RUN: llvm-readelf --sections --segments %t3 | FileCheck %s --check-prefix=FILL-AT-END
46 # FILL-AT-END: [Nr] Name Type Address Off Size
47 # FILL-AT-END: [ 4] .nobits.2 NOBITS 0000000000000006 0000b4 000004
48 ## .fill of size 0x5 is placed here.
49 # FILL-AT-END: [ 5] .data.last PROGBITS 000000000000000f 0000bd 000006
51 # FILL-AT-END: Type Offset VirtAddr PhysAddr FileSiz MemSiz
52 # FILL-AT-END-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003
53 # FILL-AT-END-NEXT: LOAD 0x0000b4 0x0000000000000000 0x0000000000000000 0x000009 0x000009
86 ## We have 2 segments, the first is predefined and the second can be customized.
87 ## We want to have more than one segment to show we check all of them when
88 ## trying to find a non-nobits section after a nobits one.
91 FirstSec: .data.before
98 ## Case D. We have a segment with SHT_NOBITS sections on its borders and one
99 ## non-nobits in the middle. Check we allocate the file space only for
100 ## the first nobits section.
102 # RUN: yaml2obj --docnum=2 %s -o %t4
103 # RUN: llvm-readelf --sections --segments %t4 | FileCheck %s --check-prefix=MIDDLE
105 # MIDDLE: [Nr] Name Type Address Off Size
106 # MIDDLE: [ 1] .nobits.1 NOBITS 0000000000000000 000078 000001
107 # MIDDLE-NEXT: [ 2] .data PROGBITS 0000000000000001 000079 000010
108 # MIDDLE-NEXT: [ 3] .nobits.2 NOBITS 0000000000000011 000089 000100
109 # MIDDLE-NEXT: [ 4] .strtab STRTAB 0000000000000000 000089 000001
111 # MIDDLE: Type Offset VirtAddr PhysAddr FileSiz MemSiz
112 # MIDDLE-NEXT: LOAD 0x000078 0x0000000000000000 0x0000000000000000 0x000011 0x000111