ok, so i am redoing the Makefile for my kernel, from being one giant messy cumbersome file, to one small one in each directory and traversing all the directories to compile all the files.
well, the end result is that it outputs all the .o files into the toplevel source directory. and from there i need to link everything together. i thought it would be as simple as doing:
ld -T kernel.ld -o kernel.bin *.o
but unfortunantly, that doesn't seem to work as my k_init.o apparently needs to be the first file linked. which is understandable. so now i am at the predicament of needing to automate the linking somehow so that it links all the .o files produced but making sure k_init.o is first. thanks in advance
in need of some scripting foo
Re:in need of some scripting foo
what about doing
so it links k_init.o first and then all the other ones, but i don't know if it would cause a problem linking k_init.o more than once though
Code: Select all
ld -T kernel.ld -o kernel.bin k_init.o *.o
Re:in need of some scripting foo
I'm not sure what will happen if you link it more than once, best case is nothing, worse case is it gets linked twice and explodes because there are multiple copies of the same symbol.
The *.o should include the files in alphabetical order (at least the Windows command prompt does) so if you put a '1' at the start it will be the first object file in the list (ie. "1k_init.o")
The *.o should include the files in alphabetical order (at least the Windows command prompt does) so if you put a '1' at the start it will be the first object file in the list (ie. "1k_init.o")
Re:in need of some scripting foo
yeah, it doesn't want to link with two copies.
i tried something like
ld -T kernel.ld -o kernel.bin kinit.o `ls *.o | grep -v kinit.o`
but then the very first file it tries to link says that it doesn't exist? odd.
i tried something like
ld -T kernel.ld -o kernel.bin kinit.o `ls *.o | grep -v kinit.o`
but then the very first file it tries to link says that it doesn't exist? odd.
Re:in need of some scripting foo
what i did is compile my main .o's in a diferent folder:
Code: Select all
ld -T link.ld -o kernel.bin MAIN\*.o SUB\*.o
Re:in need of some scripting foo
thanks for the suggestions. i ended up changing my linker script to be:
and that seemed to do the trick.
Code: Select all
SECTIONS
{
.text {
k_init.o(.text)
*(.text)
...
Re:in need of some scripting foo
I wrote this small batch file, because ..\bin\ld -T kernel.ld -o ..\output\kernel\kernel.elf ..\output\obj\*. didn't work...
Code: Select all
@echo off
if %1'==build' goto build
if %1'==' goto force
if not %1'==' goto end
:force
echo Enabeling extentions...
cmd /V:ON /C "build kernel.bat" build
goto end
:build
cd .\kernel
echo Executing nasm...
..\bin\nasm -f elf stub.asm -o ..\output\obj\stub.o
..\bin\nasm -f elf _isr.asm -o ..\output\obj\_isr.o
echo Executing freepascal...
..\bin\ppc386 -Aelf -FE..\output\obj -Fi.\include -Fu.\support -n -OG3p3 -Si -Sc -Sg -Xd -Rintel -Tlinux kernel.pas
echo Executing linker...
for %%c in (..\output\obj\*.o) do set objects=!objects! %%c
..\bin\ld -T kernel.ld -o ..\output\kernel\kernel.elf%objects%
cd ..
echo Executing strip...
.\bin\strip .\output\kernel\kernel.elf
pause
goto end
:end
@echo on