From 726ba29941a348fd79dea539be86b388e6708d88 Mon Sep 17 00:00:00 2001 From: Eduard Bachmakov Date: Tue, 3 Jun 2025 19:46:35 +0200 Subject: [PATCH] cc-wrapper: limit no-omit-leaf-frame-pointer to supported platforms Unlike omit-frame-pointer this flag is NOT globally defined and results in `unrecognized command-line option` type errors. See https://github.com/NixOS/nixpkgs/pull/399014#issuecomment-2933857698 and following for discussion. --- pkgs/build-support/cc-wrapper/default.nix | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 4758411773b4..a4b4573082f4 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -804,9 +804,21 @@ stdenvNoCC.mkDerivation { # Do not prevent omission of framepointers on x86 32bit due to the small # number of general purpose registers. Keeping EBP available provides # non-trivial performance benefits. - + optionalString (!targetPlatform.isx86_32) '' - echo " -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer " >> $out/nix-support/cc-cflags-before - '' + + ( + let + enable_fp = !targetPlatform.isx86_32; + enable_leaf_fp = + enable_fp + && ( + targetPlatform.isx86_64 + || targetPlatform.isAarch64 + || (targetPlatform.isRiscV && (!isGNU || versionAtLeast ccVersion "15.1")) + ); + in + optionalString enable_fp '' + echo " -fno-omit-frame-pointer ${optionalString enable_leaf_fp "-mno-omit-leaf-frame-pointer "}" >> $out/nix-support/cc-cflags-before + '' + ) # For clang, this is handled in add-clang-cc-cflags-before.sh + optionalString (!isClang && machineFlags != [ ]) ''