Porting GCC to my OS

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.
Hoozim
Member
Member
Posts: 53
Joined: Fri Jul 23, 2010 8:26 am

Porting GCC to my OS

Post 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
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Porting GCC to my OS

Post by Love4Boobies »

It will obviously require partial POSIX support. Also, see http://wiki.osdev.org/OS_Specific_Toolchain
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
rdos
Member
Member
Posts: 3396
Joined: Wed Oct 01, 2008 1:55 pm

Re: Porting GCC to my OS

Post by rdos »

Love4Boobies wrote:It will obviously require partial POSIX support. Also, see http://wiki.osdev.org/OS_Specific_Toolchain
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.
Hoozim
Member
Member
Posts: 53
Joined: Fri Jul 23, 2010 8:26 am

Re: Porting GCC to my OS

Post by Hoozim »

Hello,

Thank you for your replies. I should probably start by porting some simpler things for practice. Any suggestions?

Hoozim
Unkn0wn1
Member
Member
Posts: 37
Joined: Fri Jan 13, 2012 11:18 am

Re: Porting GCC to my OS

Post by Unkn0wn1 »

Newlib, perhaps?

A good start for porting anything, as you'll need a libc to port most programs including.... you guessed - GCC!
Not sane
Just remember, FIND Is Not DOS :)
rdos
Member
Member
Posts: 3396
Joined: Wed Oct 01, 2008 1:55 pm

Re: Porting GCC to my OS

Post 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.
Hoozim
Member
Member
Posts: 53
Joined: Fri Jul 23, 2010 8:26 am

Re: Porting GCC to my OS

Post 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
rdos
Member
Member
Posts: 3396
Joined: Wed Oct 01, 2008 1:55 pm

Re: Porting GCC to my OS

Post 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.
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: Porting GCC to my OS

Post by Brynet-Inc »

berkus wrote:For the binutils part there's http://sourceforge.net/apps/trac/elftoolchain/ which still misses LD, unfortunately.
It seems there is something in-tree, no idea how far along it is yet.

http://sourceforge.net/apps/trac/elftoo ... r/trunk/ld
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
invalid
Member
Member
Posts: 60
Joined: Thu Feb 23, 2012 8:39 am

Re: Porting GCC to my OS

Post by invalid »

I wanted to give Solar's PDCLib a try, is it worth something? :)
User avatar
brain
Member
Member
Posts: 247
Joined: Thu Nov 05, 2009 5:04 pm
Location: UK
Discord: https://discord.gg/brainbox
GitHub: https://github.com/braindigitalis
Contact:

Re: Porting GCC to my OS

Post by brain »

ydoom wrote:I wanted to give Solar's PDCLib a try, is it worth something? :)
Its worth about 300 internet dollars. ;-)
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Porting GCC to my OS

Post 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.
Every good solution is obvious once you've found it.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Porting GCC to my OS

Post 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
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
invalid
Member
Member
Posts: 60
Joined: Thu Feb 23, 2012 8:39 am

Re: Porting GCC to my OS

Post 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,
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Porting GCC to my OS

Post 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. 8)
Every good solution is obvious once you've found it.
Post Reply