Skip to content

Commit

Permalink
Update to GCC 14.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartatz committed May 9, 2024
1 parent c8d6470 commit 9d43490
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 24 deletions.
34 changes: 29 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,42 @@ 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
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
if-no-files-found: error
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
path: |
/tmp/x86_64-linux-gnu.tar.xz
/tmp/x86_64-linux-gnu.tar.xz.sha256
cross-build:
name: 'Cross build'
Expand Down Expand Up @@ -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
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: |
Expand All @@ -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
Expand Down
97 changes: 78 additions & 19 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

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 -r gcc_directory='/tmp/gcc-14.1.0'

declare -r optflags='-Os'
declare -r linkflags='-Wl,-s'

declare -r max_jobs="$(($(nproc) * 8))"
declare -r max_jobs="$(($(nproc) * 10))"

declare build_type="${1}"

Expand All @@ -49,12 +49,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

Expand All @@ -64,13 +64,18 @@ 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"
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}"
wget --no-verbose 'https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.xz' --output-document="${gcc_tarball}"
tar --directory="$(dirname "${gcc_directory}")" --extract --file="${gcc_tarball}"

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

[ -d "${gcc_directory}/build" ] || mkdir "${gcc_directory}/build"
Expand Down Expand Up @@ -135,20 +140,20 @@ sed -i 's/#include <stdint.h>/#include <stdint.h>\n#include <stdio.h>/g' "${tool
[ -d "${binutils_directory}/build" ] || mkdir "${binutils_directory}/build"

declare -r targets=(
'hpcsh'
'vax'
'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://web.archive.org/web/0if_/https://archive.netbsd.org/pub/NetBSD-archive/NetBSD-8.0/${target}/binary/sets"

case "${target}" in
amd64)
Expand Down Expand Up @@ -179,8 +184,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 ./*
Expand All @@ -199,13 +223,22 @@ 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")"

cd "${gcc_directory}/build"

rm --force --recursive ./*
Expand Down Expand Up @@ -236,7 +269,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 \
Expand Down Expand Up @@ -287,4 +320,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
25 changes: 25 additions & 0 deletions patches/0001-Disable-libfunc-support-for-hppa-unknown-netbsd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 615edd6d30f1e43107b639d13661be148e197471 Mon Sep 17 00:00:00 2001
From: Kartatz <[email protected]>
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

69 changes: 69 additions & 0 deletions patches/0001-Fix-issues-with-fenv.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
From 7b9532197fcca48b4b931c70166882aabe765975 Mon Sep 17 00:00:00 2001
From: Kartatz <[email protected]>
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 <bits/c++config.h>
-#if _GLIBCXX_HAVE_FENV_H
+#if !defined(__vax__) && _GLIBCXX_HAVE_FENV_H
# include_next <fenv.h>
#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 <bits/c++config.h>

-#if _GLIBCXX_HAVE_FENV_H
+#if !defined(__vax__) && _GLIBCXX_HAVE_FENV_H
# include <fenv.h>
#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

Loading

0 comments on commit 9d43490

Please sign in to comment.