-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Enable outline-atomics by default on more AArch64 platforms
#144938
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
+52
−16
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0030e8a
compiler-builtins: Change gating for outline atomic symbols
tgross35 2105a25
Make the `RUST_LSE_INIT` constructor cross-platform
tgross35 1ed1b6e
Enable `outline-atomics` by default on AArch64 Windows platforms
tgross35 c455903
Enable `outline-atomics` by default on AArch64 Android
tgross35 21525f8
Enable `outline-atomics` by default on AArch64 Fuchsia
tgross35 66c150c
Enable `outline-atomics` by default on AArch64 OpenBSD
tgross35 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,49 @@ | ||
| /// Hook into .init_array to enable LSE atomic operations at startup, if | ||
| /// supported. | ||
| #[cfg(all(target_arch = "aarch64", target_os = "linux", not(feature = "compiler-builtins-c")))] | ||
| /// Enable LSE atomic operations at startup, if supported. | ||
| /// | ||
| /// Linker sections are based on what [`ctor`] does, with priorities to run slightly before user | ||
| /// code: | ||
| /// | ||
| /// - Apple uses the section `__mod_init_func`, `mod_init_funcs` is needed to set | ||
| /// `S_MOD_INIT_FUNC_POINTERS`. There doesn't seem to be a way to indicate priorities. | ||
| /// - Windows uses `.CRT$XCT`, which is run before user constructors (these should use `.CRT$XCU`). | ||
| /// - ELF uses `.init_array` with a priority of 90, which runs before our `ARGV_INIT_ARRAY` | ||
| /// initializer (priority 99). Both are within the 0-100 implementation-reserved range, per docs | ||
| /// for the [`prio-ctor-dtor`] warning, and this matches compiler-rt's `CONSTRUCTOR_PRIORITY`. | ||
| /// | ||
| /// To save startup time, the initializer is only run if outline atomic routines from | ||
| /// compiler-builtins may be used. If LSE is known to be available then the calls are never | ||
| /// emitted, and if we build the C intrinsics then it has its own initializer using the symbol | ||
| /// `__aarch64_have_lse_atomics`. | ||
| /// | ||
| /// Initialization is done in a global constructor to so we get the same behavior regardless of | ||
| /// whether Rust's `init` is used, or if we are in a `dylib` or `no_main` situation (as opposed | ||
| /// to doing it as part of pre-main startup). This also matches C implementations. | ||
| /// | ||
| /// Ideally `core` would have something similar, but detecting the CPU features requires the | ||
| /// auxiliary vector from the OS. We do the initialization in `std` rather than as part of | ||
| /// `compiler-builtins` because a builtins->std dependency isn't possible, and inlining parts of | ||
| /// `std-detect` would be much messier. | ||
| /// | ||
| /// [`ctor`]: https://github.com/mmastrac/rust-ctor/blob/63382b833ddcbfb8b064f4e86bfa1ed4026ff356/shared/src/macros/mod.rs#L522-L534 | ||
| /// [`prio-ctor-dtor`]: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html | ||
| #[cfg(all( | ||
| target_arch = "aarch64", | ||
| target_feature = "outline-atomics", | ||
| not(target_feature = "lse"), | ||
| not(feature = "compiler-builtins-c"), | ||
| ))] | ||
| #[used] | ||
| #[unsafe(link_section = ".init_array.90")] | ||
| #[cfg_attr(target_vendor = "apple", unsafe(link_section = "__DATA,__mod_init_func,mod_init_funcs"))] | ||
| #[cfg_attr(target_os = "windows", unsafe(link_section = ".CRT$XCT"))] | ||
| #[cfg_attr( | ||
| not(any(target_vendor = "apple", target_os = "windows")), | ||
| unsafe(link_section = ".init_array.90") | ||
| )] | ||
| static RUST_LSE_INIT: extern "C" fn() = { | ||
| extern "C" fn init_lse() { | ||
| use crate::arch; | ||
|
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. This comment is actually for line 37 below. Shouldn't the comment be updated to refer to the renamed file?
Contributor
Author
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. Thanks for catching this! Updated |
||
|
|
||
| // This is provided by compiler-builtins::aarch64_linux. | ||
| // This is provided by compiler-builtins::aarch64_outline_atomics. | ||
| unsafe extern "C" { | ||
| fn __rust_enable_lse(); | ||
| } | ||
|
|
||
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.