I am asking for help by professionals because of lack of my knowledge in using GCC and ld.I'm writing OS for educational purposes, and i have a problem with compiling and linking C code. To be honest, the is no any problem, but I'm confused by the unncessary data in output files generated by the GCC and LD like
GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 symtab..strtab..shstrtab..text..eh_frame..data..comment
.ELF..|
and etc. I really need to know which parameters use both with gcc and ld to reduce this unuseful (for my OS) data
Parameters I used before: -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -fstrength-reduce -finline-functions I also use linker script to organise segments.
I tried objcopy to reduce such blocks as .comment and .note from output, for me it was the best solution
objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin
Split you compilation and linking stages. Use the "-s" option for GCC to reduce .o files. (the link in pmg's comment is of particular interest, though not related to linker scripts)
The linker's script for a simple kernel is described here (tutorial for building the kernel using LD).
Use the
ld -T <yourscript> <objectfilelist> -o kernel.bin
command to get the desired binary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With