Problem with ld (?)
Posted: Mon Apr 03, 2006 11:00 pm
Hello, there is a newbies problem:
I'm writting a small "hello world" operating system according to this-howto. Now I have problem with my linker (ld):
This is my main.c:
Now when I compile my "kernel", gcc and nasm seems to work (there are main.o and start.o binary files), but when ld links these files, the result is 1MB plain text file which includes just "Hello"-string. If I remove line int i = strlen("Hello"); result is correct (4kB binary and it works).
I have same problem with every other functions which takes a char* parameter. If I use that parameter in the function, result is similar plain text file.
And my Makefile:
Link.ld is same than in the howto: link.ld.
And start.asm is similar than in the howto: start.asm (I have just added extern _main and call _main).
I have tried to update my ld (bintools-package) but it didn't work. I tried versions 2.15.92.0.2-r10, 2.16.1-r2 and 2.16.91.0.7. My gcc is version 3.4.5-r1 (I have tried version 3.3). System is Gentoo Linux.
So have I done something wrong or is it a ld's bug? I have used Google but i havn't found any similar problems...
I'm writting a small "hello world" operating system according to this-howto. Now I have problem with my linker (ld):
This is my main.c:
Code: Select all
#include "include/system.h" /* just extern int strlen(char *str); */
int strlen(char *str)
{
/* This loops through character array 'str', returning how
* many characters it needs to check before it finds a 0.
* In simple words, it returns the length in bytes of a string */
int retval;
for(retval = 0; *str != '\0'; str++) retval++;
return retval;
/* I have tried my own strlen function but it didn't help, this is a copy from howto */
}
/* This is a very simple main() function. */
void main()
{
int i= strlen("Hello");
/* ...and leave this loop in. There is an endless loop in
* 'start.asm' also, if you accidentally delete this next line */
for (;;);
}
I have same problem with every other functions which takes a char* parameter. If I use that parameter in the function, result is similar plain text file.
And my Makefile:
Code: Select all
all:
nasm -f aout -o start.o start.asm
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -fleading-underscore -finline-functions -nostdinc -fno-builtin -c -o main.o main.c
ld -T link.ld -o kernel.bin main.o start.o
And start.asm is similar than in the howto: start.asm (I have just added extern _main and call _main).
I have tried to update my ld (bintools-package) but it didn't work. I tried versions 2.15.92.0.2-r10, 2.16.1-r2 and 2.16.91.0.7. My gcc is version 3.4.5-r1 (I have tried version 3.3). System is Gentoo Linux.
So have I done something wrong or is it a ld's bug? I have used Google but i havn't found any similar problems...