galeb

Једноставна статичка дистрибуција заснована на musl-у
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 33a7b62b21422f21b4d960faa4f540aec637887c
родитељ 3a6bd8a90eaa04ee036ecd30c4d888b94d70ac7c
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sun, 26 Jun 2022 20:39:39 +0200

Add GCC

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
M01-cross.sh | 213++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mlib/env.sh | 16++++++++++++----
Mlib/fun.sh | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
Apat/gcc-alpine/0001-posix_memalign.patch | 42++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0002-gcc-poison-system-directories.patch | 203+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0003-Turn-on-Wl-z-relro-z-now-by-default.patch | 39+++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch | 46++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch | 242+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0006-Enable-Wformat-and-Wformat-security-by-default.patch | 34++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0007-Enable-Wtrampolines-by-default.patch | 25+++++++++++++++++++++++++
Apat/gcc-alpine/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch | 45+++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch | 28++++++++++++++++++++++++++++
Apat/gcc-alpine/0011-libiberty-copy-PIC-objects-during-build-process.patch | 24++++++++++++++++++++++++
Apat/gcc-alpine/0012-libitm-disable-FORTIFY.patch | 33+++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0013-libgcc_s.patch | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0014-nopie.patch | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu.patch | 25+++++++++++++++++++++++++
Apat/gcc-alpine/0016-dlang-update-zlib-binding.patch | 425+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0017-dlang-fix-fcntl-on-mips-add-libucontext-dep.patch | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0018-ada-fix-shared-linking.patch | 42++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0019-build-fix-CXXFLAGS_FOR_BUILD-passing.patch | 24++++++++++++++++++++++++
Apat/gcc-alpine/0020-add-fortify-headers-paths.patch | 25+++++++++++++++++++++++++
Apat/gcc-alpine/0021-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch | 31+++++++++++++++++++++++++++++++
Apat/gcc-alpine/0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0023-Pure-64-bit-MIPS.patch | 47+++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0024-use-pure-64-bit-configuration-where-appropriate.patch | 121+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0025-always-build-libgcc_eh.a.patch | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0026-ada-libgnarl-compatibility-for-musl.patch | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0027-ada-musl-support-fixes.patch | 223+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0028-gcc-go-Use-_off_t-type-instead-of-_loff_t.patch | 48++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0029-gcc-go-Don-t-include-sys-user.h.patch | 30++++++++++++++++++++++++++++++
Apat/gcc-alpine/0030-gcc-go-Fix-ucontext_t-on-PPC64.patch | 29+++++++++++++++++++++++++++++
Apat/gcc-alpine/0031-gcc-go-Fix-handling-of-signal-34-on-musl.patch | 43+++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch | 38++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0033-gcc-go-Fix-st_-a-m-c-tim-fields-in-generated-sysinfo.patch | 24++++++++++++++++++++++++
Apat/gcc-alpine/0034-gcc-go-signal-34-is-special-on-musl-libc.patch | 29+++++++++++++++++++++++++++++
Apat/gcc-alpine/0035-gcc-go-Prefer-_off_t-over-_off64_t.patch | 30++++++++++++++++++++++++++++++
Apat/gcc-alpine/0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c.patch | 27+++++++++++++++++++++++++++
Apat/gcc-alpine/0037-gcc-go-link-to-libucontext.patch | 25+++++++++++++++++++++++++
Apat/gcc-alpine/0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct.patch | 26++++++++++++++++++++++++++
Apat/gcc-alpine/0040-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch | 264+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0041-Use-generic-errstr.go-implementation-on-musl.patch | 48++++++++++++++++++++++++++++++++++++++++++++++++
Apat/gcc-alpine/0042-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch | 21+++++++++++++++++++++
Apat/gcc-alpine/0043-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch | 21+++++++++++++++++++++
Apat/gcc-alpine/apply_patches_ct.sh | 40++++++++++++++++++++++++++++++++++++++++
Apat/gcc-mlfs/fix_fenv_header.patch | 32++++++++++++++++++++++++++++++++
измењених датотека: 47, додавања: 3275(+), брисања: 33(-)

