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

Constrain -Clto and -Cembed-bitcode flag inheritance to be clang-only #1379

Merged
merged 2 commits into from
Jan 31, 2025

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Jan 31, 2025

In rust-lang/rust#136338 we noticed two unsupported inherited flag warnings when the underlying cc is gcc and not clang:

warning: rustc_llvm@0.0.0: Inherited flag "-flto=thin" is not supported by the currently used CC
warning: rustc_llvm@0.0.0: Inherited flag "-fembed-bitcode=all" is not supported by the currently used CC

This PR constraints -Clto and -Cembed-bitcode flag inheritance to be clang-only, compared the current behavior of inheriting the flags for both clang and gcc.

Constrain -Cembed-bitcode flag inheritance to be clang-only

embed-bitcode refers to embedding LLVM bitcode, which is not a thing for gcc1.

This PR moves the -Cembed-bitcode flag inheritance from being shared by gcc/clang to be clang-only.

Constrain -Clto flag inheritance to be clang-only

While clang supports -flto={thin,fat}, gcc does not support this form. Furthermore, there isn't really a 1-to-1 mapping between clang's ThinLTO/FatLTO and gcc's LTO.

We noticed this in rust-lang/rust#136338 when trying to compile rustc_llvm but with the underlying cc being gcc:

warning: rustc_llvm@0.0.0: Inherited flag "-flto=thin" is not supported by the currently used CC

For instance, gcc has multiple LTO-related / LTO-affecting flags:

This PR moves the -Clto flag inheritance from being shared by gcc/clang to be clang-only.

Footnotes

  1. I suppose if you squint super super hard, embedding GIMPLE bytecode somehow...?

Copy link
Collaborator

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Similar in spirit to #1363, CC @mrkajetanp, why were these originally marked enabled on GCC too? Are there other options here that we are not considering that we should be?

@madsmtm madsmtm added the bug label Jan 31, 2025
@madsmtm
Copy link
Collaborator

madsmtm commented Jan 31, 2025

I'm gonna merge this immediately, because this PR is clearly correct. I'll look into the other options myself, and file a follow-up PR if needed.

@madsmtm madsmtm merged commit 65b4d9a into rust-lang:main Jan 31, 2025
52 checks passed
@jieyouxu jieyouxu deleted the dont-inherit-lto-gcc branch January 31, 2025 08:09
@jieyouxu
Copy link
Member Author

jieyouxu commented Jan 31, 2025

I'm gonna merge this immediately, because this PR is clearly correct. I'll look into the other options myself, and file a follow-up PR if needed.

There may also be cases that while a specific flag-form is supported for both clang and gcc, their exact semantics/behavior do not mirror each other (this is the case of value-less flag-value-form -flto, which is supported by both clang and gcc but they do not mean nearly the same thing AFAIK). However, I haven't looked into that, just a remark.

@madsmtm
Copy link
Collaborator

madsmtm commented Jan 31, 2025

Filed #1380. And yes, you're correct, they may not have the same semantics.

@mrkajetanp
Copy link
Contributor

As originally written, clang and gcc flags were just all one group because if either of the compilers didn't support one you'd just get this warning but it wouldn't be an actual error. Somewhat useful for when someone was using a different compiler than they intended etc.
Now that it's been changed to be more granular it does make sense to move some of these to clang-only, I agree :)

src/flags.rs Show resolved Hide resolved
@github-actions github-actions bot mentioned this pull request Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants