Repository navigation
require a consistent codegen backend when -Zllvm-target-feature is present #160618
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
Open
RalfJung
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
RalfJung:llvm-target-feature-codegen-backends
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -390,7 +390,7 @@ impl CStore { | |||||
| assert!(local_features.len() > 0 || extern_features.len() > 0); | ||||||
|
|
||||||
| let diag = format!( | ||||||
| "mixing target features will cause an ABI mismatch in crate `{local_crate}`" | ||||||
| "mixing target features may cause an ABI mismatch in crate `{local_crate}`" | ||||||
| ); | ||||||
| let mut diag = tcx.dcx().struct_warn(diag); | ||||||
| diag.help("some target features modify the ABI so Rust crates compiled with different values for these target features cannot be used together safely"); | ||||||
|
|
@@ -411,6 +411,16 @@ impl CStore { | |||||
| diag.help("if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=target-feature` to silence this warning"); | ||||||
| diag.emit(); | ||||||
| } | ||||||
| "codegen-backend-name" => { | ||||||
| let diag = format!( | ||||||
| "mixing codegen backends while using backend-specific target features may cause an ABI mismatch in crate `{local_crate}`" | ||||||
| ); | ||||||
| let mut diag = tcx.dcx().struct_err(diag); | ||||||
| diag.help("this crate has `-Zllvm-target-features` set, which means different codegen backends could interpret the target features differently, or ignore them entirely"); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Probably grep to see if this happened anywhere else. |
||||||
| diag.help("some target features modify the ABI so Rust crates compiled with different target features cannot be used together safely"); | ||||||
| diag.help("if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=codegen-backend-name` to silence this warning"); | ||||||
| diag.emit(); | ||||||
| } | ||||||
| _ => panic!("unhandled synthetic target feature {opt_name}"), | ||||||
| } | ||||||
| return; | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
tests/ui-fulldeps/codegen-backend/auxiliary/with_llvm_target_feature.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| //! A crate that uses the default codegen backend and an LLVM target feature. | ||
|
|
||
| //@ compile-flags: --target arm-unknown-linux-gnueabi --emit=metadata | ||
| //@ needs-llvm-components: arm | ||
| //@ compile-flags: -Zllvm-target-feature=+thumb2 | ||
|
|
||
| #![feature(no_core)] | ||
| #![no_core] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //! When using llvm-target-features, we cannot mix codegen backends. | ||
|
|
||
| //@ ignore-stage1 (requires matching sysroot built with in-tree compiler) | ||
| //@ ignore-backends: gcc | ||
|
|
||
| //@ aux-codegen-backend: the_backend.rs | ||
| //@ aux-build: with_llvm_target_feature.rs | ||
|
|
||
| // Pick a target that requires no target features in the ABI check, so that no warning is shown | ||
| // about missing target features. | ||
| //@ compile-flags: --target arm-unknown-linux-gnueabi --crate-type=lib | ||
| //@ needs-llvm-components: arm | ||
| //@ compile-flags: -Zllvm-target-feature=+thumb2 | ||
|
|
||
| #![feature(no_core)] | ||
| #![no_core] | ||
|
|
||
| extern crate with_llvm_target_feature; | ||
|
|
||
| //~? ERROR: mixing codegen backends while using backend-specific target features may cause an ABI mismatch |
8 changes: 8 additions & 0 deletions
8
tests/ui-fulldeps/codegen-backend/llvm-target-features.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| error: mixing codegen backends while using backend-specific target features may cause an ABI mismatch in crate `llvm_target_features` | ||
| | | ||
| = help: this crate has `-Zllvm-target-features` set, which means different codegen backends could interpret the target features differently, or ignore them entirely | ||
| = help: some target features modify the ABI so Rust crates compiled with different target features cannot be used together safely | ||
| = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=codegen-backend-name` to silence this warning | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
2 changes: 1 addition & 1 deletion
2
tests/ui/target-feature/abi-relevant-target-modifier.baseline.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This is mostly a drive-by fix -- not all target feature mixing will cause ABI trouble, so I used "may" in the new message and updated the old one to match.
View changes since the review