Page 1 of 1

Can you solve my problem about linking ?

Posted: Mon Aug 25, 2008 12:23 am
by behzad24b
how can i compile and link my os parts in windows environment and with GCC & NASM ?
pleas help me and say with wich commandline options i can compile my kernel truly in windows?
the commandlins that i use are :

for NASM:
nasm -f aout loader.asm -o loader.o

for gcc :
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-funct
ions -nostdinc -fno-builtin -I./include -c -o kernel.o kernel.c

for linking :
ld -r -i -e _start -Ttext 0x1000 -o os.o kernel.o graphic.o

for create binary file :
C:\cygwin\bin>objcopy -R .note -R .comment -S -O binary os.o os.bin

for example my problem is in linking , when i want to call an external function that i write in other file for example an OBJ file that compiled with nasm or an OBJ file that compiled with GCC same as graphic.o , after linking these parts , I disassemble the output obj file and i see that when a function called , the call function in assembly code , called an incorrect address that there not exist a valid function .
my NASM version is 2.02
my GCC version is 3.4.4

pleeeeeeas help to me , i work on this problem about 3 month but still i can't solve that . [-o<

im sorry for my bad english writing. :oops:

Re: Can you solve my problem about linking ?

Posted: Mon Aug 25, 2008 12:28 am
by albeva
I take it you are using mingw? mingw is bad for OS deving.

Check out this: http://wiki.osdev.org/GCC_Cross-Compiler

Re: Can you solve my problem about linking ?

Posted: Mon Aug 25, 2008 12:29 am
by Laksen
You use the -r flag for ld. That means that the linked object will be a relocatable executable, thus no function calls will be pointing to the correct locations yet

Re: Can you solve my problem about linking ?

Posted: Mon Aug 25, 2008 1:09 am
by behzad24b
thanks .
I use Cygwin .
now i tray it without -r but still have that problem :(

Re: Can you solve my problem about linking ?

Posted: Mon Aug 25, 2008 3:08 am
by ru2aqare
behzad24b wrote:thanks .
I use Cygwin .
now i tray it without -r but still have that problem :(
If you want, you could try my linker. It accepts COFF files only, and produces PE or flat binary output. Read more here.

Re: Can you solve my problem about linking ?

Posted: Mon Aug 25, 2008 7:10 am
by behzad24b
i download your linker . please help me how it work and how i can use that ?
please say an example about commandline options.