Skip to content

Comments

cc-wrapper: keep machine cflags if the same target is passed#391944

Merged
alyssais merged 2 commits intoNixOS:stagingfrom
mildsunrise:fix-llvm-stdenv-rt-cflags
Mar 28, 2025
Merged

cc-wrapper: keep machine cflags if the same target is passed#391944
alyssais merged 2 commits intoNixOS:stagingfrom
mildsunrise:fix-llvm-stdenv-rt-cflags

Conversation

@mildsunrise
Copy link
Contributor

Since #291901 / #317273, compiler-rt doesn't honor machine cflags. This can yield unusable LLVM stdenvs, for example this one even fails to build:

nix-build \
  --arg crossSystem '{ config = "riscv32-unknown-linux-gnu"; gcc.arch = "rv32ima"; useLLVM = true; }' \
  -A stdenv

This is because compiler-rt always passes --target, causing machine flags to be dropped.

Reading comments from @alyssais, @emilazy and #379593, I think there is general agreement that it's okay for things like compiler-rt to expect a multi-target compiler and pass --target. #379593 dropped the warning when a --target matching the wrapper's is passed. I believe the most natural behavior is for the machine flags to be kept in that case, too, so that

$CC ...
$CC --target=$TARGET ...

produce the same binaries. WDYT?

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • N/A (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • N/A (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@nix-owners nix-owners bot requested a review from Ericson2314 March 21, 2025 20:56
@github-actions github-actions bot added 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. labels Mar 21, 2025
@alyssais
Copy link
Member

Sounds sensible.

Could you split needsTarget -> targetPassed into its own commit before changing the logic? Otherwise it's a bit difficult to see what the actual logic change being made here is.

12b0e8a/6f756b4 work around clang errors when a
nix-wrapped compiler is used like a multi-target compiler.
it does so by dropping the machineFlags whenever
-target/--target is found in the arguments.

however this breaks compiler-rt, which is designed to
acommodate multi-target builds and always passes `--target`.
in its packaging we make sure to only build it for the target
we need, essentially disabling the multi-target aspect,
but because it still passes --target, the machineFlags are
dropped and compiler-rt could end up being for an invalid
ABI, producing an unusable stdenv.cc.

we could manually pass machineFlags to compiler-rt's
cmake build, but IMO it makes more sense to tolerate
--target arguments whose value coincides with the wrapper's,
keeping the machineFlags in this case.
@mildsunrise mildsunrise force-pushed the fix-llvm-stdenv-rt-cflags branch from 070933d to 220608b Compare March 27, 2025 16:39
@mildsunrise
Copy link
Contributor Author

done

@alyssais alyssais merged commit 923d687 into NixOS:staging Mar 28, 2025
24 of 27 checks passed
@mildsunrise mildsunrise deleted the fix-llvm-stdenv-rt-cflags branch March 28, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants