From d6d18979043b65685de9163743558ece2365d18f Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 13 Jan 2023 08:30:20 -0500 Subject: [PATCH] gcc: Backport fix of GCC Issue 80431 from version 12 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 This bug annoys me because I hit it when working on Nix. It causes miscompilations in such a way that I am hard-pressed to think how a program could inadvertainly rely on the bug (such that it would be broken by the fix). The bug is longstanding, and the (quite small) applies without modification to many older GCCs. I have confirmed by running the test in that commit that does indeed fix the bug with the backports too. --- pkgs/development/compilers/gcc/10/default.nix | 10 ++++++++-- pkgs/development/compilers/gcc/11/default.nix | 10 ++++++++-- pkgs/development/compilers/gcc/6/default.nix | 7 +++++++ pkgs/development/compilers/gcc/7/default.nix | 7 +++++++ pkgs/development/compilers/gcc/8/default.nix | 10 ++++++++-- pkgs/development/compilers/gcc/9/default.nix | 11 ++++++++--- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/pkgs/development/compilers/gcc/10/default.nix b/pkgs/development/compilers/gcc/10/default.nix index e4cebab266e8..373c35f4b4fe 100644 --- a/pkgs/development/compilers/gcc/10/default.nix +++ b/pkgs/development/compilers/gcc/10/default.nix @@ -51,8 +51,14 @@ let majorVersion = "10"; inherit (stdenv) buildPlatform hostPlatform targetPlatform; - patches = [ ] - ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch + patches = [ + # Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 + (fetchurl { + name = "fix-bug-80431.patch"; + url = "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=de31f5445b12fd9ab9969dc536d821fe6f0edad0"; + sha256 = "0sd52c898msqg7m316zp0ryyj7l326cjcn2y19dcxqp15r74qj0g"; + }) + ] ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch ++ optional noSysDirs ../no-sys-dirs.patch ++ optional (noSysDirs && hostPlatform.isRiscV) ../no-sys-dirs-riscv.patch /* ++ optional (hostPlatform != buildPlatform) (fetchpatch { # XXX: Refine when this should be applied diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index de764b9ccc7c..f34901e12341 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -51,8 +51,14 @@ let majorVersion = "11"; inherit (stdenv) buildPlatform hostPlatform targetPlatform; - patches = - optional (targetPlatform != hostPlatform) ../libstdc++-target.patch + patches = [ + # Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 + (fetchurl { + name = "fix-bug-80431.patch"; + url = "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=de31f5445b12fd9ab9969dc536d821fe6f0edad0"; + sha256 = "0sd52c898msqg7m316zp0ryyj7l326cjcn2y19dcxqp15r74qj0g"; + }) + ] ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch ++ optional noSysDirs ../no-sys-dirs.patch ++ optional (noSysDirs && hostPlatform.isRiscV) ../no-sys-dirs-riscv.patch /* ++ optional (hostPlatform != buildPlatform) (fetchpatch { # XXX: Refine when this should be applied diff --git a/pkgs/development/compilers/gcc/6/default.nix b/pkgs/development/compilers/gcc/6/default.nix index 8bd9d41f1eae..c4bf872697e6 100644 --- a/pkgs/development/compilers/gcc/6/default.nix +++ b/pkgs/development/compilers/gcc/6/default.nix @@ -64,6 +64,13 @@ let majorVersion = "6"; patches = optionals (!stdenv.targetPlatform.isRedox) [ ../use-source-date-epoch.patch ./0001-Fix-build-for-glibc-2.31.patch + + # Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 + (fetchurl { + name = "fix-bug-80431.patch"; + url = "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=de31f5445b12fd9ab9969dc536d821fe6f0edad0"; + sha256 = "0sd52c898msqg7m316zp0ryyj7l326cjcn2y19dcxqp15r74qj0g"; + }) ] ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch ++ optional noSysDirs ../no-sys-dirs.patch ++ optional langAda ../gnat-cflags.patch diff --git a/pkgs/development/compilers/gcc/7/default.nix b/pkgs/development/compilers/gcc/7/default.nix index 637be9fd971c..6538f43cf4a0 100644 --- a/pkgs/development/compilers/gcc/7/default.nix +++ b/pkgs/development/compilers/gcc/7/default.nix @@ -56,6 +56,13 @@ let majorVersion = "7"; ./gcc8-asan-glibc-2.34.patch ./0001-Fix-build-for-glibc-2.31.patch + + # Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 + (fetchurl { + name = "fix-bug-80431.patch"; + url = "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=de31f5445b12fd9ab9969dc536d821fe6f0edad0"; + sha256 = "0sd52c898msqg7m316zp0ryyj7l326cjcn2y19dcxqp15r74qj0g"; + }) ] ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch ++ optionals targetPlatform.isNetBSD [ diff --git a/pkgs/development/compilers/gcc/8/default.nix b/pkgs/development/compilers/gcc/8/default.nix index 4eb47d00c5c2..4b456de81524 100644 --- a/pkgs/development/compilers/gcc/8/default.nix +++ b/pkgs/development/compilers/gcc/8/default.nix @@ -46,8 +46,14 @@ let majorVersion = "8"; inherit (stdenv) buildPlatform hostPlatform targetPlatform; - patches = - optional (targetPlatform != hostPlatform) ../libstdc++-target.patch + patches = [ + # Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 + (fetchurl { + name = "fix-bug-80431.patch"; + url = "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=de31f5445b12fd9ab9969dc536d821fe6f0edad0"; + sha256 = "0sd52c898msqg7m316zp0ryyj7l326cjcn2y19dcxqp15r74qj0g"; + }) + ] ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch ++ optional targetPlatform.isNetBSD ../libstdc++-netbsd-ctypes.patch ++ optional noSysDirs ../no-sys-dirs.patch /* ++ optional (hostPlatform != buildPlatform) (fetchpatch { # XXX: Refine when this should be applied diff --git a/pkgs/development/compilers/gcc/9/default.nix b/pkgs/development/compilers/gcc/9/default.nix index 4c49cdaa3e25..7c2d784a79f7 100644 --- a/pkgs/development/compilers/gcc/9/default.nix +++ b/pkgs/development/compilers/gcc/9/default.nix @@ -55,9 +55,14 @@ let majorVersion = "9"; inherit (stdenv) buildPlatform hostPlatform targetPlatform; - patches = - [ ] - ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch + patches = [ + # Fix https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80431 + (fetchurl { + name = "fix-bug-80431.patch"; + url = "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=de31f5445b12fd9ab9969dc536d821fe6f0edad0"; + sha256 = "0sd52c898msqg7m316zp0ryyj7l326cjcn2y19dcxqp15r74qj0g"; + }) + ] ++ optional (targetPlatform != hostPlatform) ../libstdc++-target.patch ++ optional targetPlatform.isNetBSD ../libstdc++-netbsd-ctypes.patch ++ optional noSysDirs ../no-sys-dirs.patch ++ optional (noSysDirs && hostPlatform.isRiscV) ../no-sys-dirs-riscv-gcc9.patch