Thursday, February 16, 2012

Cross-compiling for S/390

Playing with hercules S/390 emulator I wanted an up-to-date Linux kernel. And to get that you need tools: binutils (assembler and linker) and gcc (C compiler). Cross-compiling binutils and gcc that is able to build a kernel is very easy, just follow these steps and you should end up with a gcc able to build a kernel for you.

Download and build binutils:
wget http://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2
tar jxvf binutils-2.22.tar.bz2
mkdir os390 && cd os390
../binutils-2.22/configure --prefix=/opt/s390 --target=s390-ibm-linux
make
make install

Ok, now you have binutils built and installed, next the compiler itself. So, download and build gcc:
(Note the make build and install targets!)
wget http://ftp.gnu.org/gnu/gcc/gcc-4.6.2/gcc-4.6.2.tar.bz2
tar jxvf gcc-4.6.2.tar.bz2
mkdir gs390 && cd gs390
../gcc-4.6.2/configure --prefix=/opt/s390 --target=s390-ibm-linux --enable-languages=c
make all-gcc
make install-gcc

Now you have gcc that you can use to build a kernel for your S/390 mainframe (or Hercules emulator if you are like me and can't afford one :)

5 comments:

pallavi pathak said...

430hi,

Thanks for this post, I followed the steps you mentioned but running a simple hello world program returning me error as :

/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find crt1.o: No such file or directory
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find crti.o: No such file or directory
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find crtbegin.o: No such file or directory
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find -lgcc
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find -lgcc_s
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find -lc
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find -lgcc
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find -lgcc_s
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find crtend.o: No such file or directory
/opt/s390/lib/gcc/s390-ibm-linux/4.5.2/../../../../s390-ibm-linux/bin/ld: cannot find crtn.o: No such file or directory

Can you please look in to this, and suggest if anymore changes are required

Onion said...

My instructions was only for binutils+gcc, that is enough to build a kernel but not any userland applications.

You need to build glibc too to be able to build userland applications. I didn't get that far as at the time hercules had some issues with newer kernels requiring something that hercules didn't support, I don't remember the exact details so I never got as far as to building full userland cross compilation environment.

pallavi pathak said...

I just tried but glibc what option to be used for building it for s390 and should I install glibc with the local gcc or the s390-ibm-linuxgcc (as by the blog).

Onion said...

Yes, you need to compile glibc with the cross compiler and then you need to rebuild gcc so that it knows about the new glibc.

You will also need kernel headers for S390 to be able to compile glibc.

It can be a bit complicated.

pallavi pathak said...

It is a circular dependency now, running glibc again have issues using LD_libraries,

we are actually trying to build Cross Compiler for Z/OS on Linux 64.

If you know a little on this, or you can guide?