section-offset.yaml
4.87 KB
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
## Check we are able to set an offset field for sections using the 'Offset' key.
## Show how the 'Offset' field key can be used.
## Show that it can affect the layout of the rest of the file.
# RUN: yaml2obj --docnum=1 %s -o %t1
# RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=DEFAULT
# DEFAULT: [Nr] Name Type Address Off
# DEFAULT: [ 1] .foo PROGBITS 0000000000000000 000040
# DEFAULT-NEXT: [ 2] .bar PROGBITS 0000000000000000 000048
# DEFAULT-NEXT: [ 3] .strtab STRTAB 0000000000000000 000058
# DEFAULT-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 000059
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Sections:
- Name: .foo
Type: SHT_PROGBITS
Size: 0x8
- Name: .bar
Type: SHT_PROGBITS
Size: 0x10
## It is a no-op. We set it to reduce amount
## of differences with the second YAML below.
AddressAlign: 0x0
## The same as previous, but an arbitrary 'Offset' is set for the .bar section.
# RUN: yaml2obj --docnum=2 %s -o %t2 -DOFFSET=0x50 -DALIGN=0x0
# RUN: llvm-readelf --sections %t2 | FileCheck %s --check-prefix=OFFSET
# OFFSET: [Nr] Name Type Address Off
# OFFSET: [ 1] .foo PROGBITS 0000000000000000 000040
# OFFSET-NEXT: [ 2] .bar PROGBITS 0000000000000000 000050
# OFFSET-NEXT: [ 3] .strtab STRTAB 0000000000000000 000060
# OFFSET-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 000061
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Sections:
- Name: .foo
Type: SHT_PROGBITS
Size: 0x8
- Name: .bar
Type: SHT_PROGBITS
Size: 0x10
Offset: [[OFFSET]]
AddressAlign: [[ALIGN]]
## Set the 'Offset' to the same value as was set by default to show
## that there is no difference in the output in this case.
# RUN: yaml2obj --docnum=2 %s -o %t3 -DOFFSET=0x48 -DALIGN=0x0
# RUN: cmp %t1 %t3
## Show that we can set an offset and an address alignment independently for a section.
# RUN: yaml2obj --docnum=2 %s -o %t4 -DOFFSET=0x48 -DALIGN=0x5
# RUN: llvm-readelf --sections %t4 | FileCheck %s --check-prefix=OFFSET-AND-ALIGN
# OFFSET-AND-ALIGN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
# OFFSET-AND-ALIGN: [ 2] .bar PROGBITS 0000000000000000 000048 000010 00 0 0 5
## Show we do not allow an 'Offset' to go backward.
# RUN: not yaml2obj --docnum=2 %s -DOFFSET=0x47 -DALIGN=0x0 2>&1 | \
# RUN: FileCheck %s --check-prefix=ERR-BACKWARD
# ERR-BACKWARD: error: the 'Offset' value (0x47) goes backward
## Show that the 'Offset' key can be used together with the 'ShOffset' key.
## Case 1: set the same value for 'Offset' and 'ShOffset' keys.
# RUN: yaml2obj --docnum=3 %s -o %t5 -DSHOFFSET=0x100 -DOFFSET=0x100
# RUN: llvm-readelf --headers --sections %t5 | FileCheck %s --check-prefix=BOTH-SAME
## The same offset as in the Case 3.
# BOTH-SAME: Start of section headers: 288 (bytes into file)
# BOTH-SAME: [Nr] Name Type Address Off
# BOTH-SAME: [ 1] .foo PROGBITS 0000000000000000 000100
# BOTH-SAME-NEXT: [ 2] .bar PROGBITS 0000000000000000 000101
# BOTH-SAME-NEXT: [ 3] .strtab STRTAB 0000000000000000 000102
## Case 2: set the 'Offset' value to be less than the 'ShOffset'.
# RUN: yaml2obj --docnum=3 %s -o %t6 -DSHOFFSET=0x100 -DOFFSET=0x90
# RUN: llvm-readelf --headers --sections %t6 | FileCheck %s --check-prefix=BOTH-A
## 176 < 288 (start of section headers in Case 1).
# BOTH-A: Start of section headers: 176 (bytes into file)
## Show that the 'Offset' field sets the physical offset in a file and the `ShOffset`
## field only overrides the sh_offset value of the .foo section.
# BOTH-A: [Nr] Name Type Address Off
# BOTH-A: [ 1] .foo PROGBITS 0000000000000000 000100
# BOTH-A-NEXT: [ 2] .bar PROGBITS 0000000000000000 000091
# BOTH-A-NEXT: [ 3] .strtab STRTAB 0000000000000000 000092
## Case 3: set the 'Offset' value to be greater than the 'ShOffset' value.
# RUN: yaml2obj --docnum=3 %s -o %t7 -DSHOFFSET=0x90 -DOFFSET=0x100
# RUN: llvm-readelf --sections --headers %t7 | FileCheck %s --check-prefix=BOTH-B
## The same offset as in Case 1.
# BOTH-B: Start of section headers: 288 (bytes into file)
## Show that the 'Offset' field sets the physical offset in file and `ShOffset`
## field only affects the sh_offset value of the .foo section (overrides it).
# BOTH-B: [Nr] Name Type Address Off
# BOTH-B: [ 1] .foo PROGBITS 0000000000000000 000090
# BOTH-B-NEXT: [ 2] .bar PROGBITS 0000000000000000 000101
# BOTH-B-NEXT: [ 3] .strtab STRTAB 0000000000000000 000102
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Sections:
- Name: .foo
Type: SHT_PROGBITS
Size: 0x1
ShOffset: [[SHOFFSET]]
Offset: [[OFFSET]]
- Name: .bar
Type: SHT_PROGBITS
Size: 0x1