about summary refs log tree commit diff
path: root/library/std/src/sys/configure_builtins.rs
diff options
context:
space:
mode:
authorPaul Murphy <murp@redhat.com>2025-07-31 17:25:00 -0400
committerPaul Murphy <murp@redhat.com>2025-08-05 10:35:13 -0500
commit6936bb975a50bf3c575d5642018ce19c58dcacf1 (patch)
treefe9bfc67dfe974322332d6f6f98798cf0ab4a31a /library/std/src/sys/configure_builtins.rs
parent3b50253b57b130fdcef167fc0c03a9a19210fae2 (diff)
downloadrust-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.
Diffstat (limited to 'library/std/src/sys/configure_builtins.rs')
-rw-r--r--library/std/src/sys/configure_builtins.rs22
1 files changed, 22 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
+};