diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5d42d2..02d4ee0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,15 +13,27 @@ jobs: - uses: actions/checkout@main with: submodules: true + - name: Check for cache + id: check-cache + uses: actions/cache@main + with: + key: gcc-14.1.0-2 + lookup-only: true + path: | + /tmp/x86_64-linux-gnu.tar.xz + /tmp/x86_64-linux-gnu.tar.xz.sha256 - name: Build Dakini + if: ${{ steps.check-cache.outputs.cache-hit != 'true' }} run: | bash './build.sh' 'native' - name: Generate tarball + if: ${{ steps.check-cache.outputs.cache-hit != 'true' }} run: | declare tarball_filename='/tmp/x86_64-linux-gnu.tar.xz' tar --directory='/tmp' --create --file=- 'dakini' | xz --threads='0' --compress -9 > "${tarball_filename}" sha256sum "${tarball_filename}" | sed 's|/tmp/||' > "${tarball_filename}.sha256" - name: Upload artifact + if: ${{ steps.check-cache.outputs.cache-hit != 'true' }} uses: actions/upload-artifact@main with: name: native-toolchain @@ -29,6 +41,14 @@ jobs: path: | /tmp/x86_64-linux-gnu.tar.xz /tmp/x86_64-linux-gnu.tar.xz.sha256 + - name: Cache artifact + if: ${{ steps.check-cache.outputs.cache-hit != 'true' }} + uses: actions/cache@main + with: + key: gcc-14.1.0-2 + path: | + /tmp/x86_64-linux-gnu.tar.xz + /tmp/x86_64-linux-gnu.tar.xz.sha256 cross-build: name: 'Cross build' @@ -56,13 +76,17 @@ jobs: - uses: actions/checkout@main with: submodules: true - - name: Download artifact - uses: actions/download-artifact@main + - name: Restore from cache + uses: actions/cache@main with: - name: native-toolchain + key: gcc-14.1.0-2 + fail-on-cache-miss: true + path: | + /tmp/x86_64-linux-gnu.tar.xz + /tmp/x86_64-linux-gnu.tar.xz.sha256 - name: Setup toolchain run: | - tar --directory='/tmp' --extract --file='./x86_64-linux-gnu.tar.xz' + tar --directory='/tmp' --extract --file='/tmp/x86_64-linux-gnu.tar.xz' mv '/tmp/dakini' '/tmp/dakini-toolchain' - name: Build Dakini with OBGGCC run: | @@ -78,7 +102,7 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@main with: - name: cross-toolchain + name: ${{ matrix.target }} if-no-files-found: error path: | /tmp/${{ matrix.target }}.tar.xz diff --git a/build.sh b/build.sh index d5ce080..379672a 100644 --- a/build.sh +++ b/build.sh @@ -2,29 +2,71 @@ set -eu -declare -r revision="$(git rev-parse --short HEAD)" +declare -r workdir="${PWD}" -declare -r toolchain_tarball="${PWD}/netbsd-cross.tar.xz" +declare -r revision="$(git rev-parse --short HEAD)" declare -r gmp_tarball='/tmp/gmp.tar.xz' -declare -r gmp_directory='/tmp/gmp-6.2.1' +declare -r gmp_directory='/tmp/gmp-6.3.0' declare -r mpfr_tarball='/tmp/mpfr.tar.xz' -declare -r mpfr_directory='/tmp/mpfr-4.2.0' +declare -r mpfr_directory='/tmp/mpfr-4.2.1' declare -r mpc_tarball='/tmp/mpc.tar.gz' declare -r mpc_directory='/tmp/mpc-1.3.1' declare -r binutils_tarball='/tmp/binutils.tar.xz' -declare -r binutils_directory='/tmp/binutils-2.41' +declare -r binutils_directory='/tmp/binutils-2.42' -declare -r gcc_tarball='/tmp/gcc.tar.xz' -declare -r gcc_directory='/tmp/gcc-12.3.0' +declare gcc_directory='' + +function setup_gcc_source() { + + local gcc_version='' + local gcc_url='' + local gcc_tarball='' + local tgt="${1}" + + declare -r tgt + + if [ "${tgt}" = 'hpcsh' ] || [ "${tgt}" = 'emips' ]; then + gcc_version='12' + gcc_directory='/tmp/gcc-12.3.0' + gcc_url='https://ftp.gnu.org/gnu/gcc/gcc-12.3.0/gcc-12.3.0.tar.xz' + else + gcc_version='14' + gcc_directory='/tmp/gcc-14.1.0' + gcc_url='https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.xz' + fi + + gcc_tarball="/tmp/gcc-${gcc_version}.tar.xz" + + declare -r gcc_version + declare -r gcc_url + declare -r gcc_tarball + + if ! [ -f "${gcc_tarball}" ]; then + wget --no-verbose "${gcc_url}" --output-document="${gcc_tarball}" + tar --directory="$(dirname "${gcc_directory}")" --extract --file="${gcc_tarball}" + fi + + [ -d "${gcc_directory}/build" ] || mkdir "${gcc_directory}/build" + + if ! [ -f "${gcc_directory}/patched" ]; then + if (( gcc_version >= 14 )); then + patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/patches/0001-Disable-libfunc-support-for-hppa-unknown-netbsd.patch" + patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/patches/0001-Fix-issues-with-fenv.patch" + fi + + touch "${gcc_directory}/patched" + fi + +} declare -r optflags='-Os' declare -r linkflags='-Wl,-s' -declare -r max_jobs="$(($(nproc) * 8))" +declare -r max_jobs="$(($(nproc) * 17))" declare build_type="${1}" @@ -49,12 +91,12 @@ if ! (( is_native )); then fi if ! [ -f "${gmp_tarball}" ]; then - wget --no-verbose 'https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz' --output-document="${gmp_tarball}" + wget --no-verbose 'https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz' --output-document="${gmp_tarball}" tar --directory="$(dirname "${gmp_directory}")" --extract --file="${gmp_tarball}" fi if ! [ -f "${mpfr_tarball}" ]; then - wget --no-verbose 'https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.0.tar.xz' --output-document="${mpfr_tarball}" + wget --no-verbose 'https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz' --output-document="${mpfr_tarball}" tar --directory="$(dirname "${mpfr_directory}")" --extract --file="${mpfr_tarball}" fi @@ -64,17 +106,13 @@ if ! [ -f "${mpc_tarball}" ]; then fi if ! [ -f "${binutils_tarball}" ]; then - wget --no-verbose 'https://ftp.gnu.org/gnu/binutils/binutils-2.41.tar.xz' --output-document="${binutils_tarball}" + wget --no-verbose 'https://ftp.gnu.org/gnu/binutils/binutils-2.42.tar.xz' --output-document="${binutils_tarball}" tar --directory="$(dirname "${binutils_directory}")" --extract --file="${binutils_tarball}" + + patch --directory="${binutils_directory}" --strip='1' --input="${workdir}/patches/0001-Revert-gold-Use-char16_t-char32_t-instead-of-uint16_.patch" + patch --directory="${binutils_directory}" --strip='1' --input="${workdir}/patches/0001-Disable-annoying-local-symbol-warning-on-bfd-linker.patch" fi -if ! [ -f "${gcc_tarball}" ]; then - wget --no-verbose 'https://ftp.gnu.org/gnu/gcc/gcc-12.3.0/gcc-12.3.0.tar.xz' --output-document="${gcc_tarball}" - tar --directory="$(dirname "${gcc_directory}")" --extract --file="${gcc_tarball}" -fi - -[ -d "${gcc_directory}/build" ] || mkdir "${gcc_directory}/build" - declare -r toolchain_directory="/tmp/dakini" [ -d "${gmp_directory}/build" ] || mkdir "${gmp_directory}/build" @@ -135,20 +173,20 @@ sed -i 's/#include /#include \n#include /g' "${tool [ -d "${binutils_directory}/build" ] || mkdir "${binutils_directory}/build" declare -r targets=( + 'hpcsh' + 'vax' + 'emips' + 'evbppc' 'hppa' 'amd64' 'i386' - 'emips' 'alpha' 'sparc' 'sparc64' - 'vax' - 'hpcsh' - 'evbppc' ) for target in "${targets[@]}"; do - declare url="https://cdn.netbsd.org/pub/NetBSD/NetBSD-8.0/${target}/binary/sets" + declare url="https://archive.netbsd.org/pub/NetBSD-archive/NetBSD-8.0/${target}/binary/sets" case "${target}" in amd64) @@ -179,8 +217,27 @@ for target in "${targets[@]}"; do declare base_output="/tmp/$(basename "${base_url}")" declare comp_output="/tmp/$(basename "${comp_url}")" - wget --no-verbose "${base_url}" --output-document="${base_output}" - wget --no-verbose "${comp_url}" --output-document="${comp_output}" + curl \ + --url "${base_url}" \ + --retry '30' \ + --retry-all-errors \ + --retry-delay '0' \ + --retry-max-time '0' \ + --location \ + --verbose \ + --silent \ + --output "${base_output}" + + curl \ + --url "${comp_url}" \ + --retry '30' \ + --retry-all-errors \ + --retry-delay '0' \ + --retry-max-time '0' \ + --location \ + --verbose \ + --silent \ + --output "${comp_output}" cd "${binutils_directory}/build" rm --force --recursive ./* @@ -199,13 +256,24 @@ for target in "${targets[@]}"; do CXXFLAGS="${optflags}" \ LDFLAGS="${linkflags}" - make all --jobs="${max_jobs}" + make all --jobs make install tar --directory="${toolchain_directory}/${triplet}" --strip=2 --extract --file="${base_output}" './usr/lib' './usr/include' tar --directory="${toolchain_directory}/${triplet}" --extract --file="${base_output}" './lib' tar --directory="${toolchain_directory}/${triplet}" --strip=2 --extract --file="${comp_output}" './usr/lib' './usr/include' + # Update permissions + while read name; do + if [ -f "${name}" ]; then + chmod 644 "${name}" + elif [ -d "${name}" ]; then + chmod 755 "${name}" + fi + done <<< "$(find "${toolchain_directory}/${triplet}/include" "${toolchain_directory}/${triplet}/lib")" + + setup_gcc_source "${target}" + cd "${gcc_directory}/build" rm --force --recursive ./* @@ -236,7 +304,7 @@ for target in "${targets[@]}"; do --with-mpfr="${toolchain_directory}" \ --with-bugurl='https://github.com/AmanoTeam/Dakini/issues' \ --with-gcc-major-version-only \ - --with-pkgversion="Dakini v0.4-${revision}" \ + --with-pkgversion="Dakini v0.5-${revision}" \ --with-sysroot="${toolchain_directory}/${triplet}" \ --with-native-system-header-dir='/include' \ --enable-__cxa_atexit \ @@ -287,4 +355,30 @@ for target in "${targets[@]}"; do patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/cc1" patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/cc1plus" patchelf --add-rpath '$ORIGIN/../../../../lib' "${toolchain_directory}/libexec/gcc/${triplet}/"*"/lto1" + + # Strip debug symbols from shared libraries + while read name; do + name="$(realpath "${name}")" + + if [[ "$(file --brief --mime-type "${name}")" != 'application/x-sharedlib' ]]; then + continue + fi + + if (( is_native )); then + "${toolchain_directory}/bin/${triplet}-strip" "${name}" + else + "${DAKINI_HOME}/bin/${triplet}-strip" "${name}" + fi + done <<< "$(find "${toolchain_directory}/${triplet}/lib" -wholename '*.so')" + + # Fix some libraries not being found during linkage + if [ "${target}" == 'hpcsh' ]; then + cd "${toolchain_directory}/${triplet}/lib" + + for name in $(ls '!m3'); do + if ! [ -f "./${name}" ]; then + ln --symbolic './!m3/'"${name}" "./${name}" + fi + done + fi done diff --git a/patches/0001-Disable-annoying-local-symbol-warning-on-bfd-linker.patch b/patches/0001-Disable-annoying-local-symbol-warning-on-bfd-linker.patch new file mode 100644 index 0000000..15ba113 --- /dev/null +++ b/patches/0001-Disable-annoying-local-symbol-warning-on-bfd-linker.patch @@ -0,0 +1,41 @@ +From d3254de82bf38235c4e714440a93454f91cd71d8 Mon Sep 17 00:00:00 2001 +From: Kartatz <105828205+Kartatz@users.noreply.github.com> +Date: Fri, 10 May 2024 05:12:10 +0200 +Subject: [PATCH] Disable annoying 'local symbol' warning on bfd linker + +--- + bfd/elflink.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/bfd/elflink.c b/bfd/elflink.c +index c2494b3..6910577 100644 +--- a/bfd/elflink.c ++++ b/bfd/elflink.c +@@ -4820,7 +4820,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) + bool common; + bool discarded; + unsigned int old_alignment; +- unsigned int shindex; ++ /* unsigned int shindex; */ + bfd *old_bfd; + bool matched; + +@@ -4852,13 +4852,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info) + /* If we aren't prepared to handle locals within the globals + then we'll likely segfault on a NULL symbol hash if the + symbol is ever referenced in relocations. */ ++ /* + shindex = elf_elfheader (abfd)->e_shstrndx; + name = bfd_elf_string_from_elf_section (abfd, shindex, hdr->sh_name); + _bfd_error_handler (_("%pB: %s local symbol at index %lu" + " (>= sh_info of %lu)"), + abfd, name, (long) (isym - isymbuf + extsymoff), + (long) extsymoff); +- ++ */ + /* Dynamic object relocations are not processed by ld, so + ld won't run into the problem mentioned above. */ + if (dynamic) +-- +2.36.6 + diff --git a/patches/0001-Disable-libfunc-support-for-hppa-unknown-netbsd.patch b/patches/0001-Disable-libfunc-support-for-hppa-unknown-netbsd.patch new file mode 100644 index 0000000..a5a970c --- /dev/null +++ b/patches/0001-Disable-libfunc-support-for-hppa-unknown-netbsd.patch @@ -0,0 +1,25 @@ +From 615edd6d30f1e43107b639d13661be148e197471 Mon Sep 17 00:00:00 2001 +From: Kartatz <105828205+Kartatz@users.noreply.github.com> +Date: Tue, 7 May 2024 23:43:09 +0200 +Subject: [PATCH] Disable libfunc support for hppa-unknown-netbsd + +For some reason, it does not work for that target. The following error is printed when attempting to link a specific object file of the libgcc: + +/tmp/ccigQ6Ux.s: Assembler messages: +/tmp/ccigQ6Ux.s:80: Error: Unknown opcode: `stws|stw %r23,-16(%sp)' +/tmp/ccigQ6Ux.s:83: Error: Invalid operands + +I do not know if this is a GCC bug or it just happens that our target does not support this feature. +--- +diff --git a/libgcc/config/pa/t-netbsd b/libgcc/config/pa/t-netbsd +index 13943940a..8b99068ce 100644 +--- a/libgcc/config/pa/t-netbsd ++++ b/libgcc/config/pa/t-netbsd +@@ -7,4 +7,3 @@ LIB1ASMFUNCS = _divI _divU _remI _remU _div_const _mulI _dyncall + HOST_LIBGCC2_CFLAGS += -DELF=1 -DLINUX=1 + + LIB2ADD = $(srcdir)/config/pa/fptr.c +-LIB2ADD_ST = $(srcdir)/config/pa/sync-libfuncs.c +-- +2.36.6 + diff --git a/patches/0001-Fix-issues-with-fenv.patch b/patches/0001-Fix-issues-with-fenv.patch new file mode 100644 index 0000000..8a0a052 --- /dev/null +++ b/patches/0001-Fix-issues-with-fenv.patch @@ -0,0 +1,69 @@ +From 7b9532197fcca48b4b931c70166882aabe765975 Mon Sep 17 00:00:00 2001 +From: Kartatz <105828205+Kartatz@users.noreply.github.com> +Date: Wed, 8 May 2024 21:43:08 +0200 +Subject: [PATCH] Fix issues with fenv + +--- +diff --git a/libstdc++-v3/include/c_compatibility/fenv.h b/libstdc++-v3/include/c_compatibility/fenv.h +index 6800814bc..f2d400991 100644 +--- a/libstdc++-v3/include/c_compatibility/fenv.h ++++ b/libstdc++-v3/include/c_compatibility/fenv.h +@@ -32,13 +32,13 @@ + #pragma GCC system_header + + #include +-#if _GLIBCXX_HAVE_FENV_H ++#if !defined(__vax__) && _GLIBCXX_HAVE_FENV_H + # include_next + #endif + + #if __cplusplus >= 201103L + +-#if _GLIBCXX_USE_C99_FENV ++#if !defined(__vax__) && _GLIBCXX_USE_C99_FENV + + #undef feclearexcept + #undef fegetexceptflag +diff --git a/libstdc++-v3/include/c_global/cfenv b/libstdc++-v3/include/c_global/cfenv +index fd32daa8d..22d97f047 100644 +--- a/libstdc++-v3/include/c_global/cfenv ++++ b/libstdc++-v3/include/c_global/cfenv +@@ -37,11 +37,11 @@ + + #include + +-#if _GLIBCXX_HAVE_FENV_H ++#if !defined(__vax__) && _GLIBCXX_HAVE_FENV_H + # include + #endif + +-#ifdef _GLIBCXX_USE_C99_FENV ++#if !defined(__vax__) && defined(_GLIBCXX_USE_C99_FENV) + + #undef feclearexcept + #undef fegetexceptflag +diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc b/libstdc++-v3/src/c++17/floating_to_chars.cc +index 2c9da977c..1b066b0c7 100644 +--- a/libstdc++-v3/src/c++17/floating_to_chars.cc ++++ b/libstdc++-v3/src/c++17/floating_to_chars.cc +@@ -1048,7 +1048,7 @@ namespace + { + int len; + +-#if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST) ++#if !defined(__sh__) && _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST) + const int saved_rounding_mode = fegetround(); + if (saved_rounding_mode != FE_TONEAREST) + fesetround(FE_TONEAREST); // We want round-to-nearest behavior. +@@ -1082,7 +1082,7 @@ namespace + #endif + len = sprintf(buffer, format_string, args..., value); + +-#if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST) ++#if !defined(__sh__) && _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST) + if (saved_rounding_mode != FE_TONEAREST) + fesetround(saved_rounding_mode); + #endif +-- +2.36.6 + diff --git a/patches/0001-Revert-gold-Use-char16_t-char32_t-instead-of-uint16_.patch b/patches/0001-Revert-gold-Use-char16_t-char32_t-instead-of-uint16_.patch new file mode 100644 index 0000000..9a850ab --- /dev/null +++ b/patches/0001-Revert-gold-Use-char16_t-char32_t-instead-of-uint16_.patch @@ -0,0 +1,77 @@ +From c5fcba3bc2b47e1061e066deac04efbbdb53362d Mon Sep 17 00:00:00 2001 +From: Kartatz <105828205+Kartatz@users.noreply.github.com> +Date: Wed, 8 May 2024 07:04:54 +0200 +Subject: [PATCH] Revert "gold: Use char16_t, char32_t instead of uint16_t, + uint32_t as character types" + +This reverts commit 5e9091dab8858b25210a91d22fbbbfdee9c969ad. +--- +diff --git a/gold/merge.cc b/gold/merge.cc +index ca15149c767..55de3013a1b 100644 +--- a/gold/merge.cc ++++ b/gold/merge.cc +@@ -665,10 +665,10 @@ template + class Output_merge_string; + + template +-class Output_merge_string; ++class Output_merge_string; + + template +-class Output_merge_string; ++class Output_merge_string; + + #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG) + template +diff --git a/gold/output.cc b/gold/output.cc +index ead67f20363..3375d322506 100644 +--- a/gold/output.cc ++++ b/gold/output.cc +@@ -29,7 +29,6 @@ + #include + #include + #include +-#include + + #ifdef HAVE_SYS_MMAN_H + #include +@@ -2707,10 +2706,10 @@ Output_section::add_merge_input_section(Relobj* object, unsigned int shndx, + pomb = new Output_merge_string(addralign); + break; + case 2: +- pomb = new Output_merge_string(addralign); ++ pomb = new Output_merge_string(addralign); + break; + case 4: +- pomb = new Output_merge_string(addralign); ++ pomb = new Output_merge_string(addralign); + break; + default: + return false; +diff --git a/gold/stringpool.cc b/gold/stringpool.cc +index d8f38cfabc1..2e4a746d1a8 100644 +--- a/gold/stringpool.cc ++++ b/gold/stringpool.cc +@@ -25,7 +25,6 @@ + #include + #include + #include +-#include + + #include "output.h" + #include "parameters.h" +@@ -528,9 +527,9 @@ template + class Stringpool_template; + + template +-class Stringpool_template; ++class Stringpool_template; + + template +-class Stringpool_template; ++class Stringpool_template; + + } // End namespace gold. +-- +2.36.6 +