File: program-header-nobits.yaml

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (136 lines) | stat: -rw-r--r-- 5,644 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
## In this test we check that we allocate file space for SHT_NOBITS sections when
## there are non-nobits sections in the same segment after them. When an object has
## multiple segments, we check each and allocate the space if at least one matches the
## condition mentioned.

## Case A. In this case there are no non-nobits sections after SHT_NOBITS sections in segments.
##         Because of this the file space for SHT_NOBITS sections is not allocated.
# RUN: yaml2obj %s -D SEC1=.data.before -D SEC2=.nobits.1 -o %t1
# RUN: llvm-readelf --sections --segments %t1 | FileCheck %s --check-prefix=NO-ALLOC

# NO-ALLOC:      [Nr] Name         Type     Address          Off    Size
# NO-ALLOC:      [ 1] .data.before PROGBITS 0000000000000000 0000b0 000001
# NO-ALLOC-NEXT: [ 2] .nobits.1    NOBITS   0000000000000001 0000b1 000002
# NO-ALLOC-NEXT: [ 3] .data.after  PROGBITS 0000000000000003 0000b1 000003
# NO-ALLOC-NEXT: [ 4] .nobits.2    NOBITS   0000000000000006 0000b4 000004
## .fill of size 0x5 is placed here.
# NO-ALLOC-NEXT: [ 5] .data.last   PROGBITS 000000000000000f 0000b9 000006

# NO-ALLOC:       Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
# NO-ALLOC-NEXT:  LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003
# NO-ALLOC-NEXT:  LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003

## Case B. We have a segment that has a non-nobits section after the SHT_NOBITS section ".nobits.1".
##         The file space is allocated for it, but not for ".nobits.2",
##         which does not belong to any segment.
# RUN: yaml2obj %s -D SEC1=.nobits.1 -D SEC2=.data.after -o %t2
# RUN: llvm-readelf --sections --segments %t2 | FileCheck %s --check-prefix=ALLOC-FIRST

# ALLOC-FIRST:      [Nr] Name         Type     Address          Off    Size
# ALLOC-FIRST:      [ 1] .data.before PROGBITS 0000000000000000 0000b0 000001
# ALLOC-FIRST-NEXT: [ 2] .nobits.1    NOBITS   0000000000000001 0000b1 000002
# ALLOC-FIRST-NEXT: [ 3] .data.after  PROGBITS 0000000000000003 0000b3 000003
# ALLOC-FIRST-NEXT: [ 4] .nobits.2    NOBITS   0000000000000006 0000b6 000004
## .fill of size 0x5 is placed here.
# ALLOC-FIRST-NEXT: [ 5] .data.last   PROGBITS 000000000000000f 0000bb 000006

# ALLOC-FIRST:       Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
# ALLOC-FIRST-NEXT:  LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003
# ALLOC-FIRST-NEXT:  LOAD 0x0000b1 0x0000000000000000 0x0000000000000000 0x000005 0x000005

## Case C. We have a Fill after the ".nobits.2" section. In this case the file space is
##         allocated for it, because fills are handled just like any other non-nobits sections.
# RUN: yaml2obj %s -D SEC1=.nobits.2 -D SEC2=.fill -o %t3
# RUN: llvm-readelf --sections --segments %t3 | FileCheck %s --check-prefix=FILL-AT-END

# FILL-AT-END: [Nr] Name       Type     Address          Off    Size
# FILL-AT-END: [ 4] .nobits.2  NOBITS   0000000000000006 0000b4 000004
## .fill of size 0x5 is placed here.
# FILL-AT-END: [ 5] .data.last PROGBITS 000000000000000f 0000bd 000006

# FILL-AT-END:      Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
# FILL-AT-END-NEXT: LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x000001 0x000003
# FILL-AT-END-NEXT: LOAD 0x0000b4 0x0000000000000000 0x0000000000000000 0x000009 0x000009

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name:  .data.before
    Type:  SHT_PROGBITS
    Flags: [ SHF_ALLOC ]
    Size:  0x1
  - Name:  .nobits.1
    Type:  SHT_NOBITS
    Flags: [ SHF_ALLOC ]
    Size:  0x2
  - Name:  .data.after
    Type:  SHT_PROGBITS
    Flags: [ SHF_ALLOC ]
    Size:  0x3
  - Name:  .nobits.2
    Type:  SHT_NOBITS
    Flags: [ SHF_ALLOC ]
    Size:  0x4
  - Type:    Fill
    Name:    .fill
    Pattern: "00"
    Size:    5
  - Name:  .data.last
    Type:  SHT_PROGBITS
    Flags: [ SHF_ALLOC ]
    Size:  0x6
ProgramHeaders:
## We have 2 segments, the first is predefined and the second can be customized.
## We want to have more than one segment to show we check all of them when
## trying to find a non-nobits section after a nobits one.
  - Type:     PT_LOAD
    Flags:    [ PF_R ]
    FirstSec: .data.before
    LastSec:  .nobits.1
  - Type:     PT_LOAD
    Flags:    [ PF_R ]
    FirstSec: [[SEC1]]
    LastSec:  [[SEC2]]

## Case D. We have a segment with SHT_NOBITS sections on its borders and one
##         non-nobits in the middle. Check we allocate the file space only for
##         the first nobits section.

# RUN: yaml2obj --docnum=2 %s -o %t4
# RUN: llvm-readelf --sections --segments %t4 | FileCheck %s --check-prefix=MIDDLE

# MIDDLE:      [Nr] Name      Type     Address          Off    Size
# MIDDLE:      [ 1] .nobits.1 NOBITS   0000000000000000 000078 000001
# MIDDLE-NEXT: [ 2] .data     PROGBITS 0000000000000001 000079 000010
# MIDDLE-NEXT: [ 3] .nobits.2 NOBITS   0000000000000011 000089 000100
# MIDDLE-NEXT: [ 4] .strtab   STRTAB   0000000000000000 000089 000001

# MIDDLE:      Type Offset   VirtAddr           PhysAddr           FileSiz  MemSiz
# MIDDLE-NEXT: LOAD 0x000078 0x0000000000000000 0x0000000000000000 0x000011 0x000111

--- !ELF
FileHeader:
  Class: ELFCLASS64
  Data:  ELFDATA2LSB
  Type:  ET_EXEC
Sections:
  - Name:  .nobits.1
    Type:  SHT_NOBITS
    Flags: [ SHF_ALLOC ]
    Size:  0x1
  - Name:  .data
    Type:  SHT_PROGBITS
    Flags: [ SHF_ALLOC ]
    Size:  0x10
  - Name:  .nobits.2
    Type:  SHT_NOBITS
    Flags: [ SHF_ALLOC ]
    Size:  0x100
ProgramHeaders:
  - Type:     PT_LOAD
    Flags:    [ PF_R ]
    FirstSec: .nobits.1
    LastSec:  .nobits.2