-
Notifications
You must be signed in to change notification settings - Fork 13.4k
retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features #135927
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
Conversation
rustbot has assigned @compiler-errors. Use |
Some changes occurred in compiler/rustc_codegen_gcc |
e808e83
to
12b286f
Compare
This comment has been minimized.
This comment has been minimized.
r? compiler |
This comment was marked as resolved.
This comment was marked as resolved.
12b286f
to
f331c60
Compare
This comment has been minimized.
This comment has been minimized.
f331c60
to
434a25f
Compare
This comment has been minimized.
This comment has been minimized.
434a25f
to
945d0f1
Compare
This comment has been minimized.
This comment has been minimized.
r? compiler |
945d0f1
to
0ea46d2
Compare
This comment has been minimized.
This comment has been minimized.
r? compiler |
0ea46d2
to
386c90e
Compare
r? @davidtwco maybe 😅 |
This comment has been minimized.
This comment has been minimized.
0321253
to
99ece33
Compare
This comment has been minimized.
This comment has been minimized.
99ece33
to
14f651e
Compare
@rustbot ready |
This comment was marked as resolved.
This comment was marked as resolved.
…o enable retpoline-related target features
14f651e
to
5601490
Compare
@bors r+ |
Rollup of 9 pull requests Successful merges: - #128425 (Make `missing_fragment_specifier` an unconditional error) - #135927 (retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features) - #140770 (add `extern "custom"` functions) - #142176 (tests: Split dont-shuffle-bswaps along opt-levels and arches) - #142248 (Add supported asm types for LoongArch32) - #142267 (assert more in release in `rustc_ast_lowering`) - #142274 (Update the stdarch submodule) - #142276 (Update dependencies in `library/Cargo.lock`) - #142308 (Upgrade `object`, `addr2line`, and `unwinding` in the standard library) Failed merges: - #140920 (Extract some shared code from codegen backend target feature handling) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl try-job: test-various
Rollup of 9 pull requests Successful merges: - #128425 (Make `missing_fragment_specifier` an unconditional error) - #135927 (retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features) - #140770 (add `extern "custom"` functions) - #142176 (tests: Split dont-shuffle-bswaps along opt-levels and arches) - #142248 (Add supported asm types for LoongArch32) - #142267 (assert more in release in `rustc_ast_lowering`) - #142274 (Update the stdarch submodule) - #142276 (Update dependencies in `library/Cargo.lock`) - #142308 (Upgrade `object`, `addr2line`, and `unwinding` in the standard library) Failed merges: - #140920 (Extract some shared code from codegen backend target feature handling) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl try-job: test-various
Rollup merge of #135927 - azhogin:azhogin/retpoline, r=davidtwco retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features `-Zretpoline` and `-Zretpoline-external-thunk` flags are target modifiers (tracked to be equal in linked crates). * Enables target features for `-Zretpoline-external-thunk`: `+retpoline-external-thunk`, `+retpoline-indirect-branches`, `+retpoline-indirect-calls`. * Enables target features for `-Zretpoline`: `+retpoline-indirect-branches`, `+retpoline-indirect-calls`. It corresponds to clang -mretpoline & -mretpoline-external-thunk flags. Also this PR forbids to specify those target features manually (warning). Issue: #116852
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in #140920, codegen_ssa is probably a much better place for this target feature handling.
@@ -34,6 +34,9 @@ pub enum Stability { | |||
/// particular for features are actually ABI configuration flags (not all targets are as nice as | |||
/// RISC-V and have an explicit way to set the ABI separate from target features). | |||
Forbidden { reason: &'static str }, | |||
/// This feature can not be set via `-Ctarget-feature` or `#[target_feature]`, it can only be set | |||
/// by target modifier flag. Target modifier flags are tracked to be consistent in linked modules. | |||
TargetModifierOnly { reason: &'static str, flag: &'static str }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are such features even listed here? The entire point of this file is to define the Rust feature names used for -Ctarget-feature
and #[target_feature]
and cfg(target_feature)
. Mixing in other things here seems like a big mess...
Stability::TargetModifierOnly { reason, flag } => { | ||
if !sess.opts.target_feature_flag_enabled(*flag) { Err(reason) } else { Ok(()) } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this logic. Somewhere it says these target features are not allowed in -Ctarget-features
, but now here it seems to allow them... sometimes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you are taking the named -Z
options and mixing them with the -Ctarget-features
flag. Then of course things become messy and they have to masquerade as actual target features in parts of the compiler even though they aren't, actually, target features for us.
I think it's a bad idea to ever mix these. The code paths should be entirely separate all the way until actually generating backend target features. Please let's not make the target feature code even more spaghetti than it already was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this PR correctly, then once I set -Zretpoline-external-thunk
this would actually let me set -Ctarget-features=-retpoline-external-thunk
without any warning. My refactor in #140920 fixes that.
@@ -707,6 +707,12 @@ pub(crate) fn target_cpu(sess: &Session) -> &str { | |||
handle_native(cpu_name) | |||
} | |||
|
|||
fn llvm_features_by_flags(sess: &Session) -> Vec<&str> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handling for fixed_x18
should probably be merged with this. (That would also have been an easier model to follow for adding the new flags.)
#140920 now also changes the logic for these new flags quite a bit, in an attempt to reduce the spaghetti. Might be worth taking a look. |
@@ -49,6 +52,7 @@ impl<CTX> HashStable<CTX> for Stability { | |||
Stability::Forbidden { reason } => { | |||
reason.hash_stable(hcx, hasher); | |||
} | |||
Stability::TargetModifierOnly { .. } => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not hashing the fields here is sus... but I'm anyway going to entirely remove this variant in my PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it deliberate that these are added to the list of possible values for cfg(target_feature)
? They are not set via -Ctarget-feature
, so that seems confusing. Also, I can't find any logic here that would actually ever make cfg!(target_feature="retpoline-external-thunk")
be "true", and no test checking that it would ever be "true". This seems like an accidental side-effect of adding a new target_features::Stability
variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is being set as a target feature "because LLVM treats it as a target feature". There was no discussion of exposing this to the language that I remember.
-Zretpoline
and-Zretpoline-external-thunk
flags are target modifiers (tracked to be equal in linked crates).-Zretpoline-external-thunk
:+retpoline-external-thunk
,+retpoline-indirect-branches
,+retpoline-indirect-calls
.-Zretpoline
:+retpoline-indirect-branches
,+retpoline-indirect-calls
.It corresponds to clang -mretpoline & -mretpoline-external-thunk flags.
Also this PR forbids to specify those target features manually (warning).
Issue: #116852