Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 28, 2025

Conversation

mildsunrise
Copy link

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.

@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
Author

done

@alyssais alyssais merged commit 923d687 into NixOS:staging Mar 28, 2025
26 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants