mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-08-31 20:54:56 +00:00
- `gccNGPackages.libbacktrace`: Remove, in favor of the `libbacktrace` package in `pkgs/by-name` - `stdenvNoCxx`: New, a compiler with a libc but no C++ standard library - `libbacktrace`: Build with `stdenvNoCxx`, so `libstdc++` can link it without a cycle - `gccNGPackages.gcc`, `gccNGPackages.libgfortran`, `gccNGPackages.libstdcxx`: Take `libbacktrace` as a build input and pass `--with-system-libbacktrace` That option is not upstream; it comes from a patch posted to gcc-patches[^1], which we fetch from the archive rather than vendor. One posting covers every component that links libbacktrace, so each package filters it down to the files its own `src` carries, and leaves out the generated files because we regenerate those locally anyway. `gcc` and `libgfortran` were already using this `libbacktrace`, but by faking up the sibling directory an in-tree build would have had -- archive, libtool archive and headers -- for the relative paths to resolve against. Passing the flag lets that go. Note that this means our libstdc++ is getting `std::stacktrace` support for the first time; we were unwittingly excluding the vendored support. Nothing failed, which is why it went unnoticed: `--enable-libstdcxx-backtrace` defaults to `auto`, and `auto` means yes wherever the library is hosted, so the feature was asked for. But the probe that picks the object format runs `libbacktrace/filetype.awk`, which was not among the files we copied, so it got nothing back, warned "could not determine output file type", and quietly settled on `enable_libstdcxx_backtrace=no`. Note also that with this approach, a downstream `libbacktrace` *cannot* be built by the regular `stdenv` with `useGccNG = true`, because its symbols would conflict. We'll see whether that is acceptable or not. If it isn't, we can still avoid vendoring, but we will need to replicate the symbol renaming that GCC would have done externally. [^1]: https://inbox.sourceware.org/gcc-patches/20260814013206.3818461-1-git@JohnEricson.me/ Assisted-by: Claude Code (Claude Opus 5)
93 lines
2.9 KiB
Nix
93 lines
2.9 KiB
Nix
{
|
|
stdenvNoCC,
|
|
stdenv,
|
|
overrideCC,
|
|
buildPackages,
|
|
lib,
|
|
fetchFromGitHub,
|
|
enableStatic ? stdenv.hostPlatform.isStatic,
|
|
enableShared ? !stdenv.hostPlatform.isStatic,
|
|
unstableGitUpdater,
|
|
autoreconfHook,
|
|
}:
|
|
|
|
let
|
|
# With GCC NG, `libstdc++` links this rather than compiling its own copy,
|
|
# which puts it below the C++ standard library rather than above; built with
|
|
# the ordinary `stdenv` the two would create a cycle.
|
|
#
|
|
# I would rather this bootstrapping detail not leak into the `package.nix`,
|
|
# but I don't see another solution available since all-package.nix overrides
|
|
# of "by-name" packages are no longer allowed.
|
|
#
|
|
# TODO: hoist this back out to a `stdenvNoCXX` in `all-packages.nix`,
|
|
# where the next package needing a hosted-but-C++-free compiler can
|
|
# share it. `nixpkgs-vet` blocks that today: it wants `strictDeps` and
|
|
# `__structuredAttrs`, but this is only relevant for derivations made
|
|
# with `stdenv.mkDerivation` --- `stdenv` itself is *not* such a
|
|
# derivation!
|
|
stdenv' =
|
|
if stdenvNoCC.hostPlatform.useLLVM or false then
|
|
overrideCC stdenvNoCC buildPackages.llvmPackages.clangNoLibcxx
|
|
else if stdenvNoCC.hostPlatform.useGccNG or false then
|
|
overrideCC stdenvNoCC buildPackages.gccNGPackages.gccWithLibatomic
|
|
else
|
|
stdenv;
|
|
in
|
|
let
|
|
stdenv = stdenv';
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
pname = "libbacktrace";
|
|
version = "0-unstable-2026-05-03";
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "ianlancetaylor";
|
|
repo = "libbacktrace";
|
|
rev = "96664e69b1ecdb76e824be1d9e8f475b76dd08cf";
|
|
hash = "sha256-+tV6W8SnFWKweAASvFfb+i6bz73ssVGikNhVpq3YbT4=";
|
|
};
|
|
|
|
patches = [
|
|
# Support multiple debug dirs.
|
|
# https://github.com/ianlancetaylor/libbacktrace/pull/100
|
|
./0002-libbacktrace-Allow-configuring-debug-dir.patch
|
|
./0003-libbacktrace-Support-multiple-build-id-directories.patch
|
|
|
|
# Support NIX_DEBUG_INFO_DIRS environment variable.
|
|
./0004-libbacktrace-Support-NIX_DEBUG_INFO_DIRS-environment.patch
|
|
];
|
|
|
|
# https://github.com/ianlancetaylor/libbacktrace/issues/163
|
|
postPatch =
|
|
lib.optionalString
|
|
(stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isBigEndian && stdenv.hostPlatform.isAbiElfv1)
|
|
''
|
|
substituteInPlace Makefile.am \
|
|
--replace-fail 'MAKETESTS += mtest_minidebug' '# MAKETESTS += mtest_minidebug'
|
|
'';
|
|
|
|
nativeBuildInputs = [
|
|
autoreconfHook
|
|
];
|
|
|
|
configureFlags = [
|
|
(lib.enableFeature enableStatic "static")
|
|
(lib.enableFeature enableShared "shared")
|
|
];
|
|
|
|
doCheck = stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isMusl;
|
|
|
|
passthru = {
|
|
updateScript = unstableGitUpdater { };
|
|
};
|
|
|
|
meta = {
|
|
description = "C library that may be linked into a C/C++ program to produce symbolic backtraces";
|
|
homepage = "https://github.com/ianlancetaylor/libbacktrace";
|
|
maintainers = with lib.maintainers; [ twey ];
|
|
license = lib.licenses.bsd3;
|
|
};
|
|
}
|