compile_link.sh¶
Links all object files and libraries into the final kernel binary.
Overview¶
compile_link.sh collects every .o object file in lib/, locates libgcc for i386, and invokes the GNU linker (ld) to produce bin/kernel.bin. The linker script toolchain/linker.script controls the memory layout of the resulting binary.
Prerequisites¶
ld(GNU linker) andgccmust be available.- All object files must have been produced by prior build steps (
compile_stub.sh,compile_sources.sh). lib/liblvgl.amust exist (produced bycompile_lvgl.sh).toolchain/linker.scriptmust exist.- The
bin/output directory must exist.
Inputs¶
| Source | Description |
|---|---|
lib/*.o |
All ELF object files (boot stub, Pascal units, splash screen, etc.). |
lib/liblvgl.a |
Static LVGL library archive. |
libgcc (system) |
GCC runtime support library for i386, located via gcc -m32 -print-libgcc-file-name. |
toolchain/linker.script |
Linker script defining section layout and entry point. |
Outputs¶
| File | Description |
|---|---|
bin/kernel.bin |
The final linked, stripped kernel binary. |
Behavior¶
- Collects all
.ofiles fromlib/, excludinglib/stub.ofrom the general list. - Prepends
lib/stub.oto the front of the object list so the boot entry point is linked first. - Locates
libgccfor the 32-bit target usinggcc -m32 -print-libgcc-file-name. - Invokes
ldwith the following flags: -m elf_i386-- Target i386 ELF format.-s-- Strip all symbol information.--gc-sections-- Remove unused sections (works with FPC's-CX -XXssmart-linking).-T toolchain/linker.script-- Use the project linker script.--start-group/--end-group-- Wrapsliblvgl.aandlibgccto resolve circular references between them.
Notes¶
stub.omust be first in the link order because it contains the multiboot header and the initial entry point that GRUB transfers control to.- The
--start-group/--end-groupconstruct allows the linker to iterate overliblvgl.aandlibgccmultiple times to resolve all symbols, which is necessary when C library objects have mutual dependencies.