Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Add custom toolchains for powerpc* and s390x #149

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions slaves/linux-cross/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ RUN apt-get install -y --force-yes --no-install-recommends \
zlib1g-dev \
bzip2 xz-utils \
g++ libc6-dev \
g++-powerpc-linux-gnu libc6-dev-powerpc-cross \
g++-5-powerpc64-linux-gnu libc6-dev-ppc64-powerpc-cross \
g++-powerpc64le-linux-gnu libc6-dev-ppc64el-cross \
g++-s390x-linux-gnu \
bsdtar \
cmake \
rpm2cpio cpio \
g++-5-mips-linux-gnu libc6-dev-mips-cross \
g++-5-mipsel-linux-gnu libc6-dev-mipsel-cross \
pkg-config
Expand Down Expand Up @@ -60,7 +57,11 @@ COPY linux-cross/build_toolchain.sh \
linux-cross/mipsel-linux-musl.config \
linux-cross/armv7-linux-gnueabihf.config \
linux-cross/armv7-linux-musleabihf.config \
linux-cross/powerpc-linux-gnu.config \
linux-cross/powerpc64-linux-gnu.config \
linux-cross/s390x-linux-gnu.config \
/build/
COPY linux-cross/patches /build/patches
USER rustbuild

# Build three full toolchains for the `arm-unknown-linux-gneuabi`,
Expand Down Expand Up @@ -108,11 +109,18 @@ RUN /bin/bash build_toolchain.sh arm-linux-musleabi
RUN /bin/bash build_toolchain.sh arm-linux-musleabihf
RUN /bin/bash build_toolchain.sh armv7-linux-musleabihf

# Also build toolchains for {powerpc{,64},s390x}-unknown-linux-gnu,
# primarily to support older glibc than found in the Ubuntu root.
RUN /bin/bash build_toolchain.sh powerpc-linux-gnu
RUN /bin/bash build_toolchain.sh powerpc64-linux-gnu
RUN /bin/bash build_toolchain.sh s390x-linux-gnu

USER root

# Rename all the compilers we just built into /usr/bin and also without
# `-unknown-` in the name because it appears lots of other compilers in Ubuntu
# don't have this name in the component by default either.
# Also rename `-ibm-` out of the s390x compilers.
# Also the aarch64 compiler is prefixed with `aarch64-unknown-linux-gnueabi`
# by crosstool-ng, but Ubuntu just prefixes it with `aarch64-linux-gnu` so
# we'll, additionally, strip the eabi part from its binaries.
Expand All @@ -121,6 +129,10 @@ RUN \
g=`basename $f`; \
ln -vs $f /usr/bin/`echo $g | sed -e 's/-unknown//'`; \
done && \
for f in `ls /x-tools/*-ibm-linux-*/bin/*-ibm-linux-*`; do \
g=`basename $f`; \
ln -vs $f /usr/bin/`echo $g | sed -e 's/-ibm//'`; \
done && \
for f in `ls /usr/bin/aarch64-linux-gnueabi-*`; do \
g=`basename $f`; \
mv -v $f /usr/bin/`echo $g | sed -e 's/eabi//'`; \
Expand All @@ -134,6 +146,11 @@ RUN bash /tmp/build_dragonfly_toolchain.sh
COPY linux-cross/build_netbsd_toolchain.sh /tmp/
RUN bash /tmp/build_netbsd_toolchain.sh

# powerpc64le is built using centos7 glibc, because that has
# backports that weren't committed upstream until glibc-2.19.
COPY linux-cross/build_powerpc64le_linux_toolchain.sh /tmp/
RUN bash /tmp/build_powerpc64le_linux_toolchain.sh

