Thursday, 24 May 2012

Building GCC with Ada on Solaris x86

This note documents (with some elisions!) building FSF GCC for Ada on Solaris 11 for x86.

I started off setting up an account on oracle.com, then downloaded and installed VirtualBox and Oracle Solaris 11 VM for Oracle VM VirtualBox. Installation was pretty straightforward.

You need a GCC including a working Ada compiler in order to build a new one. GNAT GPL 2007 from GNUAda at Sourceforge is such a compiler, but it had a problem with the assembler. It turned out it was configured to expect the GNU assembler at /opt/sfw/bin/gas. I installed the Solaris gnu-binutils package and made a symbolic link from /opt/sfw/bin/gas to /usr/gnu/bin/as, and all was well.

Now to build GCC 4.7.0, using the same general approach as on the Mac but with

  • gmp-5.0.5
  • mpfr-3.0.1 (can't use mpfr-3.1.0, the source layout isn't compatible with mpc - at any rate, when building together with gcc)
  • mpc-0.9

The build triplet chosen by default was i386-pc-solaris2.11; I used --build=x86_64-pc-solaris2.11.

You have to use gmake, not the Solaris make.

There was a puzzling failure:

   /lib/cpp fails sanity check
which turned out to be a missing <assert.h>, cured by installing the Solaris system/header package.

MPC 0.9 won't build on Solaris, because Solaris's <complex.h> expects a couple of compiler intrinsics (_COMPLEX_I, _IMAGINARY_I) which GCC doesn't know about: see here.

It turns out we need to get an up-to-date MPC from SVN; I got r1158.

Now we have to run autoreconf --install. Unfortunately, the set from the Solaris package manager doesn't seem to work (missing LIBTOOL macros, I think, but could have been pilot error).

Followed the advice here and installed autoconf-2.69, automake-1.12, libtool-2.4 and m4-1.4.16 in /opt/gnu.

Building m4 needs as; Sun's is in /usr/bin/as and /usr/ccs/bin/as, GNU as is in /usr/bin/gas and /usr/gnu/bin/as, so put the last on the PATH (as well as /opt/gnat-gpl-2007/bin for a working GCC).

The GCC build failed: there was a C compiler assertion failure in varasm.c.

So the next thing to try is, rather than making the giant leap from GCC 4.1.3 (the base of GNAT GPL 2007), build as many intermediate compilers as needed; starting with GCC 4.4.7 (bisecting the gap!)

We can't configure for x86_64-pc-solaris2.11, and we need older support libraries (gmp-4.3.2, mpfr-2.4.2).

Multilib isn't supported in i386-pc-solaris2.11 with this release, so --disable-multilib (I should add, I've been using --disable-bootstrap for these builds; it's not as though I'm using experimental compiler versions).

This builds OK, and make check-ada results in

                    === acats Summary ===
    # of expected passes            2315
    # of unexpected failures        0

                    === gnat Summary ===

    # of expected passes            618
    # of expected failures          6
    # of unsupported tests          1

I installed this compiler and returned to try GCC 4.7.0. This led to some confusion with the assembler (as).

I'd configured as x86_64-pc-solaris2.11, which led to failures while building libgcc:

   /usr/bin/gnu/as: unrecognized option '-xarch=generic64'

This turned out to mean that the built compiler had found /usr/bin/gnu/as but thought it was the Sun assembler. Letting the build process use /usr/ccs/bin/as failed in building libiberty.

The fix I adopted for this was to configure with

  • --with-as=/usr/gnu/bin/as
  • --with-gnu-as
and then
  • put /usr/gnu/bin on the PATH
  • move /usr/ccs/bin/as out of the way.

A further change to the approach resulted from reading the GCC build instructions: my final configure command was

   ../gcc-4.7.0/configure \
      --prefix=/opt/gcc-4.7.0 \
      --enable-languages=c,ada \
      --with-as=/usr/gnu/bin/as \
      --with-gnu-as \
      --disable-bootstrap
which results in a natively 32-bit compiler which will build 64-bit binaries with -m64.

make check-ada results in

                   === acats Summary ===
   # of expected passes            2319
   # of unexpected failures        1
   *** FAILURES: c761010

                   === gnat Summary ===

   # of expected passes            1078
   # of expected failures          13
   # of unsupported tests          5

I don't know what went wrong with c761010, but when I ran it again by hand it succeeded without trouble.

The resulting compiler is available at the GNUAda project on Sourceforge. The README says

This is GCC 4.7.0 built to compile C and Ada on Solaris 11/Intel.

With the -m64 switch it compiles in amd64 (64-bit) mode.

It requires the Solaris gnu-binutils package.

To install,

# cd /
# tar zxvf /where/downloaded/gcc-4.7.0-i386-pc-solaris2.11-bin.tar.gz

To use, put /opt/gcc-4.7.0/bin on your PATH.

Revised 25.v.12: minor clarifications.

No comments:

Post a Comment