From 07bce58d9c4c7a3be573688ff62f750b24fceacd Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Mon, 21 Jul 2025 14:06:01 +0200 Subject: [PATCH] cc-wrapper: Workaround gnuabielfv{1,2} support deficiency on Clang Clang cannot handle the gnuabielfv{1,2} ABI specification in the triplet properly. It used to parse it as just "gnu", disregarding the ABI version in it and defaulting to ELFv1. Now, it completely fails to parse such target triplet: > clang: error: version 'abielfv1' in target triple 'powerpc64-unknown-linux-gnuabielfv1' is invalid So when it comes time to passing the target triplet to Clang, handle this support deficiency: 1. If the triplet ends in gnuabielfv*, shorten it to just gnu. This makes it get parsed properly. 2. After the above, re-add the ABI via the separate -mabi option. This makes it use the correct ABI for the platform. --- .../cc-wrapper/add-clang-cc-cflags-before.sh | 4 +++ pkgs/build-support/cc-wrapper/default.nix | 26 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh b/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh index b56bb39c97a9..2b7cd00783a5 100644 --- a/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh +++ b/pkgs/build-support/cc-wrapper/add-clang-cc-cflags-before.sh @@ -30,4 +30,8 @@ if $targetPassed && [[ "$targetValue" != "@defaultTarget@" ]] && (( "${NIX_CC_WR echo "Warning: supplying the --target $targetValue != @defaultTarget@ argument to a nix-wrapped compiler may not work correctly - cc-wrapper is currently not designed with multi-target compilers in mind. You may want to use an un-wrapped compiler instead." >&2 elif [[ $0 != *cpp ]]; then extraBefore+=(-target @defaultTarget@ @machineFlags@) + + if [[ "@explicitAbiValue@" != "" ]]; then + extraBefore+=(-mabi=@explicitAbiValue@) + fi fi diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index eecaacbd6fea..5aa688ebd6ba 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -94,12 +94,14 @@ let getLib getName getVersion + hasPrefix mapAttrsToList optional optionalAttrs optionals optionalString removePrefix + removeSuffix replaceStrings toList versionAtLeast @@ -900,12 +902,24 @@ stdenvNoCC.mkDerivation { ## General Clang support ## Needs to go after ^ because the for loop eats \n and makes this file an invalid script ## - + optionalString isClang '' - # Escape twice: once for this script, once for the one it gets substituted into. - export machineFlags=${escapeShellArg (escapeShellArgs machineFlags)} - export defaultTarget=${targetPlatform.config} - substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh - '' + + optionalString isClang ( + let + hasUnsupportedGnuSuffix = hasPrefix "gnuabielfv" targetPlatform.parsed.abi.name; + clangCompatibleConfig = + if hasUnsupportedGnuSuffix then + removeSuffix (removePrefix "gnu" targetPlatform.parsed.abi.name) targetPlatform.config + else + targetPlatform.config; + explicitAbiValue = if hasUnsupportedGnuSuffix then targetPlatform.parsed.abi.abi else ""; + in + '' + # Escape twice: once for this script, once for the one it gets substituted into. + export machineFlags=${escapeShellArg (escapeShellArgs machineFlags)} + export defaultTarget=${clangCompatibleConfig} + export explicitAbiValue=${explicitAbiValue} + substituteAll ${./add-clang-cc-cflags-before.sh} $out/nix-support/add-local-cc-cflags-before.sh + '' + ) ## ## Extra custom steps