# Also build libunwind.a for the ARM musl targets
COPY linux-cross/build-libunwind.sh \
/build/
Expand Down Expand Up @@ -183,9 +200,12 @@ ENV AR_armv7_unknown_linux_gnueabihf=armv7-linux-gnueabihf-ar \
AR_mipsel_unknown_linux_musl=mipsel-linux-musl-ar \
CC_mipsel_unknown_linux_musl=mipsel-linux-musl-gcc \
CXX_mipsel_unknown_linux_musl=mipsel-linux-musl-g++ \
AR_powerpc_unknown_linux_gnu=powerpc-linux-gnu-ar \
CC_powerpc_unknown_linux_gnu=powerpc-linux-gnu-gcc \
CXX_powerpc_unknown_linux_gnu=powerpc-linux-gnu-g++ \
AR_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-ar \
CC_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-gcc-5 \
CXX_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-g++-5 \
CC_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-gcc \
CXX_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-g++ \
AR_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-ar \
CC_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-gcc \
CXX_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-g++ \
Expand Down
55 changes: 55 additions & 0 deletions slaves/linux-cross/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,58 @@ For targets: `mipsel-unknown-linux-musl`
(+) These options have been selected to match the gcc flags we use to compile C
libraries like jemalloc. See the mk/cfg/mips(el)-uknown-linux-musl.mk
file in Rust's source code.

## `powerpc-linux-gnu.config`

For targets: `powerpc-unknown-linux-gnu`

- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
- Path and misc options > Patches origin = Bundled, then local
- Path and misc options > Local patch directory = /build/patches
- Target options > Target Architecture = powerpc
- Target options > Emit assembly for CPU = power4 -- (+)
- Target options > Tune for CPU = power6 -- (+)
- Operating System > Target OS = linux
- Operating System > Linux kernel version = 2.6.32.68 -- ~RHEL6 kernel
- C-library > glibc version = 2.12.2 -- ~RHEL6 glibc
- C compiler > gcc version = 4.9.3
- C compiler > Core gcc extra config = --with-cpu-32=power4 --with-cpu=default32 -- (+)
- C compiler > gcc extra config = --with-cpu-32=power4 --with-cpu=default32 -- (+)
- C compiler > C++ = ENABLE -- to cross compile LLVM

(+) These CPU options match the configuration of the toolchains in RHEL6.

## `powerpc64-linux-gnu.config`

For targets: `powerpc64-unknown-linux-gnu`

- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
- Path and misc options > Patches origin = Bundled, then local
- Path and misc options > Local patch directory = /build/patches
- Target options > Target Architecture = powerpc
- Target options > Bitness = 64-bit
- Target options > Emit assembly for CPU = power4 -- (+)
- Target options > Tune for CPU = power6 -- (+)
- Operating System > Target OS = linux
- Operating System > Linux kernel version = 2.6.32.68 -- ~RHEL6 kernel
- C-library > glibc version = 2.12.2 -- ~RHEL6 glibc
- C compiler > gcc version = 4.9.3
- C compiler > C++ = ENABLE -- to cross compile LLVM

(+) These CPU options match the configuration of the toolchains in RHEL6.

## `s390x-linux-gnu.config`

For targets: `s390x-unknown-linux-gnu`

- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
- Path and misc options > Patches origin = Bundled, then local
- Path and misc options > Local patch directory = /build/patches
- Target options > Target Architecture = s390
- Target options > Bitness = 64-bit
- Operating System > Target OS = linux
- Operating System > Linux kernel version = 2.6.32.68 -- ~RHEL6 kernel
- C-library > glibc version = 2.12.2 -- ~RHEL6 glibc
- C compiler > gcc version = 4.9.3
- C compiler > gcc extra config = --with-arch=z10 -- LLVM's minimum support
- C compiler > C++ = ENABLE -- to cross compile LLVM
4 changes: 2 additions & 2 deletions slaves/linux-cross/build-libunwind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ set -ex
# To build MUSL targets we're going to need a libunwind lying around, so acquire that
# here and build it.
if [ ! -d "llvm-3.8.0.src" ]; then
curl http://llvm.org/releases/3.8.0/llvm-3.8.0.src.tar.xz | tar xJf -
curl http://releases.llvm.org/3.8.0/llvm-3.8.0.src.tar.xz | tar xJf -
fi

if [ ! -d "libunwind-3.8.0.src" ]; then
curl http://llvm.org/releases/3.8.0/libunwind-3.8.0.src.tar.xz | tar xJf -
curl http://releases.llvm.org/3.8.0/libunwind-3.8.0.src.tar.xz | tar xJf -
fi

