Commit | Line | Data |
---|---|---|
8eca5c7d SC |
1 | /* PR 25662: objcopy sets invalid sh_offset for the first section in a |
2 | no_contents segment containing program headers. | |
3 | ||
4 | Several conditions are required for the bug to manifest: | |
5 | - The first loadable segment (which contains the program headers) must only | |
6 | contain SHT_NOBITS sections. .bss is the SHT_NOBITS section in this test. | |
7 | - The next loadable segment must have a !SHT_NOBITS loadable section. .data | |
8 | is the !SHT_NOBITS section in this test. | |
9 | - .bss must be positioned after .data in the executable file itself. | |
10 | - The size of .data must be such that the calculated VMA of the .bss | |
11 | section that follows it is not congruent with the file offset of .bss, | |
12 | modulo the p_align of its segment, i.e.: | |
13 | (VMA(.data) + sizeof(.data)) % (.bss_segment.p_align) != 0 | |
14 | This will force the sh_offset of .bss to be aligned so it appears within | |
15 | .data. | |
16 | - The size of .data must be larger than the program headers in the first | |
17 | loadable segment, so that the file offset of .bss is immediately | |
18 | after .data, and not padded to a valid alignment by the program headers. | |
19 | ||
20 | The bug originally only manifested for ELF targets, but there's no reason not | |
21 | to run this testcase for other file formats. This variant source for pdp11 | |
22 | uses .text rather than .section text, etc., because the latter are not | |
23 | supported, */ | |
24 | ||
25 | .bss | |
26 | a: | |
27 | .zero 0x2 | |
28 | ||
29 | .data | |
30 | c: | |
31 | .zero 0x201 | |
32 | ||
33 | .text | |
34 | .global _start | |
35 | _start: | |
36 | .long 0 |