Skip to content

Commit bf091ff

Browse files
committed
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.
1 parent 9494033 commit bf091ff

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// Hook into .init_array to enable LSE atomic operations at startup, if
2+
/// supported.
3+
#[cfg(all(
4+
target_arch = "aarch64",
5+
target_os = "linux",
6+
any(target_env = "gnu", target_env = "musl"),
7+
not(feature = "compiler-builtins-c")
8+
))]
9+
#[used]
10+
#[unsafe(link_section = ".init_array.90")]
11+
static RUST_LSE_INIT: extern "C" fn() = {
12+
extern "C" fn init_lse() {
13+
use crate::arch;
14+
15+
// This is provided by compiler-builtins::aarch64_linux.
16+
unsafe extern "C" {
17+
fn __rust_enable_lse();
18+
}
19+
20+
if arch::is_aarch64_feature_detected!("lse") {
21+
unsafe {
22+
__rust_enable_lse();
23+
}
24+
}
25+
}
26+
init_lse
27+
};

library/std/src/sys/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![allow(unsafe_op_in_unsafe_fn)]
22

3+
/// The configure builtins provides runtime support compiler-builtin features
4+
/// which require dynamic intialization to work as expected, e.g. aarch64
5+
/// outline-atomics.
6+
mod configure_builtins;
7+
38
/// The PAL (platform abstraction layer) contains platform-specific abstractions
49
/// for implementing the features in the other submodules, e.g. UNIX file
510
/// descriptors.

0 commit comments

Comments
 (0)