Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling and linking C code without any additional data in output file

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
like image 838
hrust Avatar asked May 11 '26 23:05

hrust


1 Answers

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.

like image 163
Viktor Latypov Avatar answered May 13 '26 17:05

Viktor Latypov