I use objcopy -S -g -O binary test.elf test.bin
to get a .bin
file from .elf
.
$ ll test.bin
-rwxr-xr-x 1 hongzhuwang md_psw 1472320 Oct 28 19:07 test.bin
$ size test.elf
text data bss dec hex filename
173062 6328 6605424 6784814 67872e test.elf
The size of test.bin
is apparently larger than the sum of text and data in test.elf
. Why is there such a huge difference? Which sections will objcopy
copy from .elf
into .bin
?
I found some NOBITS
sections between PROGBITS
sections in the linker script. The binary file will occupy a continuous address space, so the NOBITS
sections' space are filled by zero by objcopy
. I think that's the root cause for the difference.