www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Minimal D Cross Compiler

reply Brian Madden <untwisted gmail.com> writes:
Hi all,

I'd just like to preface this with saying that I'm sorry if this doesn't quite
belong here, I wasn't sure where to post it, and it is a repost from the D
group which looks like it hadn't received any activity for 2 months prior to
my post.

A few students at the University of Pittsburgh have been gathering and coding
up a new operating system.  We've played in C, gotten some bootable code, etc,
but we'd really like to write this all in D (save the asm parts that need to
be done at the low level).  We're trying to target the x86_64 architecture,
but not everyone has 64bit machines (myself included).

We're working on building our cross compiler toolchains BUT we're running in
to problems left and right.  Most of us are on non-windows boxen, (about half
are on macs, the other are running linux).

I've read a few different instructions on how to compile a D cross compiler,
however since we're writing an OS we don't need any of the standard libraries,
just the basics.

Can anyone help walk through the steps of this.  I've been trying to combine
two different methods (the method for just building gcc with an x86_64 target,
and then trying to build D too), and when I finally got a build, just
compiling the following code:

void main() {
  return 1;
}

The compiler barfed with the following error:

~/bin/x86_64-pc-elf-gdc test.d
<built-in>:0: internal compiler error: Bus error
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

I have tried to recompile my xcompiler since then and am having no luck (now
I'm getting language glue errors hehe).  I figure rather than keep beating my
head off of the wall I'd just ask if anyone else had done something similar,
or could help out with this!

Thanks much in advance!

-Brian
Sep 12 2007
next sibling parent BCS <BCS pathlink.com> writes:
Brian Madden wrote:
 Hi all,
 
 I'd just like to preface this with saying that I'm sorry if this doesn't quite
 belong here, I wasn't sure where to post it, and it is a repost from the D
 group which looks like it hadn't received any activity for 2 months prior to
 my post.

I think that NG is depricated digitalmars.d.learn might be a better choice sorry can't help you on the rest.
Sep 12 2007
prev sibling next sibling parent jcc7 <technocrat7 gmail.com> writes:
== Quote from Brian Madden (untwisted gmail.com)'s article
 Hi all,
 I'd just like to preface this with saying that I'm sorry if this
 doesn't quite belong here, I wasn't sure where to post it, and it is a
 repost from the D group which looks like it hadn't received any
 activity for 2 months prior to my post.

I think this is the right newsgroup. (It's the one I would've chosen.) As to the answer to your actual question, I have no idea. I'm afraid you're trying to do things that are much fancier than I've ever done with D. I've never even used GDC at this point, since all of my development is on Windows (32-bit), I just use DMD. About the old "D" newsgroup... I guess you missed a post from April (only about the 7th post below yours). It's called "[Helpful Information] This is the old D newsgroup. It's abandoned." (http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=D&artnum=29460) We've resisted deleting the old newsgroup (since it's nice to have the existing posts for the sake of reference of the "early days" of D), but we try to discourage people from posting new threads. Occasionally, I've posted in that newsgroup advising people that it's old and no one's reading it anymore, but that newsgroup still seem to get 1 or 2 posts per months. (Maybe there's something that the server admin can do to prevent new posts, but just asking people not to post hasn't completely worked.)
Sep 12 2007
prev sibling next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Brian Madden" <untwisted gmail.com> wrote in message 
news:fc9hvt$24ga$1 digitalmars.com...

BRIAN MADDEN UR SO DUM. 
Sep 12 2007
prev sibling next sibling parent Gregor Richards <Richards codu.org> writes:
Brian Madden wrote:
 Hi all,
 
 I'd just like to preface this with saying that I'm sorry if this doesn't quite
 belong here, I wasn't sure where to post it, and it is a repost from the D
 group which looks like it hadn't received any activity for 2 months prior to
 my post.
 
 A few students at the University of Pittsburgh have been gathering and coding
 up a new operating system.  We've played in C, gotten some bootable code, etc,
 but we'd really like to write this all in D (save the asm parts that need to
 be done at the low level).  We're trying to target the x86_64 architecture,
 but not everyone has 64bit machines (myself included).
 
 We're working on building our cross compiler toolchains BUT we're running in
 to problems left and right.  Most of us are on non-windows boxen, (about half
 are on macs, the other are running linux).
 
 I've read a few different instructions on how to compile a D cross compiler,
 however since we're writing an OS we don't need any of the standard libraries,
 just the basics.
 
 Can anyone help walk through the steps of this.  I've been trying to combine
 two different methods (the method for just building gcc with an x86_64 target,
 and then trying to build D too), and when I finally got a build, just
 compiling the following code:
 
 void main() {
   return 1;
 }
 
 The compiler barfed with the following error:
 
 ~/bin/x86_64-pc-elf-gdc test.d
 <built-in>:0: internal compiler error: Bus error
 Please submit a full bug report,
 with preprocessed source if appropriate.
 See <URL:http://gcc.gnu.org/bugs.html> for instructions.
 
 I have tried to recompile my xcompiler since then and am having no luck (now
 I'm getting language glue errors hehe).  I figure rather than keep beating my
 head off of the wall I'd just ask if anyone else had done something similar,
 or could help out with this!
 
 Thanks much in advance!
 
 -Brian

The only complicated part in making a cross-compiler of GDC is Phobos. Since you don't WANT Phobos (and you certainly don't want Phobos with a non-OS target), you can actually disable that entirely. I believe the flag is just --disable-libphobos, but I'm not positive, I've never had to do it. Suffice to say it can be done :). At the very least, you should be able to make only the compiler component and its dependencies (you don't need any of the other garbage GCC comes with) with something like: $ make SUBDIRS="gcc" $ make install-gcc I believe that that will build GDC and not build libphobos. But the configuration --disable flag is probably the way to go. If you can reliably produce cross-compilers that crashes on a simple test case like the one you provided, that's probably a compiler bug. - Gregor Richards
Sep 12 2007
prev sibling next sibling parent Bruce Adams <tortoise_74 yeah.who.co.uk> writes:
Brian Madden Wrote:

 Hi all,
 
 I'd just like to preface this with saying that I'm sorry if this doesn't quite
 belong here, I wasn't sure where to post it, and it is a repost from the D
 group which looks like it hadn't received any activity for 2 months prior to
 my post.
 
 A few students at the University of Pittsburgh have been gathering and coding
 up a new operating system.  We've played in C, gotten some bootable code, etc,
 but we'd really like to write this all in D (save the asm parts that need to
 be done at the low level).  We're trying to target the x86_64 architecture,
 but not everyone has 64bit machines (myself included).
 
 We're working on building our cross compiler toolchains BUT we're running in
 to problems left and right.  Most of us are on non-windows boxen, (about half
 are on macs, the other are running linux).
 
 I've read a few different instructions on how to compile a D cross compiler,
 however since we're writing an OS we don't need any of the standard libraries,
 just the basics.
 
 Can anyone help walk through the steps of this.  I've been trying to combine
 two different methods (the method for just building gcc with an x86_64 target,
 and then trying to build D too), and when I finally got a build, just
 compiling the following code:
 
 void main() {
   return 1;
 }
 
 The compiler barfed with the following error:
 
 ~/bin/x86_64-pc-elf-gdc test.d
 <built-in>:0: internal compiler error: Bus error
 Please submit a full bug report,
 with preprocessed source if appropriate.
 See <URL:http://gcc.gnu.org/bugs.html> for instructions.
 
 I have tried to recompile my xcompiler since then and am having no luck (now
 I'm getting language glue errors hehe).  I figure rather than keep beating my
 head off of the wall I'd just ask if anyone else had done something similar,
 or could help out with this!
 
 Thanks much in advance!
 
 -Brian

This is nice meaty project idea. It will really test the mettle of both D and hopefully demonstrate its worth to the wider world. I do hope it ends up being open source. Getting cross gcc is quite a fraught process so if you've got that far you've already done well. I'm not sure if gdc is mature enough yet for use in a cross compiler so you will probably need to modify/fix it yourselves. Good luck. I'm sure many people here will be interested and willing to help but you might want to visit a cross gcc forum or two for the people with the right skills. It would be great to hear how you get on and any specific issues we might be able to help with. Regards, Bruce.
Sep 12 2007
prev sibling next sibling parent Sean Kelly <sean f4.ca> writes:
Brian Madden wrote:
 
 We're working on building our cross compiler toolchains BUT we're running in
 to problems left and right.  Most of us are on non-windows boxen, (about half
 are on macs, the other are running linux).
 
 I've read a few different instructions on how to compile a D cross compiler,
 however since we're writing an OS we don't need any of the standard libraries,
 just the basics.

Assuming you aren't averse to the idea, Tango may be your best bet here. See: http://www.dsource.org/projects/tango/wiki/TopicAdvancedConfiguration http://www.dsource.org/projects/tango/wiki/LibraryIntegrationGuide What I'd do is stub out the common library and do something very minimal for the garbage collector. Perhaps use this as a starting point: http://www.dsource.org/projects/tango/browser/trunk/lib/gc/stub/gc.d That should free you from the need to define almost any OS-level routines. If I recall, the compiler runtime portion uses memset and a few similar routines for convenience, but these should be easily replaceable. All this should at least strip out all unnecessary code from your application to get it up and running as quickly as possible. I'm afraid I can't help much for cross-compilation, though it sounds like you'll be using GDC if that's the case. Sean
Sep 12 2007
prev sibling next sibling parent reply untwisted <untwisted gmail.com> writes:
Thanks all for the support, I'll be working on this a lot over the 
weekend, and will be sure to keep everyone updated.  The eventual goal 
is to have an open source kernel, so everyone will get a chance to look 
and play if they want ;).
Sep 13 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"untwisted" <untwisted gmail.com> wrote in message 
news:fcbk8n$jc1$1 digitalmars.com...
 Thanks all for the support, I'll be working on this a lot over the 
 weekend,

SO WILL I
Sep 13 2007
parent reply Alexander Panek <alexander.panek brainsware.org> writes:
Jarrett Billingsley wrote:
 "untwisted" <untwisted gmail.com> wrote in message 
 news:fcbk8n$jc1$1 digitalmars.com...
 Thanks all for the support, I'll be working on this a lot over the 
 weekend,

SO WILL I

So that's why you're rarely online on IRC! Gotcha!
Sep 13 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Alexander Panek" <alexander.panek brainsware.org> wrote in message 
news:fcbnu7

 So that's why you're rarely online on IRC! Gotcha!

No, I'm rarely on IRC because (1) I'm not at work anymore and so don't have time for it and (2) I got pretty sick of it. Stupid drama bullshit that I don't need.
Sep 13 2007
parent Alexander Panek <a.panek brainsware.org> writes:
Jarrett Billingsley wrote:
 "Alexander Panek" <alexander.panek brainsware.org> wrote in message 
 news:fcbnu7
 
 So that's why you're rarely online on IRC! Gotcha!

No, I'm rarely on IRC because (1) I'm not at work anymore and so don't have time for it and (2) I got pretty sick of it. Stupid drama bullshit that I don't need.

Ad 1: Haha.. good point! :D Ad 2: What's with all the drama in #d.minid ?
Sep 13 2007
prev sibling next sibling parent reply Brian Madden <untwisted gmail.com> writes:
Just recompiled a D cross compiler from scratch using gcc 4.1.2 and gdc .24.

