-
Notifications
You must be signed in to change notification settings - Fork 13.6k
compiler-builtins: plumb LSE support for aarch64 on linux/gnu when optimized-compiler-builtins not enabled #144705
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
base: master
Are you sure you want to change the base?
Conversation
Agreed that we should be able to support these in Would things work if the check+init routine was moved into I'm certain @Amanieu has some thoughts here |
library/compiler-builtins/compiler-builtins/src/aarch64_linux.rs
Outdated
Show resolved
Hide resolved
library/compiler-builtins/compiler-builtins/src/aarch64_linux.rs
Outdated
Show resolved
Hide resolved
Hrm, the check does need to move out. Where in Technically, I don't think the switchover to LSE has to happen very early, but earlier is probably better for performance. |
Looking closer, if optimized-compiler-builtins are enabled and How much trouble would it be to explicitly require a user to supply |
There probably isn't a good fit currently. Maybe a new module like
Would the library where the configuration code lives make a difference for timing? I think rust/library/std/src/sys/args/unix.rs Line 120 in 3fb1b53
Good point, that part probably doesn't actually matter then. It is likely still beneficial to keep |
library/compiler-builtins/compiler-builtins/src/aarch64_linux.rs
Outdated
Show resolved
Hide resolved
Add dynamic support for aarch64 LSE atomic ops on linux/gnu targets when optimized-compiler-builtins is not enabled. The resulting asm should exactly match that of LLVM's compiler-rt builtins, though the symbol naming for the support function and global does not.
Create a private module to hold the bootstrap code needed enable LSE at startup on aarch64-*-linux-gnu* 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.
/// Call to enable LSE atomic operations. | ||
pub fn enable_lse() { | ||
HAVE_LSE_ATOMICS.store(1, Ordering::Relaxed); | ||
} |
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.
It's probably okay to call this directly in std
, but all builtins intrinsics are called by extern
so it's probably safest to do the same here (the std
dependency should actually be removed in 42bf044). The intrinsics macro handles no_mangle
and weak linkage:
intrinsics! {
pub extern "C" fn __rust_enable_lse() {
// ...
}
}
Any reason this is a draft still? Assuming you have tested that the current setup works, it lgtm with the above change (though I'll ask Amaieu to take a look)
#[cfg(all( | ||
target_arch = "aarch64", | ||
target_os = "linux", | ||
target_env = "gnu", |
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.
Looks like we actually do have this on musl since very recently 3d0dedd. Gating on target_feature = "outline-atomics"
would be ideal, but that doesn't seem to work for some reason.
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.
Gating on
target_feature = "outline-atomics"
would be ideal, but that doesn't seem to work for some reason.
At the moment this is the only way I can see this working. Fundamentally compiler-builtins is not able to call into other libraries so LSE must be manually initialized from outside. |
Add dynamic support for aarch64 LSE atomic ops on linux/gnu targets when optimized-compiler-builtins is not enabled.
Enabling LSE is the primary motivator for #143689, though extending the rust version doesn't seem too farfetched. Are there more details which I have overlooked which make this impractical? I've tested this on an aarch64 host with LSE.
r? @tgross35