Page 1 of 2
Porting GCC to my OS
Posted: Sat Mar 24, 2012 8:29 am
by Hoozim
Hello,
I am looking into porting GCC to my hobby OS. I need to know what API functions it requires. I have searched around and am unable to find what I am looking for. If anyone knows what API functions are needed, it would help me greatly.
Hoozim
Re: Porting GCC to my OS
Posted: Sat Mar 24, 2012 9:09 am
by Love4Boobies
It will obviously require partial POSIX support. Also, see
http://wiki.osdev.org/OS_Specific_Toolchain
Re: Porting GCC to my OS
Posted: Sat Mar 24, 2012 10:09 am
by rdos
I like the tutorial, but there is one problem with the approach: Whenever any of these projects are updated (and they are updated all the time), your build will not easily be able to use these updates. You will be stuck on an outdated version. To remedy this, you need to provide patches (and get them accepted) by the maintainers, which is no easy task. A serious, long-term, OS project definitely needs live support in the toolchains it uses.
Re: Porting GCC to my OS
Posted: Sat Mar 24, 2012 11:01 am
by Hoozim
Hello,
Thank you for your replies. I should probably start by porting some simpler things for practice. Any suggestions?
Hoozim
Re: Porting GCC to my OS
Posted: Sat Mar 24, 2012 11:47 am
by Unkn0wn1
Newlib, perhaps?
A good start for porting anything, as you'll need a libc to port most programs including.... you guessed - GCC!
Re: Porting GCC to my OS
Posted: Sat Mar 24, 2012 11:51 am
by rdos
Just checked the proposed changes in binutils, and all of these contain rdos. Seems like I could go ahead and try to provide patches for GCC if I want to support this environment now. The only problem is that I state to use elf32 as output format. I should have used PE, but I suppose that was not fully functional at the time.
Even if all the propositions in the wiki-article are covered in the rdos port, does not mean there might not be some other files as well that I modified.
Re: Porting GCC to my OS
Posted: Sat Mar 24, 2012 12:14 pm
by Hoozim
Hello,
I am current writing my own C library instead of porting Newlib. If it works out, I will stick with my C library, otherwise I will port Newlib.
Hoozim
Re: Porting GCC to my OS
Posted: Sat Mar 24, 2012 12:56 pm
by rdos
Hoozim wrote:I am current writing my own C library instead of porting Newlib. If it works out, I will stick with my C library, otherwise I will port Newlib.
That's another way to go about it. I suppose you could use GCC to link to your own library, provided some minimal requirements are met (like using the correct startup-code). The downside would be that you might be less POSIX-compatible. By using libc or newlib you are guaranteed a high level of POSIX compliance. This would be the major reason why I would try to provide a GCC port, as my current compiler (OpenWatcom) has poor C and POSIX compliance.
I also suppose I could use the files I already provided to OpenWatcom's clib and use them for a C library instead of using libc or newlib, but I probably won't as I want the best possible POSIX compliance.
Re: Porting GCC to my OS
Posted: Sat Mar 24, 2012 1:51 pm
by Brynet-Inc
It seems there is something in-tree, no idea how far along it is yet.
http://sourceforge.net/apps/trac/elftoo ... r/trunk/ld
Re: Porting GCC to my OS
Posted: Sun Mar 25, 2012 9:34 am
by invalid
I wanted to give Solar's PDCLib a try, is it worth something?

Re: Porting GCC to my OS
Posted: Sun Mar 25, 2012 11:07 am
by brain
ydoom wrote:I wanted to give Solar's PDCLib a try, is it worth something?

Its worth about 300 internet dollars.

Re: Porting GCC to my OS
Posted: Sun Mar 25, 2012 11:28 pm
by Solar
ydoom wrote:I wanted to give Solar's PDCLib a try, is it worth something?

It is not complete. Locale support, wide / multibyte character support, the functions from <time.h> and anything having to do with floating points is not yet implemented.
It is also not optimized. It comes with generic (and naive) implementations of memcpy(), memmove() etc.; if your compiler of choice comes with builtin functions of these, making the apropriate adjustments for using them will benefit performance. (I will add an appropriately optimized GCC overlay in the future. It's not difficult at all, given the structure of PDCLib actively
enabling such patching; it just didn't have priority for me so far.)
malloc() / free() are also naively implemented placeholders, and could do with being replaced with something more... apropriate. (In the long run, I plan to integrate dlmalloc().)
But what is there
is fully functional, and if I may say so, reasonably well-tested. I have several users who use PDCLib for their OS projects, including one running a full-blown, dash-shell based usespace on top.
Overall, development is in hiatus for now, as I am working on another large (non-software) project, which I will probably finish during the summer.
Re: Porting GCC to my OS
Posted: Mon Mar 26, 2012 1:04 am
by piranha
IIRC, porting gcc isn't terribly difficult. The previously linked to OS Specific Toolchain tutorial + a simple implementation of sysconf is mostly all of what you need. I have a fairly functional port of gcc running on my OS (by fairly functional I mean it compiles my OS correctly). It can be a fairly lengthy procedure to port it, I remember having numerous errors in compilation that I had to fix, and I recall various runtime errors that needed to be fixed as well, but overall it's not terrible complicated.
Good luck.
-JL
Re: Porting GCC to my OS
Posted: Tue Mar 27, 2012 7:04 am
by invalid
Solar wrote:Overall, development is in hiatus for now, as I am working on another large (non-software) project, which I will probably finish during the summer.
I like the comment about "I really want to think about something else than stdio!" in
readme 
Please forgive careless language, I know that it's "worth something"

What I meant was, is it enough to compile GCC, or will I have to port newlib anyway?
Regards,
Re: Porting GCC to my OS
Posted: Tue Mar 27, 2012 8:33 am
by Solar
ydoom wrote:What I meant was, is it enough to compile GCC, or will I have to port newlib anyway?
It will definitely not be enough. I expect GCC to make use of several POSIX calls, whereas PDCLib is "only" C99 (so that it does not limit your design choices by making additional demands on the kind of system calls that you provide). That means that stuff like execve(), fchdir(), stat() etc. will need to be implemented
on top and
beside of PDCLib. Have a look at Rink Springer's
Ananas project. He has got dash, Lua and coreutils running on top of PDCLib plus POSIX extensions of his making, and is actively working towards getting binutils / GCC to compile on his OS. You might want to link up with him and combine efforts. I
might be interested in hosting a "PDCLib POSIX layer" somewhere down the line, and will certainly accept any sensible patches to PDCLib that might turn up during your endeavour (as I accepted Rink's patches). His code is beerware, by the way.
Edit: A quick sketch. PDCLib provides
only the "CLib" part (with the aforementioned limitations as it's not yet "released"), while keeping a minimal footprint. Newlib would give you POSIX, with more demands on your kernel, and a different licensing / upstream situation. It's your choice. PDCLib is mostly for those people who don't
want to support POSIX, or shun the available libraries for aesthetic reasons.
