Skip to content.
Infrastructure > SolarisGCC
This probably won't come up too often, but it's good reference. Arash requested gcc4 on cerebro-cc. Unfortunately, the Sun Freeware edition does not have support for the "-m64" flag compiled in. There are quite a few caveats in compiling from source (note that this applies to Solaris 10 -- I don't know if they're going to replace gcc3 or include it alongside in future distributions):

  • This step might be possible using Sun Studio's 'dmake', but just to be safe: download, compile, and install GNU make.
  • Download the source for binutils. As of 2.17, it has issues with the amd64 library and ld will spew errors during the gcc build. This patch (loosely based on a fix from OpenSolaris?) fixed for me:
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.347
diff -u -2 -r1.347 elf.c
--- bfd/elf.c   23 Jun 2006 02:58:00 -0000   1.347
+++ bfd/elf.c   28 Jun 2006 00:32:08 -0000
@@ -2104,4 +2104,9 @@
       break;
 
+    case SHT_GNU_dof:
+    case SHT_GNU_signature:
+    case SHT_GNU_syminfo:
+      return TRUE;
+
     case SHT_GNU_verdef:
       elf_dynverdef (abfd) = shindex;
Index: include/elf/common.h
===================================================================
RCS file: /cvs/src/src/include/elf/common.h,v
retrieving revision 1.77
diff -u -2 -r1.77 common.h
--- include/elf/common.h   17 Feb 2006 14:36:26 -0000   1.77
+++ include/elf/common.h   28 Jun 2006 00:41:58 -0000
@@ -341,14 +341,20 @@
 #define SHT_GNU_LIBLIST   0x6ffffff7   /* List of prelink dependencies */
 
-/* The next three section types are defined by Solaris, and are named
+/* The next six section types are defined by Solaris, and are named
    SHT_SUNW*.  We use them in GNU code, so we also define SHT_GNU*
    versions.  */
-#define SHT_SUNW_verdef   0x6ffffffd   /* Versions defined by file */
-#define SHT_SUNW_verneed 0x6ffffffe   /* Versions needed by file */
-#define SHT_SUNW_versym   0x6fffffff   /* Symbol versions */
-
-#define SHT_GNU_verdef   SHT_SUNW_verdef
-#define SHT_GNU_verneed   SHT_SUNW_verneed
-#define SHT_GNU_versym   SHT_SUNW_versym
+#define SHT_SUNW_dof       0x6ffffff4   /* Solaris DTrace Object Format */
+#define SHT_SUNW_signature  0x6ffffff6   /* Solaris Cryptographic Framework: Digital Signature */
+#define SHT_SUNW_syminfo    0x6ffffffc   /* Symbol information */
+#define SHT_SUNW_verdef       0x6ffffffd   /* Versions defined by file */
+#define SHT_SUNW_verneed    0x6ffffffe   /* Versions needed by file */
+#define SHT_SUNW_versym       0x6fffffff   /* Symbol versions */
+
+#define SHT_GNU_dof       SHT_SUNW_dof
+#define SHT_GNU_signature   SHT_SUNW_signature
+#define SHT_GNU_syminfo       SHT_SUNW_syminfo
+#define SHT_GNU_verdef       SHT_SUNW_verdef
+#define SHT_GNU_verneed       SHT_SUNW_verneed
+#define SHT_GNU_versym       SHT_SUNW_versym
 
 #define SHT_LOPROC   0x70000000   /* Processor-specific semantics, lo */
Index: ld/configure.tgt
===================================================================
RCS file: /cvs/src/src/ld/configure.tgt,v
retrieving revision 1.189
diff -u -2 -r1.189 configure.tgt
--- ld/configure.tgt   23 Jun 2006 18:11:47 -0000   1.189
+++ ld/configure.tgt   28 Jun 2006 00:42:40 -0000
@@ -164,10 +164,10 @@
 i[3-7]86-*-solaris2*)   targ_emul=elf_i386_ldso
                         targ_extra_emuls="elf_i386 elf_x86_64"
+         targ_extra_libpath=$targ_extra_emuls
                         ;;
 i[3-7]86-*-unixware)   targ_emul=elf_i386 ;;
 i[3-7]86-*-solaris*)   targ_emul=elf_i386_ldso
                         targ_extra_emuls="elf_i386"
+         targ_extra_libpath=$targ_extra_emuls
                         ;;
 i[3-7]86-*-netbsdelf* | \
Index: ld/emulparams/elf_x86_64.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf_x86_64.sh,v
retrieving revision 1.17
diff -u -2 -r1.17 elf_x86_64.sh
--- ld/emulparams/elf_x86_64.sh   30 May 2006 16:45:32 -0000   1.17
+++ ld/emulparams/elf_x86_64.sh   28 Jun 2006 00:42:47 -0000
@@ -23,5 +23,5 @@
 fi
 
-# Linux modify the default library search path to first include
+# Linux/solaris modify the default library search path to first include
 # a 64-bit specific directory.
 case "$target" in
@@ -31,3 +31,7 @@
     esac
     ;;
+  *-*-solaris2*) 
+      LIBPATH_SUFFIX=/amd64
+      ELF_INTERPRETER_NAME=\"/lib/amd64/ld.so.1\"
+    ;;
 esac

There is a good chance you'll need to inspect and patch by hand beyond 2.17 (if necessary at all).

  • (Still binutils:) ./configure --disable-nls, make, and make install.
  • The gcc documentation claims bison isn't necessary, but it will error out constantly without it. Download, compile, and install.
  • Download gcc4. Solaris doesn't use GNU tar, so you'll get an error during the untar process. I just untarred on my own machine and scp'd the directory.
  • I used the following line to configure (this is more for posterity and less of a note): ../src/configure --prefix=/usr/local/gcc4 --with-local-prefix=/usr/local --with-gnu-as --with-as=/usr/local/i386-pc-solaris2.10/bin/as --with-gnu-ld --with-ld=/usr/local/i386-pc-solaris2.10/bin/ld --enable-threads=posix --enable-shared --enable-multilib --disable-nls --with-included-gettext --with-system-zlib --enable-languages=c,c++
  • Build, go to lunch, and install.
  • Path /usr/local/gcc4/bin and test.