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 13, 2024
1 parent c8d6470 commit a4eafda
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 32 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-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
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-2
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-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: |
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
148 changes: 121 additions & 27 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand All @@ -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

Expand All @@ -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"
Expand Down Expand Up @@ -135,20 +173,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'
'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)
Expand Down Expand Up @@ -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 ./*
Expand All @@ -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 ./*
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From d3254de82bf38235c4e714440a93454f91cd71d8 Mon Sep 17 00:00:00 2001
From: Kartatz <[email protected]>
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

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

Loading

0 comments on commit a4eafda

Please sign in to comment.