diff --git a/toolchain/build-toolchain.sh b/toolchain/build-toolchain.sh index 9f7728f4..6aa628d6 100755 --- a/toolchain/build-toolchain.sh +++ b/toolchain/build-toolchain.sh @@ -90,6 +90,12 @@ download() { log "downloading GCC dependencies" (cd "$GCC" && ./contrib/download_prerequisites) + + log "downloading additional GCC patches" + # Note: Changes to symbol visibility on riscv in newer binutils that got solved as of gcc 11.3 + wget -O "$GCC-99-libgcc-riscv.patch" "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=45116f342057b7facecd3d05c2091ce3a77eda59" + # Note: Patch needed for previously downloaded patch to apply. + wget -O "$GCC-98-libgcc-udiv.patch" "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=4013baf99c38f7bca06a51f8301e8fb195ccfa33" } build_binutils() { @@ -108,6 +114,7 @@ build_binutils() { ../configure --target="${TARGET}" --prefix="${TOOLCHAIN_PREFIX}" \ --with-sysroot="${SYSROOT}" --enable-lto --enable-deterministic-archives + make log "installing binutils" @@ -119,6 +126,7 @@ build_gcc_stage1() { log "patching ${GCC}" for patchfile in "${GCC}"-*.patch; do if [ ! -f "${GCC}/$patchfile.applied" ]; then + echo $patchfile patch -d "${GCC}" -p1 < "$patchfile" touch "${GCC}/$patchfile.applied" fi @@ -145,20 +153,25 @@ build_gcc_stage1() { # stage1 compiler (gcc only) ../configure --target="${TARGET}" --prefix="${TOOLCHAIN_PREFIX}" \ --with-sysroot="${SYSROOT}" \ - --with-gxx-include-dir="${SYSROOT}/include/c++" \ - --enable-languages=c,c++ --with-newlib \ - --with-headers=yes \ + --enable-languages=c \ + --without-headers \ + --with-newlib \ --enable-tls \ --enable-initfini-array \ --disable-decimal-float \ --disable-libquadmath \ --disable-libssp --disable-nls \ - --enable-threads=posix + --disable-threads \ + --disable-shared \ + --disable-libatomic \ + --disable-libgomp \ + --disable-libvtv \ + --disable-libstdcxx - make all-gcc + make all log "installing GCC (stage1)" - make install-gcc + make install popd > /dev/null } @@ -182,43 +195,65 @@ build_libc() { # FIXME: libphoenix should be installed for all supported multilib target variants log "[$phx_target] installing libphoenix" # LIBPHOENIX cannot be build shared as libgcc is not yet build. - make -C "$SCRIPT_DIR/../../libphoenix" NOCHECKENV=1 LIBPHOENIX_SHARED=n TARGET="$phx_target" clean install + make -C "$SCRIPT_DIR/../../libphoenix" NOCHECKENV=1 TOOLCHAIN_BUILD=y TARGET="$phx_target" clean install done + if [[ "$TARGET" = "arm-phoenix" || "$TARGET" = "sparc-phoenix" ]]; then + # Hack: Currently multilib only for archs supported in phoenix is created, which leads to invalid multilib on other archs. + # Copy any libc to generic multilib folder to which linker fallsback if arch specific libc is not found + # this probably leads to not working libgcc_s.so and libstdc++.so on targets not supported on Phoenix. + libc_path=$(find "$BUILD_ROOT" -name libc.so | head -n 1) + libc_folder=$(dirname "$libc_path") + generic_folder="$("$TARGET-gcc" -print-sysroot)/lib/$("$TARGET-gcc" -print-multi-directory)" + find "$libc_folder" -name "libc.so*" -exec cp {} "$generic_folder" \; + fi + PATH="$OLDPATH" } build_gcc_stage2() { - pushd "$BUILD_DIR/${GCC}/build" > /dev/null + log "building GCC (stage2)" + rm -rf "${GCC}/build" + mkdir -p "${GCC}/build" + pushd "${GCC}/build" > /dev/null - # (hackish) instead of reconfiguring and rebuilding whole gcc - # just force rebuilding internal includes (and fixincludes) - # remove stamp file for internal headers generation - rm gcc/stmp-int-hdrs + # GCC compilation options + # --with-sysroot -> cross-compiler sysroot + # --with-gxx-include-dir -> configure as a subdir of sysroot for c++ includes to work with external (out-of-toolchain) sysroot + # --with-newlib -> do note generate standard library includes by fixincludes, do not include _eprintf in libgcc + # --disable-libssp -> stack smashing protector library disabled + # --disable-nls -> all compiler messages will be in english + # --enable-tls -> enable Thread Local Storage + # --enable-initfini-array -> force init/fini array support instead of .init .fini sections + # --disable-decimal-float -> not relevant for other than i386 and PowerPC + # --disable-libquadmath -> not using fortran and quad floats + # --enable-threads=posix -> enable POSIX threads - log "building GCC (stage2)" - make all-gcc all-target-libgcc + + # stage1 compiler (gcc only) + ../configure --target="${TARGET}" --prefix="${TOOLCHAIN_PREFIX}" \ + --with-sysroot="${SYSROOT}" \ + --with-gxx-include-dir="${SYSROOT}/include/c++" \ + --enable-languages=c,c++ --with-newlib \ + --with-headers=yes \ + --enable-tls \ + --enable-initfini-array \ + --disable-decimal-float \ + --disable-libquadmath \ + --disable-libssp --disable-nls \ + --enable-threads=posix \ + --enable-shared \ + --disable-libstdcxx + + make log "installing GCC (stage2)" - make install-gcc install-target-libgcc + make install # remove `include` symlink to install c++ headers in $SYSROOT/include/c++ as expected rm -rf "${SYSROOT:?}/include" - popd > /dev/null -} -build_libc_shared() { - # use new compiler for the below builds - OLDPATH="$PATH" - PATH="$TOOLCHAIN_PREFIX/bin":$PATH - export PATH - - for phx_target in $PHOENIX_TARGETS; do - log "[$phx_target] installing shared libphoenix" - make -C "$SCRIPT_DIR/../../libphoenix" TOOLCHAIN_BUILD=y TARGET="$phx_target" install - done - - PATH="$OLDPATH" + popd > /dev/null } build_libstdcpp() { @@ -292,7 +327,6 @@ build_gcc_stage1 build_libc build_gcc_stage2 -build_libc_shared build_libstdcpp strip_binaries