Answer the question
In order to leave comments, you need to log in
How to generate pure binary using GCC?
Can you tell me how to generate a binary file without DWARF and CFI sections. So that there are just bare instructions?
I do this:
gcc -c -o kmain.o kmain.c
ld -e kmain -Ttext 0x7e00 --oformat=binary -o kernel.bin
and I get a binary with DWARF garbage that I don’t need, following the instructions.
It seems to me that it should be possible to remove it if it's not C++ (i.e. no need to support exceptions). Thank you.
Answer the question
In order to leave comments, you need to log in
Or another option without objcopy, but with a linker script:
$ cat kernel.lds
SECTIONS {
.text 0x7e00:
{
*(.text)
}
/DISCARD/ :
{
*(*)
}
}
$ ld -e kmain -T kernel.lds test.o --oformat=binary -o kernel-lds.bin
$ hexdump -Cv kernel-lds.bin
00000000 55 48 89 e5 b8 01 00 00 00 5d c3 |UH.......].|
0000000b
Maybe
ld -e kmain -Ttext 0x7e00 -o kernel.elf
objcopy --strip-all -R .comment -R .note.gnu.build-id -O binary kernel.elf kernel.bin
and add names of unnecessary sections to -R ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question