diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f522758..952d88e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,15 +22,12 @@ jobs: path: | /tmp/x86_64-linux-gnu.tar.xz /tmp/x86_64-linux-gnu.tar.xz.sha256 - - name: Install Ninja - if: ${{ steps.check-cache.outputs.cache-hit != 'true' }} - run: | - sudo apt-get install --assume-yes 'ninja-build' - name: Build Atar 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=- 'atar' | xz --threads='0' --compress -9 > "${tarball_filename}" diff --git a/build.sh b/build.sh index 7dced1a..7e96a9d 100644 --- a/build.sh +++ b/build.sh @@ -61,29 +61,10 @@ function setup_gcc_source() { patch --directory="${gcc_directory}" --strip='0' --input="${name}" done - touch "${gcc_directory}/libversions" - - sed -ri 's/strlcpy\s\((.+),\s(.+),\s.+\)/strcpy(\1, \2)/g' "${gcc_directory}/gcc/targhooks.c" "${gcc_directory}/libiberty/cp-demangle.c" - - echo "LIBestdc++_LTVERSION = -version-info 20:0" >> "${gcc_directory}/libversions" - echo "LIBgfortran_LTVERSION = -version-info 9:0" >> "${gcc_directory}/libversions" - echo "LIBobjc_LTVERSION = -version-info 9:0" >> "${gcc_directory}/libversions" - echo "LIBlto_plugin_LTVERSION = -version-info 6:0" >> "${gcc_directory}/libversions" - echo "LIBitm_LTVERSION = -version-info 5:0" >> "${gcc_directory}/libversions" - echo "LIBatomic_LTVERSION = -version-info 4:0" >> "${gcc_directory}/libversions" - echo "LIBquadmath_LTVERSION = -version-info 4:0" >> "${gcc_directory}/libversions" - echo "LIBcc1_LTVERSION = -version-info 2:0" >> "${gcc_directory}/libversions" - echo "LIBcc1plugin_LTVERSION = -version-info 2:0" >> "${gcc_directory}/libversions" - echo "LIBcp1plugin_LTVERSION = -version-info 1:0" >> "${gcc_directory}/libversions" - echo "LIBgphobos_LTVERSION = -version-info 0:0" >> "${gcc_directory}/libversions" - echo "LIBgdruntime_LTVERSION = -version-info 0:0" >> "${gcc_directory}/libversions" - - sed -i 's/gsed/sed/g' $gcc_directory/libgcc/config/t-hardfp + patch --directory="${gcc_directory}" --strip='0' --input="${workdir}/patches/0001-Thats-not-openbsd.patch" + patch --directory="${gcc_directory}" --strip='0' --input="${workdir}/patches/0001-Add-libversions.patch" elif (( gcc_version >= 14 )); then - - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87231 - sed -i 's/USER_H/# USER_H/g' "${gcc_directory}/gcc/config/t-openbsd" - + patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/patches/0001-Fix-libatomic-build-with-newer-GCC-versions.patch" patch --directory="${gcc_directory}" --strip='1' --input="${workdir}/patches/0001-Disable-libfunc-support-for-hppa-unknown-openbsd.patch" fi @@ -113,10 +94,14 @@ declare OBGGCC_TOOLCHAIN='/tmp/obggcc-toolchain' declare CROSS_COMPILE_TRIPLET='' declare cross_compile_flags='' +declare cmake_cross_compile_flags='' + + if ! (( is_native )); then source "./submodules/obggcc/toolchains/${build_type}.sh" cross_compile_flags+="--host=${CROSS_COMPILE_TRIPLET}" + cmake_cross_compile_flags+="-DCMAKE_TOOLCHAIN_FILE=$(realpath "./submodules/obggcc/toolchains/${build_type}.cmake")" fi if ! [ -f "${gmp_tarball}" ]; then @@ -211,18 +196,18 @@ cmake \ -DCMAKE_CXX_FLAGS='-static-libgcc -static-libstdc++ -Wl,-s' \ -DLLVM_ENABLE_PROJECTS='lld' \ -DCMAKE_INSTALL_PREFIX="${toolchain_directory}" \ + ${cmake_cross_compile_flags} \ "${llvm_directory}/llvm" -# cmake --build ./ --target lld -- -j $((max_jobs / 2)) -# make install -# cmake --install ./ +cmake --build ./ -- -j $((max_jobs / 2)) +cmake --install ./ sed -i 's/#include /#include \n#include /g' "${toolchain_directory}/include/mpc.h" [ -d "${binutils_directory}/build" ] || mkdir "${binutils_directory}/build" declare -r targets=( - # 'amd64' + 'amd64' 'armv7' 'riscv64' 'arm64' @@ -300,9 +285,10 @@ for target in "${targets[@]}"; do cd "${toolchain_directory}/bin" + ln --symbolic './ld.lld' "./${triplet}-ld.lld" + if (( require_lld )); then - # ln --symbolic './ld.lld' "./${triplet}-ld" - ln --symbolic '/usr/bin/ld.lld-15' "./${triplet}-ld" + ln --symbolic './ld.lld' "./${triplet}-ld" fi tar --directory="${toolchain_directory}/${triplet}" --strip=2 --extract --file='/tmp/base.tgz' './usr/lib' './usr/include' @@ -346,6 +332,7 @@ for target in "${targets[@]}"; do extra_configure_flags+='--disable-libatomic ' fi + # The compiler for powerpc64 breaks if compiled with -Os if [ "${target}" == 'powerpc64' ]; then optflags='-O2' else @@ -396,9 +383,12 @@ for target in "${targets[@]}"; do CXXFLAGS="${optflags}" \ LDFLAGS="-Wl,-rpath-link,${OBGGCC_TOOLCHAIN}/${CROSS_COMPILE_TRIPLET}/lib ${linkflags}" + declare CFLAGS_FOR_TARGET="${optflags} ${linkflags}" + declare CXXFLAGS_FOR_TARGET="${optflags} ${linkflags} -nostdinc++" + LD_LIBRARY_PATH="${toolchain_directory}/lib" PATH="${PATH}:${toolchain_directory}/bin" make \ - CFLAGS_FOR_TARGET="${optflags} ${linkflags}" \ - CXXFLAGS_FOR_TARGET="${optflags} ${linkflags} -fpermissive -nostdinc++" \ + CFLAGS_FOR_TARGET="${CFLAGS_FOR_TARGET}" \ + CXXFLAGS_FOR_TARGET="${CXXFLAGS_FOR_TARGET}" \ all --jobs="${max_jobs}" make install diff --git a/patches/0001-Add-libversions.patch b/patches/0001-Add-libversions.patch new file mode 100644 index 0000000..bf1117f --- /dev/null +++ b/patches/0001-Add-libversions.patch @@ -0,0 +1,32 @@ +From 4e35f3b7621f6ff22f1f2b76d4a95ff32fc401b3 Mon Sep 17 00:00:00 2001 +From: Kartatz <105828205+Kartatz@users.noreply.github.com> +Date: Fri, 17 May 2024 16:43:54 +0200 +Subject: [PATCH] Add libversions + +This is dynamically generated by the Makefile in OpenBSD ports, but since we are not using it, let's define those values manually +--- + libversions | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + create mode 100644 libversions + +diff --git a/libversions b/libversions +new file mode 100644 +index 0000000..f3e875d +--- /dev/null ++++ b/libversions +@@ -0,0 +1,12 @@ ++LIBestdc++_LTVERSION = -version-info 20:0 ++LIBgfortran_LTVERSION = -version-info 9:0 ++LIBobjc_LTVERSION = -version-info 9:0 ++LIBlto_plugin_LTVERSION = -version-info 6:0 ++LIBitm_LTVERSION = -version-info 5:0 ++LIBatomic_LTVERSION = -version-info 4:0 ++LIBquadmath_LTVERSION = -version-info 4:0 ++LIBcc1_LTVERSION = -version-info 2:0 ++LIBcc1plugin_LTVERSION = -version-info 2:0 ++LIBcp1plugin_LTVERSION = -version-info 1:0 ++LIBgphobos_LTVERSION = -version-info 0:0 ++LIBgdruntime_LTVERSION = -version-info 0:0 +-- +2.36.6 + diff --git a/patches/0001-Fix-libatomic-build-with-newer-GCC-versions.patch b/patches/0001-Fix-libatomic-build-with-newer-GCC-versions.patch new file mode 100644 index 0000000..083a940 --- /dev/null +++ b/patches/0001-Fix-libatomic-build-with-newer-GCC-versions.patch @@ -0,0 +1,24 @@ +From 294e57ba5a44bd5c9553033aa61b5f00613b25d9 Mon Sep 17 00:00:00 2001 +From: Kartatz <105828205+Kartatz@users.noreply.github.com> +Date: Fri, 17 May 2024 16:57:52 +0200 +Subject: [PATCH] Fix libatomic build with newer GCC versions + +This is required due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87231 +--- + gcc/config/t-openbsd | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/gcc/config/t-openbsd b/gcc/config/t-openbsd +index 3b625d6..3123d34 100644 +--- a/gcc/config/t-openbsd ++++ b/gcc/config/t-openbsd +@@ -1,5 +1,5 @@ + # We don't need GCC's own include files. +-USER_H = $(EXTRA_HEADERS) ++# USER_H = $(EXTRA_HEADERS) + + # OpenBSD-specific D support. + openbsd-d.o: $(srcdir)/config/openbsd-d.cc +-- +2.36.6 + diff --git a/patches/0001-Thats-not-openbsd.patch b/patches/0001-Thats-not-openbsd.patch new file mode 100644 index 0000000..3f316c1 --- /dev/null +++ b/patches/0001-Thats-not-openbsd.patch @@ -0,0 +1,70 @@ +From 9676b6bc275b9914db045d9258790c788aa4c7b1 Mon Sep 17 00:00:00 2001 +From: Kartatz <105828205+Kartatz@users.noreply.github.com> +Date: Fri, 17 May 2024 16:35:36 +0200 +Subject: [PATCH] That's not OpenBSD + +--- + gcc/targhooks.c | 4 ++-- + libgcc/config/t-hardfp | 6 +++--- + libiberty/cp-demangle.c | 2 +- + 3 files changed, 6 insertions(+), 6 deletions(-) + +diff --git a/gcc/targhooks.c b/gcc/targhooks.c +index 947b88e..6ce2036 100644 +--- a/gcc/targhooks.c ++++ b/gcc/targhooks.c +@@ -900,9 +900,9 @@ default_external_stack_protect_fail (void) + + name = (char *)xmalloc(32); + if (NULL == (tmp_name = fname_as_string (0))) { +- strlcpy (name, "*unknown*", 32); ++ strcpy (name, "*unknown*"); + } else { +- strlcpy (name, tmp_name, 32); ++ strcpy (name, tmp_name); + } + + length = strlen (name); +diff --git a/libgcc/config/t-hardfp b/libgcc/config/t-hardfp +index 2df7088..85140be 100644 +--- a/libgcc/config/t-hardfp ++++ b/libgcc/config/t-hardfp +@@ -60,11 +60,11 @@ hardfp_func_list += $(foreach pair, $(hardfp_truncations), \ + hardfp_func_list := $(filter-out $(hardfp_exclusions),$(hardfp_func_list)) + + # Regexp for matching a floating-point mode. +-hardfp_mode_regexp := $(shell echo $(hardfp_float_modes) | gsed 's/ /\\|/g') ++hardfp_mode_regexp := $(shell echo $(hardfp_float_modes) | sed 's/ /\\|/g') + + # Regexp for matching the end of a function name, after the last + # floating-point mode. +-hardfp_suffix_regexp := $(shell echo $(hardfp_int_modes) 2 3 | gsed 's/ /\\|/g') ++hardfp_suffix_regexp := $(shell echo $(hardfp_int_modes) 2 3 | sed 's/ /\\|/g') + + # Add -D options to define: + # FUNC: the function name (e.g. __addsf3) +@@ -73,7 +73,7 @@ hardfp_suffix_regexp := $(shell echo $(hardfp_int_modes) 2 3 | gsed 's/ /\\|/g') + # TYPE: the last floating-point mode (e.g. sf) + hardfp_defines_for = \ + $(shell echo $1 | \ +- gsed 's/\(.*\)\($(hardfp_mode_regexp)\)\($(hardfp_suffix_regexp)\|\)$$/-DFUNC=__& -DOP_\1\3 -DTYPE=\2/') ++ sed 's/\(.*\)\($(hardfp_mode_regexp)\)\($(hardfp_suffix_regexp)\|\)$$/-DFUNC=__& -DOP_\1\3 -DTYPE=\2/') + + hardfp-o = $(patsubst %,%$(objext),$(hardfp_func_list)) + $(hardfp-o): %$(objext): $(srcdir)/config/hardfp.c +diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c +index e21e7b5..2f7e3a3 100644 +--- a/libiberty/cp-demangle.c ++++ b/libiberty/cp-demangle.c +@@ -6619,7 +6619,7 @@ __cxa_demangle (const char *mangled_name, char *output_buffer, + { + if (strlen (demangled) < *length) + { +- strlcpy (output_buffer, demangled, *length); ++ strcpy (output_buffer, demangled); + free (demangled); + demangled = output_buffer; + } +-- +2.36.6 + diff --git a/patches/0001-x.patch b/patches/0001-x.patch deleted file mode 100644 index 9d329d7..0000000 --- a/patches/0001-x.patch +++ /dev/null @@ -1,25 +0,0 @@ -From 8775ee179fb3ca98b618c19cbd0cc7b80f369745 Mon Sep 17 00:00:00 2001 -From: Your Name -Date: Wed, 15 May 2024 20:40:13 +0200 -Subject: [PATCH] x - ---- - libssp/ssp.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/libssp/ssp.c b/libssp/ssp.c -index 5ce2d09..a3300f6 100644 ---- a/libssp/ssp.c -+++ b/libssp/ssp.c -@@ -35,6 +35,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see - #include "config.h" - #ifdef HAVE_ALLOCA_H - # include -+#else -+# include - #endif - #ifdef HAVE_MALLOC_H - # include --- -2.36.6 -