Friday, March 7, 2008

osdev/crossgcc first try

Started working on learning to build a custom OS. First step is the cross compiler. Went to the GCC Cross-Compiler page on osdev-wiki. That page lists the steps to get my cross compiler up and running.

Got the binutils, gcc-core and g++ sources.. Created a new login on my linux box and set it up as recommended in the LFS tutorial, to have minimal environment.. This was my pure whim :D.

Then went by the steps mentioned in the osdev page; made my binutils; made my gcc.. Then came the problem.. What libc to use?

Tried PDClib but found it lacking in cross compilation support etc.
Then got a newlib downloaded and built that.. It seems to have worked..

Then recompiled the gcc with headers.

And once all that was done, your's truly tried to compile a very simple .c file using the cross-compiler..

The linker failed saying no crt0.o !


hm.. vaguely remember something about crt0.o from my hardware classes at NITC.. or was it from some unix system programmer's reference I read back at college?

Anyways.. searched on the osdev wiki.. Hit a page on how to install "newlib" !! Now that could have helped me a little earlier :D.. I just broke my head figuring out what was already documented :D..
doesn't harm.. things learned the hard way stick longer :)

But coming back, somebody had cooked up a simple crt0.S on that page.. used that..

And know what! IT WORKED !!

Well, not exactly.. ld still cribs about missing syscall wrapper function definitions..
I need to take the newlib-libc-documentation, go to chapter 12 - Syscalls, and then either implement wrappers for each of those syscalls (thankfully not too many) aimed at my kernel (ah, but I still haven't even started thinking about it !! ) .. or I have to provide a set of stubs for those syscalls .. or maybe route those syscalls to my hosts syscalls ( possible in this case because my host is a Centrino processor, and my cross compiler target is i586 :D )

Anyways.. so far so good..

But there are some things which still worries me..
1. I still don't know shit about that newlib internal implementation and it's source is over 11 Megs !!
2. I did a "du -sh" on the final build environment I have (excluding all intermediate files) and it's a whopping 162 Megs.. Guess programmers really have lost the ability to make efficient code, as Andrew Tannenbaum puts it.
3. What if the present generation who maintains glibc, gcc, binutils, newlib etc dies out and it's the next generation's turn to maintain all of that.. my generation's turn.. Will there be anyone left who has a holistic understanding of all that code to maintain it ?

Ah, but I'm a small fry making too much noise; and staying up at 4:30 AM to set up a cross compiler.. no wonder I'm an oddity.. maybe that explains why I still don't have a girlfriend :D


No comments: