Page 1 of 1
Help with the GCC Cross-Compiler (Mac OS X)
Posted: Thu Oct 20, 2011 12:42 pm
by hafai
I've been trying to build a cross-compiler for a couple of weeks now using both the tutorial on the wiki and through other tutorials that I've found by Google.
I keep getting Segmentation Faults however on the first line of my source file when I invoke GCC. The various programs in Binutils appear to work properly.
I'm using GCC 4.6.1 (core only but I did try the full version originally) and Binutils 2.21.1, a combination that
http://wiki.osdev.org/Cross-Compiler_Successful_Builds says should work on Mac OS X. In my latest attempt I loaded the latest libiconv source code into the gcc-core-4.6.1 folder as suggested on the wiki and did the same for MPFR, GMP, and MPC. Furthermore I had installed the latest versions of MPFR, GMP, and MPC during my first attempt.
I'm using x86_64-elf as my target.
I'm pretty sure it isn't an issue with my hardware as it is brand new and the standard installation of GCC runs properly but at the same time I doubt it is a software bug in GCC either. The only thing I can think of is that there is an issue being caused with Lion itself as it was released July 20th while the latest version of GCC was released June 27th.
Does anyone have any suggestions?
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Thu Oct 20, 2011 2:18 pm
by gerryg400
When Lion first came out I built a cross-compiler using the GCC that comes with the new Xcode 4.2. The toolchain built, but like you I got SEGFAULTS when I ran GCC.
I gave up immediately and reverted to Xcode 3.2 and everything is fine.
There are some other Lion users on the forum and hopefully some have a better solution than mine.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Thu Oct 20, 2011 3:43 pm
by hafai
I think what's next for me to try is grab the latest snapshot (Not sure if I'd try the latest 4.6 or 4.7) and see if that works. I'll have to get back to my Mac and try it.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Thu Oct 20, 2011 4:11 pm
by gerryg400
I don't think that will help. The issue isn't with the GCC that you are building. There is a problem with the host GCC.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Fri Oct 21, 2011 12:26 am
by hafai
I think I have found a solution.
I followed the instructions at
http://beardedcodewarrior.net/2011/07/2 ... os-x-lion/ but instead of "installing like normal" as it says to in step 4 I jumped over to the tutorial for the cross-compiler. I won't know for certain if it worked until I check with a virtual machine showing my test "kernel" running properly but it is not segmentation faulting.
Totally unrelated, I just noticed you and I joined on the same day, only a year off.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Fri Oct 21, 2011 12:29 am
by gerryg400
Cool, thanks for that. I'm gonna try it now on my son's machine.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Fri Oct 21, 2011 12:15 pm
by hafai
I finally got Bochs working (the Carbon GUI wasn't compiling right and had to compile for the terminal) but the kernel I compiled with the resulting cross-compiler worked correctly.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Fri Oct 21, 2011 2:40 pm
by gerryg400
hafai wrote:I finally got Bochs working (the Carbon GUI wasn't compiling right and had to compile for the terminal) but the kernel I compiled with the resulting cross-compiler worked correctly.
May I ask which version of Bochs you have working ? And which compile options etc. ?
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Fri Oct 21, 2011 3:14 pm
by hafai
I'm using 2.4.6 and I compiled it with the following.
Code: Select all
--with-term --enable-x86-64 --enable-smp
Later I'm going to recompile it with "--enable-debugger" and "--enable-disasm" but for now I just wanted something that worked and showed me the compiler was working.
Interestingly though when I started using a script to run the cross-compiler, mount the virtual drive, copy the binary, unmount the drive, and then execute bochs with the correct config it (the cross-compiler) began to say that "-nostdlibs" and "-nodefaultlibs" were invalid flags when it was compiling happily with them before. It has no problem with the "-nostartfiles" flag. I took out the newly offending flags and the resulting binary didn't change. But it's weird that it started complaining about the flags (whether I use the script or not) after I started using the script. I'm going to try a full restart (with no reopening of programs) but I don't think that will fix it.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Fri Oct 21, 2011 7:57 pm
by Chandra
hafai wrote:Interestingly though when I started using a script to run the cross-compiler, mount the virtual drive, copy the binary, unmount the drive, and then execute bochs with the correct config it (the cross-compiler) began to say that "-nostdlibs" and "-nodefaultlibs" were invalid flags
I'd say, that should have been
-nostdlib. I'm not surprised that the compiler complains on appending 's'.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Mon Oct 24, 2011 2:35 pm
by hafai
Thanks, that would actually have been the problem. >.<
When I typed it into the script file I accidentally added an "s" to "-nostdlib" and dropped the "s" on "-nodefaultlibs." I haven't noticed any difference between with and without the two flags but I'm going to use them as that is what is suggested.
@gerryg400: I actually recompiled it again, this time with X11 as the gui, because I noticed that using the console makes the virtual-pc's console the size of the host terminal. This made it 80*24 instead of the standard 80*25 and I didn't feel like changing all the settings for terminal. The added benefit of using X11 is I can close bochs without closing the terminal as it is in a separate window, so I don't have to keep reopening terminal. I just threw in an extra line to quit the X server after I'm done with it into my script that compiles everything and loads bochs.
Re: Help with the GCC Cross-Compiler (Mac OS X)
Posted: Sat Oct 29, 2011 9:01 pm
by Andy1988
I also ran into the segfault issue with GCC on Lion.
The reason for that is that gcc isn't a real gcc, but only the GCC frontend for LLVM (LLVM-GCC).
If you now build your cross compiling gcc with this thing, it uses LLVM as a backend which doesn't work.
There are a bunch of open source packages which either don't compile correctly or are having runtime issues when built with LLVM. You can see this in several
homebrew recipes ("fails_with_llvm keyword). Qemu for example has this set in its recipe file.
The solution is setting all those environment variables the buildsystem uses to resolve your host-compiler to the real GCC (not the LLVM-GCC):
Code: Select all
CC=/usr/bin/gcc-4.2 CPP=/usr/bin/cpp-4.2 CXX=/usr/bin/g++-4.2 LD=/usr/bin/gcc-4.2 ./configure <your config options here>
Took me a while to figure this out.