S
S
Semyon Prikhodko2012-12-13 10:49:14
C++ / C#
Semyon Prikhodko, 2012-12-13 10:49:14

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

3 answer(s)
J
jcmvbkbc, 2012-12-13
@ababo

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

Again, if there are other necessary sections in the source objects besides .text, their names should be written inside .text: {} after *(.text).

J
jcmvbkbc, 2012-12-13
@jcmvbkbc

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 ?

Q
qxfusion, 2012-12-13
@qxfusion

try to make broadcast in asm and then manual assembly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question