Saturday, February 27, 2010

Compiling GCC 4.4.3 on Solaris

First I have to say the compiling on solaris can be a major pain in the ass. I found my-self wanting gnu find on one of our solaris 10 machines but had issues compiling it, there was a known bug in gcc that can be fixed by upgrading gcc. That is when the fun began. I download gcc from gnu.org. The first problem I ran into was that I didn't read the dependency list, my bad. I needed to grab gmp and mpfr. I downloaded and compiled both and passed the --with-gmp and --with-mpfr flags and I though I was all set. Turns out that I was wrong I ran into a problem finding the mpfr lib. That sucked seeing as I just downloaded and compiled them. After looking at the config.log it was pretty obvious, I was building against 64 bit libraries. Adding the following got me to the next error:
env CC="gcc -m64"
The next problem was similar, apparently Solaris includes the 32 bit binaries in the search path but not 64 bit. The error I got was:
configure: error: cannot compute suffix of object files
When I checked the config.log the specific error I found was:
libgcc_s.so.1: wrong ELF class: ELFCLASS32
I was able to fix it with the following:
export LD_LIBRARY_PATH=/usr/sfw/lib/64/
Ok so now things looked to be on the right path. The compile went on for an hour and half and died with a new error, again the error was wrong ELF class. At this point I was about to pull my hair out. The problem was the CFLAGS were not being passed down to the cross coplier, note the following line:

/users/srb55/gcc-4.4.3/host-sparc-sun-solaris2.10/prev-gcc/xgcc -B/users/srb55/gcc-4.4.3/host-sparc-sun-solaris2.10/prev-gcc/ -B/global/inf/sys/software/gcc/gcc-4.4.2/sparc-sun-solaris2.10/bin/ -c -g -O2 -DIN_GCC
--- snip ---
So the fix to this wasnt so bad I just disbabled the bootstrap compile with --disable-bootstrap. This time the compile completed (after like 3 hours). The configure line that worked in the end was:
./configure --prefix=/global/inf/sys/software/gcc/gcc-4.4.3 --with-mpfr=/global/inf/sys/software/mpfr/mpfr-2.4.0 --with-gmp=/global/inf/sys/software/gmp/gmp-5.0.1/ --enable-shared --disable-nls --disable-bootstrap --disable-multilib -enable-languages=c,c++
Victory!