How to import GCC to my own os , so I can compile c programs under my os ?
thanks
Import GCC
Re:Import GCC
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.)
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.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Import GCC
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...
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...
Re:Import GCC
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?
Re:Import GCC
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.
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.