nixpkgs/pkgs/build-support/cc-wrapper
Adam Joseph 0b2036cad0 cc-wrapper: fix -mtune= validation, add ARM, add fallbacks
Before this commit, cc-wrapper/default.nix was using
`isGccArchSupported` to validate `-mtune=` values.  This has two
problems:

- On x86, `-mtune=` can take the same values as `-march`, plus two
  additional values `generic` and `intel` which are not valid for
  `-march`.

- On ARM, `-mtune=` does not take the same values as `-march=`;
  instead it takes the same values as `-mcpu`.

This commit fixes these two problems by adding a new
`isGccTuneSupported` function.  For `isx86` this returns `true` for
the two special values and otherwise defers to `isGccArchSupported`.

This commit also adds support for `-mtune=` on Aarch64.

Unfortunately on Aarch64, Clang does not accept as wide a variety of
`-mtune=` values as Gcc does.  In particular, Clang does not tune
for big.LITTLE mixed-model chips like the very popular RK3399, which
is targeted using `-march=cortex-a72.cortex-a53` in gcc.

To address this problem, this commit also adds a function
`findBestTuneApproximation` which can be used to map
clang-unsupported tunings like `cortex-a72.cortex-a53` to
less-precise tunings like `cortex-a53`.

The work which led to this commit arose because we now have
packages, like `crosvm`, which use *both* `clang` *and* `gcc`.
Previously I had been using `overrideAttrs` to set
`NIX_CFLAGS_COMPILE` on a package-by-package basis based on which
compiler that package used.  Since we now have packages which use
*both* compilers, this strategy no longer works.

I briefly considered splitting `NIX_CFLAGS_COMPILE` into
`NIX_CFLAGS_COMPILE_GCC` and `NIX_CFLAGS_COMPILE_CLANG`, but since
`NIX_CFLAGS_COMPILE` is sort of a hack to begin with I figured that
adding the logic to `cc-wrapper` would be preferable.
2023-10-23 01:31:21 +00:00
..
add-clang-cc-cflags-before.sh cc-wrapper: Add clang specific options to clang specific file 2022-06-15 11:34:53 -04:00
add-flags.sh cc-wrapper: change cflags order from cc/crt1/libc to crt1/libc/cc 2022-02-20 10:45:45 +00:00
add-gnat-extra-flags.sh cc-wrapper: Fix gnatmake wrapper 2023-01-07 18:32:12 +11:00
add-hardening.sh cc-wrapper: add fortify flags after invocation args, not before 2023-08-19 14:59:06 +01:00
cc-wrapper.sh cc-wrapper: Account for NIX_LDFLAGS and NIX_CFLAGS_LINK in linkType 2023-09-03 13:49:50 +01:00
default.nix cc-wrapper: fix -mtune= validation, add ARM, add fallbacks 2023-10-23 01:31:21 +00:00
fortran-hook.sh cc-wrapper: fortran: enable stackprotector on M1 2022-08-19 16:41:36 -07:00
gnat-wrapper.sh cc-wrapper: Wrap/link all other GNAT commands 2023-01-07 18:32:12 +11:00
go-wrapper.sh gccgo: wrap go binary (#207670) 2023-01-20 14:31:54 +01:00
setup-hook.sh hardening flags: enable fortify3 by default 2023-06-25 11:50:46 +01:00