Compiled fine after a bit of a tweak, but I still got this error again:

canora-dubh:~/private/projects/d untwisted$ x86_64-pc-elf-gdc test.d
<built-in>:0: internal compiler error: Bus error
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
canora-dubh:~/private/projects/d untwisted$

Sad, I really wanted to use D, and was hoping it would just work! :(
Sep 13 2007
parent reply Gregor Richards <Richards codu.org> writes:
Brian Madden wrote:
 Just recompiled a D cross compiler from scratch using gcc 4.1.2 and gdc 
 .24.
 
 Compiled fine after a bit of a tweak, but I still got this error again:
 
 canora-dubh:~/private/projects/d untwisted$ x86_64-pc-elf-gdc test.d
 <built-in>:0: internal compiler error: Bus error
 Please submit a full bug report,
 with preprocessed source if appropriate.
 See <URL:http://gcc.gnu.org/bugs.html> for instructions.
 canora-dubh:~/private/projects/d untwisted$
 
 Sad, I really wanted to use D, and was hoping it would just work! :(

Backtrace. - Gregor Richards
Sep 13 2007
parent reply Brian Madden <untwisted gmail.com> writes:
Gregor Richards wrote:
 Brian Madden wrote:
 Just recompiled a D cross compiler from scratch using gcc 4.1.2 and 
 gdc .24.

 Compiled fine after a bit of a tweak, but I still got this error again:

 canora-dubh:~/private/projects/d untwisted$ x86_64-pc-elf-gdc test.d
 <built-in>:0: internal compiler error: Bus error
 Please submit a full bug report,
 with preprocessed source if appropriate.
 See <URL:http://gcc.gnu.org/bugs.html> for instructions.
 canora-dubh:~/private/projects/d untwisted$

 Sad, I really wanted to use D, and was hoping it would just work! :(

Backtrace. - Gregor Richards

I tried to get a backtrace in gdb using the backtrace command, but didn't get anything. I'm not entirely sure how to go about getting any useful info other than that. I tried some of the flags that gdc has, but most of them didn't give me anything useful either. The best I got was this: dhcpw210:~/private/projects/d untwisted$ x86_64-pc-elf-gdc -dH test.d <built-in>:0: internal compiler error: Bus error x86_64-pc-elf-gdc: Internal error: Abort trap (program cc1d) Please submit a full bug report. See <URL:http://gcc.gnu.org/bugs.html> for instructions. dhcpw210:~/private/projects/d untwisted$ If you can suggest something better, let me know and I'll be happy to share my findings. Thanks for all your help! -Brian
Sep 14 2007
parent reply Gregor Richards <Richards codu.org> writes:
Brian Madden wrote:
 Gregor Richards wrote:
 Brian Madden wrote:
 Just recompiled a D cross compiler from scratch using gcc 4.1.2 and 
 gdc .24.

 Compiled fine after a bit of a tweak, but I still got this error again:

 canora-dubh:~/private/projects/d untwisted$ x86_64-pc-elf-gdc test.d
 <built-in>:0: internal compiler error: Bus error
 Please submit a full bug report,
 with preprocessed source if appropriate.
 See <URL:http://gcc.gnu.org/bugs.html> for instructions.
 canora-dubh:~/private/projects/d untwisted$

 Sad, I really wanted to use D, and was hoping it would just work! :(

Backtrace. - Gregor Richards

I tried to get a backtrace in gdb using the backtrace command, but didn't get anything. I'm not entirely sure how to go about getting any useful info other than that. I tried some of the flags that gdc has, but most of them didn't give me anything useful either. The best I got was this: dhcpw210:~/private/projects/d untwisted$ x86_64-pc-elf-gdc -dH test.d <built-in>:0: internal compiler error: Bus error x86_64-pc-elf-gdc: Internal error: Abort trap (program cc1d) Please submit a full bug report. See <URL:http://gcc.gnu.org/bugs.html> for instructions. dhcpw210:~/private/projects/d untwisted$ If you can suggest something better, let me know and I'll be happy to share my findings. Thanks for all your help! -Brian

`gdc` is just a driver for a compiler, assembler and linker, namely cc1d, as and ld. So, when you backtrace gdc itself, you won't get anything useful (GDC didn't fail, cc1d did). Use GDC's (well, really, GCC's) verbose output to tell you what the real compilation command is, and backtrace that in gdb. $ x86_64-pc-elf-gdc -dH -v test.d <tons of garbage output> cc1d <huge input here> <more garbage output> - Gregor Richards
Sep 14 2007
parent reply Brian Madden <untwisted gmail.com> writes:
Sorry for the slow response, however I did manage to fix my error.  It 
turns out I had nulled out a variable in the d-lang.cc file because it 
was bugging out when I tried to make.  Later, it caused a problem 
because it was doing a string comparison on it.  I changed it from NULL 
to "w00t" and magically everything works, EXCEPT!!!!  I am getting some 
funky errors where D is looking for includes that don't exist.  First D 
wanted object.d, which I found and included via command line arg with 
the -I flag.  Then D wanted outofmemory.d, which I also found and gave 
it.  Then it wanted config.d which I could find nowhere, and gave up for 
the day.

After that I ended up getting a new hard drive and reinstalling OS X.  I 
will be giving this another go shortly.  Maybe the fresh install will do 
me well.

I'll let you know how it goes, but some good news for a change is that 
we have a 32bit cross compiled kernel building and booting.  If we can 
beat this 64bit monster we'll be in business!!

-Brian
Sep 20 2007
next sibling parent Gregor Richards <Richards codu.org> writes:
Brian Madden wrote:
 Sorry for the slow response, however I did manage to fix my error.  It 
 turns out I had nulled out a variable in the d-lang.cc file because it 
 was bugging out when I tried to make.  Later, it caused a problem 
 because it was doing a string comparison on it.  I changed it from NULL 
 to "w00t" and magically everything works, EXCEPT!!!!  I am getting some 
 funky errors where D is looking for includes that don't exist.  First D 
 wanted object.d, which I found and included via command line arg with 
 the -I flag.  Then D wanted outofmemory.d, which I also found and gave 
 it.  Then it wanted config.d which I could find nowhere, and gave up for 
 the day.
 
 After that I ended up getting a new hard drive and reinstalling OS X.  I 
 will be giving this another go shortly.  Maybe the fresh install will do 
 me well.
 
 I'll let you know how it goes, but some good news for a change is that 
 we have a 32bit cross compiled kernel building and booting.  If we can 
 beat this 64bit monster we'll be in business!!
 
 -Brian

These files are part of the runtime environment. Since you're not targeting an OS, you're going to need to roll your own runtime environment. Unlike C, D cannot function without a runtime environment. I would recommend looking at Tango's lib/ directory and starting from there. The GC is probably the only part that will need significant change to be rolled into a kernel. - Gregor Richards
Sep 20 2007
prev sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Brian Madden" <untwisted gmail.com> wrote in message 
news:fcu4df$2iap$1 digitalmars.com...
 Sorry for the slow response, however I did manage to fix my error.  It 
 turns out I had nulled out a variable in the d-lang.cc file because it was 
 bugging out when I tried to make.  Later, it caused a problem because it 
 was doing a string comparison on it.  I changed it from NULL to "w00t" and 
 magically everything works, EXCEPT!!!!  I am getting some funky errors 
 where D is looking for includes that don't exist.  First D wanted 
 object.d, which I found and included via command line arg with the -I 
 flag.  Then D wanted outofmemory.d, which I also found and gave it.  Then 
 it wanted config.d which I could find nowhere, and gave up for the day.

 After that I ended up getting a new hard drive and reinstalling OS X.  I 
 will be giving this another go shortly.  Maybe the fresh install will do 
 me well.

 I'll let you know how it goes, but some good news for a change is that we 
 have a 32bit cross compiled kernel building and booting.  If we can beat 
 this 64bit monster we'll be in business!!

Yeah, I had to stub out the runtime to get the 32-bit compiler working. Check out /branch/d32/dstubs.d (I think). There's also an object.d and the std/typeinfo directory. That'll all have to be cleaned up and expanded to ALL the runtime functions (since I only included just waht was needed to get it to compile).
Sep 20 2007
prev sibling next sibling parent reply Brian Madden <untwisted gmail.com> writes:
Good news everyone!  We've managed to get ourselves situated and now 
have a 32 and 64 bit D version of our little kernel booting!  Thanks for 
all of the help everyone!  We'll keep you updated on our progress :)
Oct 15 2007
next sibling parent reply Alexander Panek <a.panek brainsware.org> writes:
Brian Madden wrote:
 Good news everyone!  We've managed to get ourselves situated and now 
 have a 32 and 64 bit D version of our little kernel booting!  Thanks for 
 all of the help everyone!  We'll keep you updated on our progress :)

Are there sources available somewhere? Can't wait to get my hands/eyes dirty on those.
Oct 15 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Alexander Panek" <a.panek brainsware.org> wrote in message 
news:ff0le7$u77$1 digitalmars.com...
 Brian Madden wrote:
 Good news everyone!  We've managed to get ourselves situated and now have 
 a 32 and 64 bit D version of our little kernel booting!  Thanks for all 
 of the help everyone!  We'll keep you updated on our progress :)

Are there sources available somewhere? Can't wait to get my hands/eyes dirty on those.

We have an SVN set up which is publically browseable at http://www.pittgeeks.org/pgos/PaGanOS/. /trunk/src is the most interesting part ;)
Oct 15 2007
prev sibling next sibling parent Bruce Adams <tortoise_74 yeah.who.co.uk> writes:
Brian Madden Wrote:

 Good news everyone!  We've managed to get ourselves situated and now 
 have a 32 and 64 bit D version of our little kernel booting!  Thanks for 
 all of the help everyone!  We'll keep you updated on our progress :)

Great stuff.
Oct 15 2007
prev sibling parent reply Brian Madden <untwisted gmail.com> writes:
Brian Madden wrote:
 Good news everyone!  We've managed to get ourselves situated and now 
 have a 32 and 64 bit D version of our little kernel booting!  Thanks for 
 all of the help everyone!  We'll keep you updated on our progress :)

An update for those who care. If you check out the code at http://www.pittgeeks.org/pgos/trunk/src we've hit a new goal point (the kernel boots and exceptions work! [now to write the handlers hehe]). If you'd like to see our roadmap, and where we'll be going check out http://wiki.pittgeeks.org/index.php?title=PGOS where we keep our checklist. Feel free to comment, but keep in mind we're mostly groping in the dark here ;)
Oct 20 2007
parent Gregor Richards <Richards codu.org> writes:
Brian Madden wrote:
 Brian Madden wrote:
 Good news everyone!  We've managed to get ourselves situated and now 
 have a 32 and 64 bit D version of our little kernel booting!  Thanks 
 for all of the help everyone!  We'll keep you updated on our progress :)

An update for those who care. If you check out the code at http://www.pittgeeks.org/pgos/trunk/src we've hit a new goal point (the kernel boots and exceptions work! [now to write the handlers hehe]). If you'd like to see our roadmap, and where we'll be going check out http://wiki.pittgeeks.org/index.php?title=PGOS where we keep our checklist. Feel free to comment, but keep in mind we're mostly groping in the dark here ;)

You may want to move these update posts into a new thread, I'm sure there are people who would be interested in seeing a kernel in D but don't notice "Re: Minimal D Cross Compiler" - Gregor Richards
Oct 21 2007
prev sibling parent Alexander Panek <alexander.panek brainsware.org> writes:
On Mon, 15 Oct 2007 21:54:10 -0400
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote:
 We have an SVN set up which is publically browseable at 

Oh neat, thank you!
 http://www.pittgeeks.org/pgos/PaGanOS/.  /trunk/src is the most
 interesting part ;) 

I figured that, given the fact there's nothing in bin/ and doc/ .. :P -- Alexander Panek <alexander.panek brainsware.org>
Oct 16 2007