From 219aaa8f9a18a39c28c0cc99b4c67348e0f6628f Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Wed, 7 Dec 2022 18:23:45 -0800 Subject: [PATCH] cc-wrapper: add support for ARM feature flags GCC and Clang both accept a suffix consisting of zero or more "feature flags" to the values of `-march` and `-mcpu`: https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/AArch64-Options.html#g_t-march-and--mcpu-Feature-Modifiers Let's provide a way for users to enable these feature modifiers in `{local,cross}System.gcc`. --- pkgs/build-support/cc-wrapper/default.nix | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index a59505d082584..b532b9d728bf4 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -114,6 +114,14 @@ let darwinMinVersionVariable = optionalString stdenv.targetPlatform.isDarwin stdenv.targetPlatform.darwinMinVersionVariable; + + # this converts, e.g. [ "fp" "crc" ] to "+fp+crc" which can be + # appended to `-march` and `-mcpu`; see + # https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/AArch64-Options.html#g_t-march-and--mcpu-Feature-Modifiers + featureModifiersToString = gcc: + lib.strings.concatMapStrings + (s: "+${s}") + (gcc.featureModifiers or []); in # Ensure bintools matches @@ -438,14 +446,14 @@ stdenv.mkDerivation { # TODO: aarch64-darwin has mcpu incompatible with gcc + optionalString ((targetPlatform ? gcc.arch) && (isClang || !(stdenv.isDarwin && stdenv.isAarch64)) && isGccArchSupported targetPlatform.gcc.arch) '' - echo "-march=${targetPlatform.gcc.arch}" >> $out/nix-support/cc-cflags-before + echo "-march=${targetPlatform.gcc.arch}${featureModifiersToString targetPlatform.gcc}" >> $out/nix-support/cc-cflags-before '' # -mcpu is not very useful. You should use mtune and march # instead. It’s provided here for backwards compatibility. # TODO: aarch64-darwin has mcpu incompatible with gcc + optionalString ((targetPlatform ? gcc.cpu) && (isClang || !(stdenv.isDarwin && stdenv.isAarch64))) '' - echo "-mcpu=${targetPlatform.gcc.cpu}" >> $out/nix-support/cc-cflags-before + echo "-mcpu=${targetPlatform.gcc.cpu}${featureModifiersToString targetPlatform.gcc}" >> $out/nix-support/cc-cflags-before '' # -mfloat-abi only matters on arm32 but we set it here