Yes At the moment it's a "hello-world" kernel so there's no way to link at runtime.andreaorru wrote:Aren't you linking all the library to your kernel, in that way?
What does your Makefile look like? (or, how to build kernel)
Re: What does your Makefile look like? (or, how to build kernel)
- AndreaOrru
- Member
- Posts: 50
- Joined: Fri Apr 25, 2008 2:50 pm
- Location: New York
Re: What does your Makefile look like? (or, how to build kernel)
Is there a way to (statically) link the kernel only with the library's files which get included?stealther wrote:Yes At the moment it's a "hello-world" kernel so there's no way to link at runtime.andreaorru wrote:Aren't you linking all the library to your kernel, in that way?
Close the world, txEn eht nepO
Re: What does your Makefile look like? (or, how to build kernel)
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.
Maybe ld does it automatically.
It's beyond my knowledge database.
- AndreaOrru
- Member
- Posts: 50
- Joined: Fri Apr 25, 2008 2:50 pm
- Location: New York
Re: What does your Makefile look like? (or, how to build kernel)
I'll wait for Solar or someone else, then =)
Thanks anyway.
Thanks anyway.
Close the world, txEn eht nepO
Re: What does your Makefile look like? (or, how to build kernel)
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.
- AndreaOrru
- Member
- Posts: 50
- Joined: Fri Apr 25, 2008 2:50 pm
- Location: New York
Re: What does your Makefile look like? (or, how to build kernel)
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.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.
Close the world, txEn eht nepO
Re: What does your Makefile look like? (or, how to build kernel)
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.
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.
Code: Select all
lib.a: $(LIB_OBJFILES)
@$(AR) $(ARFLAGS) lib.a $?
kernel: lib.a $(KERN_OBJFILES)
@$(LD) $(LDFLAGS) -T linker.ld -o kernel.bin $(KERN_OBJFILES) lib.a
Every good solution is obvious once you've found it.
- AndreaOrru
- Member
- Posts: 50
- Joined: Fri Apr 25, 2008 2:50 pm
- Location: New York
Re: What does your Makefile look like? (or, how to build kernel)
Ok, thank you!
Close the world, txEn eht nepO
Re: What does your Makefile look like? (or, how to build kernel)
You can actually replace these lines with:manonthemoon wrote:Code: Select all
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 $<
Code: Select all
%.o: %.s:
nasm -f elf $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
It' a great timesaver.