Skip to content

gcc: only use zerocallusedregs on gcc11+ x86, aarch64#377690

Open
conroy-cheers wants to merge 1 commit intoNixOS:masterfrom
conroy-cheers:gcc-zerocallusedregs-weird-platforms-fix
Open

gcc: only use zerocallusedregs on gcc11+ x86, aarch64#377690
conroy-cheers wants to merge 1 commit intoNixOS:masterfrom
conroy-cheers:gcc-zerocallusedregs-weird-platforms-fix

Conversation

@conroy-cheers
Copy link
Contributor

@conroy-cheers conroy-cheers commented Jan 29, 2025

-fzero-call-used-regs flag isn't supported by all platforms; for example, the following currently fails to build on master:

nix-build -A hello --arg crossSystem '{
      config = "arm-none-eabi";
      libc = "newlib";
      gcc = {
        cpu = "cortex-m0";
        thumb = true;
      };
    }'

This change restricts the -fzero-call-used-regs flag to x86 and aarch64 platforms.

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)
    • (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
    • (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.

@github-actions github-actions bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. labels Jan 29, 2025
@conroy-cheers conroy-cheers force-pushed the gcc-zerocallusedregs-weird-platforms-fix branch from 0eec75a to 3b33990 Compare January 29, 2025 13:41
@conroy-cheers conroy-cheers changed the title gcc: only use zerocallusedregs on gcc11+ x86_64, aarch64 gcc: only use zerocallusedregs on gcc11+ x86, aarch64 Jan 29, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. and removed 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. labels Jan 29, 2025
Copy link
Contributor

@tobim tobim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not restricting it when it was originally introduced in #274089 was probably an oversight.

@conroy-cheers conroy-cheers force-pushed the gcc-zerocallusedregs-weird-platforms-fix branch from 3b33990 to e701dda Compare February 4, 2025 12:32
@github-actions github-actions bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. and removed 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Feb 4, 2025
@conroy-cheers conroy-cheers force-pushed the gcc-zerocallusedregs-weird-platforms-fix branch from e701dda to 8fab1b7 Compare February 5, 2025 10:18
@hacker1024 hacker1024 requested a review from tobim February 12, 2025 00:32
@tobim tobim requested a review from risicle February 12, 2025 07:59
@risicle
Copy link
Contributor

risicle commented Feb 12, 2025

It was less an oversight, more that the limited supported platforms is helpfully not documented (https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fzero-call-used-regs) and I struggled to find reliable information on this short of reading the (byzantine) gcc source.

I'd be interested to know what information we're basing the set of supported platforms on - for instance I'm pretty sure this hasn't caused issues on i686 or risc-v since it was enabled by default, both of which this would disable it for.

@conroy-cheers
Copy link
Contributor Author

For context, I originally ran into this compiling embedded firmware for cortex-m0, which would be the armv6-m arch. Perhaps we can run a minimal test for each of GCC's supported architectures to see which support the flag.

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Feb 14, 2025
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 2, 2025
Signed-off-by: conroy-cheers <conroy@corncheese.org>
@conroy-cheers conroy-cheers force-pushed the gcc-zerocallusedregs-weird-platforms-fix branch from 8fab1b7 to 90c37d3 Compare May 30, 2025 02:37
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label May 30, 2025
Copy link
Contributor

@risicle risicle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just going to put my above objections to this on the record lest someone see the above approval and reach for the merge button. This goes too far and disables zerocallusedregs for platforms it seems to work fine on.

Possibly we should explicitly disable it for some targets it's known not to work for, but TBH I don't think people should be using wrapped compilers for embedded targets anyway. cc-wrapper makes a lot of assumptions that it's building something for running on a general-purpose os and it's a bit of an accident that it works at all for embedded targets.

See also the rat's nest of issues around #323869 which exposed a bunch of places in nixpkgs that were using wrapped compilers to build GPU kernels, BPF filters etc.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Aug 23, 2025
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants