-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Target-feature documented as unsafe #64145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Known Issues | ||
This section informs you about known "gotchas". Keep in mind, that this section is (and always will be) incomplete. For suggestions and amendments, feel free to [contribute](../contributing.md) to this guide. | ||
|
||
## Target Features | ||
Most target-feature problems arise, when mixing code that have the target-feature _enabled_ with code that have it _disabled_. If you want to avoid undefined behavior, it is recommended to build _all code_ (including the standard library and imported crates) with a common set of target-features. | ||
|
||
By default, compiling your code with the `-C target-feature` flag will not recompile the entire standard library and/or imported crates with matching target features. Therefore, target features are generally considered as unsafe. Using `#[target_feature]` on individual functions makes the function unsafe. | ||
|
||
Examples: | ||
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. I'm not sure how useful this would be. I don't think it is practical for us to document all features on all architectures that could cause problems when combined in different ways, and would very much prefer a solution to the problem that does not rely on documentation. Right now Rust does not know much about how target-features interact with call ABI. It probably should. 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. You're invited to wish for a better solution but we're not even generating shims for the more specific sub-problem of vector values and we've been suffering from that problem for the several years. Documenting that it is de facto unsafe now and underlining that with some scary examples is a good step forward. I agree that an exhaustive list is not practical but that's not necessary. 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. @eddyb a quick workaround for this form of UB would be to pass This would be a temporary solution, until we can either diagnose these issues or generate appropriate shims. It might be horrible for performance of numeric code, I don't know. |
||
|
||
| Target-Feature | Issue | Seen on | Description | Details | | ||
| -------------- | ----- | ------- | ----------- | ------- | | ||
| `+soft-float` <br> and <br> `-sse` | Segfaults and ABI mismatches | `x86` and `x86-64` | The `x86` and `x86_64` architecture uses SSE registers (aka `xmm`) for floating point operations. Using software emulated floats ("soft-floats") disables usage of `xmm` registers, but parts of Rust's core libraries (e.g. `std::f32` or `std::f64`) are compiled without soft-floats and expect parameters to be passed in `xmm` registers. This leads to ABI mismatches. <br><br> Attempting to compile with disabled SSE causes the same error, too. | [#63466](https://github.com/rust-lang/rust/issues/63466) | |
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 isn't this in the
target_feature
section? (i.e. why do we need a new section for this?).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 far as I understood, there are waay more issues, which are not documented yet.
Niko asked me to create a dedicated page, where all issues are listed.
The benefit is, that this vital info is not scattered/fragmented across many pages.
I am always open to suggestions :)