1 ## The computed LMA of a section in a PT_LOAD equals sh_offset-p_offset+p_paddr.
2 ## The byte offset difference between two sections equals the difference between their LMAs.
4 ## Corollary: if two sections are in the same PT_LOAD, the byte offset
5 ## difference equals the difference between their sh_addr fields.
7 # RUN: yaml2obj --docnum=1 %s -o %t1
8 # RUN: llvm-objcopy -O binary %t1 %t1.out
9 # RUN: od -A x -t x2 %t1.out | FileCheck %s --check-prefix=CHECK1 --ignore-case
10 # RUN: wc -c %t1.out | FileCheck %s --check-prefix=SIZE1
12 # CHECK1: 000000 c3c3 c3c3 0000 0000 0000 0000 0000 0000
13 # CHECK1-NEXT: 000010 0000 0000 0000 0000 0000 0000 0000 0000
15 # CHECK1-NEXT: 001000 3232
27 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
33 Flags: [ SHF_ALLOC, SHF_WRITE ]
43 ## The computed LMA of a section not in a PT_LOAD equals its sh_addr.
45 # RUN: yaml2obj --docnum=2 %s -o %t2
46 # RUN: llvm-objcopy -O binary %t2 %t2.out
47 # RUN: od -A x -t x2 %t2.out | FileCheck %s --check-prefix=CHECK2 --ignore-case
48 # RUN: wc -c %t2.out | FileCheck %s --check-prefix=SIZE2
50 ## The computed LMA of .data is 0x4000. The minimum LMA of all non-empty sections is 0x1000.
51 ## The content of .data will be written at 0x4000-0x1000 = 0x3000.
52 # CHECK2: 000000 c3c3 c3c3 0000 0000 0000 0000 0000 0000
53 # CHECK2-NEXT: 000010 0000 0000 0000 0000 0000 0000 0000 0000
55 # CHECK2-NEXT: 003000 3232
67 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
68 ## Not in a PT_LOAD. LMA = sh_addr = 0x1000.
74 Flags: [ SHF_ALLOC, SHF_WRITE ]
75 ## LMA = sh_offset-p_offset+p_paddr = 0x2000-0x2000+0x4000 = 0x4000.
83 ## p_vaddr is increased from 0x2000 to 0x4000.
88 ## Check that we use sh_offset instead of sh_addr to decide where to write section contents.
90 # RUN: yaml2obj --docnum=3 %s -o %t3
91 # RUN: llvm-objcopy -O binary %t3 %t3.out
92 # RUN: od -A x -t x2 %t3.out | FileCheck %s --check-prefix=CHECK3 --ignore-case
93 # RUN: wc -c %t3.out | FileCheck %s --check-prefix=SIZE3
95 ## The minimum LMA of all non-empty sections is 0x1000.
96 ## The content of .data will be written at 0x3000-0x1000 = 0x2000.
97 # CHECK3: 000000 c3c3 c3c3 0000 0000 0000 0000 0000 0000
98 # CHECK3-NEXT: 000010 0000 0000 0000 0000 0000 0000 0000 0000
100 # CHECK3-NEXT: 002000 3232
112 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
113 ## Not in a PT_LOAD. LMA = sh_addr = 0x1000.
119 Flags: [ SHF_ALLOC, SHF_WRITE ]
120 ## sh_addr is increased from 0x2000 to 0x3000, but it is ignored.
121 ## LMA = sh_offset-p_offset+p_paddr = 0x2000-0x2000+0x3000 = 0x3000.
127 Flags: [ PF_R, PF_W ]
132 ## The first section (.text) is empty. Test that we skip its LMA until the first
133 ## non-empty section, otherwise we would leave a large number of leading zeroes.
134 # RUN: yaml2obj --docnum=4 %s -o %t4
135 # RUN: llvm-objcopy -O binary %t4 %t4.out
136 # RUN: od -A x -t x2 %t4.out | FileCheck %s --check-prefix=SKIPEMPTY
138 # SKIPEMPTY: 000000 3232
139 # SKIPEMPTY-NEXT: 000002
150 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
158 Flags: [ SHF_ALLOC, SHF_WRITE ]
161 ## The last section (.data) is empty. Test that we stop dumping after the last
162 ## non-empty section, otherwise we would leave a large number of trailing zeroes.
163 # RUN: yaml2obj --docnum=5 %s -o %t5
164 # RUN: llvm-objcopy -O binary %t5 %t5.out
165 # RUN: od -A x -t x2 %t5.out | FileCheck %s --check-prefix=SKIPEMPTY
176 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
185 Flags: [ SHF_ALLOC, SHF_WRITE ]
187 ## NOBITS sections should not appear in output.
188 # RUN: yaml2obj --docnum=6 %s -o %t6
189 # RUN: llvm-objcopy -O binary %t6 %t6.out
190 # RUN: od -A x -t x2 %t6.out | FileCheck %s --check-prefix=SKIPNOBITS --ignore-case
192 # SKIPNOBITS: 000000 c3c3 c3c3
193 # SKIPNOBITS-NEXT: 000004
213 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]