From 86a1764b1b8b07a1c970b58ac3b1995b84943593 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Wed, 16 Jul 2025 13:30:11 +0100 Subject: [PATCH 01/15] Remove Meson and CMake flag configurations --- build-clang-with-args.sh | 8 -- build-gcc-with-args.sh | 3 - generate-clang-cmake-toolchain.sh | 90 ---------------------- generate-clang-meson-cross-file.sh | 115 ----------------------------- generate-gcc-meson-cross-file.sh | 107 --------------------------- 5 files changed, 323 deletions(-) delete mode 100755 generate-clang-cmake-toolchain.sh delete mode 100755 generate-clang-meson-cross-file.sh delete mode 100755 generate-gcc-meson-cross-file.sh diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index 1dc5c09..916a1dc 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -134,14 +134,6 @@ cmake --build "${llvm_build_dir}" \ cd "${build_top_dir}" -## Create Toolchain Files! -# These don't yet add cflags ldflags -"${build_top_dir}/generate-clang-cmake-toolchain.sh" \ - "${toolchain_target}" "${toolchain_dest}" "${toolchain_cflags[@]}" -"${build_top_dir}/generate-clang-meson-cross-file.sh" \ - "${toolchain_target}" "${toolchain_dest}" ${march} ${mabi} ${mcmodel} \ - "${toolchain_cflags[@]}" - # Copy LLVM licenses into toolchain mkdir -p "${toolchain_dest}/share/licenses/llvm" cp "${llvm_dir}/llvm/LICENSE.TXT" "${toolchain_dest}/share/licenses/llvm" diff --git a/build-gcc-with-args.sh b/build-gcc-with-args.sh index 720691d..dd61255 100755 --- a/build-gcc-with-args.sh +++ b/build-gcc-with-args.sh @@ -99,9 +99,6 @@ cd "${build_top_dir}" # These don't yet add cflags ldflags "${build_top_dir}/generate-gcc-cmake-toolchain.sh" \ "${toolchain_target}" "${toolchain_dest}" "${toolchain_cflags[@]}" -"${build_top_dir}/generate-gcc-meson-cross-file.sh" \ - "${toolchain_target}" "${toolchain_dest}" ${march} ${mabi} ${mcmodel} \ - "${toolchain_cflags[@]}" ls -l "${toolchain_dest}" diff --git a/generate-clang-cmake-toolchain.sh b/generate-clang-cmake-toolchain.sh deleted file mode 100755 index f676357..0000000 --- a/generate-clang-cmake-toolchain.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash -# Copyright lowRISC contributors. -# Licensed under the Apache License, Version 2.0, see LICENSE for details. -# SPDX-License-Identifier: Apache-2.0 - -## generate-clang-cmake-toolchain.sh -# -# This generates a cmake-toolchains(7) file to configure CMake for -# cross-compiling with clang. -# -# Docs: https://cmake.org/cmake/help/v3.15/manual/cmake-toolchains.7.html - -set -e -set -x -set -o pipefail - -if ! [ "$#" -ge 2 ]; then - echo "Usage: $0 " - exit 2 -fi; - -## Take configuration from arguments -# This is the gcc target triple -toolchain_target="${1}" -# This is the directory where the toolchain has been installed. -toolchain_dest="${2}" -# Remaining cflags for build configurations -toolchain_cflags=("${@:3}") - -cmake_cflags="" -for flag in "${toolchain_cflags[@]}"; do - if [ -z "${cmake_cflags}" ]; then - cmake_cflags+="${flag}"; - else - cmake_cflags+=";${flag}" - fi -done - -config_dest="${toolchain_dest}/${toolchain_target}-clang.cmake" -sysroot_config="" -system_name="" - -case "${toolchain_target}" in - riscv*-*-linux-gnu) - system_name="Linux" - sysroot_config="set(CMAKE_SYSROOT \"\${LOWRISC_TOOLCHAIN}/${toolchain_target}/sysroot\" CACHE STRING \"\" FORCE)"; - ;; - riscv*-*-elf) - system_name="Generic" - ;; -esac; - -tee "${config_dest}" < " - exit 2 -fi; - -## Take configuration from arguments -# This is the gcc target triple -toolchain_target="${1}" -# This is the directory where the toolchain has been installed. -toolchain_dest="${2}" -# -march option default value -march="${3}" -# -mabi option default value -mabi="${4}" -# -mcmodel option default value -mcmodel="${5}" -# Remaining cflags for build configurations -toolchain_cflags=("${@:6}") - -# Meson uses the driver when both compiling and linking, which may need flags to -# identify exactly how to set up paths and defaults for both. -meson_driver_flags="" -for flag in "${toolchain_cflags[@]}"; do - if [ -z "${meson_driver_flags}" ]; then - meson_driver_flags+="'${flag}'"; - else - meson_driver_flags+=", '${flag}'" - fi -done - -config_dest="${toolchain_dest}/meson-${toolchain_target}-gcc.txt" -sysroot_config=""; -system_name="" - -case "${toolchain_target}" in - riscv*-*-linux-gnu) - sysroot_config="sys_root = toolchain_path / '${toolchain_target}/sysroot'"; - system_name="linux"; - ;; - riscv*-*-elf) - system_name="bare metal"; - ;; -esac; - -tee "${config_dest}" < Date: Wed, 16 Jul 2025 13:39:35 +0100 Subject: [PATCH 02/15] Remove support for multilib builds --- .github/workflows/toolchain_build.yml | 8 ---- README.md | 2 - ...sc-toolchain-gcc-multilib-baremetal.config | 27 ------------- lowrisc-toolchain-gcc-multilib-linux.config | 40 ------------------- 4 files changed, 77 deletions(-) delete mode 100644 lowrisc-toolchain-gcc-multilib-baremetal.config delete mode 100644 lowrisc-toolchain-gcc-multilib-linux.config diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index 4c3d227..74745ac 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -38,14 +38,6 @@ jobs: march: rv64imac mabi: lp64 mcmodel: medany -# - name: multilib-baremetal -# display_name: RV64 GCC (Multilib Baremetal) -# target: riscv64-unknown-elf -# output_dir: /opt/riscv-baremetal-toolchain -# - name: multilib-linux -# display_name: RV64 GCC (Multilib Linux) -# target: riscv64-unknown-linux-gnu -# output_dir: /opt/riscv-linux-toolchain name: ${{ matrix.host_arch }} build of ${{ matrix.display_name }} runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 549d2b5..99db5f6 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,6 @@ for pre-built toolchains. * A GCC RV32IMC without hardfloat support, targeting [Ibex](https://github.com/lowRISC/ibex/) * A GCC RV64IMAC, targeting [Muntjac](https://github.com/lowRISC/muntjac) -* A GCC elf multilib toolchain -* A GCC linux multilib toolchain How to do a release ------------------- diff --git a/lowrisc-toolchain-gcc-multilib-baremetal.config b/lowrisc-toolchain-gcc-multilib-baremetal.config deleted file mode 100644 index f998926..0000000 --- a/lowrisc-toolchain-gcc-multilib-baremetal.config +++ /dev/null @@ -1,27 +0,0 @@ -CT_CONFIG_VERSION="3" -CT_EXPERIMENTAL=y -CT_ARCH_RISCV=y -CT_ARCH_64=y -CT_ARCH_USE_MMU=y -CT_MULTILIB=y -# CT_DEMULTILIB is not set -CT_CC_LANG_CXX=y -# CT_KERNEL_LINUX is not set -CT_DEBUG_GDB=y -# CT_GDB_CROSS_PYTHON is not set -# CT_GDB_GDBSERVER is not set -CT_ZLIB_NEEDED=y - -# Disable progress bar for CI builds, it generates too much log output -# CT_LOG_PROGRESS_BAR is not set - -# Installation prefix directory; the toolchain will end up in exactly -# this directory. CT_PREFIX_DIR will be added by the -# ./build-gcc-with-args.sh script - -# Don't save tarballs for re-use (needs writable and pre-created -# CT_LOCAL_TARBALLS_DIR otherwise) -# CT_SAVE_TARBALLS is not set - -# Don't chmod the CT_PREFIX_DIR read-only after the install. -# CT_PREFIX_DIR_RO is not set diff --git a/lowrisc-toolchain-gcc-multilib-linux.config b/lowrisc-toolchain-gcc-multilib-linux.config deleted file mode 100644 index 17bc852..0000000 --- a/lowrisc-toolchain-gcc-multilib-linux.config +++ /dev/null @@ -1,40 +0,0 @@ -CT_CONFIG_VERSION="3" -CT_EXPERIMENTAL=y -CT_ARCH_RISCV=y -CT_ARCH_64=y -CT_ARCH_USE_MMU=y - -# We wish MULTILIB was supported, but it's not - gcc says its built a multilib -# for rv32, but then glibc fails to build for 32-bit RISC-V. The solution is -# to not do a multilib build for the moment, but to just match the rv64 default -# lib, so that later we can add a multilib without breaking everything -# (hopefully). -# CT_MULTILIB is not set -# CT_ARCH_ARCH="rv64gc" -# CT_ARCH_ABI="lp64d" - -# CT_DEMULTILIB is not set -CT_CC_LANG_CXX=y -CT_KERNEL_LINUX=y -CT_DEBUG_GDB=y -# CT_GDB_CROSS_PYTHON is not set -# CT_GDB_GDBSERVER is not set -CT_ZLIB_NEEDED=y - -# Disable progress bar for CI builds, it generates too much log output -# CT_LOG_PROGRESS_BAR is not set - -# Installation prefix directory; the toolchain will end up in exactly -# this directory. CT_PREFIX_DIR will be added by the -# ./build-gcc-with-args.sh script - -# Don't save tarballs for re-use (needs writable and pre-created -# CT_LOCAL_TARBALLS_DIR otherwise) -# CT_SAVE_TARBALLS is not set - -# Having errors building linux (due to sched.h issues) -# CT_LINUX_V_5_3 is not set -CT_LINUX_V_5_2=y - -# Don't chmod the CT_PREFIX_DIR read-only after the install. -# CT_PREFIX_DIR_RO is not set From 50f35f4df291990e8826d111be807f8d272be1cd Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Wed, 16 Jul 2025 13:42:23 +0100 Subject: [PATCH 03/15] Remove gcc-rv32imc config We were no longer building this. --- lowrisc-toolchain-gcc-rv32imc.config | 63 ---------------------------- 1 file changed, 63 deletions(-) delete mode 100644 lowrisc-toolchain-gcc-rv32imc.config diff --git a/lowrisc-toolchain-gcc-rv32imc.config b/lowrisc-toolchain-gcc-rv32imc.config deleted file mode 100644 index 366d4d5..0000000 --- a/lowrisc-toolchain-gcc-rv32imc.config +++ /dev/null @@ -1,63 +0,0 @@ -CT_CONFIG_VERSION="3" -CT_EXPERIMENTAL=y - -CT_ARCH_RISCV=y - -# CT_ARCH_ARCH controls the specific architecture that the toolchain's libraries -# are built with. It should specify the minimum RISC-V extensions that need to -# be implemented by any processor that this toolchain will compile programs for. -# -CT_ARCH_ARCH="rv32imc" - -# CT_ARCH_ABI controls the specific ABI that the toolchain's libraries are built -# with. All programs built against this toolchain should follow exactly this -# ABI. -CT_ARCH_ABI="ilp32" - -CT_TARGET_VENDOR="" -CT_TOOLCHAIN_BUGURL="toolchains@lowrisc.org" - -CT_DOWNLOAD_AGENT_CURL=y - -CT_CC_GCC_STATIC_LIBSTDCXX=y -# CT_CC_GCC_LDBL_128 is not set -CT_CC_LANG_CXX=y -CT_GCC_V_9=y -CT_DEBUG_GDB=y -CT_GDB_V_11_1=y -# CT_GDB_CROSS_PYTHON is not set -CT_PATCH_ORDER="bundled,local" -CT_PATCH_BUNDLED_LOCAL=y -CT_PATCH_USE_LOCAL=y - -# Disable progress bar for CI builds, it generates too much log output -# CT_LOG_PROGRESS_BAR is not set - -# Installation prefix directory; the toolchain will end up in exactly -# this directory. -CT_PREFIX_DIR="/tools/riscv" - -# Don't save tarballs for re-use (needs writable and pre-created -# CT_LOCAL_TARBALLS_DIR otherwise) -# CT_SAVE_TARBALLS is not set - -# Don't chmod the CT_PREFIX_DIR read-only after the install. -# CT_PREFIX_DIR_RO is not set - -# Binutils 2.35 (tag binutils-2_35, commit 2cb5c79dad3) -CT_BINUTILS_SRC_DEVEL=y -CT_BINUTILS_DEVEL_VCS_git=y -CT_BINUTILS_DEVEL_URL="https://github.com/bminor/binutils-gdb.git" -CT_BINUTILS_DEVEL_REVISION="2cb5c79dad39dd438fb0f7372ac04cf5aa2a7db7" - -# GCC 10.2.0 (tag releases/gcc-10.2.0, commit ee5c3db6c5b) -CT_GCC_SRC_DEVEL=y -CT_GCC_DEVEL_VCS_git=y -CT_GCC_DEVEL_URL="https://gcc.gnu.org/git/gcc.git" -CT_GCC_DEVEL_REVISION="ee5c3db6c5b2c3332912fb4c9cfa2864569ebd9a" - -# This is a baremetal target so don't use syscalls. -CT_LIBC_NEWLIB_DISABLE_SUPPLIED_SYSCALLS=y - -# The build script appends a definition of CT_LOCAL_PATCH_DIR down here, that -# points to the repo's patch directory. From e77ee422a22b93bc019f1065f469287f83c07ba7 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Thu, 17 Jul 2025 15:02:44 +0100 Subject: [PATCH 04/15] Move tarballing step out of GCC/Clang build scripts The output directory is reused in CI so that the Clang tarball includes the GCC and Binutils parts of the toolchain. It doesn't make sense to me to prepare the tarballs inside the build scripts when they bleed into each other. This commit changes CI to prepare a single tarball including GCC, Clang, and Binutils. --- .github/workflows/toolchain_build.yml | 8 +++++++- build-clang-with-args.sh | 12 ------------ build-gcc-with-args.sh | 10 ---------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index 74745ac..c674240 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -95,6 +95,13 @@ jobs: "${{ matrix.mcmodel }}" \ "${{ matrix.cflags }}" + - name: Package toolchains + run: | + ./create-prefixed-archive.sh \ + "lowrisc-toolchain-${{ matrix.name }}-${HOST_ARCH}-${RELEASE_TAG}" \ + "${{ matrix.output_dir }}" \ + "${ARTIFACT_STAGING_DIR}" + - uses: actions/upload-artifact@v4 with: name: ${{ matrix.name }}-${{ matrix.host_arch }}-toolchains @@ -120,4 +127,3 @@ jobs: # Upload this job's artifacts. gh release upload "$RELEASE_TAG" --clobber \ "${ARTIFACT_STAGING_DIR}/lowrisc-toolchain-${{ matrix.name }}-${HOST_ARCH}-${RELEASE_TAG}.tar.xz" \ - "${ARTIFACT_STAGING_DIR}/lowrisc-toolchain-gcc-${{ matrix.name }}-${HOST_ARCH}-${RELEASE_TAG}.tar.xz" diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index 916a1dc..4f688f2 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -49,8 +49,6 @@ build_top_dir="${PWD}" source "${build_top_dir}/sw-versions.sh" tag_name="${RELEASE_TAG:-HEAD}" -host_arch="${HOST_ARCH:-x86_64}" -toolchain_full_name="${toolchain_name}-${host_arch}-${tag_name}" mkdir -p "${build_top_dir}/build" cd "${build_top_dir}/build" @@ -187,13 +185,3 @@ tee "${toolchain_dest}/buildinfo.json" < Date: Thu, 17 Jul 2025 14:14:52 +0100 Subject: [PATCH 05/15] Build binutils without crosstool-ng --- .github/workflows/toolchain_build.yml | 6 ++ build-binutils.sh | 72 +++++++++++++++++++ lowrisc-toolchain-gcc-rv32imcb.config | 8 --- lowrisc-toolchain-gcc-rv64imac.config | 6 -- .../001-bitmanip.patch | 0 .../001-glob-libc-config.patch | 10 +-- .../gdb/11.1/001-glob-libc-config.patch | 25 ------- .../gdb/11.1/001-glob-libc-config.patch | 25 ------- sw-versions.sh | 5 ++ 9 files changed, 88 insertions(+), 69 deletions(-) create mode 100755 build-binutils.sh rename patches/{lowrisc-toolchain-gcc-rv32imcb/binutils/git-7c9dd840 => binutils}/001-bitmanip.patch (100%) rename patches/{lowrisc-toolchain-gcc-rv32imc/gdb/11.1 => binutils}/001-glob-libc-config.patch (70%) delete mode 100644 patches/lowrisc-toolchain-gcc-rv32imcb/gdb/11.1/001-glob-libc-config.patch delete mode 100644 patches/lowrisc-toolchain-gcc-rv64imac/gdb/11.1/001-glob-libc-config.patch diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index c674240..494b0b4 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -73,6 +73,12 @@ jobs: echo Creating artifact staging directory... mkdir "$ARTIFACT_STAGING_DIR" + - name: Build Binutils + run: | + ./build-binutils.sh \ + "${{ matrix.target }}" \ + "${{ matrix.output_dir }}" + - name: Build GCC toolchain run: | ./build-gcc-with-args.sh \ diff --git a/build-binutils.sh b/build-binutils.sh new file mode 100755 index 0000000..160156d --- /dev/null +++ b/build-binutils.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# Copyright lowRISC contributors. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 + +## build-binutils.sh +# +# Builds: +# - GNU Binutils, GDB +# +# Then: +# - Creates a tar file of the whole install directory + +set -e -o pipefail + +repo_dir="$(git rev-parse --show-toplevel)" +build_dir="${repo_dir}/build" +patch_dir="${repo_dir}/patches" + +source "${repo_dir}/sw-versions.sh" + +if [ "$#" -ne 2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + echo "USAGE: $0 " >&2 + echo >&2 + echo "EXAMPLE:" >&2 + echo " $0 riscv32 dist/" >&2 + exit 1 +fi + +target="$1" + +# Double check the arch part of the target tuple. +target_arch="${target/%-*}" +if [ "$target_arch" != "riscv32" ] && [ "$target_arch" != "riscv64" ]; then + echo "Error: unsupported target '${target}'" >&2 + echo >&2 + echo "Supported arches are: riscv32, riscv64" >&2 + exit 1 +fi + +set -x + +dist_dir="$(realpath "$2")" +mkdir -p "$dist_dir" + +mkdir -p "$build_dir" +cd "$build_dir" + +if [ ! -d binutils ]; then + git clone "$BINUTILS_URL" binutils \ + --branch "$BINUTILS_BRANCH" \ + --depth 1 +fi + +cd binutils +git reset --hard +git checkout "$BINUTILS_COMMIT" +git apply "${patch_dir}/binutils/"* + +mkdir -p build +cd build + +# NOTE: We don't want to require `libexpat` to be dynamically linked. +# It turns out to be quite hard to statically link *only* `libexpat`. +../configure \ + --target "$target" \ + --program-prefix="$target-" \ + --prefix "$dist_dir" \ + --with-expat=no + +make -j "$(nproc)" +make install diff --git a/lowrisc-toolchain-gcc-rv32imcb.config b/lowrisc-toolchain-gcc-rv32imcb.config index e164625..4b062f2 100644 --- a/lowrisc-toolchain-gcc-rv32imcb.config +++ b/lowrisc-toolchain-gcc-rv32imcb.config @@ -58,14 +58,6 @@ CT_PREFIX_DIR="/tools/riscv" # Don't chmod the CT_PREFIX_DIR read-only after the install. # CT_PREFIX_DIR_RO is not set -# Binutils 2.35, RISC-V bitmanip fork (branch riscv-binutils-2.35-rvb, -# commit 7c9dd840fb from 2021-03-10). -# A bitmanip 1.0+0.93 patch will be applied on top. -CT_BINUTILS_SRC_DEVEL=y -CT_BINUTILS_DEVEL_VCS_git=y -CT_BINUTILS_DEVEL_URL="https://github.com/riscv-collab/riscv-binutils-gdb.git" -CT_BINUTILS_DEVEL_REVISION="7c9dd840fbb6a1171a51feb08afb859288615137" - # GCC 10.2.0, RISC-V bitmanip fork (branch riscv-gcc-10.2.0-rvb, # commit 73055647d33 from 2021-07-09) CT_GCC_SRC_DEVEL=y diff --git a/lowrisc-toolchain-gcc-rv64imac.config b/lowrisc-toolchain-gcc-rv64imac.config index 792b250..4860b01 100644 --- a/lowrisc-toolchain-gcc-rv64imac.config +++ b/lowrisc-toolchain-gcc-rv64imac.config @@ -46,12 +46,6 @@ CT_PREFIX_DIR="/tools/riscv" # Don't chmod the CT_PREFIX_DIR read-only after the install. # CT_PREFIX_DIR_RO is not set -# Binutils 2.35 (tag binutils-2_35, commit 2cb5c79dad3) -CT_BINUTILS_SRC_DEVEL=y -CT_BINUTILS_DEVEL_VCS_git=y -CT_BINUTILS_DEVEL_URL="https://github.com/bminor/binutils-gdb.git" -CT_BINUTILS_DEVEL_REVISION="2cb5c79dad39dd438fb0f7372ac04cf5aa2a7db7" - # GCC 10.2.0 (tag releases/gcc-10.2.0, commit ee5c3db6c5b) CT_GCC_SRC_DEVEL=y CT_GCC_DEVEL_VCS_git=y diff --git a/patches/lowrisc-toolchain-gcc-rv32imcb/binutils/git-7c9dd840/001-bitmanip.patch b/patches/binutils/001-bitmanip.patch similarity index 100% rename from patches/lowrisc-toolchain-gcc-rv32imcb/binutils/git-7c9dd840/001-bitmanip.patch rename to patches/binutils/001-bitmanip.patch diff --git a/patches/lowrisc-toolchain-gcc-rv32imc/gdb/11.1/001-glob-libc-config.patch b/patches/binutils/001-glob-libc-config.patch similarity index 70% rename from patches/lowrisc-toolchain-gcc-rv32imc/gdb/11.1/001-glob-libc-config.patch rename to patches/binutils/001-glob-libc-config.patch index 77a75ed..be3bedd 100644 --- a/patches/lowrisc-toolchain-gcc-rv32imc/gdb/11.1/001-glob-libc-config.patch +++ b/patches/binutils/001-glob-libc-config.patch @@ -1,5 +1,5 @@ diff --git a/gnulib/import/glob.c b/gnulib/import/glob.c -index 1bfcafb..9947f24 100644 +index f1b20d4869..b10bea1d9f 100644 --- a/gnulib/import/glob.c +++ b/gnulib/import/glob.c @@ -21,7 +21,7 @@ @@ -12,13 +12,13 @@ index 1bfcafb..9947f24 100644 #endif diff --git a/gnulib/import/libc-config.h b/gnulib/import/libc-config.h -index e3571ee..44c3d0f 100644 +index 124f1d77e0..f1e9f59c81 100644 --- a/gnulib/import/libc-config.h +++ b/gnulib/import/libc-config.h -@@ -189,3 +189,7 @@ +@@ -181,3 +181,7 @@ + /* A substitute for glibc , good enough for Gnulib. */ #define SHLIB_COMPAT(lib, introduced, obsoleted) 0 - #define compat_symbol(lib, local, symbol, version) extern int dummy - #define versioned_symbol(lib, local, symbol, version) extern int dummy + #define versioned_symbol(lib, local, symbol, version) + +#ifndef __THROWNL +#define __THROWNL __THROW diff --git a/patches/lowrisc-toolchain-gcc-rv32imcb/gdb/11.1/001-glob-libc-config.patch b/patches/lowrisc-toolchain-gcc-rv32imcb/gdb/11.1/001-glob-libc-config.patch deleted file mode 100644 index 77a75ed..0000000 --- a/patches/lowrisc-toolchain-gcc-rv32imcb/gdb/11.1/001-glob-libc-config.patch +++ /dev/null @@ -1,25 +0,0 @@ -diff --git a/gnulib/import/glob.c b/gnulib/import/glob.c -index 1bfcafb..9947f24 100644 ---- a/gnulib/import/glob.c -+++ b/gnulib/import/glob.c -@@ -21,7 +21,7 @@ - optimizes away the pattern == NULL test below. */ - # define _GL_ARG_NONNULL(params) - --# include -+# include - - #endif - -diff --git a/gnulib/import/libc-config.h b/gnulib/import/libc-config.h -index e3571ee..44c3d0f 100644 ---- a/gnulib/import/libc-config.h -+++ b/gnulib/import/libc-config.h -@@ -189,3 +189,7 @@ - #define SHLIB_COMPAT(lib, introduced, obsoleted) 0 - #define compat_symbol(lib, local, symbol, version) extern int dummy - #define versioned_symbol(lib, local, symbol, version) extern int dummy -+ -+#ifndef __THROWNL -+#define __THROWNL __THROW -+#endif diff --git a/patches/lowrisc-toolchain-gcc-rv64imac/gdb/11.1/001-glob-libc-config.patch b/patches/lowrisc-toolchain-gcc-rv64imac/gdb/11.1/001-glob-libc-config.patch deleted file mode 100644 index 77a75ed..0000000 --- a/patches/lowrisc-toolchain-gcc-rv64imac/gdb/11.1/001-glob-libc-config.patch +++ /dev/null @@ -1,25 +0,0 @@ -diff --git a/gnulib/import/glob.c b/gnulib/import/glob.c -index 1bfcafb..9947f24 100644 ---- a/gnulib/import/glob.c -+++ b/gnulib/import/glob.c -@@ -21,7 +21,7 @@ - optimizes away the pattern == NULL test below. */ - # define _GL_ARG_NONNULL(params) - --# include -+# include - - #endif - -diff --git a/gnulib/import/libc-config.h b/gnulib/import/libc-config.h -index e3571ee..44c3d0f 100644 ---- a/gnulib/import/libc-config.h -+++ b/gnulib/import/libc-config.h -@@ -189,3 +189,7 @@ - #define SHLIB_COMPAT(lib, introduced, obsoleted) 0 - #define compat_symbol(lib, local, symbol, version) extern int dummy - #define versioned_symbol(lib, local, symbol, version) extern int dummy -+ -+#ifndef __THROWNL -+#define __THROWNL __THROW -+#endif diff --git a/sw-versions.sh b/sw-versions.sh index ca2623c..859b1bd 100644 --- a/sw-versions.sh +++ b/sw-versions.sh @@ -17,3 +17,8 @@ export QEMU_VERSION=23967e5b2a6c6d04b8db766a8a149f3631a7b899 export LLVM_URL=https://github.com/lowRISC/llvm-project.git export LLVM_BRANCH=ot-llvm-16-hardening export LLVM_VERSION=dec908d48facb6041c12b95b8ade64719a894917 + +# RISC-V fork of Binutils 2.35 with bitmanip instruction support +export BINUTILS_URL=https://github.com/riscv-collab/riscv-binutils-gdb.git +export BINUTILS_BRANCH=riscv-binutils-2.35-rvb +export BINUTILS_COMMIT=7c9dd840fbb6a1171a51feb08afb859288615137 From fa52ffdbad1454c34a456cf63b71413fdcd6dbaf Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Thu, 17 Jul 2025 15:48:29 +0100 Subject: [PATCH 06/15] Remove GCC support --- .github/workflows/toolchain_build.yml | 15 +-- README.md | 4 +- build-clang-with-args.sh | 11 +- build-gcc-with-args.sh | 143 -------------------------- check-tarball.sh | 2 +- generate-gcc-cmake-toolchain.sh | 89 ---------------- lowrisc-toolchain-gcc-rv32imcb.config | 72 ------------- lowrisc-toolchain-gcc-rv64imac.config | 56 ---------- 8 files changed, 6 insertions(+), 386 deletions(-) delete mode 100755 build-gcc-with-args.sh delete mode 100755 generate-gcc-cmake-toolchain.sh delete mode 100644 lowrisc-toolchain-gcc-rv32imcb.config delete mode 100644 lowrisc-toolchain-gcc-rv64imac.config diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index 494b0b4..529a73f 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -25,14 +25,14 @@ jobs: - os: ubuntu-24.04-arm host_arch: aarch64 - name: rv32imcb - display_name: Toolchains targeting Ibex with bit-manipulation extensions + display_name: RV32IMCB toolchains (Ibex) target: riscv32-unknown-elf output_dir: /tools/riscv march: rv32imc_zba_zbb_zbc_zbs mabi: ilp32 mcmodel: medany - name: rv64imac - display_name: GCC and Clang/LLVM toolchains targeting RV64IMAC (Muntjac) + display_name: RV64IMAC toolchains (Muntjac) target: riscv64-unknown-elf output_dir: /tools/riscv march: rv64imac @@ -79,17 +79,6 @@ jobs: "${{ matrix.target }}" \ "${{ matrix.output_dir }}" - - name: Build GCC toolchain - run: | - ./build-gcc-with-args.sh \ - "lowrisc-toolchain-gcc-${{ matrix.name }}" \ - "${{ matrix.target }}" \ - "${{ matrix.output_dir }}" \ - "${{ matrix.march }}" \ - "${{ matrix.mabi}}" \ - "${{ matrix.mcmodel }}" \ - "${{ matrix.cflags }}" - - name: Build Clang toolchain run: | ./build-clang-with-args.sh \ diff --git a/README.md b/README.md index 99db5f6..64567a6 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Head over to the [GitHub releases for this repository](https://github.com/lowRISC/lowrisc-toolchains/releases) for pre-built toolchains. -* A GCC RV32IMC without hardfloat support, targeting [Ibex](https://github.com/lowRISC/ibex/) -* A GCC RV64IMAC, targeting [Muntjac](https://github.com/lowRISC/muntjac) +* Clang RV32IMCB without hardfloat support, targeting [Ibex](https://github.com/lowRISC/ibex/) +* Clang RV64IMAC, targeting [Muntjac](https://github.com/lowRISC/muntjac) How to do a release ------------------- diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index 4f688f2..ff2314c 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -5,8 +5,6 @@ ## build-clang-with-args.sh # -# This requires a gcc toolchain dir made by `build-gcc-with-args.sh` -# # Builds: # - Clang/LLVM # @@ -26,10 +24,8 @@ fi; ## Take configuration from arguments # This is the name for the tar file. -# Suggested to be the gcc config with s/gcc/clang/. Will be updated if it -# contains 'gcc' toolchain_name="${1}" -# This is the expected gcc target triple (so we can set a default, and invoke gcc) +# This is the expected target triple (so we can set a default) toolchain_target="${2}" # This is the directory where we want the toolchain to added to toolchain_dest="${3}" @@ -142,7 +138,6 @@ ls -l "${toolchain_dest}" set +o pipefail # head causes pipe failures, so we have to switch off pipefail while we use it. ct_ng_version_string="$( (set +o pipefail; ct-ng version | head -n1) )" clang_version_string="$("${toolchain_dest}/bin/clang" --version | head -n1)" -gcc_version_string="$("${toolchain_dest}/bin/${toolchain_target}-gcc" --version | head -n1)" build_date="$(date -u)" set -o pipefail @@ -156,9 +151,6 @@ Clang version: ${clang_version_string} (git: ${LLVM_URL} ${LLVM_VERSION}) -GCC version: - ${gcc_version_string} - Crosstool-ng version: ${ct_ng_version_string} (git: ${CROSSTOOL_NG_URL} ${CROSSTOOL_NG_VERSION}) @@ -177,7 +169,6 @@ tee "${toolchain_dest}/buildinfo.json" < " - exit 2 -fi; - -## Take configuration from arguments -# This is the name for the tar file, and also the basename of the .config file -toolchain_name="${1}" -# This is the expected gcc target triple (so we can invoke gcc) -toolchain_target="${2}" -# This is the directory where we want the toolchain to be installed. -toolchain_dest="${3}" -# -march option default value -march="${4}" -# -mabi option default value -mabi="${5}" -# -mcmodel option default value -mcmodel="${6}" -# Remaining cflags for build configurations -toolchain_cflags=("${@:7}") - -build_top_dir="${PWD}" - -# For *_VERSION variables -# shellcheck source=sw-versions.sh -source "${build_top_dir}/sw-versions.sh" - -tag_name="${RELEASE_TAG:-HEAD}" -host_arch="${HOST_ARCH:-x86_64}" -toolchain_full_name="${toolchain_name}-${host_arch}-${tag_name}" - -# crosstools-NG needs the ability to create and chmod the -# $toolchain_dest directory. -sudo mkdir -p "$(dirname "${toolchain_dest}")" -sudo chmod 777 "$(dirname "${toolchain_dest}")" - -mkdir -p "${toolchain_dest}" - -mkdir -p "${build_top_dir}/build/gcc" -cd "${build_top_dir}/build/gcc" - -# Create crosstool-ng config file with correct `CT_PREFIX_DIR` and `CT_LOCAL_PATCH_DIR` -{ - grep -v '^CT_PREFIX_DIR=' "${build_top_dir}/${toolchain_name}.config" - echo "" - echo "# ADDED BY ${0}"; - echo "CT_PREFIX_DIR=\"${toolchain_dest}\"" - echo "CT_LOCAL_PATCH_DIR=\"${build_top_dir}/patches/${toolchain_name}\"" - echo "CT_ALLOW_BUILD_AS_ROOT=y" - echo "CT_ALLOW_BUILD_AS_ROOT_SURE=y" - echo "# END ADDED BY ${0}" -} > .config -ct-ng upgradeconfig -cat .config - -# crosstool-ng doesn't work with some environment variables set, leading to -# errors like "Don't set LD_LIBRARY_PATH. It screws up the build." otherwise. -# Do so in a subshell to avoid disturbing subsequent tasks. -( - unset LD_LIBRARY_PATH - unset LIBRARY_PATH - unset LPATH - unset CPATH - unset C_INCLUDE_PATH - unset CPLUS_INCLUDE_PATH - unset OBJC_INCLUDE_PATH - unset CFLAGS - unset CXXFLAGS - unset CC - unset CXX - unset GREP_OPTIONS - - # Invoke crosstool-ng - ct-ng build -) - -cd "${build_top_dir}" - -## Create Toolchain Files! -# These don't yet add cflags ldflags -"${build_top_dir}/generate-gcc-cmake-toolchain.sh" \ - "${toolchain_target}" "${toolchain_dest}" "${toolchain_cflags[@]}" - -ls -l "${toolchain_dest}" - -# Write out build info -set +o pipefail # head causes pipe failures, so we have to switch off pipefail while we use it. -ct_ng_version_string="$(ct-ng version | head -n1)" -gcc_version_string="$("${toolchain_dest}/bin/${toolchain_target}-gcc" --version | head -n1)" -build_date="$(date -u)" -set -o pipefail - -tee "${toolchain_dest}/buildinfo" < " - exit 2 -fi; - -## Take configuration from arguments -# This is the gcc target triple -toolchain_target="${1}" -# This is the directory where the toolchain has been installed. -toolchain_dest="${2}" -# Remaining cflags for build configurations -toolchain_cflags=("${@:3}") - -cmake_cflags="" -for flag in "${toolchain_cflags[@]}"; do - if [ -z "${cmake_cflags}" ]; then - cmake_cflags+="${flag}"; - else - cmake_cflags+=";${flag}" - fi -done - -config_dest="${toolchain_dest}/${toolchain_target}-gcc.cmake" -sysroot_config="" -system_name="" - -case "${toolchain_target}" in - riscv*-*-linux-gnu) - system_name="Linux" - sysroot_config="set(CMAKE_SYSROOT \"\${LOWRISC_TOOLCHAIN}/${toolchain_target}/sysroot\" CACHE STRING \"\" FORCE)"; - ;; - riscv*-*-elf) - system_name="Generic" - ;; -esac; - -tee "${config_dest}" < Date: Thu, 17 Jul 2025 16:06:15 +0100 Subject: [PATCH 07/15] Remove mentions of crosstool-ng --- .github/workflows/toolchain_build.yml | 4 ---- README.md | 12 +++--------- build-clang-with-args.sh | 3 --- install-crosstool-ng.sh | 23 ----------------------- sw-versions.sh | 4 ---- 5 files changed, 3 insertions(+), 43 deletions(-) delete mode 100755 install-crosstool-ng.sh diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index 529a73f..42bcf14 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -54,10 +54,6 @@ jobs: ./prepare-host.sh echo ::endgroup:: - echo ::group::Install crosstool-ng - ./install-crosstool-ng.sh - echo ::endgroup:: - echo Preparing toolchain destination directory... sudo mkdir -p /tools/riscv sudo chmod 0777 /tools/riscv diff --git a/README.md b/README.md index 64567a6..7470eda 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,7 @@ for pre-built toolchains. How to do a release ------------------- -1. Modify any of the following variables to configure the build: - - `CROSSTOOL_NG_VERSION` in `install-crosstool-ng.sh` - -2. Modify any of the `*.config` files to update the crosstool-ng configurations - for a particular toolchain. - -3. Push the changes or do a pull request, and wait for the CI workflow to +1. Push the changes or do a pull request, and wait for the CI workflow to complete. The build can be tested by downloading the GitHub artifacts. @@ -29,14 +23,14 @@ How to do a release 2. Select a workflow run from the list. 4. Download the desired artifact from the bottom of the page and test it. -4. Tag a release +2. Tag a release ```bash VERSION=$(date +%Y%m%d)-1 git tag -a -m "Release version $VERSION" $VERSION ``` -5. Push the tag +3. Push the tag ```bash git push origin $VERSION diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index ff2314c..3b36ebe 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -169,9 +169,6 @@ tee "${toolchain_dest}/buildinfo.json" < Date: Thu, 17 Jul 2025 16:18:02 +0100 Subject: [PATCH 08/15] Fix Git unsafe directory warning --- .github/workflows/toolchain_build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index 42bcf14..7dcb429 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -69,6 +69,9 @@ jobs: echo Creating artifact staging directory... mkdir "$ARTIFACT_STAGING_DIR" + # Git warns about this repo having dubious ownership - ignore. + git config --global --add safe.directory "$(pwd)" + - name: Build Binutils run: | ./build-binutils.sh \ @@ -110,9 +113,6 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - # Git warns about this repo having dubious ownership - ignore. - git config --global --add safe.directory /__w/lowrisc-toolchains/lowrisc-toolchains - # Create the release if it doesn't already exist. gh release create "$RELEASE_TAG" --prerelease || echo "release exists" # Upload this job's artifacts. From dc297b845243b8877d4171933c167fe4d5e73ed6 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Mon, 21 Jul 2025 11:03:28 +0100 Subject: [PATCH 09/15] Shallow-clone LLVM --- build-clang-with-args.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index 3b36ebe..6631365 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -51,8 +51,10 @@ cd "${build_top_dir}/build" llvm_dir="${build_top_dir}/build/llvm-project" -if [ ! -d "${llvm_dir}" ]; then - git clone --branch ${LLVM_BRANCH} ${LLVM_URL} "${llvm_dir}" +if [ ! -d "$llvm_dir" ]; then + git clone "$LLVM_URL" "$llvm_dir" \ + --branch "$LLVM_BRANCH" \ + --depth 1 fi cd "${llvm_dir}" git fetch origin From 321a2dbb0f074763aa4a139c1bc12b3dc3d6f1e8 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Tue, 22 Jul 2025 11:15:08 +0100 Subject: [PATCH 10/15] Allow Clang build type to be configured --- .github/workflows/toolchain_build.yml | 1 + build-clang-with-args.sh | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index 7dcb429..2b01d4a 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -82,6 +82,7 @@ jobs: run: | ./build-clang-with-args.sh \ "lowrisc-toolchain-${{ matrix.name }}" \ + Release \ "${{ matrix.target }}" \ "${{ matrix.output_dir }}" \ "${{ matrix.march }}" \ diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index 6631365..df59c70 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -25,18 +25,20 @@ fi; ## Take configuration from arguments # This is the name for the tar file. toolchain_name="${1}" +# This is the CMake build type (e.g. Release, Debug, RelWithDebInfo) +build_type="${2}" # This is the expected target triple (so we can set a default) -toolchain_target="${2}" +toolchain_target="${3}" # This is the directory where we want the toolchain to added to -toolchain_dest="${3}" +toolchain_dest="${4}" # -march option default value -march="${4}" +march="${5}" # -mabi option default value -mabi="${5}" +mabi="${6}" # -mcmodel option default value -mcmodel="${6}" +mcmodel="${7}" # Remaining cflags for build configurations -toolchain_cflags=("${@:7}") +toolchain_cflags=("${@:8}") build_top_dir="${PWD}" @@ -106,7 +108,7 @@ llvm_distribution_components+=";${llvm_tools}" cmake "${llvm_dir}/llvm" \ -Wno-dev \ - -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_TYPE="${build_type}" \ -DCMAKE_INSTALL_PREFIX="${toolchain_dest}" \ -DLLVM_TARGETS_TO_BUILD="RISCV" \ -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \ From a289c6037562667ebcf9ad688d4dadde914db058 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Thu, 24 Jul 2025 17:29:16 +0100 Subject: [PATCH 11/15] Pin build and dist directories --- .github/workflows/toolchain_build.yml | 8 +---- build-binutils.sh | 16 +++++----- build-clang-with-args.sh | 43 +++++++++++++-------------- create-prefixed-archive.sh | 19 +++++++----- 4 files changed, 41 insertions(+), 45 deletions(-) diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index 2b01d4a..9e1f247 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -27,14 +27,12 @@ jobs: - name: rv32imcb display_name: RV32IMCB toolchains (Ibex) target: riscv32-unknown-elf - output_dir: /tools/riscv march: rv32imc_zba_zbb_zbc_zbs mabi: ilp32 mcmodel: medany - name: rv64imac display_name: RV64IMAC toolchains (Muntjac) target: riscv64-unknown-elf - output_dir: /tools/riscv march: rv64imac mabi: lp64 mcmodel: medany @@ -74,9 +72,7 @@ jobs: - name: Build Binutils run: | - ./build-binutils.sh \ - "${{ matrix.target }}" \ - "${{ matrix.output_dir }}" + ./build-binutils.sh "${{ matrix.target }}" - name: Build Clang toolchain run: | @@ -84,7 +80,6 @@ jobs: "lowrisc-toolchain-${{ matrix.name }}" \ Release \ "${{ matrix.target }}" \ - "${{ matrix.output_dir }}" \ "${{ matrix.march }}" \ "${{ matrix.mabi}}" \ "${{ matrix.mcmodel }}" \ @@ -94,7 +89,6 @@ jobs: run: | ./create-prefixed-archive.sh \ "lowrisc-toolchain-${{ matrix.name }}-${HOST_ARCH}-${RELEASE_TAG}" \ - "${{ matrix.output_dir }}" \ "${ARTIFACT_STAGING_DIR}" - uses: actions/upload-artifact@v4 diff --git a/build-binutils.sh b/build-binutils.sh index 160156d..1fb4090 100755 --- a/build-binutils.sh +++ b/build-binutils.sh @@ -16,14 +16,15 @@ set -e -o pipefail repo_dir="$(git rev-parse --show-toplevel)" build_dir="${repo_dir}/build" patch_dir="${repo_dir}/patches" +dist_dir="${build_dir}/dist" source "${repo_dir}/sw-versions.sh" -if [ "$#" -ne 2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then - echo "USAGE: $0 " >&2 - echo >&2 - echo "EXAMPLE:" >&2 - echo " $0 riscv32 dist/" >&2 +if [ "$#" -ne 1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + echo "USAGE: $0 " >&2 + echo >&2 + echo "EXAMPLE:" >&2 + echo " $0 riscv32" >&2 exit 1 fi @@ -40,9 +41,6 @@ fi set -x -dist_dir="$(realpath "$2")" -mkdir -p "$dist_dir" - mkdir -p "$build_dir" cd "$build_dir" @@ -60,6 +58,8 @@ git apply "${patch_dir}/binutils/"* mkdir -p build cd build +mkdir -p "$dist_dir" + # NOTE: We don't want to require `libexpat` to be dynamically linked. # It turns out to be quite hard to statically link *only* `libexpat`. ../configure \ diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index df59c70..fb73f73 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -22,6 +22,10 @@ if ! [ "$#" -ge 3 ]; then exit 2 fi; +repo_dir="$(git rev-parse --show-toplevel)" +build_dir="${repo_dir}/build" +dist_dir="${build_dir}/dist" + ## Take configuration from arguments # This is the name for the tar file. toolchain_name="${1}" @@ -29,30 +33,25 @@ toolchain_name="${1}" build_type="${2}" # This is the expected target triple (so we can set a default) toolchain_target="${3}" -# This is the directory where we want the toolchain to added to -toolchain_dest="${4}" # -march option default value -march="${5}" +march="${4}" # -mabi option default value -mabi="${6}" +mabi="${5}" # -mcmodel option default value -mcmodel="${7}" +mcmodel="${6}" # Remaining cflags for build configurations -toolchain_cflags=("${@:8}") - -build_top_dir="${PWD}" +toolchain_cflags=("${@:7}") # For *_VERSION variables # shellcheck source=sw-versions.sh -source "${build_top_dir}/sw-versions.sh" +source "${repo_dir}/sw-versions.sh" tag_name="${RELEASE_TAG:-HEAD}" -mkdir -p "${build_top_dir}/build" -cd "${build_top_dir}/build" - +mkdir -p "$build_dir" +cd "$build_dir" -llvm_dir="${build_top_dir}/build/llvm-project" +llvm_dir="${build_dir}/llvm-project" if [ ! -d "$llvm_dir" ]; then git clone "$LLVM_URL" "$llvm_dir" \ --branch "$LLVM_BRANCH" \ @@ -69,7 +68,7 @@ clang_links_to_create+=";${toolchain_target}-clang;${toolchain_target}-clang++" lld_links_to_create="ld.lld;ld64.lld" lld_links_to_create+=";${toolchain_target}-ld.lld;${toolchain_target}-ld64.lld" -llvm_build_dir="${build_top_dir}/build/llvm-build" +llvm_build_dir="${build_dir}/llvm-project/build" # Delete old build artifacts (if they exist) rm -rf "${llvm_build_dir}" @@ -109,7 +108,7 @@ llvm_distribution_components+=";${llvm_tools}" cmake "${llvm_dir}/llvm" \ -Wno-dev \ -DCMAKE_BUILD_TYPE="${build_type}" \ - -DCMAKE_INSTALL_PREFIX="${toolchain_dest}" \ + -DCMAKE_INSTALL_PREFIX="${dist_dir}" \ -DLLVM_TARGETS_TO_BUILD="RISCV" \ -DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \ -DLLVM_ENABLE_BACKTRACES=Off \ @@ -130,22 +129,22 @@ cmake --build "${llvm_build_dir}" \ --parallel $(( $(nproc) + 2 )) \ --target install-distribution -cd "${build_top_dir}" +cd "${repo_dir}" # Copy LLVM licenses into toolchain -mkdir -p "${toolchain_dest}/share/licenses/llvm" -cp "${llvm_dir}/llvm/LICENSE.TXT" "${toolchain_dest}/share/licenses/llvm" +mkdir -p "${dist_dir}/share/licenses/llvm" +cp "${llvm_dir}/llvm/LICENSE.TXT" "${dist_dir}/share/licenses/llvm" -ls -l "${toolchain_dest}" +ls -l "${dist_dir}" # Write out build info set +o pipefail # head causes pipe failures, so we have to switch off pipefail while we use it. ct_ng_version_string="$( (set +o pipefail; ct-ng version | head -n1) )" -clang_version_string="$("${toolchain_dest}/bin/clang" --version | head -n1)" +clang_version_string="$("${dist_dir}/bin/clang" --version | head -n1)" build_date="$(date -u)" set -o pipefail -tee "${toolchain_dest}/buildinfo" < " +if ! [ "$#" = 2 ]; then + echo "Usage: $0 " exit 2 fi; +repo_dir="$(git rev-parse --show-toplevel)" +build_dir="${repo_dir}/build" +dist_dir="${build_dir}/dist" + # These arguments are provided by `./build-*-with-args.sh` toolchain_full_name="$1" -toolchain_dest="$2" -artifact_dir="${3:-.}" +artifact_dir="${2:-.}" tar -cJ \ --show-transformed-names --verbose \ - --directory="$(dirname "${toolchain_dest}")" \ - -f "${artifact_dir}/$toolchain_full_name.tar.xz" \ - --transform="flags=rhS;s@^$(basename "${toolchain_dest}")@$toolchain_full_name@" \ + --directory="$(dirname "$dist_dir")" \ + -f "${artifact_dir}/${toolchain_full_name}.tar.xz" \ + --transform="flags=rhS;s@^$(basename "$dist_dir")@${toolchain_full_name}@" \ --owner=0 --group=0 \ - "$(basename "${toolchain_dest}")" + "$(basename "$dist_dir")" From 9ce9e16e43f3e0e41eaea064272ce7057d2b2f2e Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Mon, 4 Aug 2025 11:42:13 +0100 Subject: [PATCH 12/15] Remove unused QEMU_VERSION --- sw-versions.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/sw-versions.sh b/sw-versions.sh index 272e376..ff67711 100644 --- a/sw-versions.sh +++ b/sw-versions.sh @@ -2,9 +2,6 @@ # This documents the versions of any software checked out from git -# v4.0.1 -export QEMU_VERSION=23967e5b2a6c6d04b8db766a8a149f3631a7b899 - # LLVM 16.0.2 plus: # - hardening patches # - unratified bitmanip extensions From bdc1a05f57dc6803326cc829b163b79c6e2126b2 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Mon, 4 Aug 2025 11:42:29 +0100 Subject: [PATCH 13/15] Add script for end-to-end Ibex toolchain build --- contrib/build-opentitan-dist.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 contrib/build-opentitan-dist.sh diff --git a/contrib/build-opentitan-dist.sh b/contrib/build-opentitan-dist.sh new file mode 100755 index 0000000..046f38d --- /dev/null +++ b/contrib/build-opentitan-dist.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +set -ex + +./build-binutils.sh "riscv32-unknown-elf" + +./build-clang-with-args.sh \ + "lowrisc-toolchain-rv32imcb" \ + "Release" \ + "riscv32-unknown-elf" \ + "rv32imc_zba_zbb_zbc_zbs" \ + "ilp32" \ + "medany" + +./create-prefixed-archive.sh \ + "lowrisc-toolchain-rv32imcb" \ + "build/" From 4c138ec9141d2e068f72321e294d0577d9e230e1 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Wed, 13 Aug 2025 16:32:12 +0100 Subject: [PATCH 14/15] Change Clang args to be named Signed-off-by: James Wainwright --- .github/workflows/toolchain_build.yml | 12 ++--- build-clang-with-args.sh | 68 ++++++++++++++++++--------- contrib/build-opentitan-dist.sh | 12 ++--- 3 files changed, 57 insertions(+), 35 deletions(-) diff --git a/.github/workflows/toolchain_build.yml b/.github/workflows/toolchain_build.yml index 9e1f247..8bcf743 100644 --- a/.github/workflows/toolchain_build.yml +++ b/.github/workflows/toolchain_build.yml @@ -77,13 +77,11 @@ jobs: - name: Build Clang toolchain run: | ./build-clang-with-args.sh \ - "lowrisc-toolchain-${{ matrix.name }}" \ - Release \ - "${{ matrix.target }}" \ - "${{ matrix.march }}" \ - "${{ matrix.mabi}}" \ - "${{ matrix.mcmodel }}" \ - "${{ matrix.cflags }}" + --name "lowrisc-toolchain-${{ matrix.name }}" \ + --target "${{ matrix.target }}" \ + --march "${{ matrix.march }}" \ + --mabi "${{ matrix.mabi}}" \ + --mcmodel "${{ matrix.mcmodel }}" - name: Package toolchains run: | diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index fb73f73..2662007 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -14,33 +14,57 @@ # - Creates a tar file of the whole install directory set -e -set -x set -o pipefail -if ! [ "$#" -ge 3 ]; then - echo "Usage: $0 " - exit 2 -fi; - repo_dir="$(git rev-parse --show-toplevel)" build_dir="${repo_dir}/build" dist_dir="${build_dir}/dist" -## Take configuration from arguments -# This is the name for the tar file. -toolchain_name="${1}" -# This is the CMake build type (e.g. Release, Debug, RelWithDebInfo) -build_type="${2}" -# This is the expected target triple (so we can set a default) -toolchain_target="${3}" -# -march option default value -march="${4}" -# -mabi option default value -mabi="${5}" -# -mcmodel option default value -mcmodel="${6}" -# Remaining cflags for build configurations -toolchain_cflags=("${@:7}") +usage="\ +USAGE: ${0} [options] + +OPTIONS: + -h,--help Print this message + --debug Build with assertions and debug info + +ARGS: + --name Name of the toolchain + --target Default target triple + --march Default -march + --mabi Default -mabi + --mcmodel Default -mcmodel +" +options="$(getopt -a -o '-h' -l 'help,name:,target:,march:,mabi:,mcmodel:,debug' -- "$@")" + +err() { + echo "ERROR ${1}" >&2 + echo >&2 + echo "$usage" >&2 + exit 2 +} +[[ "$options" == *"--name"* ]] || err 'Missing argument `--name`' +[[ "$options" == *"--target"* ]] || err 'Missing argument `--target`' +[[ "$options" == *"--march"* ]] || err 'Missing argument `--march`' +[[ "$options" == *"--mabi"* ]] || err 'Missing argument `--mabi`' +[[ "$options" == *"--mcmodel"* ]] || err 'Missing argument `--mcmodel`' + +build_type=Release + +eval set -- "$options" +while true; do + case "$1" in + -h,--help) echo "$usage" && exit 0;; + --name) toolchain_name="$2"; shift 2;; + --target) toolchain_target="$2"; shift 2;; + --march) march="$2"; shift 2;; + --mabi) mabi="$2"; shift 2;; + --mcmodel) mcmodel="$2"; shift 2;; + --debug) build_type=Debug; shift 1;; + --) shift; break;; + esac +done + +set -x # For *_VERSION variables # shellcheck source=sw-versions.sh @@ -159,7 +183,7 @@ Crosstool-ng version: (git: ${CROSSTOOL_NG_URL} ${CROSSTOOL_NG_VERSION}) C Flags: - -march=${march} -mabi=${mabi} -mcmodel=${mcmodel} ${toolchain_cflags[@]} + -march=${march} -mabi=${mabi} -mcmodel=${mcmodel} Built at ${build_date} on $(hostname) BUILDINFO diff --git a/contrib/build-opentitan-dist.sh b/contrib/build-opentitan-dist.sh index 046f38d..ccbd387 100755 --- a/contrib/build-opentitan-dist.sh +++ b/contrib/build-opentitan-dist.sh @@ -5,12 +5,12 @@ set -ex ./build-binutils.sh "riscv32-unknown-elf" ./build-clang-with-args.sh \ - "lowrisc-toolchain-rv32imcb" \ - "Release" \ - "riscv32-unknown-elf" \ - "rv32imc_zba_zbb_zbc_zbs" \ - "ilp32" \ - "medany" + --name "lowrisc-toolchain-rv32imcb" \ + --target "riscv32-unknown-elf" \ + --march "rv32imc_zba_zbb_zbc_zbs" \ + --mabi "ilp32" \ + --mcmodel "medany" \ + "$@" ./create-prefixed-archive.sh \ "lowrisc-toolchain-rv32imcb" \ From aa7bb80b869189e02cc9323347aae63af628dbd2 Mon Sep 17 00:00:00 2001 From: James Wainwright Date: Wed, 13 Aug 2025 16:36:54 +0100 Subject: [PATCH 15/15] Add `--clean` option to clang script --- build-clang-with-args.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build-clang-with-args.sh b/build-clang-with-args.sh index 2662007..e3abfba 100755 --- a/build-clang-with-args.sh +++ b/build-clang-with-args.sh @@ -26,6 +26,7 @@ USAGE: ${0} [options] OPTIONS: -h,--help Print this message --debug Build with assertions and debug info + --clean Build from scratch ARGS: --name Name of the toolchain @@ -34,7 +35,7 @@ ARGS: --mabi Default -mabi --mcmodel Default -mcmodel " -options="$(getopt -a -o '-h' -l 'help,name:,target:,march:,mabi:,mcmodel:,debug' -- "$@")" +options="$(getopt -a -o '-h' -l 'help,name:,target:,march:,mabi:,mcmodel:,debug,clean' -- "$@")" err() { echo "ERROR ${1}" >&2 @@ -49,6 +50,7 @@ err() { [[ "$options" == *"--mcmodel"* ]] || err 'Missing argument `--mcmodel`' build_type=Release +clean=false eval set -- "$options" while true; do @@ -60,6 +62,7 @@ while true; do --mabi) mabi="$2"; shift 2;; --mcmodel) mcmodel="$2"; shift 2;; --debug) build_type=Debug; shift 1;; + --clean) clean=true; shift 1;; --) shift; break;; esac done @@ -94,8 +97,9 @@ lld_links_to_create+=";${toolchain_target}-ld.lld;${toolchain_target}-ld64.lld" llvm_build_dir="${build_dir}/llvm-project/build" -# Delete old build artifacts (if they exist) -rm -rf "${llvm_build_dir}" +if [[ "$clean" == true ]]; then + rm -rf "${llvm_build_dir}" +fi mkdir -p "${llvm_build_dir}" cd "${llvm_build_dir}"