From b5d2abe107e467cfcc2908ef403f3c2d9dc08198 Mon Sep 17 00:00:00 2001 From: Alexey Min Date: Thu, 16 Dec 2021 23:04:37 +0300 Subject: [PATCH] cross/gcc*: upgrade to 11.2.1_git20211128-r3 https://gitlab.alpinelinux.org/alpine/aports/-/commit/3a2eb3720b219388403f891319a8121e46969900 [ci:skip-build] Builds locally, no point to build on Gitlab CI --- ...t-stack-support-on-non-glibc-targets.patch | 95 +++++++++++++++++++ cross/gcc-aarch64/APKBUILD | 4 +- ...t-stack-support-on-non-glibc-targets.patch | 95 +++++++++++++++++++ cross/gcc-armhf/APKBUILD | 4 +- ...t-stack-support-on-non-glibc-targets.patch | 95 +++++++++++++++++++ cross/gcc-armv7/APKBUILD | 4 +- 6 files changed, 294 insertions(+), 3 deletions(-) create mode 100644 cross/gcc-aarch64/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch create mode 100644 cross/gcc-armhf/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch create mode 100644 cross/gcc-armv7/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch diff --git a/cross/gcc-aarch64/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch b/cross/gcc-aarch64/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch new file mode 100644 index 000000000..c6ec2dfa6 --- /dev/null +++ b/cross/gcc-aarch64/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch @@ -0,0 +1,95 @@ +From 5b7b256eafc888a3be2dcee1e01f8dc6a814d1a6 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?S=C3=B6ren=20Tempel?= +Date: Wed, 15 Dec 2021 00:14:19 +0100 +Subject: [PATCH] Disable -fsplit-stack support on non-glibc targets + +The -fsplit-stack option requires the pthread_t TCB definition in the +libc to provide certain struct fields at specific hardcoded offsets. As +far as I know, only glibc provides these fields at the required offsets. +Most notably, musl libc does not have these fields. However, since gcc +accesses the fields using a fixed offset this does not cause a +compile-time error but instead results in a silent memory corruption at +run-time. For example, on s390x libgcc's __stack_split_initialize CTOR +will overwrite the cancel field in the pthread_t TCB on musl. + +The -fsplit-stack option is used within the gcc code base by gcc-go by +default. On musl based systems with split-stack support (e.g. s390x or +x86) this causes Go programs compiled with gcc-go to misbehave at +run-time. + +This patch fixes gcc-go on musl by disabling -fsplit-stack in gcc itself +since it is not supported on non-glibc targets anyhow. This is achieved +by checking if TARGET_GLIBC_MAJOR is defined to a non-zero value (it +defaults to zero on non-glibc systems). The check has been added for x86 +and s390x, the rs6000 config already checks for TARGET_GLIBC_MAJOR. With +this patch applied, the gcc-go configure script will detect that +-fsplit-stack support is not available and will not use it. + +This patch has been tested on Alpine Linux Edge on the s390x +architecture by bootstrapping Google's Go implementation with gcc-go. + +See https://www.openwall.com/lists/musl/2012/10/16/12 +--- + gcc/common/config/s390/s390-common.c | 9 ++++++++- + gcc/config/i386/gnu-user-common.h | 5 +++-- + gcc/config/i386/gnu.h | 6 +++++- + 3 files changed, 16 insertions(+), 4 deletions(-) + +diff --git a/gcc/common/config/s390/s390-common.c b/gcc/common/config/s390/s390-common.c +index b6bc8501742..afbd8d3fe66 100644 +--- a/gcc/common/config/s390/s390-common.c ++++ b/gcc/common/config/s390/s390-common.c +@@ -116,13 +116,20 @@ s390_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED, + + /* -fsplit-stack uses a field in the TCB, available with glibc-2.23. + We don't verify it, since earlier versions just have padding at +- its place, which works just as well. */ ++ its place, which works just as well. For other libc implementations ++ we disable the feature entirely to avoid corrupting the TCB. */ + + static bool + s390_supports_split_stack (bool report ATTRIBUTE_UNUSED, + struct gcc_options *opts ATTRIBUTE_UNUSED) + { ++#if TARGET_GLIBC_MAJOR + return true; ++#else ++ if (report) ++ error("%<-fsplit-stack%> currently only supported on GNU/Linux"); ++ return false; ++#endif + } + + #undef TARGET_DEFAULT_TARGET_FLAGS +diff --git a/gcc/config/i386/gnu-user-common.h b/gcc/config/i386/gnu-user-common.h +index 00226f5a455..554e146dbbe 100644 +--- a/gcc/config/i386/gnu-user-common.h ++++ b/gcc/config/i386/gnu-user-common.h +@@ -66,7 +66,8 @@ along with GCC; see the file COPYING3. If not see + #define STACK_CHECK_STATIC_BUILTIN 1 + + /* We only build the -fsplit-stack support in libgcc if the +- assembler has full support for the CFI directives. */ +-#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE ++ assembler has full support for the CFI directives and ++ uses glibc. */ ++#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && TARGET_GLIBC_MAJOR + #define TARGET_CAN_SPLIT_STACK + #endif +diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h +index 25fbc07f58c..895a7369816 100644 +--- a/gcc/config/i386/gnu.h ++++ b/gcc/config/i386/gnu.h +@@ -35,7 +35,11 @@ along with GCC. If not, see . + crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" + #endif + +-#ifdef TARGET_LIBC_PROVIDES_SSP ++/* -fsplit-stack uses a field in the TCB at a fixed offset. This ++ field is only available for glibc. Disable -fsplit-stack for ++ other libc implementation to avoid silent TCB corruptions. */ ++ ++#if defined (TARGET_LIBC_PROVIDES_SSP) && TARGET_GLIBC_MAJOR + + /* i386 glibc provides __stack_chk_guard in %gs:0x14. */ + #define TARGET_THREAD_SSP_OFFSET 0x14 diff --git a/cross/gcc-aarch64/APKBUILD b/cross/gcc-aarch64/APKBUILD index 9c15045a1..e32aacfcd 100644 --- a/cross/gcc-aarch64/APKBUILD +++ b/cross/gcc-aarch64/APKBUILD @@ -31,7 +31,7 @@ pkgver=11.2.1_git20211128 [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-aarch64 -pkgrel=2 +pkgrel=3 pkgdesc="Stage2 cross-compiler for aarch64" url="https://gcc.gnu.org" arch="x86_64" @@ -242,6 +242,7 @@ source="https://dev.alpinelinux.org/~nenolod/gcc-${pkgver}.tar.xz 0039-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch 0040-stddef.h-add-support-for-musl-typedef-macro-guards.patch 0041-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch + 0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch " # we build out-of-tree @@ -745,4 +746,5 @@ ca185b3e0644dab6a87bf524042c72069ffda0cde578e803bd59a9c5e40ba4d7d6f0be49836bc3aa 2c5edf9e3fe6822a322c1dc75218062afb56799c304aa583c4e1e80136c6262cbd9bb950843f167b40639c6623a33a0475990c4452e03307af434dc8760d437d 0039-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch 8e44678fc77094a2c0cbc78575759ee51d50ea53189cf4d651c8501eb1b46210bb6d5969b81f5f63532914320971e7a1e2e80b32cb679ab41af86f21742b4c19 0040-stddef.h-add-support-for-musl-typedef-macro-guards.patch e4d2466191b4acde115917506c285b617d6210bf3603e705ca3d905e4e28b12e399b16898f6ab9996b1d4fbfa3aed554e86931ed7f13fc13a9459af7f29f4393 0041-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +5e04b9a6d39b708daedcef494e4aed59b1a97d2052ed7eb8d1e3da5faa70dc5e1fa3ee249c685e820109d5605ee2b66154856b0ffccf7b8a49af1a1da9350ebf 0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch " diff --git a/cross/gcc-armhf/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch b/cross/gcc-armhf/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch new file mode 100644 index 000000000..c6ec2dfa6 --- /dev/null +++ b/cross/gcc-armhf/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch @@ -0,0 +1,95 @@ +From 5b7b256eafc888a3be2dcee1e01f8dc6a814d1a6 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?S=C3=B6ren=20Tempel?= +Date: Wed, 15 Dec 2021 00:14:19 +0100 +Subject: [PATCH] Disable -fsplit-stack support on non-glibc targets + +The -fsplit-stack option requires the pthread_t TCB definition in the +libc to provide certain struct fields at specific hardcoded offsets. As +far as I know, only glibc provides these fields at the required offsets. +Most notably, musl libc does not have these fields. However, since gcc +accesses the fields using a fixed offset this does not cause a +compile-time error but instead results in a silent memory corruption at +run-time. For example, on s390x libgcc's __stack_split_initialize CTOR +will overwrite the cancel field in the pthread_t TCB on musl. + +The -fsplit-stack option is used within the gcc code base by gcc-go by +default. On musl based systems with split-stack support (e.g. s390x or +x86) this causes Go programs compiled with gcc-go to misbehave at +run-time. + +This patch fixes gcc-go on musl by disabling -fsplit-stack in gcc itself +since it is not supported on non-glibc targets anyhow. This is achieved +by checking if TARGET_GLIBC_MAJOR is defined to a non-zero value (it +defaults to zero on non-glibc systems). The check has been added for x86 +and s390x, the rs6000 config already checks for TARGET_GLIBC_MAJOR. With +this patch applied, the gcc-go configure script will detect that +-fsplit-stack support is not available and will not use it. + +This patch has been tested on Alpine Linux Edge on the s390x +architecture by bootstrapping Google's Go implementation with gcc-go. + +See https://www.openwall.com/lists/musl/2012/10/16/12 +--- + gcc/common/config/s390/s390-common.c | 9 ++++++++- + gcc/config/i386/gnu-user-common.h | 5 +++-- + gcc/config/i386/gnu.h | 6 +++++- + 3 files changed, 16 insertions(+), 4 deletions(-) + +diff --git a/gcc/common/config/s390/s390-common.c b/gcc/common/config/s390/s390-common.c +index b6bc8501742..afbd8d3fe66 100644 +--- a/gcc/common/config/s390/s390-common.c ++++ b/gcc/common/config/s390/s390-common.c +@@ -116,13 +116,20 @@ s390_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED, + + /* -fsplit-stack uses a field in the TCB, available with glibc-2.23. + We don't verify it, since earlier versions just have padding at +- its place, which works just as well. */ ++ its place, which works just as well. For other libc implementations ++ we disable the feature entirely to avoid corrupting the TCB. */ + + static bool + s390_supports_split_stack (bool report ATTRIBUTE_UNUSED, + struct gcc_options *opts ATTRIBUTE_UNUSED) + { ++#if TARGET_GLIBC_MAJOR + return true; ++#else ++ if (report) ++ error("%<-fsplit-stack%> currently only supported on GNU/Linux"); ++ return false; ++#endif + } + + #undef TARGET_DEFAULT_TARGET_FLAGS +diff --git a/gcc/config/i386/gnu-user-common.h b/gcc/config/i386/gnu-user-common.h +index 00226f5a455..554e146dbbe 100644 +--- a/gcc/config/i386/gnu-user-common.h ++++ b/gcc/config/i386/gnu-user-common.h +@@ -66,7 +66,8 @@ along with GCC; see the file COPYING3. If not see + #define STACK_CHECK_STATIC_BUILTIN 1 + + /* We only build the -fsplit-stack support in libgcc if the +- assembler has full support for the CFI directives. */ +-#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE ++ assembler has full support for the CFI directives and ++ uses glibc. */ ++#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && TARGET_GLIBC_MAJOR + #define TARGET_CAN_SPLIT_STACK + #endif +diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h +index 25fbc07f58c..895a7369816 100644 +--- a/gcc/config/i386/gnu.h ++++ b/gcc/config/i386/gnu.h +@@ -35,7 +35,11 @@ along with GCC. If not, see . + crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" + #endif + +-#ifdef TARGET_LIBC_PROVIDES_SSP ++/* -fsplit-stack uses a field in the TCB at a fixed offset. This ++ field is only available for glibc. Disable -fsplit-stack for ++ other libc implementation to avoid silent TCB corruptions. */ ++ ++#if defined (TARGET_LIBC_PROVIDES_SSP) && TARGET_GLIBC_MAJOR + + /* i386 glibc provides __stack_chk_guard in %gs:0x14. */ + #define TARGET_THREAD_SSP_OFFSET 0x14 diff --git a/cross/gcc-armhf/APKBUILD b/cross/gcc-armhf/APKBUILD index d63d608fa..5ed9dcd91 100644 --- a/cross/gcc-armhf/APKBUILD +++ b/cross/gcc-armhf/APKBUILD @@ -31,7 +31,7 @@ pkgver=11.2.1_git20211128 [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-armhf -pkgrel=2 +pkgrel=3 pkgdesc="Stage2 cross-compiler for armhf" url="https://gcc.gnu.org" arch="x86_64" @@ -242,6 +242,7 @@ source="https://dev.alpinelinux.org/~nenolod/gcc-${pkgver}.tar.xz 0039-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch 0040-stddef.h-add-support-for-musl-typedef-macro-guards.patch 0041-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch + 0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch " # we build out-of-tree @@ -745,4 +746,5 @@ ca185b3e0644dab6a87bf524042c72069ffda0cde578e803bd59a9c5e40ba4d7d6f0be49836bc3aa 2c5edf9e3fe6822a322c1dc75218062afb56799c304aa583c4e1e80136c6262cbd9bb950843f167b40639c6623a33a0475990c4452e03307af434dc8760d437d 0039-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch 8e44678fc77094a2c0cbc78575759ee51d50ea53189cf4d651c8501eb1b46210bb6d5969b81f5f63532914320971e7a1e2e80b32cb679ab41af86f21742b4c19 0040-stddef.h-add-support-for-musl-typedef-macro-guards.patch e4d2466191b4acde115917506c285b617d6210bf3603e705ca3d905e4e28b12e399b16898f6ab9996b1d4fbfa3aed554e86931ed7f13fc13a9459af7f29f4393 0041-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +5e04b9a6d39b708daedcef494e4aed59b1a97d2052ed7eb8d1e3da5faa70dc5e1fa3ee249c685e820109d5605ee2b66154856b0ffccf7b8a49af1a1da9350ebf 0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch " diff --git a/cross/gcc-armv7/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch b/cross/gcc-armv7/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch new file mode 100644 index 000000000..c6ec2dfa6 --- /dev/null +++ b/cross/gcc-armv7/0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch @@ -0,0 +1,95 @@ +From 5b7b256eafc888a3be2dcee1e01f8dc6a814d1a6 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?S=C3=B6ren=20Tempel?= +Date: Wed, 15 Dec 2021 00:14:19 +0100 +Subject: [PATCH] Disable -fsplit-stack support on non-glibc targets + +The -fsplit-stack option requires the pthread_t TCB definition in the +libc to provide certain struct fields at specific hardcoded offsets. As +far as I know, only glibc provides these fields at the required offsets. +Most notably, musl libc does not have these fields. However, since gcc +accesses the fields using a fixed offset this does not cause a +compile-time error but instead results in a silent memory corruption at +run-time. For example, on s390x libgcc's __stack_split_initialize CTOR +will overwrite the cancel field in the pthread_t TCB on musl. + +The -fsplit-stack option is used within the gcc code base by gcc-go by +default. On musl based systems with split-stack support (e.g. s390x or +x86) this causes Go programs compiled with gcc-go to misbehave at +run-time. + +This patch fixes gcc-go on musl by disabling -fsplit-stack in gcc itself +since it is not supported on non-glibc targets anyhow. This is achieved +by checking if TARGET_GLIBC_MAJOR is defined to a non-zero value (it +defaults to zero on non-glibc systems). The check has been added for x86 +and s390x, the rs6000 config already checks for TARGET_GLIBC_MAJOR. With +this patch applied, the gcc-go configure script will detect that +-fsplit-stack support is not available and will not use it. + +This patch has been tested on Alpine Linux Edge on the s390x +architecture by bootstrapping Google's Go implementation with gcc-go. + +See https://www.openwall.com/lists/musl/2012/10/16/12 +--- + gcc/common/config/s390/s390-common.c | 9 ++++++++- + gcc/config/i386/gnu-user-common.h | 5 +++-- + gcc/config/i386/gnu.h | 6 +++++- + 3 files changed, 16 insertions(+), 4 deletions(-) + +diff --git a/gcc/common/config/s390/s390-common.c b/gcc/common/config/s390/s390-common.c +index b6bc8501742..afbd8d3fe66 100644 +--- a/gcc/common/config/s390/s390-common.c ++++ b/gcc/common/config/s390/s390-common.c +@@ -116,13 +116,20 @@ s390_handle_option (struct gcc_options *opts ATTRIBUTE_UNUSED, + + /* -fsplit-stack uses a field in the TCB, available with glibc-2.23. + We don't verify it, since earlier versions just have padding at +- its place, which works just as well. */ ++ its place, which works just as well. For other libc implementations ++ we disable the feature entirely to avoid corrupting the TCB. */ + + static bool + s390_supports_split_stack (bool report ATTRIBUTE_UNUSED, + struct gcc_options *opts ATTRIBUTE_UNUSED) + { ++#if TARGET_GLIBC_MAJOR + return true; ++#else ++ if (report) ++ error("%<-fsplit-stack%> currently only supported on GNU/Linux"); ++ return false; ++#endif + } + + #undef TARGET_DEFAULT_TARGET_FLAGS +diff --git a/gcc/config/i386/gnu-user-common.h b/gcc/config/i386/gnu-user-common.h +index 00226f5a455..554e146dbbe 100644 +--- a/gcc/config/i386/gnu-user-common.h ++++ b/gcc/config/i386/gnu-user-common.h +@@ -66,7 +66,8 @@ along with GCC; see the file COPYING3. If not see + #define STACK_CHECK_STATIC_BUILTIN 1 + + /* We only build the -fsplit-stack support in libgcc if the +- assembler has full support for the CFI directives. */ +-#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE ++ assembler has full support for the CFI directives and ++ uses glibc. */ ++#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && TARGET_GLIBC_MAJOR + #define TARGET_CAN_SPLIT_STACK + #endif +diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h +index 25fbc07f58c..895a7369816 100644 +--- a/gcc/config/i386/gnu.h ++++ b/gcc/config/i386/gnu.h +@@ -35,7 +35,11 @@ along with GCC. If not, see . + crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" + #endif + +-#ifdef TARGET_LIBC_PROVIDES_SSP ++/* -fsplit-stack uses a field in the TCB at a fixed offset. This ++ field is only available for glibc. Disable -fsplit-stack for ++ other libc implementation to avoid silent TCB corruptions. */ ++ ++#if defined (TARGET_LIBC_PROVIDES_SSP) && TARGET_GLIBC_MAJOR + + /* i386 glibc provides __stack_chk_guard in %gs:0x14. */ + #define TARGET_THREAD_SSP_OFFSET 0x14 diff --git a/cross/gcc-armv7/APKBUILD b/cross/gcc-armv7/APKBUILD index 055d2a1a3..1b0959012 100644 --- a/cross/gcc-armv7/APKBUILD +++ b/cross/gcc-armv7/APKBUILD @@ -31,7 +31,7 @@ pkgver=11.2.1_git20211128 [ "$CHOST" != "$CTARGET" ] && _target="-$CTARGET_ARCH" || _target="" pkgname=gcc-armv7 -pkgrel=2 +pkgrel=3 pkgdesc="Stage2 cross-compiler for armv7" url="https://gcc.gnu.org" arch="x86_64" @@ -242,6 +242,7 @@ source="https://dev.alpinelinux.org/~nenolod/gcc-${pkgver}.tar.xz 0039-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch 0040-stddef.h-add-support-for-musl-typedef-macro-guards.patch 0041-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch + 0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch " # we build out-of-tree @@ -745,4 +746,5 @@ ca185b3e0644dab6a87bf524042c72069ffda0cde578e803bd59a9c5e40ba4d7d6f0be49836bc3aa 2c5edf9e3fe6822a322c1dc75218062afb56799c304aa583c4e1e80136c6262cbd9bb950843f167b40639c6623a33a0475990c4452e03307af434dc8760d437d 0039-Fix-attempt-to-use-poisoned-calloc-error-in-libgccji.patch 8e44678fc77094a2c0cbc78575759ee51d50ea53189cf4d651c8501eb1b46210bb6d5969b81f5f63532914320971e7a1e2e80b32cb679ab41af86f21742b4c19 0040-stddef.h-add-support-for-musl-typedef-macro-guards.patch e4d2466191b4acde115917506c285b617d6210bf3603e705ca3d905e4e28b12e399b16898f6ab9996b1d4fbfa3aed554e86931ed7f13fc13a9459af7f29f4393 0041-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch +5e04b9a6d39b708daedcef494e4aed59b1a97d2052ed7eb8d1e3da5faa70dc5e1fa3ee249c685e820109d5605ee2b66154856b0ffccf7b8a49af1a1da9350ebf 0042-Disable-fsplit-stack-support-on-non-glibc-targets.patch "