gccNGPackages.libatomic: fix the two ways GCC 16 assumes a monorepo build

Both are new in 16 and both come from `libatomic` no longer being buildable
on its own without help.

`configure.ac` now refuses to run with an empty `CFLAGS`: it appends
`-fno-link-libatomic` and needs `AC_PROG_CC`'s conftests to see it, so it
will not let `AC_PROG_CC` supply the default instead.

    configure: error: CFLAGS must be set.

The top level passes them down in a monorepo build; here each library is
configured on its own, so pass what `AC_PROG_CC` would have chosen anyway.

`Makefile.am` then grew an `all-local` hook copying `libatomic.la` into
`../../gcc/`, so a compiler built in the same object tree can link
`-latomic`. There is no such tree here -- the compiler is a finished package
and gets the library through its wrapper -- so the rule just fails:

    install: cannot create regular file '/build/build/../../gcc/libatomic.so.1.2.0'

Drop the hook rather than the rule, to keep the difference from upstream
small.

Neither is caught by checking that patches apply: both are build failures on
a tree that patched cleanly.

Co-authored-by: Ben Siraphob <bensiraphob@gmail.com>
Assisted-by: Claude Code (Claude Opus 5)
This commit is contained in:
John Ericson
2026-08-28 00:31:44 -04:00
parent f0e0d97d92
commit 0fdf5b63f9
3 changed files with 64 additions and 16 deletions

View File

@@ -0,0 +1,26 @@
From: John Ericson <git@JohnEricson.me>
Subject: [PATCH] libatomic: Do not install into the toplevel gcc objdir
GCC 16 added an `all-local` hook that copies `libatomic.la` into
`../../gcc/`, so that the compiler being built in the same object tree can
link `-latomic`. There is no such tree here: each runtime library is built
on its own, against an already-finished compiler, which is given the library
through the wrapper instead. The rule just fails:
install: cannot create regular file '/build/build/../../gcc/libatomic.so.1.2.0'
Drop the hook rather than the rule, so the difference from upstream stays as
small as possible.
---
diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am
index 49689d451..c389e8cd6 100644
--- a/libatomic/Makefile.am
+++ b/libatomic/Makefile.am
@@ -181,7 +181,6 @@ all-multi: $(libatomic_la_LIBADD)
# from $gcc_objdir seems to fix the issue.
gcc_objdir = `pwd`/$(MULTIBUILDTOP)../../gcc/
-all-local: stmp-libatomic
stmp-libatomic: libatomic.la
$(LIBTOOL) --mode=install $(INSTALL_DATA) libatomic.la $(gcc_objdir)$(MULTISUBDIR)/
if LIBAT_BUILD_ASNEEDED_SOLINK

View File

@@ -43,22 +43,26 @@ stdenv.mkDerivation (finalAttrs: {
''
);
# Both are the same upstream change, which is in the GCC 16 release branch:
# the backport itself, and the hand-edit of the generated `aclocal.m4` that
# `fetchpatch` cannot carry. GCC 16 already includes `../config/gthr.m4`
# there.
patches = lib.optionals (lib.versionOlder release_version "16") [
(fetchpatch {
name = "custom-threading-model.patch";
url = "https://github.com/gcc-mirror/gcc/commit/e5d853bbe9b05d6a00d98ad236f01937303e40c4.diff";
hash = "sha256-U1Eh6ByhmseHQigfHIyO4MlAQB3fECmpPEP/M00DOg0=";
includes = [
"config/*"
"libatomic/configure.ac"
];
})
(getVersionFile "libatomic/gthr-include.patch")
];
patches =
lib.optionals (lib.versionAtLeast release_version "16") [
(getVersionFile "libatomic/no-gcc-objdir-install.patch")
]
# Both are the same upstream change, which is in the GCC 16 release
# branch: the backport itself, and the hand-edit of the generated
# `aclocal.m4` that `fetchpatch` cannot carry. GCC 16 already includes
# `../config/gthr.m4` there.
++ lib.optionals (lib.versionOlder release_version "16") [
(fetchpatch {
name = "custom-threading-model.patch";
url = "https://github.com/gcc-mirror/gcc/commit/e5d853bbe9b05d6a00d98ad236f01937303e40c4.diff";
hash = "sha256-U1Eh6ByhmseHQigfHIyO4MlAQB3fECmpPEP/M00DOg0=";
includes = [
"config/*"
"libatomic/configure.ac"
];
})
(getVersionFile "libatomic/gthr-include.patch")
];
postUnpack = ''
mkdir -p ./build
@@ -87,6 +91,15 @@ stdenv.mkDerivation (finalAttrs: {
"--disable-multilib"
];
# GCC 16's `libatomic/configure.ac` refuses to run with an empty `CFLAGS`:
# it appends `-fno-link-libatomic` to them and needs `AC_PROG_CC`'s conftests
# to see it, so it will not let `AC_PROG_CC` supply the default instead. In
# the monorepo build the top level passes them down; each library is
# configured on its own here, so pass what `AC_PROG_CC` would have chosen.
env = lib.optionalAttrs (lib.versionAtLeast release_version "16") {
CFLAGS = "-g -O2";
};
preConfigure = ''
cd "$buildRoot"
configureScript=$sourceRoot/configure

View File

@@ -14,6 +14,15 @@
}
];
# Only present under `../16`, so a `gitRelease` build -- whose version
# directory is `../git` -- has to be pointed here too.
"libatomic/no-gcc-objdir-install.patch" = [
{
after = "16";
path = ../16;
}
];
# In Git: https://github.com/Ericson2314/gcc/tree/regular-dirs-in-libgcc-15
"libgcc/force-regular-dirs.patch" = [
{