From c3afdec4e8cce6ddbaf88d3d1bff1da05aa27dd3 Mon Sep 17 00:00:00 2001 From: Eduard Bachmakov Date: Thu, 17 Apr 2025 18:23:18 +0200 Subject: [PATCH] cc-wrapper: enable frame pointers by default. Allow easy system-level profiling with e.g. Linux perf or bpf(trace). Profiling applications in NixOS is quite expensive due to the size of closures of basic but widely-used libraries. Full-system profiling is even harder as it effectively requires re-compiling the world with ~0 caching. By enabling it by default, we make this trivially possible (except for the packages that explicitly specify -fomit-frame-pointers, of course) Make an exception for 32bit x86 since it only has 8 general purpose registers. Frame pointers are enabled by default in Fedora, Ubuntu, and Arch Linux. --- pkgs/build-support/cc-wrapper/default.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 7f24c1153d2d..4758411773b4 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -801,8 +801,15 @@ stdenvNoCC.mkDerivation { export hardening_unsupported_flags="${concatStringsSep " " ccHardeningUnsupportedFlags}" '' + # 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 + '' + # For clang, this is handled in add-clang-cc-cflags-before.sh - + lib.optionalString (!isClang && machineFlags != [ ]) '' + + optionalString (!isClang && machineFlags != [ ]) '' printf "%s\n" ${lib.escapeShellArgs machineFlags} >> $out/nix-support/cc-cflags-before ''