Code change:
<ins> { lib, stdenvNoLibs, buildPackages , gcc, glibc , libiberty }: let gccConfigureFlags = gcc.cc.configureFlags ++ [ "--disable-fixincludes" "--disable-intl" "--enable-threads=posix" "--with-glibc-version=${glibc.version}" # these are required in order to prevent inhibit_libc=true, # which will cripple libgcc's unwinder; see: #  https://github.com/NixOS/nixpkgs/issues/213453#issuecomment-1616346163 "--with-headers=${lib.getDev glibc}/include" "--with-native-system-header-dir=${lib.getDev glibc}${glibc.incdir or "/include"}" "--with-build-sysroot=/" ]; in stdenvNoLibs.mkDerivation (finalAttrs: { pname = "libgcc"; inherit (gcc.cc) src version; outputs = [ "out" "dev" ]; strictDeps = true; depsBuildBuild = [ buildPackages.stdenv.cc ]; nativeBuildInputs = [ libiberty ]; buildInputs = [ glibc ]; postUnpack = '' mkdir -p ./build buildRoot=$(readlink -e "./build") ''; postPatch = gcc.cc.passthru.forceLibgccToBuildCrtStuff + '' sourceRoot=$(readlink -e "./libgcc") ''; hardeningDisable = [ "pie" ]; preConfigure = '' # Drop in libiberty, as external builds are not expected cd "$buildRoot" ( mkdir -p build-${stdenvNoLibs.buildPlatform.config}/libiberty/ cd build-${stdenvNoLibs.buildPlatform.config}/libiberty/ ln -s ${buildPackages.libiberty}/lib/libiberty.a ./ ) mkdir -p "$buildRoot/gcc" cd "$buildRoot/gcc" ( # We "shift" the tools over to fake platforms perspective from the previous stage. export AS_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$AS_FOR_BUILD export CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CC_FOR_BUILD export CPP_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CPP_FOR_BUILD export CXX_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CXX_FOR_BUILD export LD_FOR_BUILD=${buildPackages.stdenv.cc.bintools}/bin/$LD_FOR_BUILD export AS=$AS_FOR_BUILD export CC=$CC_FOR_BUILD export CPP=$CPP_FOR_BUILD export CXX=$CXX_FOR_BUILD export LD=$LD_FOR_BUILD export AS_FOR_TARGET=${stdenvNoLibs.cc}/bin/$AS export CC_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CC export CPP_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CPP export LD_FOR_TARGET=${stdenvNoLibs.cc.bintools}/bin/$LD # We define GENERATOR_FILE so nothing bothers looking for GNU GMP. export NIX_CFLAGS_COMPILE_FOR_BUILD+=' -DGENERATOR_FILE=1' "$sourceRoot/../gcc/configure" ${lib.concatStringsSep " " gccConfigureFlags} # We remove the `libgcc.mvar` deps so that the bootstrap xgcc isn't built. sed -e 's,libgcc.mvars:.*$,libgcc.mvars:,' -i Makefile make  config.h  libgcc.mvars  tconfig.h  tm.h  options.h  insn-constants.h  insn-modes.h ) mkdir -p "$buildRoot/gcc/include" # Preparing to configure + build libgcc itself mkdir -p "$buildRoot/gcc/${stdenvNoLibs.hostPlatform.config}/libgcc" cd "$buildRoot/gcc/${stdenvNoLibs.hostPlatform.config}/libgcc" configureScript=$sourceRoot/configure chmod +x "$configureScript" export AS_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$AS_FOR_BUILD export CC_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CC_FOR_BUILD export CPP_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CPP_FOR_BUILD export CXX_FOR_BUILD=${buildPackages.stdenv.cc}/bin/$CXX_FOR_BUILD export LD_FOR_BUILD=${buildPackages.stdenv.cc.bintools}/bin/$LD_FOR_BUILD export AS=${stdenvNoLibs.cc}/bin/$AS export CC=${stdenvNoLibs.cc}/bin/$CC export CPP=${stdenvNoLibs.cc}/bin/$CPP export CXX=${stdenvNoLibs.cc}/bin/$CXX export LD=${stdenvNoLibs.cc.bintools}/bin/$LD export AS_FOR_TARGET=${stdenvNoLibs.cc}/bin/$AS_FOR_TARGET export CC_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CC_FOR_TARGET export CPP_FOR_TARGET=${stdenvNoLibs.cc}/bin/$CPP_FOR_TARGET export LD_FOR_TARGET=${stdenvNoLibs.cc.bintools}/bin/$LD_FOR_TARGET ''; configurePlatforms = [ "build" "host" ]; configureFlags = [ "cross_compiling=true" "--disable-gcov" "--with-glibc-version=${glibc.version}" ]; makeFlags = [ "MULTIBUILDTOP:=../" ]; postInstall = '' moveToOutput "lib/gcc/${stdenvNoLibs.hostPlatform.config}/${finalAttrs.version}/include" "$dev" mkdir -p "$out/lib" "$dev/include" ln -s "$out/lib/gcc/${stdenvNoLibs.hostPlatform.config}/${finalAttrs.version}"/* "$out/lib" ln -s "$dev/lib/gcc/${stdenvNoLibs.hostPlatform.config}/${finalAttrs.version}/include"/* "$dev/include/" ''; }) </ins>

Related discussion:
text: On or cross-compiled from , breaks: From : You can either run this on another architecture using . or should not crash: This was responsible for failing to replicate datasets to my ARM NAS. The issue does not_ occur for natively compiled builds. It appears to be a cross-compilation issue only.
It is a bug in / derivations. In non-cross cases it gets copied from used to bid into output: But in cross-case used to build does not yet provide as it needs bits of for it (and the library path is slightly incorrect). One of possible workarounds is to try to add to to get it pulled via from expected location.
We don't do the copying to glibc anymore, but this error still occurs as described on current nixpkgs master.
Yup. cross-compilation never propagated to in any form (and does not today).
Could you please try this PR? It should fix the problem.
With that PR, I'm seeing this on both (a Raspberry Pi CM4) and with QEMU on : Log from aarch64 machine: Log from machine with QEMU:
Well it's finding now, so there's clearly some other problem with addition to that. When I run it with I even get line numbers from inside : That line () is the last line in the following snippet of code: ... so is deliberately ing here due to . Grepping through the docs turns up: This is happening because uses . Once you do that, glibc needs to unwind the stack frame of any thread that calls . And unwinders are a giant headache. I'm afraid that's all I've got here. I've removed the closed-by from since it was only part of the problem here.
Ah, I think I know what it is. We can compile a without , but it won't have an unwinder. We need to pass the glibc headers to the build in order to get one of those.
would you please try ? I believe it fixes one of the two problems which caused this issue, and it includes which fixes the other one. It works for me: BTW, this issue (cross-compile , then run it under qemu) is a really valuable test case. We really ought to add it to so Hydra will catch any regressions automatically.