1 ## Check we are able to set an offset field for sections using the 'Offset' key.
3 ## Show how the 'Offset' field key can be used.
4 ## Show that it can affect the layout of the rest of the file.
6 # RUN: yaml2obj --docnum=1 %s -o %t1
7 # RUN: llvm-readelf --sections %t1 | FileCheck %s --check-prefix=DEFAULT
9 # DEFAULT: [Nr] Name Type Address Off
10 # DEFAULT: [ 1] .foo PROGBITS 0000000000000000 000040
11 # DEFAULT-NEXT: [ 2] .bar PROGBITS 0000000000000000 000048
12 # DEFAULT-NEXT: [ 3] .strtab STRTAB 0000000000000000 000058
13 # DEFAULT-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 000059
27 ## It is a no-op. We set it to reduce amount
28 ## of differences with the second YAML below.
31 ## The same as previous, but an arbitrary 'Offset' is set for the .bar section.
32 # RUN: yaml2obj --docnum=2 %s -o %t2 -DOFFSET=0x50 -DALIGN=0x0
33 # RUN: llvm-readelf --sections %t2 | FileCheck %s --check-prefix=OFFSET
35 # OFFSET: [Nr] Name Type Address Off
36 # OFFSET: [ 1] .foo PROGBITS 0000000000000000 000040
37 # OFFSET-NEXT: [ 2] .bar PROGBITS 0000000000000000 000050
38 # OFFSET-NEXT: [ 3] .strtab STRTAB 0000000000000000 000060
39 # OFFSET-NEXT: [ 4] .shstrtab STRTAB 0000000000000000 000061
54 AddressAlign: [[ALIGN]]
56 ## Set the 'Offset' to the same value as was set by default to show
57 ## that there is no difference in the output in this case.
58 # RUN: yaml2obj --docnum=2 %s -o %t3 -DOFFSET=0x48 -DALIGN=0x0
61 ## Show that we can set an offset and an address alignment independently for a section.
62 # RUN: yaml2obj --docnum=2 %s -o %t4 -DOFFSET=0x48 -DALIGN=0x5
63 # RUN: llvm-readelf --sections %t4 | FileCheck %s --check-prefix=OFFSET-AND-ALIGN
65 # OFFSET-AND-ALIGN: [Nr] Name Type Address Off Size ES Flg Lk Inf Al
66 # OFFSET-AND-ALIGN: [ 2] .bar PROGBITS 0000000000000000 000048 000010 00 0 0 5
68 ## Show we do not allow an 'Offset' to go backward.
69 # RUN: not yaml2obj --docnum=2 %s -DOFFSET=0x47 -DALIGN=0x0 2>&1 | \
70 # RUN: FileCheck %s --check-prefix=ERR-BACKWARD
72 # ERR-BACKWARD: error: the 'Offset' value (0x47) goes backward
74 ## Show that the 'Offset' key can be used together with the 'ShOffset' key.
76 ## Case 1: set the same value for 'Offset' and 'ShOffset' keys.
77 # RUN: yaml2obj --docnum=3 %s -o %t5 -DSHOFFSET=0x100 -DOFFSET=0x100
78 # RUN: llvm-readelf --headers --sections %t5 | FileCheck %s --check-prefix=BOTH-SAME
80 ## The same offset as in the Case 3.
81 # BOTH-SAME: Start of section headers: 288 (bytes into file)
83 # BOTH-SAME: [Nr] Name Type Address Off
84 # BOTH-SAME: [ 1] .foo PROGBITS 0000000000000000 000100
85 # BOTH-SAME-NEXT: [ 2] .bar PROGBITS 0000000000000000 000101
86 # BOTH-SAME-NEXT: [ 3] .strtab STRTAB 0000000000000000 000102
88 ## Case 2: set the 'Offset' value to be less than the 'ShOffset'.
90 # RUN: yaml2obj --docnum=3 %s -o %t6 -DSHOFFSET=0x100 -DOFFSET=0x90
91 # RUN: llvm-readelf --headers --sections %t6 | FileCheck %s --check-prefix=BOTH-A
93 ## 176 < 288 (start of section headers in Case 1).
94 # BOTH-A: Start of section headers: 176 (bytes into file)
96 ## Show that the 'Offset' field sets the physical offset in a file and the `ShOffset`
97 ## field only overrides the sh_offset value of the .foo section.
98 # BOTH-A: [Nr] Name Type Address Off
99 # BOTH-A: [ 1] .foo PROGBITS 0000000000000000 000100
100 # BOTH-A-NEXT: [ 2] .bar PROGBITS 0000000000000000 000091
101 # BOTH-A-NEXT: [ 3] .strtab STRTAB 0000000000000000 000092
103 ## Case 3: set the 'Offset' value to be greater than the 'ShOffset' value.
105 # RUN: yaml2obj --docnum=3 %s -o %t7 -DSHOFFSET=0x90 -DOFFSET=0x100
106 # RUN: llvm-readelf --sections --headers %t7 | FileCheck %s --check-prefix=BOTH-B
108 ## The same offset as in Case 1.
109 # BOTH-B: Start of section headers: 288 (bytes into file)
111 ## Show that the 'Offset' field sets the physical offset in file and `ShOffset`
112 ## field only affects the sh_offset value of the .foo section (overrides it).
113 # BOTH-B: [Nr] Name Type Address Off
114 # BOTH-B: [ 1] .foo PROGBITS 0000000000000000 000090
115 # BOTH-B-NEXT: [ 2] .bar PROGBITS 0000000000000000 000101
116 # BOTH-B-NEXT: [ 3] .strtab STRTAB 0000000000000000 000102
127 ShOffset: [[SHOFFSET]]