1818ab3d6SGeorgii Rymar## In this test we check that we allocate file space for SHT_NOBITS sections when 2818ab3d6SGeorgii Rymar## there are non-nobits sections in the same segment after them. When an object has 3818ab3d6SGeorgii Rymar## multiple segments, we check each and allocate the space if at least one matches the 4818ab3d6SGeorgii Rymar## condition mentioned. 563f0f54cSFangrui Song 6818ab3d6SGeorgii Rymar## Case A. In this case there are no non-nobits sections after SHT_NOBITS sections in segments. 7818ab3d6SGeorgii Rymar## Because of this the file space for SHT_NOBITS sections is not allocated. 8818ab3d6SGeorgii Rymar# RUN: yaml2obj %s -D SEC1=.data.before -D SEC2=.nobits.1 -o %t1 9818ab3d6SGeorgii Rymar# RUN: llvm-readelf --sections --segments %t1 | FileCheck %s --check-prefix=NO-ALLOC 10818ab3d6SGeorgii Rymar 11818ab3d6SGeorgii Rymar# NO-ALLOC: [Nr] Name Type Address Off Size 12818ab3d6SGeorgii Rymar# NO-ALLOC: [ 1] .data.before PROGBITS 0000000000000000 0000b0 000001 13818ab3d6SGeorgii Rymar# NO-ALLOC-NEXT: [ 2] .nobits.1 NOBITS 0000000000000001 0000b1 000002 14818ab3d6SGeorgii Rymar# NO-ALLOC-NEXT: [ 3] .data.after PROGBITS 0000000000000003 0000b1 000003 15818ab3d6SGeorgii Rymar# NO-ALLOC-NEXT: [ 4] .nobits.2 NOBITS 0000000000000006 0000b4 000004 16818ab3d6SGeorgii Rymar## .fill of size 0x5 is placed here. 17818ab3d6SGeorgii Rymar# NO-ALLOC-NEXT: [ 5] .data.last PROGBITS 000000000000000f 0000b9 000006 18818ab3d6SGeorgii Rymar 19818ab3d6SGeorgii Rymar# NO-ALLOC: Type Offset VirtAddr PhysAddr FileSiz MemSiz 20818ab3d6SGeorgii Rymar# NO-ALLOC-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003 21818ab3d6SGeorgii Rymar# NO-ALLOC-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003 22818ab3d6SGeorgii Rymar 23818ab3d6SGeorgii Rymar## Case B. We have a segment that has a non-nobits section after the SHT_NOBITS section ".nobits.1". 24818ab3d6SGeorgii Rymar## The file space is allocated for it, but not for ".nobits.2", 25818ab3d6SGeorgii Rymar## which does not belong to any segment. 26818ab3d6SGeorgii Rymar# RUN: yaml2obj %s -D SEC1=.nobits.1 -D SEC2=.data.after -o %t2 27818ab3d6SGeorgii Rymar# RUN: llvm-readelf --sections --segments %t2 | FileCheck %s --check-prefix=ALLOC-FIRST 28818ab3d6SGeorgii Rymar 29818ab3d6SGeorgii Rymar# ALLOC-FIRST: [Nr] Name Type Address Off Size 30818ab3d6SGeorgii Rymar# ALLOC-FIRST: [ 1] .data.before PROGBITS 0000000000000000 0000b0 000001 31818ab3d6SGeorgii Rymar# ALLOC-FIRST-NEXT: [ 2] .nobits.1 NOBITS 0000000000000001 0000b1 000002 32818ab3d6SGeorgii Rymar# ALLOC-FIRST-NEXT: [ 3] .data.after PROGBITS 0000000000000003 0000b3 000003 33818ab3d6SGeorgii Rymar# ALLOC-FIRST-NEXT: [ 4] .nobits.2 NOBITS 0000000000000006 0000b6 000004 34818ab3d6SGeorgii Rymar## .fill of size 0x5 is placed here. 35818ab3d6SGeorgii Rymar# ALLOC-FIRST-NEXT: [ 5] .data.last PROGBITS 000000000000000f 0000bb 000006 36818ab3d6SGeorgii Rymar 37818ab3d6SGeorgii Rymar# ALLOC-FIRST: Type Offset VirtAddr PhysAddr FileSiz MemSiz 38818ab3d6SGeorgii Rymar# ALLOC-FIRST-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003 39818ab3d6SGeorgii Rymar# ALLOC-FIRST-NEXT: LOAD 0x0000b1 0x0000000000000000 0x0000000000000000 0x000005 0x000005 40818ab3d6SGeorgii Rymar 41818ab3d6SGeorgii Rymar## Case C. We have a Fill after the ".nobits.2" section. In this case the file space is 42818ab3d6SGeorgii Rymar## allocated for it, because fills are handled just like any other non-nobits sections. 43818ab3d6SGeorgii Rymar# RUN: yaml2obj %s -D SEC1=.nobits.2 -D SEC2=.fill -o %t3 44818ab3d6SGeorgii Rymar# RUN: llvm-readelf --sections --segments %t3 | FileCheck %s --check-prefix=FILL-AT-END 45818ab3d6SGeorgii Rymar 46818ab3d6SGeorgii Rymar# FILL-AT-END: [Nr] Name Type Address Off Size 47818ab3d6SGeorgii Rymar# FILL-AT-END: [ 4] .nobits.2 NOBITS 0000000000000006 0000b4 000004 48818ab3d6SGeorgii Rymar## .fill of size 0x5 is placed here. 49818ab3d6SGeorgii Rymar# FILL-AT-END: [ 5] .data.last PROGBITS 000000000000000f 0000bd 000006 50818ab3d6SGeorgii Rymar 51818ab3d6SGeorgii Rymar# FILL-AT-END: Type Offset VirtAddr PhysAddr FileSiz MemSiz 52818ab3d6SGeorgii Rymar# FILL-AT-END-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003 53818ab3d6SGeorgii Rymar# FILL-AT-END-NEXT: LOAD 0x0000b4 0x0000000000000000 0x0000000000000000 0x000009 0x000009 54818ab3d6SGeorgii Rymar 55818ab3d6SGeorgii Rymar--- !ELF 5663f0f54cSFangrui SongFileHeader: 5763f0f54cSFangrui Song Class: ELFCLASS64 5863f0f54cSFangrui Song Data: ELFDATA2LSB 5963f0f54cSFangrui Song Type: ET_EXEC 6063f0f54cSFangrui SongSections: 61818ab3d6SGeorgii Rymar - Name: .data.before 62818ab3d6SGeorgii Rymar Type: SHT_PROGBITS 63818ab3d6SGeorgii Rymar Flags: [ SHF_ALLOC ] 64818ab3d6SGeorgii Rymar Size: 0x1 65818ab3d6SGeorgii Rymar - Name: .nobits.1 66818ab3d6SGeorgii Rymar Type: SHT_NOBITS 67818ab3d6SGeorgii Rymar Flags: [ SHF_ALLOC ] 68818ab3d6SGeorgii Rymar Size: 0x2 69818ab3d6SGeorgii Rymar - Name: .data.after 70818ab3d6SGeorgii Rymar Type: SHT_PROGBITS 71818ab3d6SGeorgii Rymar Flags: [ SHF_ALLOC ] 72818ab3d6SGeorgii Rymar Size: 0x3 73818ab3d6SGeorgii Rymar - Name: .nobits.2 74818ab3d6SGeorgii Rymar Type: SHT_NOBITS 75818ab3d6SGeorgii Rymar Flags: [ SHF_ALLOC ] 76818ab3d6SGeorgii Rymar Size: 0x4 77818ab3d6SGeorgii Rymar - Type: Fill 78818ab3d6SGeorgii Rymar Name: .fill 79818ab3d6SGeorgii Rymar Pattern: "00" 80818ab3d6SGeorgii Rymar Size: 5 81818ab3d6SGeorgii Rymar - Name: .data.last 82818ab3d6SGeorgii Rymar Type: SHT_PROGBITS 83818ab3d6SGeorgii Rymar Flags: [ SHF_ALLOC ] 84818ab3d6SGeorgii Rymar Size: 0x6 85818ab3d6SGeorgii RymarProgramHeaders: 86818ab3d6SGeorgii Rymar## We have 2 segments, the first is predefined and the second can be customized. 87818ab3d6SGeorgii Rymar## We want to have more than one segment to show we check all of them when 88818ab3d6SGeorgii Rymar## trying to find a non-nobits section after a nobits one. 89818ab3d6SGeorgii Rymar - Type: PT_LOAD 90818ab3d6SGeorgii Rymar Flags: [ PF_R ] 91*a7a447beSGeorgii Rymar FirstSec: .data.before 92*a7a447beSGeorgii Rymar LastSec: .nobits.1 93818ab3d6SGeorgii Rymar - Type: PT_LOAD 94818ab3d6SGeorgii Rymar Flags: [ PF_R ] 95*a7a447beSGeorgii Rymar FirstSec: [[SEC1]] 96*a7a447beSGeorgii Rymar LastSec: [[SEC2]] 97818ab3d6SGeorgii Rymar 98818ab3d6SGeorgii Rymar## Case D. We have a segment with SHT_NOBITS sections on its borders and one 99818ab3d6SGeorgii Rymar## non-nobits in the middle. Check we allocate the file space only for 100818ab3d6SGeorgii Rymar## the first nobits section. 101818ab3d6SGeorgii Rymar 102818ab3d6SGeorgii Rymar# RUN: yaml2obj --docnum=2 %s -o %t4 103818ab3d6SGeorgii Rymar# RUN: llvm-readelf --sections --segments %t4 | FileCheck %s --check-prefix=MIDDLE 104818ab3d6SGeorgii Rymar 105818ab3d6SGeorgii Rymar# MIDDLE: [Nr] Name Type Address Off Size 106818ab3d6SGeorgii Rymar# MIDDLE: [ 1] .nobits.1 NOBITS 0000000000000000 000078 000001 107818ab3d6SGeorgii Rymar# MIDDLE-NEXT: [ 2] .data PROGBITS 0000000000000001 000079 000010 108818ab3d6SGeorgii Rymar# MIDDLE-NEXT: [ 3] .nobits.2 NOBITS 0000000000000011 000089 000100 109818ab3d6SGeorgii Rymar# MIDDLE-NEXT: [ 4] .strtab STRTAB 0000000000000000 000089 000001 110818ab3d6SGeorgii Rymar 111818ab3d6SGeorgii Rymar# MIDDLE: Type Offset VirtAddr PhysAddr FileSiz MemSiz 112818ab3d6SGeorgii Rymar# MIDDLE-NEXT: LOAD 0x000078 0x0000000000000000 0x0000000000000000 0x000011 0x000111 113818ab3d6SGeorgii Rymar 114818ab3d6SGeorgii Rymar--- !ELF 115818ab3d6SGeorgii RymarFileHeader: 116818ab3d6SGeorgii Rymar Class: ELFCLASS64 117818ab3d6SGeorgii Rymar Data: ELFDATA2LSB 118818ab3d6SGeorgii Rymar Type: ET_EXEC 119818ab3d6SGeorgii RymarSections: 120818ab3d6SGeorgii Rymar - Name: .nobits.1 121818ab3d6SGeorgii Rymar Type: SHT_NOBITS 122818ab3d6SGeorgii Rymar Flags: [ SHF_ALLOC ] 123818ab3d6SGeorgii Rymar Size: 0x1 12463f0f54cSFangrui Song - Name: .data 12563f0f54cSFangrui Song Type: SHT_PROGBITS 12663f0f54cSFangrui Song Flags: [ SHF_ALLOC ] 127818ab3d6SGeorgii Rymar Size: 0x10 128818ab3d6SGeorgii Rymar - Name: .nobits.2 12963f0f54cSFangrui Song Type: SHT_NOBITS 13063f0f54cSFangrui Song Flags: [ SHF_ALLOC ] 131818ab3d6SGeorgii Rymar Size: 0x100 13263f0f54cSFangrui SongProgramHeaders: 13363f0f54cSFangrui Song - Type: PT_LOAD 13463f0f54cSFangrui Song Flags: [ PF_R ] 135*a7a447beSGeorgii Rymar FirstSec: .nobits.1 136*a7a447beSGeorgii Rymar LastSec: .nobits.2 137