Import GCC

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
firas981

Import GCC

Post by firas981 »

How to import GCC to my own os , so I can compile c programs under my os ?

thanks
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Import GCC

Post by Solar »

What you ask for is called "bootstrapping".

It's not really *that* difficult. Your OS must be capable of loading and executing programs. You will need a C runtime - i.e. a C library for your platform, and the code that does the startup and shutdown of a program. (There are things happening before int main() is called, and things happening after main() returns. This code usually resides in crt0.o.) You need to have a platform definition for GCC - if you are working with files of a known format on a known platform (e.g. ELF / x86), such a definition is already available.

At this point, you can build a cross-compiler for your platform - the GCC Cross-Compiler page tells you the first few steps, and links to other pages explaining further steps.

And once you have a working cross-compiler, all you have to do is to cross-compile GCC itself... and there you have a GCC that runs on your platform.

(Note, that's the easy answer. There can be any number of problems, including necessary tweaks to GCC to understand your file system layout, bugs in your OS, or adaptions to your executable type etc. etc.)
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Import GCC

Post by Pype.Clicker »

well, make sure your kernel can load files generated by GCC and offer the STDlib (or at least the parts which GCC requires) ...

You may also want to use a simpler compiler at start (Tiny C Compiler, for instance) as the xMB of GCC sources might be a pain to crawl for library dependencies...
Nairou

Re:Import GCC

Post by Nairou »

What about posix? I always assumed GCC and all the GNU tools relied heavily on the posix API. What about OSs (like mine) that don't plan on having posix compliance?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Import GCC

Post by Solar »

I'd daresay the API dependencies of GCC and binutils are much less serious than you might think. Basically, they are reading files, and writing files / printing to screen. There's little (if anything) in there that isn't covered by the plain C standard.

Regarding the Tiny C compiler... note that newer GCC versions require a C90 compatible compiler.
Every good solution is obvious once you've found it.
Post Reply