diff options
| author | Paul Murphy <murp@redhat.com> | 2025-07-31 17:25:00 -0400 |
|---|---|---|
| committer | Paul Murphy <murp@redhat.com> | 2025-08-05 10:35:13 -0500 |
| commit | 6936bb975a50bf3c575d5642018ce19c58dcacf1 (patch) | |
| tree | fe9bfc67dfe974322332d6f6f98798cf0ab4a31a | |
| parent | 3b50253b57b130fdcef167fc0c03a9a19210fae2 (diff) | |
| download | rust-6936bb975a50bf3c575d5642018ce19c58dcacf1.tar.gz rust-6936bb975a50bf3c575d5642018ce19c58dcacf1.zip | |
Dynamically enable LSE for aarch64 rust provided intrinsics
Create a private module to hold the bootstrap code needed enable LSE at startup on aarch64-*-linux-* targets when rust implements the intrinsics. This is a bit more heavyweight than compiler-rt's LSE initialization, but has the benefit of initializing the aarch64 cpu feature detection for other uses. Using the rust initialization code does use some atomic operations, that's OK. Mixing LSE and non-LSE operations should work while the update flag propagates.
| -rw-r--r-- | library/std/src/sys/configure_builtins.rs | 22 | ||||
| -rw-r--r-- | library/std/src/sys/mod.rs | 5 |
2 files changed, 27 insertions, 0 deletions
diff --git a/library/std/src/sys/configure_builtins.rs b/library/std/src/sys/configure_builtins.rs new file mode 100644 index 00000000000..9d776b778dc --- /dev/null +++ b/library/std/src/sys/configure_builtins.rs @@ -0,0 +1,22 @@ +/// 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")))] +#[used] +#[unsafe(link_section = ".init_array.90")] +static RUST_LSE_INIT: extern "C" fn() = { + extern "C" fn init_lse() { + use crate::arch; + + // This is provided by compiler-builtins::aarch64_linux. + unsafe extern "C" { + fn __rust_enable_lse(); + } + + if arch::is_aarch64_feature_detected!("lse") { + unsafe { + __rust_enable_lse(); + } + } + } + init_lse +}; diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index f9a02b522e5..8ec0a0e3302 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -1,5 +1,10 @@ #![allow(unsafe_op_in_unsafe_fn)] +/// The configure builtins provides runtime support compiler-builtin features +/// which require dynamic intialization to work as expected, e.g. aarch64 +/// outline-atomics. +mod configure_builtins; + /// The PAL (platform abstraction layer) contains platform-specific abstractions /// for implementing the features in the other submodules, e.g. UNIX file /// descriptors. |
