Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Maybe there's some linker switch which omits unreferenced object files (or even contents of object files).
Maybe ld does it automatically.
It's beyond my knowledge database.
andreaorru wrote:I'll wait for Solar or someone else, then =)
That one cracked me up. Thanks for the laugh.
I know that, when linking from a linker archive (*.ar), 'ld' only takes those object files actually required to satisfy dependencies, leaving any others out of the resulting executable. Perhaps that's the feature you are looking for.
Every good solution is obvious once you've found it.
Solar wrote:I know that, when linking from a linker archive (*.ar), 'ld' only takes those object files actually required to satisfy dependencies, leaving any others out of the resulting executable. Perhaps that's the feature you are looking for.
Any other way? I'd want my Makefile to build and link only what is needed from the library. I think it would be more clean.
I don't understand, really. I understood correctly that you have a (static) function library which is linked with your kernel, and you want in the resulting binary only that part of the library which is actually used. Correct?
Well then, individually compile the translation units (*.c and *.asm files) of your library (resulting in a *.o file each), and put them in a linker archive. Link your kernel with that linker archive, and 'ld' does the selection automatically.
loader.o: src/loader.asm
nasm -f elf $< -o $@
# a source code file. You need one of these for each file in your project
bin/main.o: src/main.cpp
$(CC) $(CFLAGS) -o $@ -c $<
bin/kio.o: src/kio.cpp
$(CC) $(CFLAGS) -o $@ -c $<