<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55246>55246</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
llvm-objcopy missing padding between sections
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Kimplul
</td>
</tr>
</table>
<pre>
I have an elf file that I would like to turn into a raw binary, and I'm trying to allocate the `.bss` section directly in the binary. For some reason, there is a small gap between my `.text` and `.bss`, which is padded with some bytes when using GNU objcopy, but seemingly ignored when using llvm-objcopy.
To illustrate:
`riscv64-unknown-elf-objcopy -Obinary --set-section-flags .bss=alloc,load,contents --gap-fill 255 example.elf example.bin`
produces a raw binary ending in
```
...
00000240: ef00 e000 0100 e270 4274 2161 8280 2a86 .......pBt!a..*.
00000250: 2e85 0286 ffff ffff 0000 0000 0000 0000 ................
```
where `ffff ffff` is padding. (The actual value of the padding is irrelevant, I just used `ff` for demonstration purposes). The equivalent command with `llvm-objcopy`
`llvm-objcopy -Obinary --set-section-flags .bss=alloc,load,contents example.elf example.bin`
produces
```
...
00000240: ef00 e000 0100 e270 4274 2161 8280 2a86 .......pBt!a..*.
00000250: 2e85 0286 0000 0000 0000 0000 ............
```
For context, here's the `readelf` output for `example.elf`:
```
readelf --sections example.elf
There are 15 section headers, starting at offset 0x20d0:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000000080080000 00001000
0000000000000254 0000000000000000 AX 0 0 2
[ 2] .bss NOBITS 0000000080080258 00001254
0000000000000008 0000000000000000 WA 0 0 8
[ 3] .debug_info PROGBITS 0000000000000000 00001254
000000000000030e 0000000000000000 0 0 1
[ 4] .debug_abbrev PROGBITS 0000000000000000 00001562
0000000000000187 0000000000000000 0 0 1
[ 5] .debug_aranges PROGBITS 0000000000000000 000016f0
0000000000000060 0000000000000000 0 0 16
[ 6] .debug_line PROGBITS 0000000000000000 00001750
0000000000000292 0000000000000000 0 0 1
[ 7] .debug_str PROGBITS 0000000000000000 000019e2
00000000000001aa 0000000000000001 MS 0 0 1
[ 8] .debug_line_str PROGBITS 0000000000000000 00001b8c
0000000000000098 0000000000000001 MS 0 0 1
[ 9] .comment PROGBITS 0000000000000000 00001c24
0000000000000012 0000000000000001 MS 0 0 1
[10] .riscv.attributes RISCV_ATTRIBUTE 0000000000000000 00001c36
0000000000000039 0000000000000000 0 0 1
[11] .debug_frame PROGBITS 0000000000000000 00001c70
00000000000000d0 0000000000000000 0 0 8
[12] .symtab SYMTAB 0000000000000000 00001d40
0000000000000270 0000000000000018 13 17 8
[13] .strtab STRTAB 0000000000000000 00001fb0
0000000000000080 0000000000000000 0 0 1
[14] .shstrtab STRTAB 0000000000000000 00002030
000000000000009e 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
D (mbind), p (processor specific)
```
I'm assuming the bug is on LLVM's side in this case, because the start address of `.bss` matches when using GNU objcopy, whereas its four bytes short when using LLVM.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFWEtz4jgQ_jVw6cJlCwzmwCGZTGapzWMrMI89Tcm2DJ7xayU5hP312y3bYAfiJbOHVYHBbenTp-5Wu1t-Hu4XS9jyZwE8A5FEEMWJAL3lGpawy8skhCT-iZIcdCkziDP8x0HyHfhxxuV-wD7g0BCWAzZLQct9nG2oN0-SPOCasAQMprblK4U_oESg4zyDMJb4L9kjoulSoVlwm0tQeSpACq7yjODxsRQQK5xXpYgLG16AL_ROiAzSvUHX4kUTPFE5zkajd9s42NLogoehCGEX6201g7_XQuFzRCkV0f708Bly_0eQF2ZZfqmRrkjxEfHcZLmk8cf-SfKcjuoB1sC-GdhX1XWdQ5wk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