Thursday, May 14, 2015

gccgo gcc5.1.0 Cross compile for Sparc solaris 10 on Fedora20 X86_64

gcc5.1.0 Cross compile for Sparc solaris 10

The purpose of this procedure is to demonstrate the cross compilation of gcc5.1.0 on a Fedora 20 X86_64 host for Sparc Solaris 10. When I say cross compiling it means you will build the program on your host machine (linux X86_64) that will run on a Solaris Sparc X86_64 machine. This was mainly done to have latest version of the golang (1.4.2 at the time) compiler gccgo. The process is outlined below:

PREFIX: we will install all the pre-requisites and gcc cross compiler into this directory

SYSROOT: We will put all the required files from the target machine for which we are building gcc. This is the directory, the cross compiler will look into for header files and libraries. It acts as the root of the system we will compile the programs for.

TARGET: Is the architecture/platform we are targeting I mean the target on which the executables we will produce from cross compiling will execute. You can obtain the target from: gcc -dumpmachine

We are building binutils in a separate directory as it will not affect the untared directory if any errors are encountered during building. It will be easy to wipe build-binutils directory and start again.

How to cross compile golang program for sparc solaris 10:
Assuming you have already got the gccgo cross compiler installed as described above. If you have already got the golang installed on your linux box the process is easy just pass the --compiler option to go binary during build and use --gccgoflags option to pass options to the gccgo compiler.

copy the executable hello to your solaris machine and run it. It should work.

For dynamic linking using go:
$ go build --compiler gccgo hello.go

For dynamic linking using gccgo:
$ gccgo -v -o hello hello.go

To run the dynamically linked executable mount/copy the $PREFIX on your Solaris machine and set the LD_LIBRARY_PATH to include $PREFIX/lib and $PREFIX/lib64. run $ ldd hello to see all the dynamic libraries are found.

Thanks for the nice post. I have followed your steps and started compiling binaries for SPARC. However, I noticed that the generated binaries leak memory in a very bad way. I am afraid, the issue I am facing makes the generated binaries unusable.