-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustc_target: Add some more target spec sanity checking #100537
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2e83c22
rustc_target: Add some more target spec sanity checking
petrochenkov f0d0573
rustc_target: Do not specify some target options redundantly
petrochenkov f4b5954
rustc_target: Use `Cow` and link args helpers in `apple_base`
petrochenkov f7eb7ef
Update tests for UEFI and AVR
petrochenkov 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
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
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 |
---|---|---|
|
@@ -2,18 +2,20 @@ use super::super::*; | |
use std::assert_matches::assert_matches; | ||
|
||
// Test target self-consistency and JSON encoding/decoding roundtrip. | ||
pub(super) fn test_target(target: Target) { | ||
target.check_consistency(); | ||
pub(super) fn test_target(target: Target, triple: &str) { | ||
target.check_consistency(triple); | ||
assert_eq!(Target::from_json(target.to_json()).map(|(j, _)| j), Ok(target)); | ||
} | ||
|
||
impl Target { | ||
fn check_consistency(&self) { | ||
fn check_consistency(&self, triple: &str) { | ||
assert_eq!(self.is_like_osx, self.vendor == "apple"); | ||
assert_eq!(self.is_like_solaris, self.os == "solaris" || self.os == "illumos"); | ||
assert_eq!(self.is_like_windows, self.os == "windows" || self.os == "uefi"); | ||
assert_eq!(self.is_like_wasm, self.arch == "wasm32" || self.arch == "wasm64"); | ||
assert!(self.is_like_windows || !self.is_like_msvc); | ||
if self.is_like_msvc { | ||
assert!(self.is_like_windows); | ||
} | ||
|
||
// Check that default linker flavor and lld flavor are compatible | ||
// with some other key properties. | ||
|
@@ -94,8 +96,9 @@ impl Target { | |
check_noncc(LinkerFlavor::Ld); | ||
check_noncc(LinkerFlavor::Lld(LldFlavor::Ld)); | ||
} | ||
LldFlavor::Ld64 => check_noncc(LinkerFlavor::Lld(LldFlavor::Ld64)), | ||
LldFlavor::Wasm => check_noncc(LinkerFlavor::Lld(LldFlavor::Wasm)), | ||
LldFlavor::Ld64 | LldFlavor::Link => {} | ||
LldFlavor::Link => {} | ||
}, | ||
_ => {} | ||
} | ||
|
@@ -109,20 +112,56 @@ impl Target { | |
); | ||
} | ||
|
||
assert!( | ||
(self.pre_link_objects_self_contained.is_empty() | ||
&& self.post_link_objects_self_contained.is_empty()) | ||
|| self.link_self_contained != LinkSelfContainedDefault::False | ||
); | ||
if self.link_self_contained == LinkSelfContainedDefault::False { | ||
assert!( | ||
self.pre_link_objects_self_contained.is_empty() | ||
&& self.post_link_objects_self_contained.is_empty() | ||
); | ||
} | ||
|
||
// If your target really needs to deviate from the rules below, | ||
// except it and document the reasons. | ||
// Keep the default "unknown" vendor instead. | ||
assert_ne!(self.vendor, ""); | ||
assert_ne!(self.os, ""); | ||
if !self.can_use_os_unknown() { | ||
// Keep the default "none" for bare metal targets instead. | ||
assert_ne!(self.os, "unknown"); | ||
} | ||
|
||
// Check dynamic linking stuff | ||
// BPF: when targeting user space vms (like rbpf), those can load dynamic libraries. | ||
if self.os == "none" && self.arch != "bpf" { | ||
assert!(!self.dynamic_linking); | ||
} | ||
if self.only_cdylib | ||
|| self.crt_static_allows_dylibs | ||
|| !self.late_link_args_dynamic.is_empty() | ||
{ | ||
assert!(self.dynamic_linking); | ||
} | ||
// Apparently PIC was slow on wasm at some point, see comments in wasm_base.rs | ||
if self.dynamic_linking && !(self.is_like_wasm && self.os != "emscripten") { | ||
assert_eq!(self.relocation_model, RelocModel::Pic); | ||
} | ||
// PIEs are supported but not enabled by default with linuxkernel target. | ||
if self.position_independent_executables && !triple.ends_with("-linuxkernel") { | ||
assert_eq!(self.relocation_model, RelocModel::Pic); | ||
} | ||
if self.relocation_model == RelocModel::Pic { | ||
assert!(self.dynamic_linking || self.position_independent_executables); | ||
} | ||
Comment on lines
+151
to
+153
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. This requirement is a bit odd since our default values for target options violate it -- the default relocation model is PIC, but the default for |
||
if self.static_position_independent_executables { | ||
assert!(self.position_independent_executables); | ||
} | ||
if self.position_independent_executables { | ||
assert!(self.executables); | ||
} | ||
|
||
// Check crt static stuff | ||
if self.crt_static_default || self.crt_static_allows_dylibs { | ||
assert!(self.crt_static_respected); | ||
} | ||
} | ||
|
||
// Add your target to the whitelist if it has `std` library | ||
|
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
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
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.