diff --git a/01-cross.sh b/01-cross.sh @@ -3,28 +3,217 @@ . ./lib/env.sh . ./lib/fun.sh +WD=${PWD} + +trap exit_cleanup HUP PIPE INT QUIT TERM EXIT + +mkfifo ${G_FIFO} + msg info "${white}Galeb %s${green} bootstrap" "${G_VER}" -msg info "${white}Part 1 of 3: cross-tools" +msg info "${white}[1/3]: cross-tools" check_dir ${CT} +check_dir ${G_PAT} check_dir ${G_PKG} check_dir ${G_SRC} -cd_or_fail ${CT} + +fetch_pkg https://musl.cc/x86_64-linux-musl-cross.tgz +if [ -d ${CT}/bin ]; then + msg info "Directory %s exists" "${CT}"/bin +else + extract_pkg ${CT} "" x86_64-linux-musl-cross.tgz + mv_or_fail "x86_64-linux-musl-cross/*" . +fi + +msg info "${white}[1/3]: Done cross-tools" + +msg info "${white}[2/3]: tools" + +msg info "Setting environment" +OLDPATH=${PATH} +PATH=${CT}/bin:${OLDPATH} +CC=${CT_TRI}-gcc +CXX=${CT_TRI}-g++ +AR=${CT_TRI}-ar +AS=${CT_TRI}-as +RANLIB=${CT_TRI}-ranlib +LD=${CT_TRI}-ld +STRIP=${CT_TRI}-strip + +export PATH CC CXX AR AS RANLIB LD STRIP + +pkg=binutils-2.38 +if [ -x ${TL}/bin/ar ]; then + msg info "%s exists, skipping %s" "${TL}/bin/ar" ${pkg} +else +fetch_pkg https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.xz +extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz +{ + cd_or_fail ${G_SRC}/${pkg} + remove_dir build + check_dir build + cd_or_fail build + export CFLAGS='-static --static -fcommon' + export LDFLAGS='-static --static -Bstatic -fcommon' + run_configure .. \ + --prefix=${TL} \ + --with-lib-path=${TL}/lib \ + --build=${CT_TRI} \ + --host=${G_TARGET} \ + --target=${G_TARGET} \ + --disable-nls \ + --disable-werror \ + --with-static-standard-libraries \ + --with-sysroot + run_make + run_make install-strip + unset CFLAGS LDFLAGS +} +remove_dir ${G_SRC}/${pkg} +fi + +pkg=gcc-12.1.0 +if [ -x ${TL}/bin/gcc ]; then + msg info "%s exists, skipping %s" "${TL}/bin/gcc" ${pkg} +else +fetch_pkg https://ftp.gnu.org/gnu/gcc/${pkg}/${pkg}.tar.xz +extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz +{ + cd_or_fail ${G_SRC}/${pkg} + + subpkg=gmp-6.2.1 + if [ -d gmp ]; then + msg info "Subpackage %s exists" "${subpkg}" + else + fetch_pkg https://ftp.gnu.org/gnu/gmp/${subpkg}.tar.xz + extract_pkg ${G_SRC}/${pkg} ${subpkg} ${subpkg}.tar.xz + mv_or_fail ${subpkg} gmp + fi + + subpkg=mpc-1.2.1 + if [ -d mpc ]; then + msg info "Subpackage %s exists" "${subpkg}" + else + fetch_pkg https://ftp.gnu.org/gnu/mpc/${subpkg}.tar.gz + extract_pkg ${G_SRC}/${pkg} ${subpkg} ${subpkg}.tar.gz + mv_or_fail ${subpkg} mpc + fi + + subpkg=mpfr-4.1.0 + if [ -d mpfr ]; then + msg info "Subpackage %s exists" "${subpkg}" + else + fetch_pkg https://ftp.gnu.org/gnu/mpfr/${subpkg}.tar.xz + extract_pkg ${G_SRC}/${pkg} ${subpkg} ${subpkg}.tar.xz + mv_or_fail ${subpkg} mpfr + fi + + msg info "Applying patches" + for n in 1 3 4 6 7 9 10 11 12 13 14 17 18 19 20 23 24 25 27 28 29 \ + 32 35 36 37 41 42 43 + do + apply_patch -Np1 -i ${WD}/pat/gcc-alpine/$(printf "%04d" \ + $n)-*.patch + done + + apply_patch -Np1 -i ${WD}/pat/gcc-mlfs/fix_fenv_header.patch + + msg info "Generating include-fixed/limits.h" + if ! cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \ + $(realpath $(dirname $(${CT_TRI}-gcc \ + -print-libgcc-file-name)))/include-fixed/limits.h + then + msg err "Generating include-fixed/limits.h failed" + exit 1 + fi + + msg info "Modifying linux*.h" + for f in gcc/config/linux.h \ + gcc/config/i386/linux.h \ + gcc/config/i386/linux64.h + do + cp -u $f $f.orig + sed -e 's,/lib\(64\)\?\(32\)\?/ld,/'${TLD}'&,g' \ + -e 's,/usr,/'${TLD}',g' $f.orig > $f + cat <<'!' >>$f +#undef STANDARD_STARTFILE_PREFIX_1 +#undef STANDARD_STARTFILE_PREFIX_2 +! + printf "#define STANDARD_STARTFILE_PREFIX_1 \"/"${TLD}\ +"/lib/\"\n" >>$f + cat <<'!' >>$f +#define STANDARD_STARTFILE_PREFIX_2 "" +! + touch $f.orig + done + + skip_conf=0 + if [ ${skip_conf} != 1 ]; then + remove_dir build + check_dir build + cd_or_fail build + fi + + CFLAGS='-g0 -O0' + CXXFLAGS=${CFLAGS} + export CFLAGS CXXFLAGS + + if [ ${skip_conf} != 1 ]; then + run_configure .. \ + --target=${G_TARGET} \ + --build=${CT_TRI} \ + --host=${G_TARGET} \ + --prefix=${TL} \ + --with-local-prefix=${TL} \ + --with-native-system-header-dir=/${TLD}/include \ + --enable-languages=c,c++ \ + --disable-libstdcxx-pch \ + --disable-multilib \ + --disable-bootstrap \ + --disable-libgomp \ + --disable-libquadmath \ + --disable-libssp \ + --disable-libvtv \ + --disable-symvers \ + --disable-libitm \ + --disable-libsanitizer + fi + + PATH=${CT}/bin:/bin:/usr/bin:${TL}/bin + export PATH + + run_make + run_make install + + unset CFLAGS CXXFLAGS +} +exit 0 +remove_dir ${G_SRC}/${pkg} +fi + +msg info "Cleaning up environment" +export PATH=${OLDPATH} +unset OLDPATH CC CXX AR AS RANLIB STRIP +unset WD + +exit 0 + git_clone tinycc git://repo.or.cz/tinycc.git +pkg=tinycc { - cd_or_fail tinycc - run_configure --prefix=${CT} + cd_or_fail ${G_SRC}/${pkg} + run_configure . --prefix=${CT} run_make run_make install } +exit 0 -skip_linux=0 -if [ ${skip_linux} != 1 ]; then +skip=1 +if [ ${skip} != 1 ]; then fetch_pkg https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.17.13.tar.xz pkg=linux-5.17.13 -extract_pkg ${pkg} ${pkg}.tar.xz +extract_pkg ${G_SRC} ${pkg} ${pkg}.tar.xz { - cd ${G_SRC} - cd_or_fail ${pkg} + cd_or_fail ${G_SRC}/${pkg} run_make ARCH=${G_ARCH} ${JN} headers check_dir ${CT}/${G_TARGET}/include cp_or_fail -r "usr/include/*" ${CT}/${G_TARGET}/include/ @@ -34,6 +223,8 @@ extract_pkg ${pkg} ${pkg}.tar.xz remove_dir ${G_SRC}/${pkg} } fi -msg info "Done ${white}part 1 of 3: cross-tools" -unset CT GS GR TL G_ARCH G_LOG G_PKG G_SRC G_TARGET G_VER JN +skip=0 +git_clone sbase + +msg info "${white}[2/3]: Done tools" diff --git a/lib/env.sh b/lib/env.sh @@ -1,15 +1,23 @@ #!/bin/sh CT=${HOME}/galeb-cross-tools -GS=${HOME}/galeb-source -GR=${HOME}/galeb-root -TL=${HOME}/galeb-tools +CT_TRI=x86_64-linux-musl +GSD=galeb-source +GRD=galeb-root +TLD=galeb-tools +GS=${HOME}/${GSD} +GR=${HOME}/${GRD} +TL=${HOME}/${TLD} G_ARCH=x86 +#G_HOST=$(gcc -dumpmachine) +G_FIFO=${GS}/fifo G_LOG=${GS}/log +G_PAT=${GS}/pat G_PKG=${GS}/pkg G_SRC=${GS}/src G_TARGET=x86_64-galeb-linux-musl G_VER=2.0 JN=-j$(($(nproc) * 3)) -export CT GS GR TL G_ARCH G_LOG G_PKG G_SRC G_TARGET G_VER JN +export CT CT_TRI GS GR TL G_ARCH G_FIFO G_LOG G_PAT G_PKG G_SRC G_TARGET +export G_VER JN GSD GRD TLD diff --git a/lib/fun.sh b/lib/fun.sh @@ -1,20 +1,42 @@ #!/bin/sh -norm=$(printf '\033[0m') -bold=$(printf '\033[1m') -faint=$(printf '\033[2m') -green=$(printf '\033[32m') -lred=$(printf '\033[91m') +norm=$(printf '\033[0m') +bold=$(printf '\033[1m') +faint=$(printf '\033[2m') +green=$(printf '\033[32m') +bgred=$(printf '\033[41m') +lred=$(printf '\033[91m') yellow=$(printf '\033[93m') -lblue=$(printf '\033[94m') -white=$(printf '\033[97m') +lblue=$(printf '\033[94m') +white=$(printf '\033[97m') + +apply_patch() +{ + local pat + + eval pat=\$$# + if [ -f "${G_PAT}/${pat##*/}.applied" ]; then + msg info "Patch %s applied" ${pat} + return + fi + msg info "Patch %s" "$*" + if patch $* 2>&1 | tee -a ${G_LOG}; then + : > ${G_PAT}/${pat##*/}.applied + else + msg err "Patch %s failed" "$@" + exit 1 + fi +} cd_or_fail() { local dir=$1 msg info "cd %s" "${dir}" - cd ${dir} || { msg err "Cannot cd to %s" "${dir}"; exit 1; } + if ! cd ${dir}; then + msg err "Cannot cd to %s" "${dir}" + exit 1 + fi } check_dir() @@ -46,15 +68,24 @@ git_clone() git clone $@ 2>&1 | tee -a ${G_LOG} } +exit_cleanup() +{ + rm ${G_FIFO} + unset CT CT_TRI GS GR TL G_ARCH G_FIFO G_LOG G_PAT G_PKG G_SRC G_TARGET + unset G_VER JN GSD GRD TLD +} + extract_pkg() { - local dir prog + local dir parent_dir prog + parent_dir=$1 + shift dir=$1 shift - cd_or_fail ${G_SRC} - if [ -d "${dir}" ]; then + cd_or_fail ${parent_dir} + if [ -n "${dir}" ] && [ -d "${dir}" ]; then msg info "Directory %s exists" "${dir}" return fi @@ -79,7 +110,10 @@ fetch_pkg() return fi msg info "wget %s" "$@" - wget -c $@ || exit 1 + if ! wget -c $@; then + msg err "Fetching package %s failed" "${pkg}" + exit 1 + fi } msg() @@ -96,7 +130,7 @@ msg() case ${kind} in err) icon_plain="=E=" - icon="${bold}${lred}${icon_plain}";; + icon="${bold}${white}${bgred}${icon_plain}";; info) icon_plain="=I=" icon="${bold}${faint}${green}${icon_plain}";; warn) icon_plain="=W=" @@ -105,25 +139,45 @@ msg() esac printf "%s %s " "${icon}" ${tstamp} printf "%s %s " "${icon_plain}" ${tstamp} >>${G_LOG} - printf "${fmt}${norm}\n" "$*" + printf "${fmt}${norm}\n" "$@" printf "$(echo "${fmt}" | sed 's/'$(printf '\033')'\[[0-9]\+m//g')\n" \ - "$*" >>${G_LOG} + "$@" >>${G_LOG} +} + +mv_or_fail() +{ + msg info "mv %s" "$@" + mv $@ || { msg err "Cannot mv"; exit 1; } } remove_dir() { msg info "Removing directory %s" "$1" - rm -fr "$1" + if [ -d "$1" ]; then + rm -fr "$1" + fi } run_configure() { + local location=$1 + shift msg info "configure %s" "$*" - ./configure $* 2>&1 | tee -a ${G_LOG} || exit 1 + if ! ${location}/configure $* 2>&1 | tee -a ${G_LOG}; then + msg err "configure %s failed" "$*" + exit 1 + fi } run_make() { msg info "make %s" "$*" - make $* 2>&1 | tee -a ${G_LOG} || exit 1 + tee -a ${G_LOG} < ${G_FIFO} & + pid=$! + if ! make $* 2>&1; then + kill ${pid} + msg err "make %s failed" "$*" + exit 1 + fi + kill ${pid} } diff --git a/pat/gcc-alpine/0001-posix_memalign.patch b/pat/gcc-alpine/0001-posix_memalign.patch @@ -0,0 +1,42 @@ +From 0f6c64b962bb3bf75f15aec350a9d6f8997fa814 Mon Sep 17 00:00:00 2001 +From: Szabolcs Nagy <nsz@port70.net> +Date: Fri, 26 Jan 2018 20:32:50 +0000 +Subject: [PATCH] posix_memalign + +--- + gcc/config/i386/pmm_malloc.h | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h +index 87344d9383f..ece428df487 100644 +--- a/gcc/config/i386/pmm_malloc.h ++++ b/gcc/config/i386/pmm_malloc.h +@@ -27,12 +27,13 @@ + #include <stdlib.h> + + /* We can't depend on <stdlib.h> since the prototype of posix_memalign +- may not be visible. */ ++ may not be visible and we can't pollute the namespace either. */ + #ifndef __cplusplus +-extern int posix_memalign (void **, size_t, size_t); ++extern int _mm_posix_memalign (void **, size_t, size_t) + #else +-extern "C" int posix_memalign (void **, size_t, size_t) throw (); ++extern "C" int _mm_posix_memalign (void **, size_t, size_t) throw () + #endif ++__asm__("posix_memalign"); + + static __inline void * + _mm_malloc (size_t __size, size_t __alignment) +@@ -42,7 +43,7 @@ _mm_malloc (size_t __size, size_t __alignment) + return malloc (__size); + if (__alignment == 2 || (sizeof (void *) == 8 && __alignment == 4)) + __alignment = sizeof (void *); +- if (posix_memalign (&__ptr, __alignment, __size) == 0) ++ if (_mm_posix_memalign (&__ptr, __alignment, __size) == 0) + return __ptr; + else + return NULL; +-- +2.31.1 + diff --git a/pat/gcc-alpine/0002-gcc-poison-system-directories.patch b/pat/gcc-alpine/0002-gcc-poison-system-directories.patch @@ -0,0 +1,203 @@ +From 2f5ca6e3850401c628c5cc18cd606134e8b29113 Mon Sep 17 00:00:00 2001 +From: Khem Raj <raj.khem@gmail.com> +Date: Fri, 29 Mar 2013 08:59:00 +0400 +Subject: [PATCH] gcc: poison-system-directories + +Add /sw/include and /opt/include based on the original +zecke-no-host-includes.patch patch. The original patch checked for +/usr/include, /sw/include and /opt/include and then triggered a failure and +aborted. + +Instead, we add the two missing items to the current scan. If the user +wants this to be a failure, they can add "-Werror=poison-system-directories". + +Signed-off-by: Mark Hatle <mark.hatle@windriver.com> +Signed-off-by: Khem Raj <raj.khem@gmail.com> + +Upstream-Status: Pending +--- + gcc/common.opt | 4 ++++ + gcc/config.in | 6 ++++++ + gcc/configure | 16 ++++++++++++++++ + gcc/configure.ac | 10 ++++++++++ + gcc/doc/invoke.texi | 9 +++++++++ + gcc/gcc.c | 2 ++ + gcc/incpath.c | 21 +++++++++++++++++++++ + 7 files changed, 68 insertions(+) + +diff --git a/gcc/common.opt b/gcc/common.opt +index ec5235c3a41..ca942863064 100644 +--- a/gcc/common.opt ++++ b/gcc/common.opt +@@ -682,6 +682,10 @@ Wreturn-local-addr + Common Var(warn_return_local_addr) Init(1) Warning + Warn about returning a pointer/reference to a local or temporary variable. + ++Wpoison-system-directories ++Common Var(flag_poison_system_directories) Init(1) Warning ++Warn for -I and -L options using system directories if cross compiling ++ + Wshadow + Common Var(warn_shadow) Warning + Warn when one variable shadows another. Same as -Wshadow=global. +diff --git a/gcc/config.in b/gcc/config.in +index 364eba47737..9551c0dfdf9 100644 +--- a/gcc/config.in ++++ b/gcc/config.in +@@ -224,6 +224,12 @@ + #endif + + ++/* Define to warn for use of native system header directories */ ++#ifndef USED_FOR_TARGET ++#undef ENABLE_POISON_SYSTEM_DIRECTORIES ++#endif ++ ++ + /* Define if you want all operations on RTL (the basic data structure of the + optimizer and back end) to be checked for dynamic type safety at runtime. + This is quite expensive. */ +diff --git a/gcc/configure b/gcc/configure +index 8fe9c91fd7c..17b878e4b4e 100755 +--- a/gcc/configure ++++ b/gcc/configure +@@ -1010,6 +1010,7 @@ with_system_zlib + enable_maintainer_mode + enable_link_mutex + enable_version_specific_runtime_libs ++enable_poison_system_directories + enable_plugin + enable_host_shared + enable_libquadmath_support +@@ -1766,6 +1767,8 @@ Optional Features: + --enable-version-specific-runtime-libs + specify that runtime libraries should be installed + in a compiler-specific directory ++ --enable-poison-system-directories ++ warn for use of native system header directories + --enable-plugin enable plugin support + --enable-host-shared build host code as shared libraries + --disable-libquadmath-support +@@ -30276,6 +30279,19 @@ if test "${enable_version_specific_runtime_libs+set}" = set; then : + fi + + ++# Check whether --enable-poison-system-directories was given. ++if test "${enable_poison_system_directories+set}" = set; then : ++ enableval=$enable_poison_system_directories; ++else ++ enable_poison_system_directories=no ++fi ++ ++if test "x${enable_poison_system_directories}" = "xyes"; then ++ ++$as_echo "#define ENABLE_POISON_SYSTEM_DIRECTORIES 1" >>confdefs.h ++ ++fi ++ + # Substitute configuration variables + + +diff --git a/gcc/configure.ac b/gcc/configure.ac +index 84dceb8074a..bf64ffbe46f 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -6608,6 +6608,16 @@ AC_ARG_ENABLE(version-specific-runtime-libs, + [specify that runtime libraries should be + installed in a compiler-specific directory])]) + ++AC_ARG_ENABLE([poison-system-directories], ++ AS_HELP_STRING([--enable-poison-system-directories], ++ [warn for use of native system header directories]),, ++ [enable_poison_system_directories=no]) ++if test "x${enable_poison_system_directories}" = "xyes"; then ++ AC_DEFINE([ENABLE_POISON_SYSTEM_DIRECTORIES], ++ [1], ++ [Define to warn for use of native system header directories]) ++fi ++ + # Substitute configuration variables + AC_SUBST(subdirs) + AC_SUBST(srcdir) +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +index eabeec944e7..cd31b522e42 100644 +--- a/gcc/doc/invoke.texi ++++ b/gcc/doc/invoke.texi +@@ -348,6 +348,7 @@ Objective-C and Objective-C++ Dialects}. + -Wpacked -Wno-packed-bitfield-compat -Wpacked-not-aligned -Wpadded @gol + -Wparentheses -Wno-pedantic-ms-format @gol + -Wpointer-arith -Wno-pointer-compare -Wno-pointer-to-int-cast @gol ++-Wno-poison-system-directories @gol + -Wno-pragmas -Wno-prio-ctor-dtor -Wredundant-decls @gol + -Wrestrict -Wno-return-local-addr -Wreturn-type @gol + -Wno-scalar-storage-order -Wsequence-point @gol +@@ -6926,6 +6927,14 @@ made up of data only and thus requires no special treatment. But, for + most targets, it is made up of code and thus requires the stack to be + made executable in order for the program to work properly. + ++@item -Wno-poison-system-directories ++@opindex Wno-poison-system-directories ++Do not warn for @option{-I} or @option{-L} options using system ++directories such as @file{/usr/include} when cross compiling. This ++option is intended for use in chroot environments when such ++directories contain the correct headers and libraries for the target ++system rather than the host. ++ + @item -Wfloat-equal + @opindex Wfloat-equal + @opindex Wno-float-equal +diff --git a/gcc/gcc.c b/gcc/gcc.c +index 9f790db0daf..b2200c5185a 100644 +--- a/gcc/gcc.c ++++ b/gcc/gcc.c +@@ -1041,6 +1041,8 @@ proper position among the other output files. */ + "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ + "%X %{o*} %{e*} %{N} %{n} %{r}\ + %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \ ++ %{Wno-poison-system-directories:--no-poison-system-directories} \ ++ %{Werror=poison-system-directories:--error-poison-system-directories} \ + %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \ + VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \ + %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ +diff --git a/gcc/incpath.c b/gcc/incpath.c +index 8a2bda00f80..9098ab044ab 100644 +--- a/gcc/incpath.c ++++ b/gcc/incpath.c +@@ -26,6 +26,7 @@ + #include "intl.h" + #include "incpath.h" + #include "cppdefault.h" ++#include "diagnostic-core.h" + + /* Microsoft Windows does not natively support inodes. + VMS has non-numeric inodes. */ +@@ -393,6 +394,26 @@ merge_include_chains (const char *sysroot, cpp_reader *pfile, int verbose) + } + fprintf (stderr, _("End of search list.\n")); + } ++ ++#ifdef ENABLE_POISON_SYSTEM_DIRECTORIES ++ if (flag_poison_system_directories) ++ { ++ struct cpp_dir *p; ++ ++ for (p = heads[INC_QUOTE]; p; p = p->next) ++ { ++ if ((!strncmp (p->name, "/usr/include", 12)) ++ || (!strncmp (p->name, "/usr/local/include", 18)) ++ || (!strncmp (p->name, "/usr/X11R6/include", 18)) ++ || (!strncmp (p->name, "/sw/include", 11)) ++ || (!strncmp (p->name, "/opt/include", 12))) ++ warning (OPT_Wpoison_system_directories, ++ "include location \"%s\" is unsafe for " ++ "cross-compilation", ++ p->name); ++ } ++ } ++#endif + } + + /* Use given -I paths for #include "..." but not #include <...>, and +-- +2.31.1 + diff --git a/pat/gcc-alpine/0003-Turn-on-Wl-z-relro-z-now-by-default.patch b/pat/gcc-alpine/0003-Turn-on-Wl-z-relro-z-now-by-default.patch @@ -0,0 +1,39 @@ +From ef512b8fcf9c7628267ff2dbb127aa094f6754f3 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:45:49 +0000 +Subject: [PATCH] Turn on -Wl,-z,relro,-z,now by default. + +--- + gcc/doc/invoke.texi | 3 +++ + gcc/gcc.cc | 1 + + 2 files changed, 4 insertions(+) + +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +index cd31b522e42..17d371ef432 100644 +--- a/gcc/doc/invoke.texi ++++ b/gcc/doc/invoke.texi +@@ -14663,6 +14663,9 @@ For example, @option{-Wl,-Map,output.map} passes @option{-Map output.map} to the + linker. When using the GNU linker, you can also get the same effect with + @option{-Wl,-Map=output.map}. + ++NOTE: In Alpine Linux, for LDFLAGS, the option ++@option{-Wl,-z,relro,now} is used. To disable, use @option{-Wl,-z,norelro}. ++ + @item -u @var{symbol} + @opindex u + Pretend the symbol @var{symbol} is undefined, to force linking of +diff --git a/gcc/gcc.cc b/gcc/gcc.cc +index b2200c5185a..625c9ab7902 100644 +--- a/gcc/gcc.cc ++++ b/gcc/gcc.cc +@@ -1039,6 +1039,7 @@ proper position among the other output files. */ + "%{flto|flto=*:%<fcompare-debug*} \ + %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \ + "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ ++ "-z relro -z now " \ + "%X %{o*} %{e*} %{N} %{n} %{r}\ + %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \ + %{Wno-poison-system-directories:--no-poison-system-directories} \ +-- +2.31.1 + diff --git a/pat/gcc-alpine/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch b/pat/gcc-alpine/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch @@ -0,0 +1,46 @@ +From 3c848f2fbde81db336ec97d9be7a5a4a05015eef Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:46:22 +0000 +Subject: [PATCH] Turn on -D_FORTIFY_SOURCE=2 by default for C, C++, ObjC, + ObjC++, if the optimization level is > 0 + +--- + gcc/c-family/c-cppbuiltin.cc | 4 ++++ + gcc/doc/invoke.texi | 6 ++++++ + 2 files changed, 10 insertions(+) + +diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc +index db91a36794a..ed976c71404 100644 +--- a/gcc/c-family/c-cppbuiltin.cc ++++ b/gcc/c-family/c-cppbuiltin.cc +@@ -1385,6 +1385,10 @@ c_cpp_builtins (cpp_reader *pfile) + builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0); + builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0); + ++ /* Fortify Source enabled by default for optimization levels > 0 */ ++ if (optimize) ++ builtin_define_with_int_value ("_FORTIFY_SOURCE", 2); ++ + /* Misc. */ + if (flag_gnu89_inline) + cpp_define (pfile, "__GNUC_GNU_INLINE__"); +diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi +index 17d371ef432..fe793ac08db 100644 +--- a/gcc/doc/invoke.texi ++++ b/gcc/doc/invoke.texi +@@ -9230,6 +9230,12 @@ also turns on the following optimization flags: + Please note the warning under @option{-fgcse} about + invoking @option{-O2} on programs that use computed gotos. + ++NOTE: In Alpine Linux, @option{-D_FORTIFY_SOURCE=2} is ++set by default, and is activated when @option{-O} is set to 2 or higher. ++This enables additional compile-time and run-time checks for several libc ++functions. To disable, specify either @option{-U_FORTIFY_SOURCE} or ++@option{-D_FORTIFY_SOURCE=0}. ++ + @item -O3 + @opindex O3 + Optimize yet more. @option{-O3} turns on all optimizations specified +-- +2.31.1 + diff --git a/pat/gcc-alpine/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch b/pat/gcc-alpine/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch @@ -0,0 +1,242 @@ +From: Ariadne Conill <ariadne@dereferenced.org> +From: Olsken (updated patches) +Date: Sat, 21 Aug 2021 08:51:52 +0000 +Subject: [PATCH] On linux targets pass --as-needed by default to the linker, + but always link the sanitizer libraries with --no-as-needed. + +diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h +index 7f2529a2a..b097e1688 100644 +--- a/gcc/config/aarch64/aarch64-linux.h ++++ b/gcc/config/aarch64/aarch64-linux.h +@@ -35,6 +35,7 @@ + #define CPP_SPEC "%{pthread:-D_REENTRANT}" + + #define LINUX_TARGET_LINK_SPEC "%{h*} \ ++ --as-needed \ + %{static:-Bstatic} \ + %{shared:-shared} \ + %{symbolic:-Bsymbolic} \ +diff --git a/gcc/config/alpha/linux-elf.h b/gcc/config/alpha/linux-elf.h +index c1dae8ca2..a87dc7401 100644 +--- a/gcc/config/alpha/linux-elf.h ++++ b/gcc/config/alpha/linux-elf.h +@@ -37,7 +37,7 @@ along with GCC; see the file COPYING3. If not see + + #define ELF_DYNAMIC_LINKER GNU_USER_DYNAMIC_LINKER + +-#define LINK_SPEC "-m elf64alpha %{G*} %{relax:-relax} \ ++#define LINK_SPEC "-m elf64alpha --as-needed %{G*} %{relax:-relax} \ + %{O*:-O3} %{!O*:-O1} \ + %{shared:-shared} \ + %{!shared: \ +diff --git a/gcc/config/arm/linux-elf.h b/gcc/config/arm/linux-elf.h +index 0c1c4e70b..8b581afac 100644 +--- a/gcc/config/arm/linux-elf.h ++++ b/gcc/config/arm/linux-elf.h +@@ -70,6 +70,7 @@ + %{rdynamic:-export-dynamic} \ + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}} \ + -X \ ++ --as-needed \ + %{mbig-endian:-EB} %{mlittle-endian:-EL}" \ + SUBTARGET_EXTRA_LINK_SPEC + +diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h +index 5ebbf42a1..e1a04e9fd 100644 +--- a/gcc/config/gnu-user.h ++++ b/gcc/config/gnu-user.h +@@ -136,21 +136,21 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #define LIBASAN_EARLY_SPEC "%{!shared:libasan_preinit%O%s} " \ + "%{static-libasan:%{!shared:" \ + LD_STATIC_OPTION " --whole-archive -lasan --no-whole-archive " \ +- LD_DYNAMIC_OPTION "}}%{!static-libasan:-lasan}" ++ LD_DYNAMIC_OPTION "}}%{!static-libasan:%{!fuse-ld=gold:--push-state} --no-as-needed -lasan %{fuse-ld=gold:--as-needed;:--pop-state}}" + #undef LIBHWASAN_EARLY_SPEC + #define LIBHWASAN_EARLY_SPEC "%{static-libhwasan:%{!shared:" \ + LD_STATIC_OPTION " --whole-archive -lhwasan --no-whole-archive " \ +- LD_DYNAMIC_OPTION "}}%{!static-libhwasan:-lhwasan}" ++ LD_DYNAMIC_OPTION "}}%{!static-libhwasan:%{!fuse-ld=gold:--push-state} --no-as-needed -lhwasan %{fuse-ld=gold:--as-needed;:--pop-state}}" + #undef LIBTSAN_EARLY_SPEC + #define LIBTSAN_EARLY_SPEC "%{!shared:libtsan_preinit%O%s} " \ + "%{static-libtsan:%{!shared:" \ + LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \ +- LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}" ++ LD_DYNAMIC_OPTION "}}%{!static-libtsan:%{!fuse-ld=gold:--push-state} --no-as-needed -ltsan %{fuse-ld=gold:--as-needed;:--pop-state}}" + #undef LIBLSAN_EARLY_SPEC + #define LIBLSAN_EARLY_SPEC "%{!shared:liblsan_preinit%O%s} " \ + "%{static-liblsan:%{!shared:" \ + LD_STATIC_OPTION " --whole-archive -llsan --no-whole-archive " \ +- LD_DYNAMIC_OPTION "}}%{!static-liblsan:-llsan}" ++ LD_DYNAMIC_OPTION "}}%{!static-liblsan:%{!fuse-ld=gold:--push-state} --no-as-needed -llsan %{fuse-ld=gold:--as-needed;:--pop-state}}" + #endif + + #undef TARGET_F951_OPTIONS +diff --git a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h +index a23e7ab3e..12ac8cb93 100644 +--- a/gcc/config/i386/gnu-user.h ++++ b/gcc/config/i386/gnu-user.h +@@ -68,7 +68,7 @@ along with GCC; see the file COPYING3. If not see + { "link_emulation", GNU_USER_LINK_EMULATION },\ + { "dynamic_linker", GNU_USER_DYNAMIC_LINKER } + +-#define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) %{shared:-shared} \ ++#define GNU_USER_TARGET_LINK_SPEC "-m %(link_emulation) --as-needed %{shared:-shared} \ + %{!shared: \ + %{!static: \ + %{!static-pie: \ +diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h +index f3e25b141..712b0f1c3 100644 +--- a/gcc/config/i386/gnu-user64.h ++++ b/gcc/config/i386/gnu-user64.h +@@ -56,6 +56,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + "%{" SPEC_64 ":-m " GNU_USER_LINK_EMULATION64 "} \ + %{" SPEC_32 ":-m " GNU_USER_LINK_EMULATION32 "} \ + %{" SPEC_X32 ":-m " GNU_USER_LINK_EMULATIONX32 "} \ ++ --as-needed \ + %{shared:-shared} \ + %{!shared: \ + %{!static: \ +diff --git a/gcc/config/ia64/linux.h b/gcc/config/ia64/linux.h +index ac40c3dfd..6e19e25c3 100644 +--- a/gcc/config/ia64/linux.h ++++ b/gcc/config/ia64/linux.h +@@ -58,7 +58,7 @@ do { \ + #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-ia64.so.2" + + #undef LINK_SPEC +-#define LINK_SPEC "\ ++#define LINK_SPEC " --as-needed \ + %{shared:-shared} \ + %{!shared: \ + %{!static: \ +diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h +index a390bcece..be0ee2893 100644 +--- a/gcc/config/mips/gnu-user.h ++++ b/gcc/config/mips/gnu-user.h +@@ -55,6 +55,7 @@ along with GCC; see the file COPYING3. If not see + #undef GNU_USER_TARGET_LINK_SPEC + #define GNU_USER_TARGET_LINK_SPEC "\ + %{G*} %{EB} %{EL} %{mips*} %{shared} \ ++ -as-needed \ + %{!shared: \ + %{!static: \ + %{rdynamic:-export-dynamic} \ +diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h +index e3f2cd254..43499ed29 100644 +--- a/gcc/config/rs6000/linux64.h ++++ b/gcc/config/rs6000/linux64.h +@@ -374,13 +374,13 @@ extern int dot_symbols; + " -m elf64ppc") + #endif + +-#define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " %{!shared: %{!static: \ ++#define LINK_OS_LINUX_SPEC32 LINK_OS_LINUX_EMUL32 " --as-needed %{!shared: %{!static: \ + %{!static-pie: \ + %{rdynamic:-export-dynamic} \ + -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}}} \ + %(link_os_extra_spec32)" + +-#define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " %{!shared: %{!static: \ ++#define LINK_OS_LINUX_SPEC64 LINK_OS_LINUX_EMUL64 " --as-needed %{!shared: %{!static: \ + %{!static-pie: \ + %{rdynamic:-export-dynamic} \ + -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "}}} \ +diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h +index 510abe169..3c1f3a8ec 100644 +--- a/gcc/config/rs6000/sysv4.h ++++ b/gcc/config/rs6000/sysv4.h +@@ -789,7 +789,7 @@ GNU_USER_TARGET_CC1_SPEC + #define GNU_USER_DYNAMIC_LINKER GLIBC_DYNAMIC_LINKER + #endif + +-#define LINK_OS_LINUX_SPEC "-m elf32ppclinux %{!shared: %{!static: \ ++#define LINK_OS_LINUX_SPEC "-m elf32ppclinux --as-needed %{!shared: %{!static: \ + %{rdynamic:-export-dynamic} \ + -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + +diff --git a/gcc/config/s390/linux.h b/gcc/config/s390/linux.h +index daa48fdfc..2fcfc5d77 100644 +--- a/gcc/config/s390/linux.h ++++ b/gcc/config/s390/linux.h +@@ -82,7 +82,7 @@ along with GCC; see the file COPYING3. If not see + + #undef LINK_SPEC + #define LINK_SPEC \ +- "%{m31:-m elf_s390}%{m64:-m elf64_s390} \ ++ "%{m31:-m elf_s390}%{m64:-m elf64_s390} --as-needed \ + %{shared:-shared} \ + %{!shared: \ + %{static:-static} \ +diff --git a/gcc/config/sparc/linux.h b/gcc/config/sparc/linux.h +index 2550d7ee8..7596d0b27 100644 +--- a/gcc/config/sparc/linux.h ++++ b/gcc/config/sparc/linux.h +@@ -81,7 +81,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); + #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2" + + #undef LINK_SPEC +-#define LINK_SPEC "-m elf32_sparc %{shared:-shared} \ ++#define LINK_SPEC "-m elf32_sparc --as-needed %{shared:-shared} \ + %{!mno-relax:%{!r:-relax}} \ + %{!shared: \ + %{!static: \ +diff --git a/gcc/gcc.c b/gcc/gcc.c +index 4d790f9dd..5b2fa8c93 100644 +--- a/gcc/gcc.c ++++ b/gcc/gcc.c +@@ -737,8 +737,11 @@ proper position among the other output files. */ + #ifdef LIBASAN_EARLY_SPEC + #define LIBASAN_SPEC STATIC_LIBASAN_LIBS + #elif defined(HAVE_LD_STATIC_DYNAMIC) +-#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \ +- "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \ ++#define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION "}" \ ++ " %{!static-libasan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \ ++ " -lasan " \ ++ " %{static-libasan:" LD_DYNAMIC_OPTION "}" \ ++ " %{!static-libasan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \ + STATIC_LIBASAN_LIBS + #else + #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS +@@ -773,8 +776,11 @@ proper position among the other output files. */ + #ifdef LIBTSAN_EARLY_SPEC + #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS + #elif defined(HAVE_LD_STATIC_DYNAMIC) +-#define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \ +- "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \ ++#define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION "}" \ ++ " %{!static-libtsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \ ++ " -ltsan " \ ++ " %{static-libtsan:" LD_DYNAMIC_OPTION "}" \ ++ " %{!static-libtsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \ + STATIC_LIBTSAN_LIBS + #else + #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS +@@ -791,8 +797,11 @@ proper position among the other output files. */ + #ifdef LIBLSAN_EARLY_SPEC + #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS + #elif defined(HAVE_LD_STATIC_DYNAMIC) +-#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \ +- "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ ++#define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION "}" \ ++ " %{!static-liblsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \ ++ " -llsan " \ ++ " %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ ++ " %{!static-liblsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \ + STATIC_LIBLSAN_LIBS + #else + #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS +@@ -807,8 +816,11 @@ proper position among the other output files. */ + #define STATIC_LIBUBSAN_LIBS \ + " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}" + #ifdef HAVE_LD_STATIC_DYNAMIC +-#define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \ +- "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ ++#define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION "}" \ ++ " %{!static-libubsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \ ++ " -lubsan " \ ++ " %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ ++ " %{!static-libubsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \ + STATIC_LIBUBSAN_LIBS + #else + #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS diff --git a/pat/gcc-alpine/0006-Enable-Wformat-and-Wformat-security-by-default.patch b/pat/gcc-alpine/0006-Enable-Wformat-and-Wformat-security-by-default.patch @@ -0,0 +1,34 @@ +From 44b1a01cbe3932122112f38e06a21b1c9efad568 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:47:43 +0000 +Subject: [PATCH] Enable -Wformat and -Wformat-security by default. + +--- + gcc/c-family/c.opt | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt +index c49da99d395..93f25319005 100644 +--- a/gcc/c-family/c.opt ++++ b/gcc/c-family/c.opt +@@ -599,7 +599,7 @@ Warn about function calls with format strings that write past the end + of the destination region. Same as -Wformat-overflow=1. + + Wformat-security +-C ObjC C++ ObjC++ Var(warn_format_security) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0) ++C ObjC C++ ObjC++ Var(warn_format_security) Init(1) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 2, 0) + Warn about possible security problems with format functions. + + Wformat-signedness +@@ -620,7 +620,7 @@ C ObjC C++ ObjC++ Var(warn_format_zero_length) Warning LangEnabledBy(C ObjC C++ + Warn about zero-length formats. + + Wformat= +-C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0) IntegerRange(0, 2) ++C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format) Init(1) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0) IntegerRange(0, 2) + Warn about printf/scanf/strftime/strfmon format string anomalies. + + Wformat-overflow= +-- +2.31.1 + diff --git a/pat/gcc-alpine/0007-Enable-Wtrampolines-by-default.patch b/pat/gcc-alpine/0007-Enable-Wtrampolines-by-default.patch @@ -0,0 +1,25 @@ +From 5679adc04a200e3a1a8dd77466eb79d03da8bf8a Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:48:24 +0000 +Subject: [PATCH] Enable -Wtrampolines by default. + +--- + gcc/common.opt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/gcc/common.opt b/gcc/common.opt +index ca942863064..0a0ab6195ee 100644 +--- a/gcc/common.opt ++++ b/gcc/common.opt +@@ -774,7 +774,7 @@ Common Var(warn_system_headers) Warning + Do not suppress warnings from system headers. + + Wtrampolines +-Common Var(warn_trampolines) Warning ++Common Var(warn_trampolines) Init(1) Warning + Warn whenever a trampoline is generated. + + Wtype-limits +-- +2.31.1 + diff --git a/pat/gcc-alpine/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch b/pat/gcc-alpine/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch @@ -0,0 +1,45 @@ +From: Ariadne Conill <ariadne@dereferenced.org> +From: Olsken (updated patches) +Date: Sat, 21 Aug 2021 08:51:52 +0000 +Subject: [PATCH] Disable ssp on -nostdlib, -nodefaultlibs and -ffreestanding + Change the buffer size. + +diff --git a/gcc/gcc.c b/gcc/gcc.c +index 5b2fa8c93..d7f3ee55c 100644 +--- a/gcc/gcc.c ++++ b/gcc/gcc.c +@@ -989,6 +989,12 @@ proper position among the other output files. */ + #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}" + #endif + ++#ifdef ENABLE_DEFAULT_SSP ++#define NO_SSP_SPEC "%{nostdlib|nodefaultlibs|ffreestanding:-fno-stack-protector} " ++#else ++#define NO_SSP_SPEC "" ++#endif ++ + #ifndef LINK_SSP_SPEC + #ifdef TARGET_LIBC_PROVIDES_SSP + #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ +@@ -1285,7 +1291,7 @@ static const char *cc1_options = + %{-version:--version}\ + %{-help=*:--help=%*}\ + %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}}\ +- %{fsyntax-only:-o %j} %{-param*}\ ++ %{fsyntax-only:-o %j} %{-param*} " NO_SSP_SPEC "\ + %{coverage:-fprofile-arcs -ftest-coverage}\ + %{fprofile-arcs|fprofile-generate*|coverage:\ + %{!fprofile-update=single:\ +diff --git a/gcc/params.opt b/gcc/params.opt +index 8ba281b4c..bab39cdf8 100644 +--- a/gcc/params.opt ++++ b/gcc/params.opt +@@ -946,7 +946,7 @@ Common Joined UInteger Var(param_ssa_name_def_chain_limit) Init(512) Param Optim + The maximum number of SSA_NAME assignments to follow in determining a value. + + -param=ssp-buffer-size= +-Common Joined UInteger Var(param_ssp_buffer_size) Init(8) IntegerRange(1, 65536) Param Optimization ++Common Joined UInteger Var(param_ssp_buffer_size) Init(4) IntegerRange(1, 65536) Param Optimization + The lower bound for a buffer to be considered for stack smashing protection. + + -param=stack-clash-protection-guard-size= diff --git a/pat/gcc-alpine/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch b/pat/gcc-alpine/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch @@ -0,0 +1,54 @@ +From 27863679bde671cdd354cba398ef71a956873e6a Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:50:33 +0000 +Subject: [PATCH] Ensure that msgfmt doesn't encounter problems during gcc + bootstrapping. + +Solves error messages like the following: + +msgfmt: /var/tmp/portage/sys-devel/gcc-4.1.2/work/build/./gcc/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.3/libstdc++.so.6) + +The libgcc_s.so used during build doesn't satisfy the needs of the +libstdc++.so that msgfmt is linked against. On the other hand, msgfmt +is used as a stand-alone application here, and what library it uses +behind the scenes is of no concern to the gcc build process. +Therefore, simply invoking it "as usual", i.e. without any special +library path, will make it work as expected here. + +2011-09-19 Martin von Gagern + +References: +https://bugs.gentoo.org/372377 +https://bugs.gentoo.org/295480 +--- + libstdc++-v3/po/Makefile.am | 1 + + libstdc++-v3/po/Makefile.in | 1 + + 2 files changed, 2 insertions(+) + +diff --git a/libstdc++-v3/po/Makefile.am b/libstdc++-v3/po/Makefile.am +index a9391d8d167..f7eee24dc8c 100644 +--- a/libstdc++-v3/po/Makefile.am ++++ b/libstdc++-v3/po/Makefile.am +@@ -38,6 +38,7 @@ MSGFMT = msgfmt + EXTRA_DIST = string_literals.cc POTFILES.in $(PACKAGE).pot $(LOCALE_IN) + + .po.mo: ++ env --unset=LD_LIBRARY_PATH \ + $(MSGFMT) -o $@ $< + + all-local: all-local-$(USE_NLS) +diff --git a/libstdc++-v3/po/Makefile.in b/libstdc++-v3/po/Makefile.in +index a0f84b0cfa0..ab24a47a2fd 100644 +--- a/libstdc++-v3/po/Makefile.in ++++ b/libstdc++-v3/po/Makefile.in +@@ -548,6 +548,7 @@ uninstall-am: + + + .po.mo: ++ env --unset=LD_LIBRARY_PATH \ + $(MSGFMT) -o $@ $< + + all-local: all-local-$(USE_NLS) +-- +2.31.1 + diff --git a/pat/gcc-alpine/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch b/pat/gcc-alpine/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch @@ -0,0 +1,28 @@ +From 953779008f2caa78c55f80c2d6096bf627080016 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:52:07 +0000 +Subject: [PATCH] Don't declare asprintf if defined as a macro. + +--- + include/libiberty.h | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/include/libiberty.h b/include/libiberty.h +index 141cb886a85..fa0e78eb62f 100644 +--- a/include/libiberty.h ++++ b/include/libiberty.h +@@ -645,8 +645,11 @@ extern int pwait (int, int *, int); + /* Like sprintf but provides a pointer to malloc'd storage, which must + be freed by the caller. */ + ++/* asprintf may be declared as a macro by glibc with __USE_FORTIFY_LEVEL. */ ++#ifndef asprintf + extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2; + #endif ++#endif + + /* Like asprintf but allocates memory without fail. This works like + xmalloc. */ +-- +2.31.1 + diff --git a/pat/gcc-alpine/0011-libiberty-copy-PIC-objects-during-build-process.patch b/pat/gcc-alpine/0011-libiberty-copy-PIC-objects-during-build-process.patch @@ -0,0 +1,24 @@ +From b43185f44ed438267db101fbe41361001c4e8a94 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:53:00 +0000 +Subject: [PATCH] libiberty: copy PIC objects during build process + +--- + libiberty/Makefile.in | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in +index d6b302e02fd..fd39928546f 100644 +--- a/libiberty/Makefile.in ++++ b/libiberty/Makefile.in +@@ -263,6 +263,7 @@ $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS) + $(AR) $(AR_FLAGS) $(TARGETLIB) \ + $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS); \ + $(RANLIB) $(TARGETLIB); \ ++ cp $(TARGETLIB) ../ ; \ + cd ..; \ + else true; fi + +-- +2.31.1 + diff --git a/pat/gcc-alpine/0012-libitm-disable-FORTIFY.patch b/pat/gcc-alpine/0012-libitm-disable-FORTIFY.patch @@ -0,0 +1,33 @@ +From 10f38bef9af2e3d6a32253ca18d5ae0123e25e1b Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:53:36 +0000 +Subject: [PATCH] libitm: disable FORTIFY + +--- + libitm/configure.tgt | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/libitm/configure.tgt b/libitm/configure.tgt +index d1beb5c9ec8..c2b50b95c01 100644 +--- a/libitm/configure.tgt ++++ b/libitm/configure.tgt +@@ -47,6 +47,16 @@ if test "$gcc_cv_have_tls" = yes ; then + esac + fi + ++# FIXME: error: inlining failed in call to always_inline ++# ‘int vfprintf(FILE*, const char*, __va_list_tag*)’ ++# : function body can be overwritten at link time ++# Disable Fortify in libitm for now. #508852 ++case "${target}" in ++ *-*-linux*) ++ XCFLAGS="${XCFLAGS} -U_FORTIFY_SOURCE" ++ ;; ++esac ++ + # Map the target cpu to an ARCH sub-directory. At the same time, + # work out any special compilation flags as necessary. + case "${target_cpu}" in +-- +2.31.1 + diff --git a/pat/gcc-alpine/0013-libgcc_s.patch b/pat/gcc-alpine/0013-libgcc_s.patch @@ -0,0 +1,57 @@ +From 3614b3586d4a0f75e454943895977a9df1b734d5 Mon Sep 17 00:00:00 2001 +From: Szabolcs Nagy <nsz@port70.net> +Date: Sat, 24 Oct 2015 20:09:53 +0000 +Subject: [PATCH] libgcc_s + +--- + gcc/config/i386/i386-expand.cc | 4 ++-- + libgcc/config/i386/cpuinfo.c | 6 +++--- + libgcc/config/i386/t-linux | 2 +- + 3 files changed, 6 insertions(+), 6 deletions(-) + +diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc +index 47d52550e5e..9cb8cc7950e 100644 +--- a/gcc/config/i386/i386-expand.cc ++++ b/gcc/config/i386/i386-expand.cc +@@ -12338,10 +12338,10 @@ + { + case IX86_BUILTIN_CPU_INIT: + { +- /* Make it call __cpu_indicator_init in libgcc. */ ++ /* Make it call __cpu_indicator_init_local in libgcc.a. */ + tree call_expr, fndecl, type; + type = build_function_type_list (integer_type_node, NULL_TREE); +- fndecl = build_fn_decl ("__cpu_indicator_init", type); ++ fndecl = build_fn_decl ("__cpu_indicator_init_local", type); + call_expr = build_call_expr (fndecl, 0); + return expand_expr (call_expr, target, mode, EXPAND_NORMAL); + } +diff --git a/libgcc/config/i386/cpuinfo.c b/libgcc/config/i386/cpuinfo.c +index 83301a1445f..89fdc7eb587 100644 +--- a/libgcc/config/i386/cpuinfo.c ++++ b/libgcc/config/i386/cpuinfo.c +@@ -516,7 +516,7 @@ __cpu_indicator_init (void) + return 0; + } + +-#if defined SHARED && defined USE_ELF_SYMVER +-__asm__ (".symver __cpu_indicator_init, __cpu_indicator_init@GCC_4.8.0"); +-__asm__ (".symver __cpu_model, __cpu_model@GCC_4.8.0"); ++#ifndef SHARED ++int __cpu_indicator_init_local (void) ++ __attribute__ ((weak, alias ("__cpu_indicator_init"))); + #endif +diff --git a/libgcc/config/i386/t-linux b/libgcc/config/i386/t-linux +index 8506a635790..564296f788e 100644 +--- a/libgcc/config/i386/t-linux ++++ b/libgcc/config/i386/t-linux +@@ -3,5 +3,5 @@ + # t-slibgcc-elf-ver and t-linux + SHLIB_MAPFILES = libgcc-std.ver $(srcdir)/config/i386/libgcc-glibc.ver + +-HOST_LIBGCC2_CFLAGS += -mlong-double-80 -DUSE_ELF_SYMVER $(CET_FLAGS) ++HOST_LIBGCC2_CFLAGS += -mlong-double-80 $(CET_FLAGS) + CRTSTUFF_T_CFLAGS += $(CET_FLAGS) +-- +2.31.1 + diff --git a/pat/gcc-alpine/0014-nopie.patch b/pat/gcc-alpine/0014-nopie.patch @@ -0,0 +1,75 @@ +From 8e58f9aa5b86dc92e5a1fa71e40e499739473894 Mon Sep 17 00:00:00 2001 +From: Szabolcs Nagy <nsz@port70.net> +Date: Sat, 7 Nov 2015 02:08:05 +0000 +Subject: [PATCH] nopie + +--- + gcc/configure | 27 +++++++++++++++++++++++++++ + gcc/configure.ac | 13 +++++++++++++ + 2 files changed, 40 insertions(+) + +diff --git a/gcc/configure b/gcc/configure +index 17b878e4b4e..808570b6c99 100755 +--- a/gcc/configure ++++ b/gcc/configure +@@ -30784,6 +30784,33 @@ fi + $as_echo "$gcc_cv_no_pie" >&6; } + if test "$gcc_cv_no_pie" = "yes"; then + NO_PIE_FLAG="-no-pie" ++else ++ # Check if -nopie works. ++ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -nopie option" >&5 ++$as_echo_n "checking for -nopie option... " >&6; } ++if test "${gcc_cv_nopie+set}" = set; then : ++ $as_echo_n "(cached) " >&6 ++else ++ saved_LDFLAGS="$LDFLAGS" ++ LDFLAGS="$LDFLAGS -nopie" ++ cat confdefs.h - <<_ACEOF >conftest.$ac_ext ++/* end confdefs.h. */ ++int main(void) {return 0;} ++_ACEOF ++if ac_fn_cxx_try_link "$LINENO"; then : ++ gcc_cv_nopie=yes ++else ++ gcc_cv_nopie=no ++fi ++rm -f core conftest.err conftest.$ac_objext \ ++ conftest$ac_exeext conftest.$ac_ext ++ LDFLAGS="$saved_LDFLAGS" ++fi ++{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_nopie" >&5 ++$as_echo "$gcc_cv_nopie" >&6; } ++ if test "$gcc_cv_nopie" = "yes"; then ++ NO_PIE_FLAG="-nopie" ++ fi + fi + + +diff --git a/gcc/configure.ac b/gcc/configure.ac +index bf64ffbe46f..9c2571de709 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -6866,6 +6866,19 @@ AC_CACHE_CHECK([for -no-pie option], + LDFLAGS="$saved_LDFLAGS"]) + if test "$gcc_cv_no_pie" = "yes"; then + NO_PIE_FLAG="-no-pie" ++else ++ # Check if -nopie works. ++ AC_CACHE_CHECK([for -nopie option], ++ [gcc_cv_nopie], ++ [saved_LDFLAGS="$LDFLAGS" ++ LDFLAGS="$LDFLAGS -nopie" ++ AC_LINK_IFELSE([int main(void) {return 0;}], ++ [gcc_cv_nopie=yes], ++ [gcc_cv_nopie=no]) ++ LDFLAGS="$saved_LDFLAGS"]) ++ if test "$gcc_cv_nopie" = "yes"; then ++ NO_PIE_FLAG="-nopie" ++ fi + fi + AC_SUBST([NO_PIE_FLAG]) + +-- +2.31.1 + diff --git a/pat/gcc-alpine/0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu.patch b/pat/gcc-alpine/0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu.patch @@ -0,0 +1,25 @@ +From c5ee6bb497f640877be668428292487eb026d79e Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:57:09 +0000 +Subject: [PATCH] libffi: use __linux__ instead of __gnu_linux__ for musl + +--- + libffi/src/closures.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libffi/src/closures.c b/libffi/src/closures.c +index 721ff00ea43..22a699c6340 100644 +--- a/libffi/src/closures.c ++++ b/libffi/src/closures.c +@@ -34,7 +34,7 @@ + #include <ffi_common.h> + + #if !FFI_MMAP_EXEC_WRIT && !FFI_EXEC_TRAMPOLINE_TABLE +-# if __gnu_linux__ && !defined(__ANDROID__) ++# if __linux__ && !defined(__ANDROID__) + /* This macro indicates it may be forbidden to map anonymous memory + with both write and execute permission. Code compiled when this + option is defined will attempt to map such pages once, but if it +-- +2.31.1 + diff --git a/pat/gcc-alpine/0016-dlang-update-zlib-binding.patch b/pat/gcc-alpine/0016-dlang-update-zlib-binding.patch @@ -0,0 +1,425 @@ +From b2e1bf216169f470ced86f1f3e95c89debf606cd Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:57:51 +0000 +Subject: [PATCH] dlang: update zlib binding + +--- + libphobos/src/std/zlib.d | 266 ++++++++++++++++++++++++++++----------- + 1 file changed, 196 insertions(+), 70 deletions(-) + +diff --git a/libphobos/src/std/zlib.d b/libphobos/src/std/zlib.d +index e6cce240fd5..bd2fe37ebec 100644 +--- a/libphobos/src/std/zlib.d ++++ b/libphobos/src/std/zlib.d +@@ -1,7 +1,7 @@ + // Written in the D programming language. + + /** +- * Compress/decompress data using the $(HTTP www._zlib.net, _zlib library). ++ * Compress/decompress data using the $(HTTP www.zlib.net, zlib library). + * + * Examples: + * +@@ -43,12 +43,12 @@ + * References: + * $(HTTP en.wikipedia.org/wiki/Zlib, Wikipedia) + * +- * Copyright: Copyright Digital Mars 2000 - 2011. ++ * Copyright: Copyright The D Language Foundation 2000 - 2011. + * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). + * Authors: $(HTTP digitalmars.com, Walter Bright) +- * Source: $(PHOBOSSRC std/_zlib.d) ++ * Source: $(PHOBOSSRC std/zlib.d) + */ +-/* Copyright Digital Mars 2000 - 2011. ++/* Copyright The D Language Foundation 2000 - 2011. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) +@@ -75,9 +75,9 @@ enum + + class ZlibException : Exception + { +- this(int errnum) +- { string msg; +- ++ private static string getmsg(int errnum) nothrow @nogc pure @safe ++ { ++ string msg; + switch (errnum) + { + case Z_STREAM_END: msg = "stream end"; break; +@@ -90,7 +90,12 @@ class ZlibException : Exception + case Z_VERSION_ERROR: msg = "version error"; break; + default: msg = "unknown error"; break; + } +- super(msg); ++ return msg; ++ } ++ ++ this(int errnum) ++ { ++ super(getmsg(errnum)); + } + } + +@@ -104,7 +109,7 @@ class ZlibException : Exception + * buf = buffer containing input data + * + * Returns: +- * A $(D uint) checksum for the provided input data and starting checksum ++ * A `uint` checksum for the provided input data and starting checksum + * + * See_Also: + * $(LINK http://en.wikipedia.org/wiki/Adler-32) +@@ -147,7 +152,7 @@ uint adler32(uint adler, const(void)[] buf) + * buf = buffer containing input data + * + * Returns: +- * A $(D uint) checksum for the provided input data and starting checksum ++ * A `uint` checksum for the provided input data and starting checksum + * + * See_Also: + * $(LINK http://en.wikipedia.org/wiki/Cyclic_redundancy_check) +@@ -191,13 +196,14 @@ uint crc32(uint crc, const(void)[] buf) + ubyte[] compress(const(void)[] srcbuf, int level) + in + { +- assert(-1 <= level && level <= 9); ++ assert(-1 <= level && level <= 9, "Compression level needs to be within [-1, 9]."); + } +-body ++do + { + import core.memory : GC; ++ import std.array : uninitializedArray; + auto destlen = srcbuf.length + ((srcbuf.length + 1023) / 1024) + 12; +- auto destbuf = new ubyte[destlen]; ++ auto destbuf = uninitializedArray!(ubyte[])(destlen); + auto err = etc.c.zlib.compress2(destbuf.ptr, &destlen, cast(ubyte *) srcbuf.ptr, srcbuf.length, level); + if (err) + { +@@ -276,7 +282,7 @@ void[] uncompress(const(void)[] srcbuf, size_t destlen = 0u, int winbits = 15) + throw new ZlibException(err); + } + } +- assert(0); ++ assert(0, "Unreachable code"); + } + + @system unittest +@@ -370,9 +376,9 @@ class Compress + this(int level, HeaderFormat header = HeaderFormat.deflate) + in + { +- assert(1 <= level && level <= 9); ++ assert(1 <= level && level <= 9, "Legal compression level are in [1, 9]."); + } +- body ++ do + { + this.level = level; + this.gzip = header == HeaderFormat.gzip; +@@ -406,6 +412,7 @@ class Compress + const(void)[] compress(const(void)[] buf) + { + import core.memory : GC; ++ import std.array : uninitializedArray; + int err; + ubyte[] destbuf; + +@@ -420,7 +427,7 @@ class Compress + inited = 1; + } + +- destbuf = new ubyte[zs.avail_in + buf.length]; ++ destbuf = uninitializedArray!(ubyte[])(zs.avail_in + buf.length); + zs.next_out = destbuf.ptr; + zs.avail_out = to!uint(destbuf.length); + +@@ -461,9 +468,10 @@ class Compress + void[] flush(int mode = Z_FINISH) + in + { +- assert(mode == Z_FINISH || mode == Z_SYNC_FLUSH || mode == Z_FULL_FLUSH); ++ assert(mode == Z_FINISH || mode == Z_SYNC_FLUSH || mode == Z_FULL_FLUSH, ++ "Mode must be either Z_FINISH, Z_SYNC_FLUSH or Z_FULL_FLUSH."); + } +- body ++ do + { + import core.memory : GC; + ubyte[] destbuf; +@@ -523,6 +531,7 @@ class UnCompress + z_stream zs; + int inited; + int done; ++ bool inputEnded; + size_t destbufsize; + + HeaderFormat format; +@@ -571,16 +580,16 @@ class UnCompress + const(void)[] uncompress(const(void)[] buf) + in + { +- assert(!done); ++ assert(!done, "Buffer has been flushed."); + } +- body ++ do + { ++ if (inputEnded || !buf.length) ++ return null; ++ + import core.memory : GC; ++ import std.array : uninitializedArray; + int err; +- ubyte[] destbuf; +- +- if (buf.length == 0) +- return null; + + if (!inited) + { +@@ -598,26 +607,152 @@ class UnCompress + + if (!destbufsize) + destbufsize = to!uint(buf.length) * 2; +- destbuf = new ubyte[zs.avail_in * 2 + destbufsize]; +- zs.next_out = destbuf.ptr; +- zs.avail_out = to!uint(destbuf.length); +- +- if (zs.avail_in) +- buf = zs.next_in[0 .. zs.avail_in] ~ cast(ubyte[]) buf; ++ auto destbuf = uninitializedArray!(ubyte[])(destbufsize); ++ size_t destFill; + + zs.next_in = cast(ubyte*) buf.ptr; + zs.avail_in = to!uint(buf.length); + +- err = inflate(&zs, Z_NO_FLUSH); +- if (err != Z_STREAM_END && err != Z_OK) ++ while (true) + { +- GC.free(destbuf.ptr); +- error(err); ++ auto oldAvailIn = zs.avail_in; ++ ++ zs.next_out = destbuf[destFill .. $].ptr; ++ zs.avail_out = to!uint(destbuf.length - destFill); ++ ++ err = inflate(&zs, Z_NO_FLUSH); ++ if (err == Z_STREAM_END) ++ { ++ inputEnded = true; ++ break; ++ } ++ else if (err != Z_OK) ++ { ++ GC.free(destbuf.ptr); ++ error(err); ++ } ++ else if (!zs.avail_in) ++ break; ++ ++ /* ++ According to the zlib manual inflate() stops when either there's ++ no more data to uncompress or the output buffer is full ++ So at this point, the output buffer is too full ++ */ ++ ++ destFill = destbuf.length; ++ ++ if (destbuf.capacity) ++ { ++ if (destbuf.length < destbuf.capacity) ++ destbuf.length = destbuf.capacity; ++ else ++ { ++ auto newLength = GC.extend(destbuf.ptr, destbufsize, destbufsize); ++ ++ if (newLength && destbuf.length < destbuf.capacity) ++ destbuf.length = destbuf.capacity; ++ else ++ destbuf.length += destbufsize; ++ } ++ } ++ else ++ destbuf.length += destbufsize; + } ++ + destbuf.length = destbuf.length - zs.avail_out; + return destbuf; + } + ++ // Test for issues 3191 and 9505 ++ @system unittest ++ { ++ import std.algorithm.comparison; ++ import std.array; ++ import std.file; ++ import std.zlib; ++ ++ // Data that can be easily compressed ++ ubyte[1024] originalData; ++ ++ // This should yield a compression ratio of at least 1/2 ++ auto compressedData = compress(originalData, 9); ++ assert(compressedData.length < originalData.length / 2, ++ "The compression ratio is too low to accurately test this situation"); ++ ++ auto chunkSize = compressedData.length / 4; ++ assert(chunkSize < compressedData.length, ++ "The length of the compressed data is too small to accurately test this situation"); ++ ++ auto decompressor = new UnCompress(); ++ ubyte[originalData.length] uncompressedData; ++ ubyte[] reusedBuf; ++ int progress; ++ ++ reusedBuf.length = chunkSize; ++ ++ for (int i = 0; i < compressedData.length; i += chunkSize) ++ { ++ auto len = min(chunkSize, compressedData.length - i); ++ // simulate reading from a stream in small chunks ++ reusedBuf[0 .. len] = compressedData[i .. i + len]; ++ ++ // decompress using same input buffer ++ auto chunk = decompressor.uncompress(reusedBuf); ++ assert(progress + chunk.length <= originalData.length, ++ "The uncompressed result is bigger than the original data"); ++ ++ uncompressedData[progress .. progress + chunk.length] = cast(const ubyte[]) chunk[]; ++ progress += chunk.length; ++ } ++ ++ auto chunk = decompressor.flush(); ++ assert(progress + chunk.length <= originalData.length, ++ "The uncompressed result is bigger than the original data"); ++ ++ uncompressedData[progress .. progress + chunk.length] = cast(const ubyte[]) chunk[]; ++ progress += chunk.length; ++ ++ assert(progress == originalData.length, ++ "The uncompressed and the original data sizes differ"); ++ assert(originalData[] == uncompressedData[], ++ "The uncompressed and the original data differ"); ++ } ++ ++ @system unittest ++ { ++ ubyte[1024] invalidData; ++ auto decompressor = new UnCompress(); ++ ++ try ++ { ++ auto uncompressedData = decompressor.uncompress(invalidData); ++ } ++ catch (ZlibException e) ++ { ++ assert(e.msg == "data error"); ++ return; ++ } ++ ++ assert(false, "Corrupted data didn't result in an error"); ++ } ++ ++ @system unittest ++ { ++ ubyte[2014] originalData = void; ++ auto compressedData = compress(originalData, 9); ++ ++ auto decompressor = new UnCompress(); ++ auto uncompressedData = decompressor.uncompress(compressedData ~ cast(ubyte[]) "whatever"); ++ ++ assert(originalData.length == uncompressedData.length, ++ "The uncompressed and the original data sizes differ"); ++ assert(originalData[] == uncompressedData[], ++ "The uncompressed and the original data differ"); ++ assert(!decompressor.uncompress("whatever").length, ++ "Compression continued after the end"); ++ } ++ + /** + * Decompress and return any remaining data. + * The returned data should be appended to that returned by uncompress(). +@@ -626,49 +761,40 @@ class UnCompress + void[] flush() + in + { +- assert(!done); ++ assert(!done, "Buffer has been flushed before."); + } + out + { +- assert(done); ++ assert(done, "Flushing failed."); + } +- body ++ do + { +- import core.memory : GC; +- ubyte[] extra; +- ubyte[] destbuf; +- int err; +- + done = 1; +- if (!inited) +- return null; ++ return null; ++ } + +- L1: +- destbuf = new ubyte[zs.avail_in * 2 + 100]; +- zs.next_out = destbuf.ptr; +- zs.avail_out = to!uint(destbuf.length); ++ /// Returns true if all input data has been decompressed and no further data ++ /// can be decompressed (inflate() returned Z_STREAM_END) ++ @property bool empty() const ++ { ++ return inputEnded; ++ } + +- err = etc.c.zlib.inflate(&zs, Z_NO_FLUSH); +- if (err == Z_OK && zs.avail_out == 0) +- { +- extra ~= destbuf; +- goto L1; +- } +- if (err != Z_STREAM_END) +- { +- GC.free(destbuf.ptr); +- if (err == Z_OK) +- err = Z_BUF_ERROR; +- error(err); +- } +- destbuf = destbuf.ptr[0 .. zs.next_out - destbuf.ptr]; +- err = etc.c.zlib.inflateEnd(&zs); +- inited = 0; +- if (err) +- error(err); +- if (extra.length) +- destbuf = extra ~ destbuf; +- return destbuf; ++ /// ++ @system unittest ++ { ++ // some random data ++ ubyte[1024] originalData = void; ++ ++ // append garbage data (or don't, this works in both cases) ++ auto compressedData = cast(ubyte[]) compress(originalData) ~ cast(ubyte[]) "whatever"; ++ ++ auto decompressor = new UnCompress(); ++ auto uncompressedData = decompressor.uncompress(compressedData); ++ ++ assert(uncompressedData[] == originalData[], ++ "The uncompressed and the original data differ"); ++ assert(decompressor.empty, "The UnCompressor reports not being done"); + } + } + +-- +2.31.1 + diff --git a/pat/gcc-alpine/0017-dlang-fix-fcntl-on-mips-add-libucontext-dep.patch b/pat/gcc-alpine/0017-dlang-fix-fcntl-on-mips-add-libucontext-dep.patch @@ -0,0 +1,51 @@ +From 76c7eb27b9dfe96f2f1db4fa6f29ce28715ad2a4 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:58:22 +0000 +Subject: [PATCH] dlang: fix fcntl on mips, add libucontext dep + +--- + libphobos/configure.tgt | 1 + + libphobos/libdruntime/core/sys/posix/fcntl.d | 15 +++++++++++++++ + 2 files changed, 16 insertions(+) + +diff --git a/libphobos/configure.tgt b/libphobos/configure.tgt +index 94e42bf5509..73f2e4b7f01 100644 +--- a/libphobos/configure.tgt ++++ b/libphobos/configure.tgt +@@ -35,6 +35,7 @@ case "${target}" in + ;; + mips*-*-linux*) + LIBPHOBOS_SUPPORTED=yes ++ LIBDRUNTIME_NEEDS_UCONTEXT=yes + ;; + power*-*-linux*) + LIBPHOBOS_SUPPORTED=yes +diff --git a/libphobos/libdruntime/core/sys/posix/fcntl.d b/libphobos/libdruntime/core/sys/posix/fcntl.d +index 9febcff849b..cb34e2108bd 100644 +--- a/libphobos/libdruntime/core/sys/posix/fcntl.d ++++ b/libphobos/libdruntime/core/sys/posix/fcntl.d +@@ -870,6 +870,21 @@ else version (CRuntime_Musl) + F_SETLKW = 7, + } + } ++ else version (MIPS_Any) ++ { ++ enum ++ { ++ O_DIRECTORY = 0x010000, // octal 0200000 ++ O_NOFOLLOW = 0x020000, // octal 0400000 ++ O_DIRECT = 0x008000, // octal 0100000 ++ O_LARGEFILE = 0x002000, // octal 0020000 ++ O_TMPFILE = 0x410000, // octal 020200000 ++ ++ F_GETLK = 33, ++ F_SETLK = 34, ++ F_SETLKW = 35, ++ } ++ } + else + static assert(0, "Platform not supported"); + +-- +2.31.1 + diff --git a/pat/gcc-alpine/0018-ada-fix-shared-linking.patch b/pat/gcc-alpine/0018-ada-fix-shared-linking.patch @@ -0,0 +1,42 @@ +From 95fee2cfb1a6a32b7e671861b58ee93978ba16b8 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:59:16 +0000 +Subject: [PATCH] ada: fix shared linking + +--- + gcc/ada/link.c | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +diff --git a/gcc/ada/link.c b/gcc/ada/link.c +index 02c413a412f..f0e52a87d6e 100644 +--- a/gcc/ada/link.c ++++ b/gcc/ada/link.c +@@ -107,9 +107,9 @@ const char *__gnat_default_libgcc_subdir = "lib"; + || defined (__NetBSD__) || defined (__OpenBSD__) \ + || defined (__QNX__) + const char *__gnat_object_file_option = "-Wl,@"; +-const char *__gnat_run_path_option = "-Wl,-rpath,"; +-char __gnat_shared_libgnat_default = STATIC; +-char __gnat_shared_libgcc_default = STATIC; ++const char *__gnat_run_path_option = ""; ++char __gnat_shared_libgnat_default = SHARED; ++char __gnat_shared_libgcc_default = SHARED; + int __gnat_link_max = 8192; + unsigned char __gnat_objlist_file_supported = 1; + const char *__gnat_object_library_extension = ".a"; +@@ -129,9 +129,9 @@ const char *__gnat_default_libgcc_subdir = "lib"; + + #elif defined (__linux__) || defined (__GLIBC__) + const char *__gnat_object_file_option = "-Wl,@"; +-const char *__gnat_run_path_option = "-Wl,-rpath,"; +-char __gnat_shared_libgnat_default = STATIC; +-char __gnat_shared_libgcc_default = STATIC; ++const char *__gnat_run_path_option = ""; ++char __gnat_shared_libgnat_default = SHARED; ++char __gnat_shared_libgcc_default = SHARED; + int __gnat_link_max = 8192; + unsigned char __gnat_objlist_file_supported = 1; + const char *__gnat_object_library_extension = ".a"; +-- +2.31.1 + diff --git a/pat/gcc-alpine/0019-build-fix-CXXFLAGS_FOR_BUILD-passing.patch b/pat/gcc-alpine/0019-build-fix-CXXFLAGS_FOR_BUILD-passing.patch @@ -0,0 +1,24 @@ +From aa0311c59892d7fbc4ffa9e2f0520391521cc4dd Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 06:59:43 +0000 +Subject: [PATCH] build: fix CXXFLAGS_FOR_BUILD passing + +--- + Makefile.in | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Makefile.in b/Makefile.in +index 36e369df6e7..63627db68cf 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -170,6 +170,7 @@ BUILD_EXPORTS = \ + # built for the build system to override those in BASE_FLAGS_TO_PASS. + EXTRA_BUILD_FLAGS = \ + CFLAGS="$(CFLAGS_FOR_BUILD)" \ ++ CXXFLAGS="$(CXXFLAGS_FOR_BUILD)" \ + LDFLAGS="$(LDFLAGS_FOR_BUILD)" + + # This is the list of directories to built for the host system. +-- +2.31.1 + diff --git a/pat/gcc-alpine/0020-add-fortify-headers-paths.patch b/pat/gcc-alpine/0020-add-fortify-headers-paths.patch @@ -0,0 +1,25 @@ +From 39e86416709d3d34f46da7cd7b8a3e5a8f0ff7cd Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 07:01:06 +0000 +Subject: [PATCH] add fortify-headers paths + +--- + gcc/config/linux.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/gcc/config/linux.h b/gcc/config/linux.h +index 95654bcdb5a..d88df8f154a 100644 +--- a/gcc/config/linux.h ++++ b/gcc/config/linux.h +@@ -167,6 +167,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + + #ifdef NATIVE_SYSTEM_HEADER_DIR + #define INCLUDE_DEFAULTS_MUSL_NATIVE \ ++ { NATIVE_SYSTEM_HEADER_DIR "/fortify", 0, 0, 0, 1, 2 }, \ ++ { NATIVE_SYSTEM_HEADER_DIR "/fortify", 0, 0, 0, 1, 0 }, \ + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \ + { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 }, + #else +-- +2.31.1 + diff --git a/pat/gcc-alpine/0021-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch b/pat/gcc-alpine/0021-Alpine-musl-package-provides-libssp_nonshared.a.-We-.patch @@ -0,0 +1,31 @@ +From c6b54651688cf062ae48ca3402d6d2e08b70ceed Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> +Date: Fri, 21 Aug 2020 07:03:00 +0000 +Subject: [PATCH] Alpine musl package provides libssp_nonshared.a. We link to + it unconditionally, as otherwise we get link failures if some objects are + -fstack-protector built and final link happens with -fno-stack-protector. + This seems to be the common case when bootstrapping gcc, the piepatches do + not seem to fully fix the crosstoolchain and bootstrap sequence wrt. + stack-protector flag usage. + +--- + gcc/gcc.c | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/gcc/gcc.c b/gcc/gcc.c +index daeb4d0c8ea..6920bec0fa0 100644 +--- a/gcc/gcc.c ++++ b/gcc/gcc.c +@@ -894,8 +894,7 @@ proper position among the other output files. */ + + #ifndef LINK_SSP_SPEC + #ifdef TARGET_LIBC_PROVIDES_SSP +-#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ +- "|fstack-protector-strong|fstack-protector-explicit:}" ++#define LINK_SSP_SPEC "-lssp_nonshared" + #else + #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ + "|fstack-protector-strong|fstack-protector-explicit" \ +-- +2.31.1 + diff --git a/pat/gcc-alpine/0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch b/pat/gcc-alpine/0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch @@ -0,0 +1,69 @@ +From 4841bee243517cd52504f97ea934f44bc0c1fd5c Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 07:03:42 +0000 +Subject: [PATCH] DP: Use --push-state/--pop-state for gold as well when + linking libtsan. + +--- + gcc/gcc.cc | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/gcc/gcc.cc b/gcc/gcc.cc +index 6920bec0fa0..40e07354b3d 100644 +--- a/gcc/gcc.cc ++++ b/gcc/gcc.cc +@@ -696,10 +696,10 @@ proper position among the other output files. */ + #define LIBASAN_SPEC STATIC_LIBASAN_LIBS + #elif defined(HAVE_LD_STATIC_DYNAMIC) + #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION "}" \ +- " %{!static-libasan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \ ++ " %{!static-libasan:--push-state --no-as-needed}" \ + " -lasan " \ + " %{static-libasan:" LD_DYNAMIC_OPTION "}" \ +- " %{!static-libasan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \ ++ " %{!static-libasan:--pop-state}" \ + STATIC_LIBASAN_LIBS + #else + #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS +@@ -717,10 +717,10 @@ proper position among the other output files. */ + #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS + #elif defined(HAVE_LD_STATIC_DYNAMIC) + #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION "}" \ +- " %{!static-libtsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \ ++ " %{!static-libtsan:--push-state --no-as-needed}" \ + " -ltsan " \ + " %{static-libtsan:" LD_DYNAMIC_OPTION "}" \ +- " %{!static-libtsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \ ++ " %{!static-libtsan:--pop-state}" \ + STATIC_LIBTSAN_LIBS + #else + #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS +@@ -738,10 +738,10 @@ proper position among the other output files. */ + #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS + #elif defined(HAVE_LD_STATIC_DYNAMIC) + #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION "}" \ +- " %{!static-liblsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \ ++ " %{!static-liblsan:--push-state --no-as-needed}" \ + " -llsan " \ + " %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ +- " %{!static-liblsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \ ++ " %{!static-liblsan:--pop-state}" \ + STATIC_LIBLSAN_LIBS + #else + #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS +@@ -757,10 +757,10 @@ proper position among the other output files. */ + " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}" + #ifdef HAVE_LD_STATIC_DYNAMIC + #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION "}" \ +- " %{!static-libubsan:%{!fuse-ld=gold:--push-state }--no-as-needed}" \ ++ " %{!static-libubsan:--push-state --no-as-needed}" \ + " -lubsan " \ + " %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ +- " %{!static-libubsan:%{fuse-ld=gold:--as-needed;:--pop-state}}" \ ++ " %{!static-libubsan:--pop-state}" \ + STATIC_LIBUBSAN_LIBS + #else + #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS +-- +2.31.1 + diff --git a/pat/gcc-alpine/0023-Pure-64-bit-MIPS.patch b/pat/gcc-alpine/0023-Pure-64-bit-MIPS.patch @@ -0,0 +1,47 @@ +From 720c0d7094d27b6cbfe9669c4f65e2021debcb07 Mon Sep 17 00:00:00 2001 +From: Nils Andreas Svee <me@lochnair.net> +Date: Thu, 21 Dec 2017 03:14:33 +0100 +Subject: [PATCH] Pure 64-bit MIPS + +--- + gcc/config/mips/mips.h | 8 ++++---- + gcc/config/mips/t-linux64 | 6 +++--- + 2 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h +index 3ce0c19a29a..b9920b49167 100644 +--- a/gcc/config/mips/mips.h ++++ b/gcc/config/mips/mips.h +@@ -3424,11 +3424,11 @@ struct GTY(()) machine_function { + /* If we are *not* using multilibs and the default ABI is not ABI_32 we + need to change these from /lib and /usr/lib. */ + #if MIPS_ABI_DEFAULT == ABI_N32 +-#define STANDARD_STARTFILE_PREFIX_1 "/lib32/" +-#define STANDARD_STARTFILE_PREFIX_2 "/usr/lib32/" ++#define STANDARD_STARTFILE_PREFIX_1 "/lib/" ++#define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/" + #elif MIPS_ABI_DEFAULT == ABI_64 +-#define STANDARD_STARTFILE_PREFIX_1 "/lib64/" +-#define STANDARD_STARTFILE_PREFIX_2 "/usr/lib64/" ++#define STANDARD_STARTFILE_PREFIX_1 "/lib/" ++#define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/" + #endif + + /* Load store bonding is not supported by micromips and fix_24k. The +diff --git a/gcc/config/mips/t-linux64 b/gcc/config/mips/t-linux64 +index ceb58d3b5f3..8116e23ebba 100644 +--- a/gcc/config/mips/t-linux64 ++++ b/gcc/config/mips/t-linux64 +@@ -21,6 +21,6 @@ MULTILIB_DIRNAMES = n32 32 64 + MIPS_EL = $(if $(filter %el, $(firstword $(subst -, ,$(target)))),el) + MIPS_SOFT = $(if $(strip $(filter MASK_SOFT_FLOAT_ABI, $(target_cpu_default)) $(filter soft, $(with_float))),soft) + MULTILIB_OSDIRNAMES = \ +- ../lib32$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabin32$(MIPS_SOFT)) \ +- ../lib$(call if_multiarch,:mips$(MIPS_EL)-linux-gnu$(MIPS_SOFT)) \ +- ../lib64$(call if_multiarch,:mips64$(MIPS_EL)-linux-gnuabi64$(MIPS_SOFT)) ++ ../lib \ ++ ../lib32 \ ++ ../lib +-- +2.31.1 + diff --git a/pat/gcc-alpine/0024-use-pure-64-bit-configuration-where-appropriate.patch b/pat/gcc-alpine/0024-use-pure-64-bit-configuration-where-appropriate.patch @@ -0,0 +1,121 @@ +From c60bb23972769f687dcac689ddf00f88e46b8bb7 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 07:04:40 +0000 +Subject: [PATCH] use pure 64-bit configuration where appropriate + +--- + gcc/config/aarch64/t-aarch64-linux | 2 +- + gcc/config/i386/t-linux64 | 4 ++-- + gcc/config/rs6000/t-linux | 6 ++++-- + gcc/config/rs6000/t-linux64 | 4 ++-- + gcc/config/rs6000/t-linux64bele | 4 ++-- + gcc/config/rs6000/t-linux64lebe | 4 ++-- + gcc/config/s390/t-linux64 | 4 ++-- + 7 files changed, 15 insertions(+), 13 deletions(-) + +diff --git a/gcc/config/aarch64/t-aarch64-linux b/gcc/config/aarch64/t-aarch64-linux +index 83e59e33b85..6ec56fdf6a8 100644 +--- a/gcc/config/aarch64/t-aarch64-linux ++++ b/gcc/config/aarch64/t-aarch64-linux +@@ -22,7 +22,7 @@ LIB1ASMSRC = aarch64/lib1funcs.asm + LIB1ASMFUNCS = _aarch64_sync_cache_range + + AARCH_BE = $(if $(findstring TARGET_BIG_ENDIAN_DEFAULT=1, $(tm_defines)),_be) +-MULTILIB_OSDIRNAMES = mabi.lp64=../lib64$(call if_multiarch,:aarch64$(AARCH_BE)-linux-gnu) ++MULTILIB_OSDIRNAMES = mabi.lp64=../lib + MULTIARCH_DIRNAME = $(call if_multiarch,aarch64$(AARCH_BE)-linux-gnu) + + MULTILIB_OSDIRNAMES += mabi.ilp32=../libilp32$(call if_multiarch,:aarch64$(AARCH_BE)-linux-gnu_ilp32) +diff --git a/gcc/config/i386/t-linux64 b/gcc/config/i386/t-linux64 +index 1171e218578..256f8c079ba 100644 +--- a/gcc/config/i386/t-linux64 ++++ b/gcc/config/i386/t-linux64 +@@ -33,6 +33,6 @@ + comma=, + MULTILIB_OPTIONS = $(subst $(comma),/,$(TM_MULTILIB_CONFIG)) + MULTILIB_DIRNAMES = $(patsubst m%, %, $(subst /, ,$(MULTILIB_OPTIONS))) +-MULTILIB_OSDIRNAMES = m64=../lib64$(call if_multiarch,:x86_64-linux-gnu) +-MULTILIB_OSDIRNAMES+= m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:i386-linux-gnu) ++MULTILIB_OSDIRNAMES = m64=../lib ++MULTILIB_OSDIRNAMES+= m32=../lib32 + MULTILIB_OSDIRNAMES+= mx32=../libx32$(call if_multiarch,:x86_64-linux-gnux32) +diff --git a/gcc/config/rs6000/t-linux b/gcc/config/rs6000/t-linux +index aeb7440c492..ab14c455d8d 100644 +--- a/gcc/config/rs6000/t-linux ++++ b/gcc/config/rs6000/t-linux +@@ -2,7 +2,8 @@ + # or soft-float. + ifeq (,$(filter $(with_cpu),$(SOFT_FLOAT_CPUS))$(findstring soft,$(with_float))) + ifneq (,$(findstring powerpc64,$(target))) +-MULTILIB_OSDIRNAMES := .=../lib64$(call if_multiarch,:powerpc64-linux-gnu) ++MULTILIB_OSDIRNAMES := m64=../lib ++MULTILIB_OSDIRNAMES += m32=../lib32 + else + MULTIARCH_DIRNAME := $(call if_multiarch,powerpc-linux-gnu) + endif +@@ -10,7 +11,8 @@ ifneq (,$(findstring powerpcle,$(target))) + MULTIARCH_DIRNAME := $(subst -linux,le-linux,$(MULTIARCH_DIRNAME)) + endif + ifneq (,$(findstring powerpc64le,$(target))) +-MULTILIB_OSDIRNAMES := $(subst -linux,le-linux,$(MULTILIB_OSDIRNAMES)) ++MULTILIB_OSDIRNAMES := m64=../lib ++MULTILIB_OSDIRNAMES += m32=../lib32 + endif + endif + +diff --git a/gcc/config/rs6000/t-linux64 b/gcc/config/rs6000/t-linux64 +index 264a7e27524..d1e460811cc 100644 +--- a/gcc/config/rs6000/t-linux64 ++++ b/gcc/config/rs6000/t-linux64 +@@ -28,8 +28,8 @@ + MULTILIB_OPTIONS := m64/m32 + MULTILIB_DIRNAMES := 64 32 + MULTILIB_EXTRA_OPTS := +-MULTILIB_OSDIRNAMES := m64=../lib64$(call if_multiarch,:powerpc64-linux-gnu) +-MULTILIB_OSDIRNAMES += m32=$(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:powerpc-linux-gnu) ++MULTILIB_OSDIRNAMES := m64=../lib ++MULTILIB_OSDIRNAMES += m32=../lib32 + + rs6000-linux.o: $(srcdir)/config/rs6000/rs6000-linux.c + $(COMPILE) $< +diff --git a/gcc/config/rs6000/t-linux64bele b/gcc/config/rs6000/t-linux64bele +index 97c1ee6fb4d..08d72639cb6 100644 +--- a/gcc/config/rs6000/t-linux64bele ++++ b/gcc/config/rs6000/t-linux64bele +@@ -2,6 +2,6 @@ + + MULTILIB_OPTIONS += mlittle + MULTILIB_DIRNAMES += le +-MULTILIB_OSDIRNAMES += $(subst =,.mlittle=,$(subst lible32,lib32le,$(subst lible64,lib64le,$(subst lib,lible,$(subst -linux,le-linux,$(MULTILIB_OSDIRNAMES)))))) +-MULTILIB_OSDIRNAMES += $(subst $(if $(findstring 64,$(target)),m64,m32).,,$(filter $(if $(findstring 64,$(target)),m64,m32).mlittle%,$(MULTILIB_OSDIRNAMES))) ++MULTILIB_OSDIRNAMES = m64=../lib ++MULTILIB_OSDIRNAMES+= m32=../lib32 + MULTILIB_MATCHES := ${MULTILIB_MATCHES_ENDIAN} +diff --git a/gcc/config/rs6000/t-linux64lebe b/gcc/config/rs6000/t-linux64lebe +index 2e63bdb9fc9..c6e1c5db65d 100644 +--- a/gcc/config/rs6000/t-linux64lebe ++++ b/gcc/config/rs6000/t-linux64lebe +@@ -2,6 +2,6 @@ + + MULTILIB_OPTIONS += mbig + MULTILIB_DIRNAMES += be +-MULTILIB_OSDIRNAMES += $(subst =,.mbig=,$(subst libbe32,lib32be,$(subst libbe64,lib64be,$(subst lib,libbe,$(subst le-linux,-linux,$(MULTILIB_OSDIRNAMES)))))) +-MULTILIB_OSDIRNAMES += $(subst $(if $(findstring 64,$(target)),m64,m32).,,$(filter $(if $(findstring 64,$(target)),m64,m32).mbig%,$(MULTILIB_OSDIRNAMES))) ++MULTILIB_OSDIRNAMES := m64=../lib ++MULTILIB_OSDIRNAMES += m32=../lib32 + MULTILIB_MATCHES := ${MULTILIB_MATCHES_ENDIAN} +diff --git a/gcc/config/s390/t-linux64 b/gcc/config/s390/t-linux64 +index cc6ab367072..7f498ee1cdc 100644 +--- a/gcc/config/s390/t-linux64 ++++ b/gcc/config/s390/t-linux64 +@@ -7,5 +7,5 @@ + + MULTILIB_OPTIONS = m64/m31 + MULTILIB_DIRNAMES = 64 32 +-MULTILIB_OSDIRNAMES = ../lib64$(call if_multiarch,:s390x-linux-gnu) +-MULTILIB_OSDIRNAMES += $(if $(wildcard $(shell echo $(SYSTEM_HEADER_DIR))/../../usr/lib32),../lib32,../lib)$(call if_multiarch,:s390-linux-gnu) ++MULTILIB_OSDIRNAMES = m64=../lib ++MULTILIB_OSDIRNAMES+= m32=../lib32 +-- +2.31.1 + diff --git a/pat/gcc-alpine/0025-always-build-libgcc_eh.a.patch b/pat/gcc-alpine/0025-always-build-libgcc_eh.a.patch @@ -0,0 +1,51 @@ +From 00917df4274ea2fb33b08c963a97cf1b28f59dd3 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 07:05:41 +0000 +Subject: [PATCH] always build libgcc_eh.a + +highly inspired by: + http://landley.net/hg/aboriginal/file/7e0747a665ab/sources/patches/gcc-core-libgcceh.patch +--- + libgcc/Makefile.in | 11 ++++++----- + 1 file changed, 6 insertions(+), 5 deletions(-) + +diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in +index 851e7657d07..99ec513a1a6 100644 +--- a/libgcc/Makefile.in ++++ b/libgcc/Makefile.in +@@ -956,8 +956,9 @@ ifneq ($(LIBUNWIND),) + all: libunwind.a + endif + ++all: libgcc_eh.a + ifeq ($(enable_shared),yes) +-all: libgcc_eh.a libgcc_s$(SHLIB_EXT) ++all: libgcc_s$(SHLIB_EXT) + ifneq ($(LIBUNWIND),) + all: libunwind$(SHLIB_EXT) + libgcc_s$(SHLIB_EXT): libunwind$(SHLIB_EXT) +@@ -1159,10 +1160,6 @@ install-libunwind: + install-shared: + $(mkinstalldirs) $(DESTDIR)$(inst_libdir) + +- $(INSTALL_DATA) libgcc_eh.a $(DESTDIR)$(inst_libdir)/ +- chmod 644 $(DESTDIR)$(inst_libdir)/libgcc_eh.a +- $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcc_eh.a +- + $(subst @multilib_dir@,$(MULTIDIR),$(subst \ + @shlib_base_name@,libgcc_s,$(subst \ + @shlib_slibdir_qual@,$(MULTIOSSUBDIR),$(SHLIB_INSTALL)))) +@@ -1179,6 +1176,10 @@ ifeq ($(enable_gcov),yes) + $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcov.a + endif + ++ $(INSTALL_DATA) libgcc_eh.a $(DESTDIR)$(inst_libdir)/ ++ chmod 644 $(DESTDIR)$(inst_libdir)/libgcc_eh.a ++ $(RANLIB) $(DESTDIR)$(inst_libdir)/libgcc_eh.a ++ + parts="$(INSTALL_PARTS)"; \ + for file in $$parts; do \ + rm -f $(DESTDIR)$(inst_libdir)/$$file; \ +-- +2.31.1 + diff --git a/pat/gcc-alpine/0026-ada-libgnarl-compatibility-for-musl.patch b/pat/gcc-alpine/0026-ada-libgnarl-compatibility-for-musl.patch @@ -0,0 +1,133 @@ +From: Ariadne Conill <ariadne@dereferenced.org> +From: Olsken (updated patches) +Date: Sat, 21 Aug 2021 08:51:52 +0000 +Subject: [PATCH] ada: libgnarl compatibility for musl + +diff --git a/gcc/ada/libgnarl/s-osinte__linux.ads b/gcc/ada/libgnarl/s-osinte__linux.ads +index 2272f83d6..1d7845654 100644 +--- a/gcc/ada/libgnarl/s-osinte__linux.ads ++++ b/gcc/ada/libgnarl/s-osinte__linux.ads +@@ -401,12 +401,6 @@ package System.OS_Interface is + PTHREAD_RWLOCK_PREFER_WRITER_NP : constant := 1; + PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP : constant := 2; + +- function pthread_rwlockattr_setkind_np +- (attr : access pthread_rwlockattr_t; +- pref : int) return int; +- pragma Import +- (C, pthread_rwlockattr_setkind_np, "pthread_rwlockattr_setkind_np"); +- + function pthread_rwlock_init + (mutex : access pthread_rwlock_t; + attr : access pthread_rwlockattr_t) return int; +@@ -468,11 +462,6 @@ package System.OS_Interface is + protocol : int) return int; + pragma Import (C, pthread_mutexattr_setprotocol); + +- function pthread_mutexattr_setprioceiling +- (attr : access pthread_mutexattr_t; +- prioceiling : int) return int; +- pragma Import (C, pthread_mutexattr_setprioceiling); +- + type struct_sched_param is record + sched_priority : int; -- scheduling priority + end record; +diff --git a/gcc/ada/libgnarl/s-taprop__linux.adb b/gcc/ada/libgnarl/s-taprop__linux.adb +index 757a6cdfd..18e60e8d1 100644 +--- a/gcc/ada/libgnarl/s-taprop__linux.adb ++++ b/gcc/ada/libgnarl/s-taprop__linux.adb +@@ -198,9 +198,6 @@ package body System.Task_Primitives.Operations is + pragma Import + (C, GNAT_pthread_condattr_setup, "__gnat_pthread_condattr_setup"); + +- function GNAT_has_cap_sys_nice return C.int; +- pragma Import +- (C, GNAT_has_cap_sys_nice, "__gnat_has_cap_sys_nice"); + -- We do not have pragma Linker_Options ("-lcap"); here, because this + -- library is not present on many Linux systems. 'libcap' is the Linux + -- "capabilities" library, called by __gnat_has_cap_sys_nice. +@@ -210,44 +207,6 @@ package body System.Task_Primitives.Operations is + -- Convert Ada priority to Linux priority. Priorities are 1 .. 99 on + -- GNU/Linux, so we map 0 .. 98 to 1 .. 99. + +- function Get_Ceiling_Support return Boolean; +- -- Get the value of the Ceiling_Support constant (see below). +- -- Note well: If this function or related code is modified, it should be +- -- tested by hand, because automated testing doesn't exercise it. +- +- ------------------------- +- -- Get_Ceiling_Support -- +- ------------------------- +- +- function Get_Ceiling_Support return Boolean is +- Ceiling_Support : Boolean := False; +- begin +- if Locking_Policy /= 'C' then +- return False; +- end if; +- +- declare +- function geteuid return Integer; +- pragma Import (C, geteuid, "geteuid"); +- Superuser : constant Boolean := geteuid = 0; +- Has_Cap : constant C.int := GNAT_has_cap_sys_nice; +- pragma Assert (Has_Cap in 0 | 1); +- begin +- Ceiling_Support := Superuser or else Has_Cap = 1; +- end; +- +- return Ceiling_Support; +- end Get_Ceiling_Support; +- +- pragma Warnings (Off, "non-preelaborable call not allowed*"); +- Ceiling_Support : constant Boolean := Get_Ceiling_Support; +- pragma Warnings (On, "non-preelaborable call not allowed*"); +- -- True if the locking policy is Ceiling_Locking, and the current process +- -- has permission to use this policy. The process has permission if it is +- -- running as 'root', or if the capability was set by the setcap command, +- -- as in "sudo /sbin/setcap cap_sys_nice=ep exe_file". If it doesn't have +- -- permission, then a request for Ceiling_Locking is ignored. +- + type RTS_Lock_Ptr is not null access all RTS_Lock; + + function Init_Mutex (L : RTS_Lock_Ptr; Prio : Any_Priority) return C.int; +@@ -344,7 +303,9 @@ package body System.Task_Primitives.Operations is + -- Init_Mutex -- + ---------------- + ++ pragma Warnings (Off, "formal parameter * is not referenced"); + function Init_Mutex (L : RTS_Lock_Ptr; Prio : Any_Priority) return C.int is ++ pragma Warnings (On, "formal parameter * is not referenced"); + Mutex_Attr : aliased pthread_mutexattr_t; + Result, Result_2 : C.int; + +@@ -356,16 +317,7 @@ package body System.Task_Primitives.Operations is + return Result; + end if; + +- if Ceiling_Support then +- Result := pthread_mutexattr_setprotocol +- (Mutex_Attr'Access, PTHREAD_PRIO_PROTECT); +- pragma Assert (Result = 0); +- +- Result := pthread_mutexattr_setprioceiling +- (Mutex_Attr'Access, Prio_To_Linux_Prio (Prio)); +- pragma Assert (Result = 0); +- +- elsif Locking_Policy = 'I' then ++ if Locking_Policy = 'I' then + Result := pthread_mutexattr_setprotocol + (Mutex_Attr'Access, PTHREAD_PRIO_INHERIT); + pragma Assert (Result = 0); +@@ -405,11 +357,6 @@ package body System.Task_Primitives.Operations is + Result := pthread_rwlockattr_init (RWlock_Attr'Access); + pragma Assert (Result = 0); + +- Result := pthread_rwlockattr_setkind_np +- (RWlock_Attr'Access, +- PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); +- pragma Assert (Result = 0); +- + Result := pthread_rwlock_init (L.RW'Access, RWlock_Attr'Access); + + pragma Assert (Result in 0 | ENOMEM); diff --git a/pat/gcc-alpine/0027-ada-musl-support-fixes.patch b/pat/gcc-alpine/0027-ada-musl-support-fixes.patch @@ -0,0 +1,223 @@ +From 21692d89e7876dcaecea3e3c961c6504be4a83e9 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill <ariadne@dereferenced.org> +Date: Fri, 21 Aug 2020 07:07:48 +0000 +Subject: [PATCH] ada: musl support fixes + +--- + gcc/ada/Makefile.rtl | 10 +++++----- + gcc/ada/adaint.c | 34 +++++++++++++++++++--------------- + gcc/ada/adaint.h | 10 ++++------ + gcc/ada/terminals.c | 8 ++++---- + 4 files changed, 32 insertions(+), 30 deletions(-) + +diff --git a/gcc/ada/Makefile.rtl b/gcc/ada/Makefile.rtl +index 55ff9b0f3d5..0fadf4e4b79 100644 +--- a/gcc/ada/Makefile.rtl ++++ b/gcc/ada/Makefile.rtl +@@ -1533,7 +1533,7 @@ ifeq ($(strip $(filter-out %86 linux%,$(target_cpu) $(target_os))),) + s-intman.adb<libgnarl/s-intman__posix.adb \ + s-tpopsp.adb<libgnarl/s-tpopsp__tls.adb \ + $(TRASYM_DWARF_UNIX_PAIRS) \ +- s-tsmona.adb<libgnat/s-tsmona__linux.adb \ ++ s-tsmona.adb<libgnat/s-tsmona.adb \ + a-exetim.adb<libgnarl/a-exetim__posix.adb \ + a-exetim.ads<libgnarl/a-exetim__default.ads \ + s-linux.ads<libgnarl/s-linux.ads \ +@@ -2083,7 +2083,7 @@ ifeq ($(strip $(filter-out powerpc% linux%,$(target_cpu) $(target_os))),) + s-osinte.adb<libgnarl/s-osinte__posix.adb \ + s-tpopsp.adb<libgnarl/s-tpopsp__tls.adb \ + $(TRASYM_DWARF_UNIX_PAIRS) \ +- s-tsmona.adb<libgnat/s-tsmona__linux.adb \ ++ s-tsmona.adb<libgnat/s-tsmona.adb \ + $(ATOMICS_TARGET_PAIRS) \ + $(ATOMICS_BUILTINS_TARGET_PAIRS) \ + system.ads<libgnat/system-linux-ppc.ads +@@ -2112,7 +2112,7 @@ ifeq ($(strip $(filter-out powerpc% linux%,$(target_cpu) $(target_os))),) + endif + + # ARM linux, GNU eabi +-ifeq ($(strip $(filter-out arm% linux-gnueabi%,$(target_cpu) $(target_os))),) ++ifeq ($(strip $(filter-out arm% linux-gnueabi% linux-musleabi% linux-muslgnueabi%,$(target_cpu) $(target_os))),) + LIBGNAT_TARGET_PAIRS = \ + a-intnam.ads<libgnarl/a-intnam__linux.ads \ + s-inmaop.adb<libgnarl/s-inmaop__posix.adb \ +@@ -2305,7 +2305,7 @@ ifeq ($(strip $(filter-out %ia64 linux%,$(target_cpu) $(target_os))),) + s-tpopsp.adb<libgnarl/s-tpopsp__tls.adb \ + s-taspri.ads<libgnarl/s-taspri__posix-noaltstack.ads \ + $(TRASYM_DWARF_UNIX_PAIRS) \ +- s-tsmona.adb<libgnat/s-tsmona__linux.adb \ ++ s-tsmona.adb<libgnat/s-tsmona.adb \ + $(ATOMICS_TARGET_PAIRS) \ + $(ATOMICS_BUILTINS_TARGET_PAIRS) \ + system.ads<libgnat/system-linux-ia64.ads +@@ -2401,7 +2401,7 @@ ifeq ($(strip $(filter-out %x86_64 linux%,$(target_cpu) $(target_os))),) + s-tpopsp.adb<libgnarl/s-tpopsp__tls.adb \ + s-taspri.ads<libgnarl/s-taspri__posix.ads \ + $(TRASYM_DWARF_UNIX_PAIRS) \ +- s-tsmona.adb<libgnat/s-tsmona__linux.adb \ ++ s-tsmona.adb<libgnat/s-tsmona.adb \ + $(ATOMICS_TARGET_PAIRS) \ + $(X86_64_TARGET_PAIRS) \ + system.ads<libgnat/system-linux-x86.ads +diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c +index 595abf87d65..00858c24f53 100644 +--- a/gcc/ada/adaint.c ++++ b/gcc/ada/adaint.c +@@ -90,6 +90,11 @@ + #include <sys/param.h> + #include <sys/pstat.h> + #endif ++ ++#if defined (linux) ++#define _GNU_SOURCE 1 ++#include <sched.h> ++#endif + + #ifdef __PikeOS__ + #define __BSD_VISIBLE 1 +@@ -3308,7 +3313,6 @@ __gnat_lwp_self (void) + #endif + + #if defined (__linux__) +-#include <sched.h> + + /* glibc versions earlier than 2.7 do not define the routines to handle + dynamically allocated CPU sets. For these targets, we use the static +@@ -3318,7 +3322,7 @@ __gnat_lwp_self (void) + + /* Dynamic cpu sets */ + +-cpu_set_t * ++void * + __gnat_cpu_alloc (size_t count) + { + return CPU_ALLOC (count); +@@ -3331,33 +3335,33 @@ __gnat_cpu_alloc_size (size_t count) + } + + void +-__gnat_cpu_free (cpu_set_t *set) ++__gnat_cpu_free (void *set) + { +- CPU_FREE (set); ++ CPU_FREE ((cpu_set_t *) set); + } + + void +-__gnat_cpu_zero (size_t count, cpu_set_t *set) ++__gnat_cpu_zero (size_t count, void *set) + { +- CPU_ZERO_S (count, set); ++ CPU_ZERO_S (count, (cpu_set_t *) set); + } + + void +-__gnat_cpu_set (int cpu, size_t count, cpu_set_t *set) ++__gnat_cpu_set (int cpu, size_t count, void *set) + { + /* Ada handles CPU numbers starting from 1, while C identifies the first + CPU by a 0, so we need to adjust. */ +- CPU_SET_S (cpu - 1, count, set); ++ CPU_SET_S (cpu - 1, count, (cpu_set_t *) set); + } + + #else /* !CPU_ALLOC */ + + /* Static cpu sets */ + +-cpu_set_t * ++void * + __gnat_cpu_alloc (size_t count ATTRIBUTE_UNUSED) + { +- return (cpu_set_t *) xmalloc (sizeof (cpu_set_t)); ++ return xmalloc (sizeof (cpu_set_t)); + } + + size_t +@@ -3367,23 +3371,23 @@ __gnat_cpu_alloc_size (size_t count ATTRIBUTE_UNUSED) + } + + void +-__gnat_cpu_free (cpu_set_t *set) ++__gnat_cpu_free (void *set) + { + free (set); + } + + void +-__gnat_cpu_zero (size_t count ATTRIBUTE_UNUSED, cpu_set_t *set) ++__gnat_cpu_zero (size_t count ATTRIBUTE_UNUSED, void *set) + { +- CPU_ZERO (set); ++ CPU_ZERO ((cpu_set_t *) set); + } + + void +-__gnat_cpu_set (int cpu, size_t count ATTRIBUTE_UNUSED, cpu_set_t *set) ++__gnat_cpu_set (int cpu, size_t count ATTRIBUTE_UNUSED, void *set) + { + /* Ada handles CPU numbers starting from 1, while C identifies the first + CPU by a 0, so we need to adjust. */ +- CPU_SET (cpu - 1, set); ++ CPU_SET (cpu - 1, (cpu_set_t *) set); + } + #endif /* !CPU_ALLOC */ + #endif /* __linux__ */ +diff --git a/gcc/ada/adaint.h b/gcc/ada/adaint.h +index 311e240dfcc..1c4d0050103 100644 +--- a/gcc/ada/adaint.h ++++ b/gcc/ada/adaint.h +@@ -316,13 +316,11 @@ extern void *__gnat_lwp_self (void); + + /* Routines for interface to required CPU set primitives */ + +-#include <sched.h> +- +-extern cpu_set_t *__gnat_cpu_alloc (size_t); ++extern void * __gnat_cpu_alloc (size_t); + extern size_t __gnat_cpu_alloc_size (size_t); +-extern void __gnat_cpu_free (cpu_set_t *); +-extern void __gnat_cpu_zero (size_t, cpu_set_t *); +-extern void __gnat_cpu_set (int, size_t, cpu_set_t *); ++extern void __gnat_cpu_free (void *); ++extern void __gnat_cpu_zero (size_t, void *); ++extern void __gnat_cpu_set (int, size_t, void *); + #endif + + #if defined (_WIN32) +diff --git a/gcc/ada/terminals.c b/gcc/ada/terminals.c +index af4417fab90..bab6bf3ca87 100644 +--- a/gcc/ada/terminals.c ++++ b/gcc/ada/terminals.c +@@ -1145,7 +1145,7 @@ __gnat_setup_winsize (void *desc, int rows, int columns) + /* POSIX does not specify how to open the master side of a terminal.Several + methods are available (system specific): + 1- using a cloning device (USE_CLONE_DEVICE) +- 2- getpt (USE_GETPT) ++ 2- posix_openpt (USE_POSIX_OPENPT) + 3- openpty (USE_OPENPTY) + + When using the cloning device method, the macro USE_CLONE_DEVICE should +@@ -1159,7 +1159,7 @@ __gnat_setup_winsize (void *desc, int rows, int columns) + #if defined (__APPLE__) || defined (BSD) + #define USE_OPENPTY + #elif defined (__linux__) +-#define USE_GETPT ++#define USE_POSIX_OPENPT + #elif defined (__sun__) + #define USE_CLONE_DEVICE "/dev/ptmx" + #elif defined (_AIX) +@@ -1208,8 +1208,8 @@ allocate_pty_desc (pty_desc **desc) { + int master_fd = -1; + char *slave_name = NULL; + +-#ifdef USE_GETPT +- master_fd = getpt (); ++#if defined(USE_POSIX_OPENPT) ++ master_fd = posix_openpt(O_RDWR | O_NOCTTY); + #elif defined (USE_OPENPTY) + status = openpty (&master_fd, &slave_fd, NULL, NULL, NULL); + #elif defined (USE_CLONE_DEVICE) +-- +2.31.1 + diff --git a/pat/gcc-alpine/0028-gcc-go-Use-_off_t-type-instead-of-_loff_t.patch b/pat/gcc-alpine/0028-gcc-go-Use-_off_t-type-instead-of-_loff_t.patch @@ -0,0 +1,48 @@ +From 1852ae06e733180f090b58c267bde8fb9501a41e Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Sun, 30 Aug 2020 17:58:08 +0200 +Subject: [PATCH] gcc-go: Use _off_t type instead of _loff_t +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Taken from Adélie Linux. +--- + libgo/go/syscall/libcall_linux.go | 16 ++++++++-------- + 1 file changed, 8 insertions(+), 8 deletions(-) + +diff --git a/libgo/go/syscall/libcall_linux.go b/libgo/go/syscall/libcall_linux.go +index 88286c07b6e..f8f5cfb5011 100644 +--- a/libgo/go/syscall/libcall_linux.go ++++ b/libgo/go/syscall/libcall_linux.go +@@ -206,19 +206,19 @@ func Gettid() (tid int) { + //sys Setxattr(path string, attr string, data []byte, flags int) (err error) + //setxattr(path *byte, name *byte, value *byte, size Size_t, flags _C_int) _C_int + +-//sys splice(rfd int, roff *_loff_t, wfd int, woff *_loff_t, len int, flags int) (n int64, err error) +-//splice(rfd _C_int, roff *_loff_t, wfd _C_int, woff *_loff_t, len Size_t, flags _C_uint) Ssize_t ++//sys splice(rfd int, roff *_off_t, wfd int, woff *_off_t, len int, flags int) (n int64, err error) ++//splice(rfd _C_int, roff *_off_t, wfd _C_int, woff *_off_t, len Size_t, flags _C_uint) Ssize_t + func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) { +- var lroff _loff_t +- var plroff *_loff_t ++ var lroff _off_t ++ var plroff *_off_t + if roff != nil { +- lroff = _loff_t(*roff) ++ lroff = _off_t(*roff) + plroff = &lroff + } +- var lwoff _loff_t +- var plwoff *_loff_t ++ var lwoff _off_t ++ var plwoff *_off_t + if woff != nil { +- lwoff = _loff_t(*woff) ++ lwoff = _off_t(*woff) + plwoff = &lwoff + } + n, err = splice(rfd, plroff, wfd, plwoff, len, flags) +-- +2.31.1 + diff --git a/pat/gcc-alpine/0029-gcc-go-Don-t-include-sys-user.h.patch b/pat/gcc-alpine/0029-gcc-go-Don-t-include-sys-user.h.patch @@ -0,0 +1,30 @@ +From 40322de36043aaa3cbb98d7f01037f53fc1b5a98 Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Sun, 30 Aug 2020 17:58:21 +0200 +Subject: [PATCH] gcc-go: Don't include sys/user.h +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Taken from Adélie Linux. +--- + libgo/sysinfo.c | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c +index 0692fd41eb7..c8d987358d9 100644 +--- a/libgo/sysinfo.c ++++ b/libgo/sysinfo.c +@@ -73,9 +73,6 @@ + #include <sys/times.h> + #include <sys/wait.h> + #include <sys/un.h> +-#if defined(HAVE_SYS_USER_H) +-#include <sys/user.h> +-#endif + #if defined(HAVE_SYS_UTSNAME_H) + #include <sys/utsname.h> + #endif +-- +2.31.1 + diff --git a/pat/gcc-alpine/0030-gcc-go-Fix-ucontext_t-on-PPC64.patch b/pat/gcc-alpine/0030-gcc-go-Fix-ucontext_t-on-PPC64.patch @@ -0,0 +1,29 @@ +From f1503cf97b5a5c6f9466145f5eb1ed3b5f200119 Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Sun, 30 Aug 2020 17:59:22 +0200 +Subject: [PATCH] gcc-go: Fix ucontext_t on PPC64 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Taken from Adélie Linux. +--- + libgo/runtime/go-signal.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c +index b429fdb2403..fd1c885f043 100644 +--- a/libgo/runtime/go-signal.c ++++ b/libgo/runtime/go-signal.c +@@ -224,7 +224,7 @@ getSiginfo(siginfo_t *info, void *context __attribute__((unused))) + #elif defined(__alpha__) && defined(__linux__) + ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.sc_pc; + #elif defined(__PPC__) && defined(__linux__) +- ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.regs->nip; ++ ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.gp_regs[32]; + #elif defined(__PPC__) && defined(_AIX) + ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.jmp_context.iar; + #elif defined(__aarch64__) && defined(__linux__) +-- +2.31.1 + diff --git a/pat/gcc-alpine/0031-gcc-go-Fix-handling-of-signal-34-on-musl.patch b/pat/gcc-alpine/0031-gcc-go-Fix-handling-of-signal-34-on-musl.patch @@ -0,0 +1,43 @@ +From fc950e32b9ebc2bae09604ebe630df6df454151d Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Sun, 30 Aug 2020 17:59:45 +0200 +Subject: [PATCH] gcc-go: Fix handling of signal 34 on musl +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Taken from Adélie Linux. +--- + libgo/mksigtab.sh | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/libgo/mksigtab.sh b/libgo/mksigtab.sh +index 11e4ec436bd..fe866eacb27 100644 +--- a/libgo/mksigtab.sh ++++ b/libgo/mksigtab.sh +@@ -82,7 +82,7 @@ checksig _SIGPWR '{_SigNotify, "SIGPWR: power failure restart"}' + checksig _SIGEMT '{_SigThrow, "SIGEMT: emulate instruction executed"}' + checksig _SIGINFO '{_SigNotify, "SIGINFO: status request from keyboard"}' + checksig _SIGTHR '{_SigNotify, "SIGTHR: reserved"}' +-checksig _SIGPOLL '{_SigNotify, "SIGPOLL: pollable event occurred"}' ++#checksig _SIGPOLL '{_SigNotify, "SIGPOLL: pollable event occurred"}' + checksig _SIGWAITING '{_SigNotify, "SIGWAITING: reserved signal no longer used by"}' + checksig _SIGLWP '{_SigNotify, "SIGLWP: reserved signal no longer used by"}' + checksig _SIGFREEZE '{_SigNotify, "SIGFREEZE: special signal used by CPR"}' +@@ -95,10 +95,12 @@ checksig _SIGLOST ' {_SigNotify, "SIGLOST: resource lost (Sun); server died (G + + # Special handling of signals 32 and 33 on GNU/Linux systems, + # because they are special to glibc. ++# Signal 34 is additionally special to Linux systems with musl. + if test "${GOOS}" = "linux"; then +- SIGLIST=$SIGLIST"_32__33_" ++ SIGLIST=$SIGLIST"_32__33__34_" + echo ' 32: {_SigSetStack + _SigUnblock, "signal 32"}, /* SIGCANCEL; see issue 6997 */' + echo ' 33: {_SigSetStack + _SigUnblock, "signal 33"}, /* SIGSETXID; see issues 3871, 9400, 12498 */' ++ echo ' 34: {_SigSetStack + _SigUnblock, "signal 34"}, /* see issue 30062 */' + fi + + if test "${GOOS}" = "aix"; then +-- +2.31.1 + diff --git a/pat/gcc-alpine/0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch b/pat/gcc-alpine/0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch @@ -0,0 +1,38 @@ +From 3be2284d92c560204e9eddb20db56d57fe584360 Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Sun, 30 Aug 2020 18:01:03 +0200 +Subject: [PATCH] gcc-go: Use int64 type as offset argument for mmap +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Taken from Adélie Linux. +--- + libgo/go/runtime/mem_gccgo.go | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go +index ba38ebaa9ab..3c9e5ce9461 100644 +--- a/libgo/go/runtime/mem_gccgo.go ++++ b/libgo/go/runtime/mem_gccgo.go +@@ -15,7 +15,7 @@ import ( + //go:linkname sysFree + + //extern mmap +-func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) unsafe.Pointer ++func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off int64) unsafe.Pointer + + //extern munmap + func munmap(addr unsafe.Pointer, length uintptr) int32 +@@ -37,7 +37,7 @@ func init() { + } + } + +-func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (unsafe.Pointer, int) { ++func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off int64) (unsafe.Pointer, int) { + p := sysMmap(addr, n, prot, flags, fd, off) + if uintptr(p) == _MAP_FAILED { + return nil, errno() +-- +2.31.1 + diff --git a/pat/gcc-alpine/0033-gcc-go-Fix-st_-a-m-c-tim-fields-in-generated-sysinfo.patch b/pat/gcc-alpine/0033-gcc-go-Fix-st_-a-m-c-tim-fields-in-generated-sysinfo.patch @@ -0,0 +1,24 @@ +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +From: Olsken (updated patches) +Date: Sat, 21 Aug 2021 08:51:52 +0000 +Subject: [PATCH] gcc-go: Fix st_{a,m,c}tim fields in generated sysinfo.go + +There are more than one st_{a,m,c}tim fields in struct stat on time64 machines. + +Run the Go-isation on all of them. + +Taken from Adélie Linux. + +diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh +index 0c52ea5d7..6fef104cc 100755 +--- a/libgo/mksysinfo.sh ++++ b/libgo/mksysinfo.sh +@@ -510,7 +510,7 @@ fi + + # For historical reasons Go uses the suffix "timespec" instead of "tim" for + # stat_t's time fields on NetBSD. +-st_times='-e s/st_atim/Atim/ -e s/st_mtim/Mtim/ -e s/st_ctim/Ctim/' ++st_times='-e s/st_atim/Atim/g -e s/st_mtim/Mtim/g -e s/st_ctim/Ctim/g' + if test "${GOOS}" = "netbsd"; then + st_times='-e s/st_atim/Atimespec/ -e s/st_mtim/Mtimespec/ -e s/st_ctim/Ctimespec/' + fi diff --git a/pat/gcc-alpine/0034-gcc-go-signal-34-is-special-on-musl-libc.patch b/pat/gcc-alpine/0034-gcc-go-signal-34-is-special-on-musl-libc.patch @@ -0,0 +1,29 @@ +From dd1465b56f76ada5c7383ebd98ef02311a3b907c Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Sun, 30 Aug 2020 18:03:03 +0200 +Subject: [PATCH] gcc-go: signal 34 is special on musl libc +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Taken from Adélie Linux. +--- + libgo/go/runtime/signal_gccgo.go | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libgo/go/runtime/signal_gccgo.go b/libgo/go/runtime/signal_gccgo.go +index c555712a03c..9e228580d37 100644 +--- a/libgo/go/runtime/signal_gccgo.go ++++ b/libgo/go/runtime/signal_gccgo.go +@@ -106,7 +106,7 @@ func getsig(i uint32) uintptr { + if sigaction(i, nil, &sa) < 0 { + // On GNU/Linux glibc rejects attempts to call + // sigaction with signal 32 (SIGCANCEL) or 33 (SIGSETXID). +- if GOOS == "linux" && (i == 32 || i == 33) { ++ if GOOS == "linux" && (i == 32 || i == 33 || i == 34) { + return _SIG_DFL + } + throw("sigaction read failure") +-- +2.31.1 + diff --git a/pat/gcc-alpine/0035-gcc-go-Prefer-_off_t-over-_off64_t.patch b/pat/gcc-alpine/0035-gcc-go-Prefer-_off_t-over-_off64_t.patch @@ -0,0 +1,30 @@ +From 382d4516db8a7c183e9d7b5ec16a9bc175523ac9 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net> +Date: Sun, 30 Aug 2020 19:26:53 +0200 +Subject: [PATCH] gcc-go: Prefer _off_t over _off64_t + +musl does not seem to have _off64_t. +--- + libgo/mksysinfo.sh | 6 +----- + 1 file changed, 1 insertion(+), 5 deletions(-) + +diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh +index 972e2c379bc..8d6da15f983 100755 +--- a/libgo/mksysinfo.sh ++++ b/libgo/mksysinfo.sh +@@ -379,11 +379,7 @@ fi + # Some basic types. + echo 'type Size_t _size_t' >> ${OUT} + echo "type Ssize_t _ssize_t" >> ${OUT} +-if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then +- echo "type Offset_t _off64_t" >> ${OUT} +-else +- echo "type Offset_t _off_t" >> ${OUT} +-fi ++echo "type Offset_t _off_t" >> ${OUT} + echo "type Mode_t _mode_t" >> ${OUT} + echo "type Pid_t _pid_t" >> ${OUT} + echo "type Uid_t _uid_t" >> ${OUT} +-- +2.31.1 + diff --git a/pat/gcc-alpine/0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c.patch b/pat/gcc-alpine/0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c.patch @@ -0,0 +1,27 @@ +From 79d8ab42aefb1d3c5f794f51df643ab040c30e30 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net> +Date: Sun, 30 Aug 2020 19:27:51 +0200 +Subject: [PATCH] gcc-go: undef SETCONTEXT_CLOBBERS_TLS in proc.c + +--- + libgo/runtime/proc.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c +index 6f7d2e27996..5afd7902497 100644 +--- a/libgo/runtime/proc.c ++++ b/libgo/runtime/proc.c +@@ -66,6 +66,10 @@ static void gscanstack(G*); + + __thread G *g __asm__(GOSYM_PREFIX "runtime.g"); + ++/* libucontext does not seem to support tlsbase, undef the macro ++ * here to make sure we define initcontext and fixcontext as dummies. */ ++#undef SETCONTEXT_CLOBBERS_TLS ++ + #ifndef SETCONTEXT_CLOBBERS_TLS + + static inline void +-- +2.31.1 + diff --git a/pat/gcc-alpine/0037-gcc-go-link-to-libucontext.patch b/pat/gcc-alpine/0037-gcc-go-link-to-libucontext.patch @@ -0,0 +1,25 @@ +From d42de24395e4f07cf6412896d4cd8c7f83a9b875 Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> +Date: Mon, 31 Aug 2020 08:59:40 +0200 +Subject: [PATCH] gcc-go: link to libucontext + +--- + Makefile.in | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile.in b/Makefile.in +index 63627db68cf..c7f1f84d683 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -48823,7 +48823,7 @@ configure-target-libgo: + esac; \ + module_srcdir=libgo; \ + rm -f no-such-file || : ; \ +- CONFIG_SITE=no-such-file $(SHELL) \ ++ CONFIG_SITE=no-such-file LIBS="-lucontext $$LIBS" $(SHELL) \ + $$s/$$module_srcdir/configure \ + --srcdir=$${topdir}/$$module_srcdir \ + $(TARGET_CONFIGARGS) --build=${build_alias} --host=${target_alias} \ +-- +2.31.1 + diff --git a/pat/gcc-alpine/0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct.patch b/pat/gcc-alpine/0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct.patch @@ -0,0 +1,26 @@ +From 570cd2b596daf12e8dfe1a444fe405a7c26fc2bc Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net> +Date: Mon, 31 Aug 2020 20:26:56 +0200 +Subject: [PATCH] gcc-go: Disable printing of unaccessible ppc64 struct members + +These struct members do not seem to exist on musl. +--- + libgo/runtime/go-signal.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c +index fd1c885f043..e845e453332 100644 +--- a/libgo/runtime/go-signal.c ++++ b/libgo/runtime/go-signal.c +@@ -333,7 +333,7 @@ dumpregs(siginfo_t *info __attribute__((unused)), void *context __attribute__((u + runtime_printf("sp %X\n", m->sc_regs[30]); + runtime_printf("pc %X\n", m->sc_pc); + } +-#elif defined(__PPC__) && defined(__LITTLE_ENDIAN__) && defined(__linux__) ++#elif defined(__PPC__) && defined(__LITTLE_ENDIAN__) && defined(__GLIBC__) + { + mcontext_t *m = &((ucontext_t*)(context))->uc_mcontext; + int i; +-- +2.31.1 + diff --git a/pat/gcc-alpine/0040-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch b/pat/gcc-alpine/0040-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch @@ -0,0 +1,264 @@ +From: Drew DeVault <sir@cmpwn.com> +From: Olsken (updated patches) +Date: Sat, 21 Aug 2021 08:51:52 +0000 +Subject: [PATCH] configure: Add --enable-autolink-libatomic, use in + LINK_GCC_C_SEQUENCE_SPEC [PR81358] + +This fixes issues with RISC-V. + +diff --git a/Makefile.in b/Makefile.in +index 047be0255..765f6b89b 100644 +--- a/Makefile.in ++++ b/Makefile.in +@@ -221,6 +221,7 @@ HOST_EXPORTS = \ + RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)"; export RANLIB_FOR_TARGET; \ + READELF_FOR_TARGET="$(READELF_FOR_TARGET)"; export READELF_FOR_TARGET; \ + TOPLEVEL_CONFIGURE_ARGUMENTS="$(TOPLEVEL_CONFIGURE_ARGUMENTS)"; export TOPLEVEL_CONFIGURE_ARGUMENTS; \ ++ TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS; \ + HOST_LIBS="$(STAGE1_LIBS)"; export HOST_LIBS; \ + GMPLIBS="$(HOST_GMPLIBS)"; export GMPLIBS; \ + GMPINC="$(HOST_GMPINC)"; export GMPINC; \ +diff --git a/gcc/config.in b/gcc/config.in +index 313c13c8e..d0287d4cc 100644 +--- a/gcc/config.in ++++ b/gcc/config.in +@@ -106,6 +106,12 @@ + #endif + + ++/* Define if libatomic should always be linked. */ ++#ifndef USED_FOR_TARGET ++#undef ENABLE_AUTOLINK_LIBATOMIC ++#endif ++ ++ + /* Define to 1 to specify that we are using the BID decimal floating point + format instead of DPD */ + #ifndef USED_FOR_TARGET +diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h +index e1a04e9fd..ef1ffa6d2 100644 +--- a/gcc/config/gnu-user.h ++++ b/gcc/config/gnu-user.h +@@ -109,8 +109,18 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + #define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} " + #endif + ++#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC) ++# ifdef LD_AS_NEEDED_OPTION ++# define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION ++# else ++# define LINK_LIBATOMIC_SPEC "-latomic" ++# endif ++#elif !defined(LINK_LIBATOMIC_SPEC) ++# define LINK_LIBATOMIC_SPEC "" ++#endif ++ + #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \ +- "%{static|static-pie:--start-group} %G %{!nolibc:%L} \ ++ "%{static|static-pie:--start-group} %G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L} \ + %{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}" + + #undef LINK_GCC_C_SEQUENCE_SPEC +diff --git a/gcc/configure b/gcc/configure +index 9b28369e3..8afa1c84f 100755 +--- a/gcc/configure ++++ b/gcc/configure +@@ -978,6 +978,7 @@ with_changes_root_url + enable_languages + with_multilib_list + with_multilib_generator ++enable_autolink_libatomic + with_zstd + with_zstd_include + with_zstd_lib +@@ -1706,6 +1707,9 @@ Optional Features: + --disable-shared don't provide a shared libgcc + --disable-gcov don't provide libgcov and related host tools + --enable-languages=LIST specify which front-ends to build ++ --enable-autolink-libatomic ++ enable automatic linking of libatomic (ignored if ++ not built) + --disable-rpath do not hardcode runtime library paths + --enable-sjlj-exceptions + arrange to use setjmp/longjmp exception handling +@@ -8076,6 +8080,33 @@ else + fi + + ++# If libatomic is available, whether it should be linked automatically ++# Check whether --enable-autolink-libatomic was given. ++if test "${enable_autolink_libatomic+set}" = set; then : ++ enableval=$enable_autolink_libatomic; ++ case $enable_autolink_libatomic in ++ yes | no) ;; ++ *) as_fn_error $? "'$enable_autolink_libatomic' is an invalid value for ++--enable-autolink-libatomic. Valid choices are 'yes' and 'no'." "$LINENO" 5 ;; ++ esac ++ ++else ++ enable_autolink_libatomic='' ++fi ++ ++ ++if test x$enable_autolink_libatomic = xyes; then ++ if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then ++ ++$as_echo "#define ENABLE_AUTOLINK_LIBATOMIC 1" >>confdefs.h ++ ++ else ++ { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libatomic is not build for this target, --enable-autolink-libatomic ignored" >&5 ++$as_echo "$as_me: WARNING: libatomic is not build for this target, --enable-autolink-libatomic ignored" >&2;} ++ fi ++fi ++ ++ + # ------------------------- + # Checks for other programs + # ------------------------- +@@ -19392,7 +19423,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 19395 "configure" ++#line 19426 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -19498,7 +19529,7 @@ else + lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 + lt_status=$lt_dlunknown + cat > conftest.$ac_ext <<_LT_EOF +-#line 19501 "configure" ++#line 19532 "configure" + #include "confdefs.h" + + #if HAVE_DLFCN_H +@@ -33588,4 +33619,3 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then + $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} + fi + +- +diff --git a/gcc/configure.ac b/gcc/configure.ac +index 162e08cbc..115ba8ac6 100644 +--- a/gcc/configure.ac ++++ b/gcc/configure.ac +@@ -1149,6 +1149,28 @@ AC_ARG_WITH(multilib-generator, + :, + with_multilib_generator=default) + ++# If libatomic is available, whether it should be linked automatically ++AC_ARG_ENABLE(autolink-libatomic, ++[AS_HELP_STRING([--enable-autolink-libatomic], ++ [enable automatic linking of libatomic (ignored if not built)])], ++[ ++ case $enable_autolink_libatomic in ++ yes | no) ;; ++ *) AC_MSG_ERROR(['$enable_autolink_libatomic' is an invalid value for ++--enable-autolink-libatomic. Valid choices are 'yes' and 'no'.]) ;; ++ esac ++], [enable_autolink_libatomic='']) ++ ++if test x$enable_autolink_libatomic = xyes; then ++ if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then ++ AC_DEFINE(ENABLE_AUTOLINK_LIBATOMIC, 1, ++ [Define if libatomic should always be linked.]) ++ else ++ AC_MSG_WARN([libatomic is not build for this target, --enable-autolink-libatomic ignored]) ++ fi ++fi ++ ++ + # ------------------------- + # Checks for other programs + # ------------------------- +@@ -7553,4 +7575,3 @@ done + ], + [subdirs='$subdirs']) + AC_OUTPUT +- +diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi +index 4c38244ae..4a544e6a4 100644 +--- a/gcc/doc/install.texi ++++ b/gcc/doc/install.texi +@@ -2213,6 +2213,14 @@ files, but these changed header paths may conflict with some compilation + environments. Enabled by default, and may be disabled using + @option{--disable-canonical-system-headers}. + ++@item --enable-autolink-libatomic ++@itemx --disable-autolink-libatomic ++Tell GCC that it should automatically link libatomic; if supported by ++the linker, the file is only linked as needed. This flag is ignored ++when libatomic is not built. Note that this conigure flag is in particular ++useful when building an offloading-target compiler; as for those, a ++user had to specify @code{-foffload=target=-latomic} otherwise. ++ + @item --with-glibc-version=@var{major}.@var{minor} + Tell GCC that when the GNU C Library (glibc) is used on the target it + will be version @var{major}.@var{minor} or later. Normally this can +diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi +index b370bc76b..acc782739 100644 +--- a/gcc/doc/tm.texi ++++ b/gcc/doc/tm.texi +@@ -381,7 +381,13 @@ the argument @option{-lgcc} to tell the linker to do the search. + + @defmac LINK_GCC_C_SEQUENCE_SPEC + The sequence in which libgcc and libc are specified to the linker. +-By default this is @code{%G %L %G}. ++By default this is @code{%G LINK_LIBATOMIC_SPEC %L %G}. ++@end defmac ++ ++@defmac LINK_LIBATOMIC_SPEC ++This macro is used in the default @code{LINK_GCC_C_SEQUENCE_SPEC} to link ++libatomic. By default, it is unset unless @code{ENABLE_AUTOLINK_LIBATOMIC} ++is set. + @end defmac + + @defmac POST_LINK_SPEC +diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in +index 2974dae27..80e003a38 100644 +--- a/gcc/doc/tm.texi.in ++++ b/gcc/doc/tm.texi.in +@@ -381,7 +381,13 @@ the argument @option{-lgcc} to tell the linker to do the search. + + @defmac LINK_GCC_C_SEQUENCE_SPEC + The sequence in which libgcc and libc are specified to the linker. +-By default this is @code{%G %L %G}. ++By default this is @code{%G LINK_LIBATOMIC_SPEC %L %G}. ++@end defmac ++ ++@defmac LINK_LIBATOMIC_SPEC ++This macro is used in the default @code{LINK_GCC_C_SEQUENCE_SPEC} to link ++libatomic. By default, it is unset unless @code{ENABLE_AUTOLINK_LIBATOMIC} ++is set. + @end defmac + + @defmac POST_LINK_SPEC +diff --git a/gcc/gcc.c b/gcc/gcc.c +index d7f3ee55c..bc1bd1686 100644 +--- a/gcc/gcc.c ++++ b/gcc/gcc.c +@@ -980,13 +980,23 @@ proper position among the other output files. */ + # define ASM_DEBUG_OPTION_SPEC "" + #endif + ++#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC) ++# ifdef LD_AS_NEEDED_OPTION ++# define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION ++# else ++# define LINK_LIBATOMIC_SPEC "-latomic" ++# endif ++#elif !defined(LINK_LIBATOMIC_SPEC) ++# define LINK_LIBATOMIC_SPEC "" ++#endif ++ + /* Here is the spec for running the linker, after compiling all files. */ + + /* This is overridable by the target in case they need to specify the + -lgcc and -lc order specially, yet not require them to override all + of LINK_COMMAND_SPEC. */ + #ifndef LINK_GCC_C_SEQUENCE_SPEC +-#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}" ++#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L %G}" + #endif + + #ifdef ENABLE_DEFAULT_SSP diff --git a/pat/gcc-alpine/0041-Use-generic-errstr.go-implementation-on-musl.patch b/pat/gcc-alpine/0041-Use-generic-errstr.go-implementation-on-musl.patch @@ -0,0 +1,48 @@ +From 70d70a1106b31ab840dbf5361312af221a2d5f04 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git@soeren-tempel.net> +Date: Mon, 19 Apr 2021 07:21:41 +0200 +Subject: [PATCH] Use generic errstr.go implementation on musl + +glibc provides two version of strerror_r() depending on a feature test +macro. The first is the XSI-compliant version which returns an int, the +second is GNU-specific and returns a char pointer. + +Similarity, gcc's libgo provides two implementations of Errstr() both of +which use strerror_r(). On Linux, it is assumed that the GNU-specific +strerror_r version is used. However, musl only provides the +XSI-compliant version of strerror_r. This patch enables the generic +Errstr() implementation which also uses the XSI-compliant version of +strerror_r. +--- + libgo/go/syscall/errstr.go | 1 - + libgo/go/syscall/errstr_glibc.go | 2 +- + 2 files changed, 1 insertion(+), 2 deletions(-) + +diff --git a/libgo/go/syscall/errstr.go b/libgo/go/syscall/errstr.go +index 6c2441d364d..8f7c5538163 100644 +--- a/libgo/go/syscall/errstr.go ++++ b/libgo/go/syscall/errstr.go +@@ -5,7 +5,6 @@ + // license that can be found in the LICENSE file. + + // +build !hurd +-// +build !linux + + package syscall + +diff --git a/libgo/go/syscall/errstr_glibc.go b/libgo/go/syscall/errstr_glibc.go +index 5b19e6f202d..8dc60172186 100644 +--- a/libgo/go/syscall/errstr_glibc.go ++++ b/libgo/go/syscall/errstr_glibc.go +@@ -7,7 +7,7 @@ + // We use this rather than errstr.go because on GNU/Linux sterror_r + // returns a pointer to the error message, and may not use buf at all. + +-// +build hurd linux ++// +build hurd !linux + + package syscall + +-- +2.31.1 + diff --git a/pat/gcc-alpine/0042-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch b/pat/gcc-alpine/0042-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch @@ -0,0 +1,21 @@ +From: Alpine Linux community +From: Olsken (updated patches) +Date: Sat, 21 Aug 2021 08:51:52 +0000 + +diff --git a/gcc/gcc.cc b/gcc/gcc.cc +index bc1bd1686..b5c83977f 100644 +--- a/gcc/gcc.cc ++++ b/gcc/gcc.cc +@@ -1005,6 +1005,12 @@ proper position among the other output files. */ + #define NO_SSP_SPEC "" + #endif + ++#ifdef ENABLE_DEFAULT_SSP ++#define NO_SSP_SPEC "%{nostdlib|nodefaultlibs|ffreestanding:-fno-stack-protector} " ++#else ++#define NO_SSP_SPEC "" ++#endif ++ + #ifndef LINK_SSP_SPEC + #ifdef TARGET_LIBC_PROVIDES_SSP + #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ diff --git a/pat/gcc-alpine/0043-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch b/pat/gcc-alpine/0043-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch @@ -0,0 +1,21 @@ +From: Alpine Linux community +From: Olsken (updated patches) +Date: Sat, 21 Aug 2021 08:51:52 +0000 + +diff --git a/gcc/config.in b/gcc/config.in +index d0287d4cc..8c10816c4 100644 +--- a/gcc/config.in ++++ b/gcc/config.in +@@ -112,6 +112,12 @@ + #endif + + ++/* Define if libatomic should always be linked. */ ++#ifndef USED_FOR_TARGET ++#undef ENABLE_AUTOLINK_LIBATOMIC ++#endif ++ ++ + /* Define to 1 to specify that we are using the BID decimal floating point + format instead of DPD */ + #ifndef USED_FOR_TARGET diff --git a/pat/gcc-alpine/apply_patches_ct.sh b/pat/gcc-alpine/apply_patches_ct.sh @@ -0,0 +1,40 @@ +#! /bin/bash + +for p in 0001-posix_memalign 0002-gcc-poison-system-directories \ + 0003-Turn-on-Wl-z-relro-z-now-by-default \ + 0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O \ + 0006-Enable-Wformat-and-Wformat-security-by-default \ + 0007-Enable-Wtrampolines-by-default \ + 0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during \ + 0010-Don-t-declare-asprintf-if-defined-as-a-macro \ + 0011-libiberty-copy-PIC-objects-during-build-process \ + 0012-libitm-disable-FORTIFY \ + 0013-libgcc_s \ + 0014-nopie \ + 0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu \ + 0016-dlang-update-zlib-binding \ + 0017-dlang-fix-fcntl-on-mips-add-libucontext-dep \ + 0018-ada-fix-shared-linking \ + 0019-build-fix-CXXFLAGS_FOR_BUILD-passing \ + 0020-add-fortify-headers-paths \ + 0023-Pure-64-bit-MIPS \ + 0024-use-pure-64-bit-configuration-where-appropriate \ + 0025-always-build-libgcc_eh.a \ + 0027-ada-musl-support-fixes \ + 0028-gcc-go-Use-_off_t-type-instead-of-_loff_t \ + 0029-gcc-go-Don-t-include-sys-user.h \ + 0030-gcc-go-Fix-ucontext_t-on-PPC64 \ + 0031-gcc-go-Fix-handling-of-signal-34-on-musl \ + 0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap \ + 0034-gcc-go-signal-34-is-special-on-musl-libc \ + 0035-gcc-go-Prefer-_off_t-over-_off64_t \ + 0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c \ + 0037-gcc-go-link-to-libucontext \ + 0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct \ + 0041-Use-generic-errstr.go-implementation-on-musl \ + 0042-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand \ + 0043-configure-Add-enable-autolink-libatomic-use-in-LINK_ \ + 0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li +do + patch -Np1 -i ../patches/gcc-alpine/$p.patch +done diff --git a/pat/gcc-mlfs/fix_fenv_header.patch b/pat/gcc-mlfs/fix_fenv_header.patch @@ -0,0 +1,32 @@ +--- gcc-11.2.0.orig/libstdc++-v3/include/c_global/cfenv 2021-07-28 01:55:09.292315320 -0500 ++++ gcc-11.2.0/libstdc++-v3/include/c_global/cfenv 2021-08-07 10:17:27.945057906 -0500 +@@ -37,9 +37,14 @@ + + #include <bits/c++config.h> + +-#if _GLIBCXX_HAVE_FENV_H +-# include <fenv.h> +-#endif ++//#if _GLIBCXX_HAVE_FENV_H ++//# include <fenv.h> ++//#endif ++// Need to ensure this finds the C library's <fenv.h> not a libstdc++ ++// wrapper that might already be installed later in the include search path. ++#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS ++# include_next <fenv.h> ++#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS + + #ifdef _GLIBCXX_USE_C99_FENV_TR1 + +--- gcc-11.2.0.orig/libstdc++-v3/include/c_compatibility/fenv.h 2021-07-28 01:55:09.292315320 -0500 ++++ gcc-11.2.0/libstdc++-v3/include/c_compatibility/fenv.h 2021-08-07 10:15:08.542063961 -0500 +@@ -25,6 +25,9 @@ + /** @file fenv.h + * This is a Standard C++ Library header. + */ ++#if !defined __cplusplus || defined _GLIBCXX_INCLUDE_NEXT_C_HEADERS ++# include_next <fenv.h> ++#else + + #ifndef _GLIBCXX_FENV_H + #define _GLIBCXX_FENV_H 1