137 lines · yaml
1## In this test we check that we allocate file space for SHT_NOBITS sections when2## there are non-nobits sections in the same segment after them. When an object has3## multiple segments, we check each and allocate the space if at least one matches the4## condition mentioned.5 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 %t19# RUN: llvm-readelf --sections --segments %t1 | FileCheck %s --check-prefix=NO-ALLOC10 11# NO-ALLOC: [Nr] Name Type Address Off Size12# NO-ALLOC: [ 1] .data.before PROGBITS 0000000000000000 0000b0 00000113# NO-ALLOC-NEXT: [ 2] .nobits.1 NOBITS 0000000000000001 0000b1 00000214# NO-ALLOC-NEXT: [ 3] .data.after PROGBITS 0000000000000003 0000b1 00000315# NO-ALLOC-NEXT: [ 4] .nobits.2 NOBITS 0000000000000006 0000b4 00000416## .fill of size 0x5 is placed here.17# NO-ALLOC-NEXT: [ 5] .data.last PROGBITS 000000000000000f 0000b9 00000618 19# NO-ALLOC: Type Offset VirtAddr PhysAddr FileSiz MemSiz20# NO-ALLOC-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x00000321# NO-ALLOC-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x00000322 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 %t227# RUN: llvm-readelf --sections --segments %t2 | FileCheck %s --check-prefix=ALLOC-FIRST28 29# ALLOC-FIRST: [Nr] Name Type Address Off Size30# ALLOC-FIRST: [ 1] .data.before PROGBITS 0000000000000000 0000b0 00000131# ALLOC-FIRST-NEXT: [ 2] .nobits.1 NOBITS 0000000000000001 0000b1 00000232# ALLOC-FIRST-NEXT: [ 3] .data.after PROGBITS 0000000000000003 0000b3 00000333# ALLOC-FIRST-NEXT: [ 4] .nobits.2 NOBITS 0000000000000006 0000b6 00000434## .fill of size 0x5 is placed here.35# ALLOC-FIRST-NEXT: [ 5] .data.last PROGBITS 000000000000000f 0000bb 00000636 37# ALLOC-FIRST: Type Offset VirtAddr PhysAddr FileSiz MemSiz38# ALLOC-FIRST-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x00000339# ALLOC-FIRST-NEXT: LOAD 0x0000b1 0x0000000000000000 0x0000000000000000 0x000005 0x00000540 41## Case C. We have a Fill after the ".nobits.2" section. In this case the file space is42## 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 %t344# RUN: llvm-readelf --sections --segments %t3 | FileCheck %s --check-prefix=FILL-AT-END45 46# FILL-AT-END: [Nr] Name Type Address Off Size47# FILL-AT-END: [ 4] .nobits.2 NOBITS 0000000000000006 0000b4 00000448## .fill of size 0x5 is placed here.49# FILL-AT-END: [ 5] .data.last PROGBITS 000000000000000f 0000bd 00000650 51# FILL-AT-END: Type Offset VirtAddr PhysAddr FileSiz MemSiz52# FILL-AT-END-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x00000353# FILL-AT-END-NEXT: LOAD 0x0000b4 0x0000000000000000 0x0000000000000000 0x000009 0x00000954 55--- !ELF56FileHeader:57 Class: ELFCLASS6458 Data: ELFDATA2LSB59 Type: ET_EXEC60Sections:61 - Name: .data.before62 Type: SHT_PROGBITS63 Flags: [ SHF_ALLOC ]64 Size: 0x165 - Name: .nobits.166 Type: SHT_NOBITS67 Flags: [ SHF_ALLOC ]68 Size: 0x269 - Name: .data.after70 Type: SHT_PROGBITS71 Flags: [ SHF_ALLOC ]72 Size: 0x373 - Name: .nobits.274 Type: SHT_NOBITS75 Flags: [ SHF_ALLOC ]76 Size: 0x477 - Type: Fill78 Name: .fill79 Pattern: "00"80 Size: 581 - Name: .data.last82 Type: SHT_PROGBITS83 Flags: [ SHF_ALLOC ]84 Size: 0x685ProgramHeaders: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 when88## trying to find a non-nobits section after a nobits one.89 - Type: PT_LOAD90 Flags: [ PF_R ]91 FirstSec: .data.before92 LastSec: .nobits.193 - Type: PT_LOAD94 Flags: [ PF_R ]95 FirstSec: [[SEC1]]96 LastSec: [[SEC2]]97 98## Case D. We have a segment with SHT_NOBITS sections on its borders and one99## non-nobits in the middle. Check we allocate the file space only for100## the first nobits section.101 102# RUN: yaml2obj --docnum=2 %s -o %t4103# RUN: llvm-readelf --sections --segments %t4 | FileCheck %s --check-prefix=MIDDLE104 105# MIDDLE: [Nr] Name Type Address Off Size106# MIDDLE: [ 1] .nobits.1 NOBITS 0000000000000000 000078 000001107# MIDDLE-NEXT: [ 2] .data PROGBITS 0000000000000001 000079 000010108# MIDDLE-NEXT: [ 3] .nobits.2 NOBITS 0000000000000011 000089 000100109# MIDDLE-NEXT: [ 4] .strtab STRTAB 0000000000000000 000089 000001110 111# MIDDLE: Type Offset VirtAddr PhysAddr FileSiz MemSiz112# MIDDLE-NEXT: LOAD 0x000078 0x0000000000000000 0x0000000000000000 0x000011 0x000111113 114--- !ELF115FileHeader:116 Class: ELFCLASS64117 Data: ELFDATA2LSB118 Type: ET_EXEC119Sections:120 - Name: .nobits.1121 Type: SHT_NOBITS122 Flags: [ SHF_ALLOC ]123 Size: 0x1124 - Name: .data125 Type: SHT_PROGBITS126 Flags: [ SHF_ALLOC ]127 Size: 0x10128 - Name: .nobits.2129 Type: SHT_NOBITS130 Flags: [ SHF_ALLOC ]131 Size: 0x100132ProgramHeaders:133 - Type: PT_LOAD134 Flags: [ PF_R ]135 FirstSec: .nobits.1136 LastSec: .nobits.2137