rm -rf libunwind-build
Expand Down
4 changes: 2 additions & 2 deletions slaves/linux-cross/build_netbsd_toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ cd gcc
curl https://ftp.gnu.org/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.bz2 | tar xjf -
cd gcc-$GCC
./contrib/download_prerequisites
PATCHES="ftp://ftp.netbsd.org/pub/pkgsrc/pkgsrc-2016Q2/pkgsrc/lang/gcc5/patches/patch-libstdc%2B%2B-v3_config_os_bsd_netbsd_ctype__base.h \
ftp://ftp.netbsd.org/pub/pkgsrc/pkgsrc-2016Q2/pkgsrc/lang/gcc5/patches/patch-libstdc%2B%2B-v3_config_os_bsd_netbsd_ctype__configure__char.cc"
PATCHES="ftp://ftp.netbsd.org/pub/pkgsrc/pkgsrc-2016Q4/pkgsrc/lang/gcc5/patches/patch-libstdc%2B%2B-v3_config_os_bsd_netbsd_ctype__base.h \
ftp://ftp.netbsd.org/pub/pkgsrc/pkgsrc-2016Q4/pkgsrc/lang/gcc5/patches/patch-libstdc%2B%2B-v3_config_os_bsd_netbsd_ctype__configure__char.cc"

for patch in $PATCHES; do
curl $patch | patch -Np0
Expand Down
70 changes: 70 additions & 0 deletions slaves/linux-cross/build_powerpc64le_linux_toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

set -ex

BINUTILS=2.25.1
GCC=5.3.0
TARGET=powerpc64le-linux-gnu
SYSROOT=/usr/local/$TARGET/sysroot

# First, download the CentOS7 glibc.ppc64le and relevant header files.
# (upstream ppc64le support wasn't added until 2.19, which el7 backported.)
mkdir -p $SYSROOT
pushd $SYSROOT

centos_base=http://mirror.centos.org/altarch/7.3.1611/os/ppc64le/Packages
glibc_v=2.17-157.el7
kernel_v=3.10.0-514.el7
for package in glibc{,-devel,-headers}-$glibc_v kernel-headers-$kernel_v; do
curl $centos_base/$package.ppc64le.rpm | \
rpm2cpio - | cpio -idm
done

ln -sT lib64 lib
ln -sT lib64 usr/lib

popd

# Next, download and build binutils.
mkdir binutils-$TARGET
pushd binutils-$TARGET
curl https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS.tar.bz2 | tar xjf -
mkdir binutils-build
cd binutils-build
../binutils-$BINUTILS/configure --target=$TARGET --with-sysroot=$SYSROOT
make -j10
make install
popd
rm -rf binutils-$TARGET

# Finally, download and build gcc.
mkdir gcc-$TARGET
pushd gcc-$TARGET
curl https://ftp.gnu.org/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.bz2 | tar xjf -
cd gcc-$GCC
./contrib/download_prerequisites

mkdir ../gcc-build
cd ../gcc-build
../gcc-$GCC/configure \
--enable-languages=c,c++ \
--target=$TARGET \
--with-cpu=power8 \
--with-sysroot=$SYSROOT \
--disable-libcilkrts \
--disable-multilib \
--disable-nls \
--disable-libgomp \
--disable-libquadmath \
--disable-libssp \
--disable-libvtv \
--disable-libcilkrt \
--disable-libada \
--disable-libsanitizer \
--disable-libquadmath-support \
--disable-lto
make -j10
make install

popd
rm -rf gcc-$TARGET
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
From b3563932f85d60bb0d38b0a5f3b8f4abc133f890 Mon Sep 17 00:00:00 2001
From: Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
Date: Thu, 1 Nov 2012 18:00:06 -0500
Subject: [PATCH] PowerPC: Remove unnecessary -mnew-mnemonics.

---
sysdeps/powerpc/Makefile | 4 ----
1 file changed, 4 deletions(-)

diff --git a/sysdeps/powerpc/Makefile b/sysdeps/powerpc/Makefile
index 79dd6fa976d5..7442b6709ad1 100644
--- a/sysdeps/powerpc/Makefile
+++ b/sysdeps/powerpc/Makefile
@@ -1,7 +1,3 @@
-# We always want to use the new mnemonic syntax even if we are on a RS6000
-# machine.
-+cflags += -mnew-mnemonics
-
ifeq ($(subdir),gmon)
sysdep_routines += ppc-mcount
endif
--
2.9.3

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From a4f388e111ce05e2ab7912cff3c9070334bb74ae Mon Sep 17 00:00:00 2001
From: Josh Stone <jistone@redhat.com>
Date: Fri, 20 Jan 2017 15:41:56 -0800
Subject: [PATCH] Prevent inlining in PPC64 initfini.s

