GCC: document & refactor patches (#413617)

Changed files
+71 -153
pkgs
-41
pkgs/development/compilers/gcc/patches/11/gcc-issue-103910.patch
···
-
From d243f4009d8071b734df16cd70f4c5d09a373769 Mon Sep 17 00:00:00 2001
-
From: Andrew Pinski <apinski@marvell.com>
-
Date: Wed, 5 Jan 2022 22:00:07 +0000
-
Subject: [PATCH] Fix target/103910: missing GTY on x86_mfence causing PCH
-
usage to ICE
-
-
With -O3 -march=opteron, a mfence builtin is added after the loop
-
to say the nontemporal stores are no longer needed. This all good
-
without precompiled headers as the function decl that is referneced
-
by x86_mfence is referenced in another variable but with precompiled
-
headers, x86_mfence is all messed up and the decl was GC'ed away.
-
This fixes the problem by marking x86_mfence as GTY to save/restore
-
during precompiled headers just like most other variables in
-
the header file.
-
-
Committed as obvious after a bootstrap/test on x86_64-linux-gnu.
-
-
gcc/ChangeLog:
-
-
PR target/103910
-
* config/i386/i386.h (x86_mfence): Mark with GTY.
-
---
-
gcc/config/i386/i386.h | 2 +-
-
1 file changed, 1 insertion(+), 1 deletion(-)
-
-
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
-
index f027608eefa..3ac0f698ae2 100644
-
--- a/gcc/config/i386/i386.h
-
+++ b/gcc/config/i386/i386.h
-
@@ -486,7 +486,7 @@ extern unsigned char ix86_prefetch_sse;
-
-
/* Fence to use after loop using storent. */
-
-
-extern tree x86_mfence;
-
+extern GTY(()) tree x86_mfence;
-
#define FENCE_FOLLOWING_MOVNT x86_mfence
-
-
/* Once GDB has been enhanced to deal with functions without frame
-
--
-
2.31.1
-
+71 -5
pkgs/development/compilers/gcc/patches/default.nix
···
## 1. Patches relevant to gcc>=12 on every platform ####################################
[ ]
-
++ optional (!atLeast12) ./fix-bug-80431.patch
+
# Backport "c++: conversion to base of vbase in NSDMI"
+
# Fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431
+
++ optional (!atLeast12) (fetchpatch {
+
name = "gcc-bug80431-fix";
+
url = "https://github.com/gcc-mirror/gcc/commit/de31f5445b12fd9ab9969dc536d821fe6f0edad0.patch";
+
hash = "sha256-bnHKJP5jR8rNJjRTi58/N/qZ5fPkuFBk7WblJWQpKOs=";
+
})
+
# Pass the path to a C++ compiler directly in the Makefile.in
++ optional (!lib.systems.equals targetPlatform hostPlatform) ./libstdc++-target.patch
++ optionals (noSysDirs) (
-
[ (if atLeast12 then ./gcc-12-no-sys-dirs.patch else ./no-sys-dirs.patch) ]
+
[
+
# Do not try looking for binaries and libraries in /lib and /usr/lib
+
(if atLeast12 then ./gcc-12-no-sys-dirs.patch else ./no-sys-dirs.patch)
+
]
++ (
{
"15" = [
+
# Do not try looking for binaries and libraries in /lib and /usr/lib
./13/no-sys-dirs-riscv.patch
+
# Mangle the nix store hash in __FILE__ to prevent unneeded runtime references
./13/mangle-NIX_STORE-in-__FILE__.patch
];
"14" = [
···
."${majorVersion}" or [ ]
)
)
+
# Pass CFLAGS on to gnat
++ optional (atLeast12 && langAda) ./gnat-cflags-11.patch
++ optional langFortran (
+
# Fix interaction of gfortran and libtool
+
# Fixes the output of -v
+
# See also https://github.com/nixOS/nixpkgs/commit/cc6f814a8f0e9b70ede5b24192558664fa1f98a2
if atLeast12 then ./gcc-12-gfortran-driving.patch else ./gfortran-driving.patch
)
+
# Do not pass a default include dir on PowerPC+Musl
+
# See https://github.com/NixOS/nixpkgs/pull/45340/commits/d6bb7d45162ac93e017cc9b665ae4836f6410710
++ [ ./ppc-musl.patch ]
+
# Patches for libphobos, the standard library of the D language
+
# - Forces libphobos to be built with -j1, as libtool misbehaves in parallel
+
# - Gets rid of -idirafter flags added by our gcc wrappers, as gdc does not understand them
+
# See https://github.com/NixOS/nixpkgs/pull/69144#issuecomment-535176453
++ optional langD ./libphobos.patch
+
# Moves the .cfi_starproc instruction to after the function label
+
# Needed to build llvm-18 and later
+
# See https://github.com/NixOS/nixpkgs/pull/354107/commits/2de1b4b14e17f42ba8b4bf43a29347c91511e008
++ optional (!atLeast14) ./cfi_startproc-reorder-label-09-1.diff
++ optional (atLeast14 && !canApplyIainsDarwinPatches) ./cfi_startproc-reorder-label-14-1.diff
···
# backport fixes to build gccgo with musl libc
++ optionals (stdenv.hostPlatform.isMusl && langGo && atLeast12) [
+
# libgo: handle stat st_atim32 field and SYS_SECCOMP
+
# syscall: gofmt
+
# Add blank lines after //sys comments where needed, and then run gofmt
+
# on the syscall package with the new formatter.
+
# See https://go-review.googlesource.com/c/gofrontend/+/412074
(fetchpatch {
excludes = [ "gcc/go/gofrontend/MERGE" ];
url = "https://github.com/gcc-mirror/gcc/commit/cf79b1117bd177d3d4c6ed24b6fa243c3628ac2d.diff";
hash = "sha256-mS5ZiYi5D8CpGXrWg3tXlbhp4o86ew1imCTwaHLfl+I=";
})
+
# libgo: permit loff_t and off_t to be macros
+
# See https://go-review.googlesource.com/c/gofrontend/+/412075
(fetchpatch {
excludes = [ "gcc/go/gofrontend/MERGE" ];
url = "https://github.com/gcc-mirror/gcc/commit/7f195a2270910a6ed08bd76e3a16b0a6503f9faf.diff";
hash = "sha256-Ze/cFM0dQofKH00PWPDoklXUlwWhwA1nyTuiDAZ6FKo=";
})
+
# libgo: handle stat st_atim32 field and SYS_SECCOMP
+
# See https://go-review.googlesource.com/c/gofrontend/+/415294
(fetchpatch {
excludes = [ "gcc/go/gofrontend/MERGE" ];
url = "https://github.com/gcc-mirror/gcc/commit/762fd5e5547e464e25b4bee435db6df4eda0de90.diff";
hash = "sha256-o28upwTcHAnHG2Iq0OewzwSBEhHs+XpBGdIfZdT81pk=";
})
+
# runtime: portable access to sigev_notify_thread_id
+
# See https://sourceware.org/bugzilla/show_bug.cgi?id=27417
+
# See https://go-review.googlesource.com/c/gofrontend/+/434755
(fetchpatch {
excludes = [ "gcc/go/gofrontend/MERGE" ];
url = "https://github.com/gcc-mirror/gcc/commit/e73d9fcafbd07bc3714fbaf8a82db71d50015c92.diff";
hash = "sha256-1SjYCVHLEUihdON2TOC3Z2ufM+jf2vH0LvYtZL+c1Fo=";
})
+
# syscall, runtime: always call XSI strerror_r
+
# See https://go-review.googlesource.com/c/gofrontend/+/454176
(fetchpatch {
excludes = [ "gcc/go/gofrontend/MERGE" ];
url = "https://github.com/gcc-mirror/gcc/commit/b6c6a3d64f2e4e9347733290aca3c75898c44b2e.diff";
hash = "sha256-RycJ3YCHd3MXtYFjxP0zY2Wuw7/C4bWoBAQtTKJZPOQ=";
})
+
# libgo: check for makecontext in -lucontext
+
# See https://go-review.googlesource.com/c/gofrontend/+/458396
(fetchpatch {
excludes = [ "gcc/go/gofrontend/MERGE" ];
url = "https://github.com/gcc-mirror/gcc/commit/2b1a604a9b28fbf4f382060bebd04adb83acc2f9.diff";
hash = "sha256-WiBQG0Xbk75rHk+AMDvsbrm+dc7lDH0EONJXSdEeMGE=";
})
+
# x86: Fix -fsplit-stack feature detection via TARGET_CAN_SPLIT_STACK
+
# Fixes compiling for non-glibc target
(fetchpatch {
url = "https://github.com/gcc-mirror/gcc/commit/c86b726c048eddc1be320c0bf64a897658bee13d.diff";
hash = "sha256-QSIlqDB6JRQhbj/c3ejlmbfWz9l9FurdSWxpwDebnlI=";
···
.${majorVersion} or [ ]
)
+
# Here we apply patches by Iains (https://github.com/iains)
+
# GitHub's "compare" API produces unstable diffs, so we resort to reusing
+
# diffs from the Homebrew repo.
++ optionals canApplyIainsDarwinPatches (
{
"15" = [
+
# Patches from https://github.com/iains/gcc-15-branch/compare/releases/gcc-15..gcc-15.1-darwin-rc1
(fetchpatch {
name = "gcc-15-darwin-aarch64-support.patch";
url = "https://raw.githubusercontent.com/Homebrew/formula-patches/a25079204c1cb3d78ba9dd7dd22b8aecce7ce264/gcc/gcc-15.1.0.diff";
···
})
];
"14" = [
+
# Patches from https://github.com/iains/gcc-14-branch/compare/04696df09633baf97cdbbdd6e9929b9d472161d3..gcc-14.2-darwin-r2
(fetchpatch {
# There are no upstream release tags nor a static branch for 14.3.0 in https://github.com/iains/gcc-14-branch.
# aa4cd614456de65ee3417acb83c6cff0640144e9 is the merge base of https://github.com/iains/gcc-14-branch/tree/gcc-14-3-darwin-pre-0 and https://github.com/gcc-mirror/gcc/releases/tag/releases%2Fgcc-14.3.0
···
hash = "sha256-BSTSYnkBJBEm++mGerVVyaCUC4dUyXq0N1tqbk25bO4=";
})
];
+
# Patches from https://github.com/iains/gcc-13-branch/compare/b71f1de6e9cf7181a288c0f39f9b1ef6580cf5c8..gcc-13-3-darwin
"13" = [
(fetchpatch {
name = "gcc-13-darwin-aarch64-support.patch";
url = "https://raw.githubusercontent.com/Homebrew/formula-patches/bda0faddfbfb392e7b9c9101056b2c5ab2500508/gcc/gcc-13.3.0.diff";
sha256 = "sha256-RBTCBXIveGwuQGJLzMW/UexpUZdDgdXprp/G2NHkmQo=";
})
+
# Needed to build LLVM>18
./cfi_startproc-reorder-label-2.diff
];
+
# Patches from https://github.com/iains/gcc-12-branch/compare/2bada4bc59bed4be34fab463bdb3c3ebfd2b41bb..gcc-12-4-darwin
"12" = [
(fetchurl {
name = "gcc-12-darwin-aarch64-support.patch";
url = "https://raw.githubusercontent.com/Homebrew/formula-patches/1ed9eaea059f1677d27382c62f21462b476b37fe/gcc/gcc-12.4.0.diff";
sha256 = "sha256-wOjpT79lps4TKG5/E761odhLGCphBIkCbOPiQg/D1Fw=";
})
+
# Needed to build LLVM>18
./cfi_startproc-reorder-label-2.diff
];
"11" = [
···
url = "https://github.com/iains/gcc-11-branch/compare/5cc4c42a0d4de08715c2eef8715ad5b2e92a23b6..gcc-11.5-darwin-r0.diff";
hash = "sha256-7lH+GkgkrE6nOp9PMdIoqlQNWK31s6oW+lDt1LIkadE=";
})
+
# Needed to build LLVM>18
./cfi_startproc-reorder-label-2.diff
];
"10" = [
···
url = "https://github.com/iains/gcc-10-branch/compare/d04fe5541c53cb16d1ca5c80da044b4c7633dbc6...gcc-10-5Dr0-pre-0.diff";
hash = "sha256-kVUHZKtYqkWIcqxHG7yAOR2B60w4KWLoxzaiFD/FWYk=";
})
+
# Needed to build LLVM>18
./cfi_startproc-reorder-label-2.diff
];
}
···
## Windows
-
# Obtain latest patch with ../update-mcfgthread-patches.sh
+
# Backported mcf thread model support from gcc13:
+
# https://github.com/gcc-mirror/gcc/commit/f036d759ecee538555fa8c6b11963e4033732463
++ optional (
!atLeast13 && !withoutTargetLibc && targetPlatform.isMinGW && threadsCross.model == "mcf"
) (./. + "/${majorVersion}/Added-mcf-thread-model-support-from-mcfgthread.patch")
···
## gcc 11.0 and older ##############################################################################
# openjdk build fails without this on -march=opteron; is upstream in gcc12
-
++ optionals (is11) [ ./11/gcc-issue-103910.patch ]
+
++ optional is11 (fetchpatch {
+
name = "darwin-aarch64-self-host-driver.patch";
+
url = "https://github.com/gcc-mirror/gcc/commit/d243f4009d8071b734df16cd70f4c5d09a373769.patch";
+
sha256 = "sha256-H97GZs2wwzfFGiFOgds/5KaweC+luCsWX3hRFf7+Sm4=";
+
})
## gcc 10.0 and older ##############################################################################
+
# Probably needed for gnat wrapper https://github.com/NixOS/nixpkgs/pull/62314
++ optional (langAda && (is9 || is10)) ./gnat-cflags.patch
++
+
# Backport native aarch64-darwin compilation fix from gcc12
+
# https://github.com/NixOS/nixpkgs/pull/167595
optional
(
is10
···
&& (!lib.systems.equals targetPlatform buildPlatform)
)
(fetchpatch {
-
url = "https://raw.githubusercontent.com/richard-vd/musl-cross-make/5e9e87f06fc3220e102c29d3413fbbffa456fcd6/patches/gcc-${version}/0008-darwin-aarch64-self-host-driver.patch";
+
name = "0008-darwin-aarch64-self-host-driver.patch";
+
url = "https://github.com/gcc-mirror/gcc/commit/834c8749ced550af3f17ebae4072fb7dfb90d271.diff";
sha256 = "sha256-XtykrPd5h/tsnjY1wGjzSOJ+AyyNLsfnjuOZ5Ryq9vA=";
})
···
## gcc 9.0 and older ##############################################################################
++ optional (majorVersion == "9") ./9/fix-struct-redefinition-on-glibc-2.36.patch
+
# Needed for NetBSD cross comp in older versions
+
# https://gcc.gnu.org/pipermail/gcc-patches/2020-January/thread.html#537548
+
# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=98d56ea8900fdcff8f1987cf2bf499a5b7399857
++ optional (!atLeast10 && targetPlatform.isNetBSD) ./libstdc++-netbsd-ctypes.patch
# Make Darwin bootstrap respect whether the assembler supports `--gstabs`,
-92
pkgs/development/compilers/gcc/patches/fix-bug-80431.patch
···
-
From de31f5445b12fd9ab9969dc536d821fe6f0edad0 Mon Sep 17 00:00:00 2001
-
From: Patrick Palka <ppalka@redhat.com>
-
Date: Mon, 21 Jun 2021 07:54:26 -0400
-
Subject: [PATCH] c++: conversion to base of vbase in NSDMI [PR80431]
-
-
The delayed processing of conversions to a virtual base in an NSDMI
-
assumes the target base type is a (possibly indirect) virtual base of
-
the current class, but the target base type could also be a base of a
-
virtual base, as in the testcase below. Since such a base isn't a part
-
of CLASSTYPE_VBASECLASSES, we end up miscompiling the testcase due to
-
the call to build_base_path (with binfo=NULL_TREE) silently returning
-
error_mark_node. Fix this by using convert_to_base to build the
-
conversion instead.
-
-
PR c++/80431
-
-
gcc/cp/ChangeLog:
-
-
* tree.c (bot_replace): Use convert_to_base to build the
-
conversion to the (morally) virtual base.
-
-
gcc/testsuite/ChangeLog:
-
-
* g++.dg/cpp0x/nsdmi-virtual1a.C: New test.
-
---
-
gcc/cp/tree.c | 14 ++++------
-
gcc/testsuite/g++.dg/cpp0x/nsdmi-virtual1a.C | 28 ++++++++++++++++++++
-
2 files changed, 33 insertions(+), 9 deletions(-)
-
create mode 100644 gcc/testsuite/g++.dg/cpp0x/nsdmi-virtual1a.C
-
-
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
-
index fec5afaa2be..297da2b1550 100644
-
--- a/gcc/cp/tree.c
-
+++ b/gcc/cp/tree.c
-
@@ -3242,15 +3242,11 @@ bot_replace (tree* t, int* /*walk_subtrees*/, void* data_)
-
else if (TREE_CODE (*t) == CONVERT_EXPR
-
&& CONVERT_EXPR_VBASE_PATH (*t))
-
{
-
- /* In an NSDMI build_base_path defers building conversions to virtual
-
- bases, and we handle it here. */
-
- tree basetype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (*t)));
-
- vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (current_class_type);
-
- int i; tree binfo;
-
- FOR_EACH_VEC_SAFE_ELT (vbases, i, binfo)
-
- if (BINFO_TYPE (binfo) == basetype)
-
- break;
-
- *t = build_base_path (PLUS_EXPR, TREE_OPERAND (*t, 0), binfo, true,
-
+ /* In an NSDMI build_base_path defers building conversions to morally
-
+ virtual bases, and we handle it here. */
-
+ tree basetype = TREE_TYPE (*t);
-
+ *t = convert_to_base (TREE_OPERAND (*t, 0), basetype,
-
+ /*check_access=*/false, /*nonnull=*/true,
-
tf_warning_or_error);
-
}
-
-
diff --git a/gcc/testsuite/g++.dg/cpp0x/nsdmi-virtual1a.C b/gcc/testsuite/g++.dg/cpp0x/nsdmi-virtual1a.C
-
new file mode 100644
-
index 00000000000..dc847cc16e5
-
--- /dev/null
-
+++ b/gcc/testsuite/g++.dg/cpp0x/nsdmi-virtual1a.C
-
@@ -0,0 +1,28 @@
-
+// PR c++/80431
-
+// { dg-do run { target c++11 } }
-
+
-
+// A variant of nsdmi-virtual1.C where A is only a morally virtual base of B.
-
+
-
+struct A
-
+{
-
+ A(): i(42) { }
-
+ int i;
-
+ int f() { return i; }
-
+};
-
+
-
+struct D : A { int pad; };
-
+
-
+struct B : virtual D
-
+{
-
+ int j = i + f();
-
+ int k = A::i + A::f();
-
+};
-
+
-
+struct C: B { int pad; };
-
+
-
+int main()
-
+{
-
+ C c;
-
+ if (c.j != 84 || c.k != 84)
-
+ __builtin_abort();
-
+}
-
--
-
2.31.1
-
-15
pkgs/development/compilers/gcc/patches/update-mcfgthread-patches.sh
···
-
#!/usr/bin/env nix-shell
-
#! nix-shell -i bash -p curl
-
-
# We use this script to download local copies instead of using
-
# fetchpatch because lmhouse/MINGW-packages-dev is constantly rebased
-
# against msys2/MINGW-packages-dev and won't have stable commit hashes.
-
-
name=Added-mcf-thread-model-support-from-mcfgthread.patch
-
source=https://raw.githubusercontent.com/lhmouse/MINGW-packages-dev/master/mingw-w64-gcc-git
-
dest=$(dirname "$0")
-
-
for majorVersion in 6 7 8 9 10; do
-
curl "$source/9000-gcc-$majorVersion-branch-$name" \
-
> "$dest/$majorVersion/$name"
-
done