<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/130058>130058</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[LLD] Wrong values used with multiple FILL commands in one output section
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ostannard
</td>
</tr>
</table>
<pre>
When multiple FILL commands are used in the same output section, the value from the last one is used throughout the section, and all of the previous ones are ignored. This differs from BFD's behaviour and documentation, where each FILL command only affects gaps in the section after it, and only until the next FILL command.
```
/* fills.ld */
SECTIONS {
.fills : {
. = 0x0;
. = 0x10;
FILL(0xaaaaaaaa);
. = 0x20;
FILL(0xbbbbbbbb);
. = 0x30;
empty.o(*)
}
}
```
With LLD, all three gaps in this section are filled with 0xbb:
```
$ /work/llvm/build/bin/llvm-mc < empty.s --triple=aarch64 -filetype=obj > empty.o
$ /work/llvm/build/bin/ld.lld -T fill.ld -o test.elf empty.o
ld.lld: warning: cannot find entry symbol _start; not setting start address
$ /work/llvm/build/bin/llvm-objdump --disassemble-symbols=.fills test.elf --disassemble-zeroes
test.elf: file format elf64-littleaarch64
Disassembly of section .fills:
0000000000000000 <.fills>:
0: bbbbbbbb <unknown>
4: bbbbbbbb <unknown>
8: bbbbbbbb <unknown>
c: bbbbbbbb <unknown>
10: bbbbbbbb <unknown>
14: bbbbbbbb <unknown>
18: bbbbbbbb <unknown>
1c: bbbbbbbb <unknown>
20: bbbbbbbb <unknown>
24: bbbbbbbb <unknown>
28: bbbbbbbb <unknown>
2c: bbbbbbbb <unknown>
```
With BFD, the first gap is filled with 0x0 (the default, because FILL sections do not affect gaps before them), the second is filled with 0xaa, and the third with 0xbb:
```
$ /arm/pdtl/builds/latest-fsf-trunk/installed/rhe8x86_64/aarch64-none-elf/bin/aarch64-none-elf-ld.bfd -T fill.ld -o test.elf empty.o
$ /work/llvm/build/bin/llvm-objdump --disassemble-symbols=.fills test.elf --disassemble-zeroes
test.elf: file format elf64-littleaarch64
Disassembly of section .fills:
0000000000000000 <.fills>:
0: 00000000 udf #0x0
4: 00000000 udf #0x0
8: 00000000 udf #0x0
c: 00000000 udf #0x0
10: aaaaaaaa orn x10, x21, x10, asr #42
14: aaaaaaaa orn x10, x21, x10, asr #42
18: aaaaaaaa orn x10, x21, x10, asr #42
1c: aaaaaaaa orn x10, x21, x10, asr #42
20: bbbbbbbb <unknown>
24: bbbbbbbb <unknown>
28: bbbbbbbb <unknown>
2c: bbbbbbbb <unknown>
```
BFD documentation for this: https://sourceware.org/binutils/docs/ld/Output-Section-Data.html
> A FILL statement covers memory locations after the point at which it occurs in the section definition; by including more than one FILL statement, you can have different fill patterns in different parts of an output section.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEV0Fv2zwS_TX0ZSBBpmzHOfjgxDHwAcH20AI9FpQ4tNhSpEFScby_fjGk7MRJ2nr7HSoYcUw9zjwOZx6HIgS9s4grNr9j881EDLFzfuVCFNYKLyeNk8fV1w4t9IOJem8Qtv88PkLr-l5YGUB4hCGgBG0hdghB9AhuiPshQsA2amcZv0-vnoQZEJR3ffppRIjgLIIO2ULsvBt2nRtitvQyW1gJwhhwKr3Ze3zSbgg0OzPQO-s8yhK-dDqA1EqhD9nV3XbD-E2ABjtBs3yyJl079GijOLk4dOgRULTdxQLBWXMEoRS2McBO7MN5oZkeCBXRg44nnmnCYKM2CWbxOV5YLFm1ps-iGj_VmvEt42tQ2phQGgmMp6Fq_fnh_ss_n_7zGdjNHavWAGXCAKvX5yGAEli9geq5YvXboemrMSLB-LJ6FuPD-O37Gfw04wxvxudDeP3KAfb7eCwd48u0gNs0zG42tML89_Waq_VXHTt4fNykyBkKl0d8FWMdXoLsMYUHJRxoFrFi9fs4zoDx7cH5H4xvjXnqGd82gzaSvrUdB4u-BVbfj3wDFEX0lNms3gjh224xg0Jpg_G4pzHXfAdWP5yXd50fWRojofiSaNOm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