Files
John Ericson 9287f5433e gccNGPackages.libgomp: size the device UID buffer for a negative int
`gomp_get_uid_for_device` allows ten digits for the `%d`, but `device_num`
is a plain `int`, whose widest rendering is `-2147483648` -- eleven. With
the eight-character `OMP_DEV_` prefix that is twenty bytes plus the NUL into
a nineteen-byte buffer. GCC 16 started noticing, and `libgomp` builds with
`-Werror`:

    target.c:5956:31: error: 'snprintf' output may be truncated before the
    last format character [-Werror=format-truncation=]

A real off-by-one rather than a false positive, so fix the size instead of
silencing the warning. My first guess was that fortify was to blame, since
the diagnostic named `__builtin___snprintf_chk`; it is not -- turning
hardening off only changes the name in the message.

Co-authored-by: Ben Siraphob <bensiraphob@gmail.com>
Assisted-by: Claude Code (Claude Opus 5)
2026-09-03 13:19:36 -04:00

97 lines
1.7 KiB
Nix

{
lib,
stdenv,
gcc_meta,
release_version,
version,
getVersionFile,
monorepoSrc ? null,
autoreconfHook269,
runCommand,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "libgomp";
inherit version;
src = runCommand "libgomp-src-${version}" { src = monorepoSrc; } (
''
runPhase unpackPhase
mkdir -p "$out/gcc"
cp gcc/BASE-VER "$out/gcc"
cp gcc/DATESTAMP "$out/gcc"
cp -r libgomp "$out"
cp -r include "$out"
cp -r config "$out"
cp -r multilib.am "$out"
cp -r libtool.m4 "$out"
cp config.guess "$out"
cp config.rpath "$out"
cp config.sub "$out"
cp config-ml.in "$out"
cp ltmain.sh "$out"
cp install-sh "$out"
cp mkinstalldirs "$out"
''
# `MD5SUMS` exists only in release tarballs, not in a VCS checkout.
+ ''
if [[ -f MD5SUMS ]]; then cp MD5SUMS "$out"; fi
''
);
outputs = [
"out"
"dev"
];
postUnpack = ''
mkdir -p ./build
buildRoot=$(readlink -e "./build")
'';
preAutoreconf = ''
sourceRoot=$(readlink -e "./libgomp")
cd $sourceRoot
'';
patches = lib.optionals (lib.versionAtLeast release_version "16") [
(getVersionFile "libgomp/uid-buffer-size.patch")
];
enableParallelBuilding = true;
nativeBuildInputs = [
autoreconfHook269
];
configurePlatforms = [
"build"
"host"
];
configureFlags = [
"--disable-dependency-tracking"
"cross_compiling=true"
"--disable-multilib"
];
preConfigure = ''
cd "$buildRoot"
configureScript=$sourceRoot/configure
'';
doCheck = true;
passthru = {
isGNU = true;
};
meta = gcc_meta // {
homepage = "https://gcc.gnu.org/";
};
})