September 24, 2013

Getting the Go programming language to work on zLinux

There is an increased interest in the new programming language Go. The standard download page doesn't have packages for s390x so I tried getting gccgo to work as described but with no success. Probably the current gccgo branch is broken for s390x.
So as a fallback I used the standard gcc 4.8.1. As the base I used a SLES 11 SP3. Here are the steps:
  1. Check out gcc 4.8.1 using svn
    svn checkout svn:// gcc481
  2. Create build directory (here build) and change to it
  3. Configure gcc with your favorite options, include go in it. I used
    ../gcc481/configure --prefix=/opt/gcc481 --enable-languages=c,c++,go --enable-shared --with-system-zlib --with-arch=z9-109 --enable-threads=posix --enable-__cxa_atexit --enable-checking --enable-lto
  4. The configure script is going to complain on various missing or outdated packages. So you probably need to try multiple times in a clean directory.
    Get the missing stuff from the SUSE DVDs and install them or build them from source. (I used gmp-4.2.3 and mpc2-0.8.2 from the SDK and compiled mpfr-3.1.2  from sources and installed in /usr/local)
  5. make
  6. make install
The result is an installation in /opt/gcc481. Before compiling any application you need to set the PATH and LD_LIBRARY_PATH to include the new environment:

export PATH=/opt/gcc481/bin:$PATH
export LD_LIBRARY_PATH=/opt/gcc481/lib64/:/opt/gcc481/lib/:$LD_LIBRARY_PATH

Finally you can enter the hellozworld.go program

package main
import "fmt"

func main() {
    fmt.Printf("Hello, z-world\n")

and compile and run it with

gccgo hellozworld.go -o hellozworld

If you think this is an interesting language please approach Red Hat and SUSE and ask for it in the next releases!