Cross compiler for z/oS

Go here: http://45.76.81.249/zOS

~.bashrc

export PATH=/opt/IBM/bin:$PATH
export CFLAGS="$CFLAGS -Wno-error"

Folders

mkdir PEP_ZOS
sudo mkdir -p /opt/IBM
sudo chown `whoami`:users -R /opt/IBM

Repositories

cd PEP_ZOS
git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux
git checkout v5.3.12
cd ..
git clone https://github.com/leviathanch/binutils.git
cd binutils
git checkout lev/master
git clone https://github.com/leviathanch/gcc.git
cd gcc
git checkout lev/master
cd ..
got clone https://github.com/leviathanch/glibc.git
cd glibc
git checkout lev/master
cd ..

Building steps

First we need to build the binutils with patches to generate and link bytecode recognized by the z/OS environment.

cd binutils/build

../configure --prefix=/opt/IBM --program-prefix=s390x-ibm-zos-gnu- --target=s390x-ibm-zos-gnu

make -j4

make install

cd ../..

Now we need to provide the kernel headers, since this is a requirement for building gcc and glibc (even if z/OS isn’t a Linux)

cd linux

make ARCH=s390 menuconfig (got to exit and save)

make ARCH=s390 INSTALL_HDR_PATH=/opt/IBM/s390x-ibm-zos-gnu headers_install

cd ..

Now we build the first stage of the gcc bootstrap phase

cd gcc/build

../configure --prefix=/opt/IBM --program-prefix=s390x-ibm-zos-gnu- --target=s390x-ibm-zos-gnu --disable-multilib --enable-languages=c,c++ --disable-shared --disable-checking

make -j4 all-gcc

make install-gcc

cd ../..

Now we build the GLIBC on which the rest of GCC depends

cd glibc/build

export CFLAGS="-Wno-error -I/opt/IBM/include -L/opt/IBM/lib64/gcc/s390x-ibm-zos-gnu/8.3.1 -I/opt/IBM/lib64/gcc/s390x-ibm-zos-gnu/8.3.1/include -static -fsplit-stack -O3 -fexec-charset=IBM-1047"

../configure --prefix=/opt/IBM/s390x-ibm-zos-gnu --host=s390x-ibm-zos-gnu --target=s390x-ibm-zos-gnu --build=s390x-ibm-zos-gnu --disable-multilib --with-headers=/opt/IBM/s390x-ibm-zos-gnu/include --disable-shared --disable-nscd

make install-bootstrap-headers=yes install-headers

make -j4 csu/subdir_lib

install csu/*.o /opt/IBM/s390x-ibm-zos-gnu/lib/

touch /opt/IBM/s390x-ibm-zos-gnu/include/gnu/stubs.h

s390x-ibm-zos-gnu-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o /opt/IBM/s390x-ibm-zos-gnu/lib/libc.so

cd ../..

Now we’ve got to build libgcc

cd gcc/build

make -j4 all-target-libgcc

make install-target-libgcc

cd ../..

Now we’ve got to finalize the GLIBC build

cd glibc/build

make -j4

make install

cd ../..

3 thoughts on “Cross compiler for z/oS”

  1. I’ve tried several branches and I always get the following error in glibc:

    configure: error:
    *** The used GCC has no support for __builtin_tbegin, which is needed for lock-elision on target S390.

    1. Hi
      Which branch are you using for the GCC?
      Seems to be a GCC error.

      configure runs through fine for me.

      However, it doesn’t compile yet properly.
      I’m working on the glibc part as we speak actually, feel like joining? 😉

      1. I’m using the lev/master branch ATM. I added ‘–enable-lock-elision=yes’ in case it helped, but it didnt. I tried the zos/2.28/master branch of glibc as well as the lev/master branch.

        “I’m working on the glibc part as we speak actually, feel like joining?”

        I’ll see what I can do once I get there. I’m using a Dockerfile to compile right now: https://gist.github.com/pwhelan/55b9b17845578d54490da76949095c66

Leave a Reply

Your email address will not be published. Required fields are marked *