Ref: https://sourceware.org/ml/libc-alpha/2012-01/msg00195.html
---
sysdeps/powerpc/powerpc64/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sysdeps/powerpc/powerpc64/Makefile b/sysdeps/powerpc/powerpc64/Makefile
index 78d4f07e575f..fe96aae4d43e 100644
--- a/sysdeps/powerpc/powerpc64/Makefile
+++ b/sysdeps/powerpc/powerpc64/Makefile
@@ -28,7 +28,7 @@ elide-routines.os += hp-timing
ifneq ($(elf),no)
# The initfini generation code doesn't work in the presence of -fPIC, so
# we use -fpic instead which is much better.
-CFLAGS-initfini.s += -fpic -O1
+CFLAGS-initfini.s += -fpic -O1 -fno-inline
endif
endif

--
2.9.3

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
From 2739047682590b1df473401b4febf424f857fccf Mon Sep 17 00:00:00 2001
From: Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
Date: Sun, 17 Apr 2011 20:43:59 -0400
Subject: [PATCH] Use .machine to prevent AS from complaining about z9-109
instructions in iconv modules

---
sysdeps/s390/s390-64/utf16-utf32-z9.c | 5 ++++-
sysdeps/s390/s390-64/utf8-utf16-z9.c | 5 ++++-
sysdeps/s390/s390-64/utf8-utf32-z9.c | 5 ++++-
3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/sysdeps/s390/s390-64/utf16-utf32-z9.c b/sysdeps/s390/s390-64/utf16-utf32-z9.c
index 14daf2118fe5..5bcaaaedec9c 100644
--- a/sysdeps/s390/s390-64/utf16-utf32-z9.c
+++ b/sysdeps/s390/s390-64/utf16-utf32-z9.c
@@ -169,7 +169,10 @@ gconv_end (struct __gconv_step *data)
register unsigned long long outlen asm("11") = outend - outptr; \
uint64_t cc = 0; \
\
- asm volatile ("0: " INSTRUCTION " \n\t" \
+ asm volatile (".machine push \n\t" \
+ ".machine \"z9-109\" \n\t" \
+ "0: " INSTRUCTION " \n\t" \
+ ".machine pop \n\t" \
" jo 0b \n\t" \
" ipm %2 \n" \
: "+a" (pOutput), "+a" (pInput), "+d" (cc), \
diff --git a/sysdeps/s390/s390-64/utf8-utf16-z9.c b/sysdeps/s390/s390-64/utf8-utf16-z9.c
index 5f73f3c59e21..812a42fae44c 100644
--- a/sysdeps/s390/s390-64/utf8-utf16-z9.c
+++ b/sysdeps/s390/s390-64/utf8-utf16-z9.c
@@ -151,7 +151,10 @@ gconv_end (struct __gconv_step *data)
register unsigned long long outlen asm("11") = outend - outptr; \
uint64_t cc = 0; \
\
- asm volatile ("0: " INSTRUCTION " \n\t" \
+ asm volatile (".machine push \n\t" \
+ ".machine \"z9-109\" \n\t" \
+ "0: " INSTRUCTION " \n\t" \
+ ".machine pop \n\t" \
" jo 0b \n\t" \
" ipm %2 \n" \
: "+a" (pOutput), "+a" (pInput), "+d" (cc), \
diff --git a/sysdeps/s390/s390-64/utf8-utf32-z9.c b/sysdeps/s390/s390-64/utf8-utf32-z9.c
index 17ef8bc890c3..0ffd848c8124 100644
--- a/sysdeps/s390/s390-64/utf8-utf32-z9.c
+++ b/sysdeps/s390/s390-64/utf8-utf32-z9.c
@@ -155,7 +155,10 @@ gconv_end (struct __gconv_step *data)
register unsigned long long outlen asm("11") = outend - outptr; \
uint64_t cc = 0; \
\
- asm volatile ("0: " INSTRUCTION " \n\t" \
+ asm volatile (".machine push \n\t" \
+ ".machine \"z9-109\" \n\t" \
+ "0: " INSTRUCTION " \n\t" \
+ ".machine pop \n\t" \
" jo 0b \n\t" \
" ipm %2 \n" \
: "+a" (pOutput), "+a" (pInput), "+d" (cc), \
--
2.9.3

Loading