-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for link_llvm_intrinsics
#29602
Comments
We should just kill this off; there aren't any in-tree users, and it would be impossible to stabilize because LLVM doesn't make any stability promises about intrinsics. |
I am using Some of these intrinsics belong in rustc, but even those would either remain unstable for a long period of time, or never be stabilized. This feature allows using these intrinsics out of tree for the benefit of the users of a nightly compiler (performance-wise). |
I've since switched to |
@aweinstock314 Are you still actively using this feature? |
@cramertj the The idea is to move the |
Is there a way to make features usable only in |
Some unstable features are named |
FWIW, this was really convenient as a way to try out whether an LLVM intrinsic is even helpful before doing all the work to make and propose a rustc intrinsic for it. |
I'm using this in https://crates.io/crates/prefetch, as mentioned; I'm also using it (through https://crates.io/crates/llvmint) in https://github.com/aweinstock314/libgarble-rust for AES-NI (inline assembly was generating suboptimal assembly relative to intrinsics). I don't think my usage depends on them being eventually stabilised, so the |
The AES-NI intrinsics might become stabilized in the future via |
As a concrete example of why I'd like this to stick around as forever-unstable, I could do the following to experiment with the new intrinsics mentioned in #55286 without a code change: #![feature(link_llvm_intrinsics)]
extern {
#[link_name="llvm.sadd.sat.i32"]
fn add_sat_i32(x: i32, y: i32) -> i32;
#[link_name="llvm.uadd.sat.i32"]
fn add_sat_u32(x: u32, y: u32) -> u32;
}
pub unsafe fn test_sfold(x: i32) -> i32 {
add_sat_i32(add_sat_i32(x, 10), 20)
}
pub unsafe fn test_ufold(x: u32) -> u32 {
add_sat_u32(add_sat_u32(x, 10), 20)
} |
Does anyone know how to represent the LLVM |
This feature only lets you link a rust function to an LLVM intrinsic function, but it doesn't let you use types that aren't available in Rust. So if you can't represent it with a Rust type, you can't do so with this feature, and might need to either add a rustc intrinsic, or a rustc type. Adding intrinsics is usually easier. |
If this feature can be removed, how will it be removed? I think rust/compiler/rustc_ast_passes/src/feature_gate.rs Lines 458 to 467 in 77b996e
|
It would turn into a hard error I would guess. |
I just wanted to add that I have never been able to make it work the same as _ReturnAddress() Rust, Not working, I should get the same address as I get with _ReturnAddress()... extern "C" {
#[link_name = "llvm.returnaddress"]
fn return_address(level: i32) -> *const i8;
}
println!("return_addresss is: {:#X?}", return_address(0)); C++, Working fine, I get the correct return address of my function. _ReturnAddress()
printf("_ReturnAddress is: 0x%p\n", _ReturnAddress()); |
What do you actually need it for? Also what would you expect it to return in case a part of a function is outlined by LLVM to improve cache locality? Do you expect the return address of the outlined function or the function out of which it was outlined? And what do you expect it to return in case the current function was inlined? And what about targets where the return address doesn't exist at all, like wasm? |
Hey @bjorn3, thanks for your answer and asking to clarify a couple of points, well foremost, I am not expert with both Rust/LLVM, but I really enjoy Rust and the community behind it, and want it to be my main programming language and drop C/C++. Nevertheless, I do know my work environment well which is mainly reverse-engineering and memory editing, thus creating software programs that affect live process. So I will surely modify this answer later, but for the moment I will describe my exact use case, which is really simple:
Now we are getting to the point where this is problematic in Rust:
I make sure that my hooked function is preceded by
In any case, I am pretty confident that this feature should stay as forever-unstable, like for the fact you mentioned that return address doesn't even exist at all for some target. But what I would like, is to at least make it work on Rust Nightly to have the same behavior as it currently is on C/C++ (only tested the _ReturnAddress intrinsic with MSVC). |
Thanks for the detailed explanation of your use case! On nightly #![feature(link_llvm_intrinsics)]
extern "C" {
#[link_name = "llvm.returnaddress"]
fn return_address(level: i32) -> *const i8;
}
fn main() {
println!("return_address is: {:#X?}", unsafe { return_address(0) });
println!("address of main is: {:#X?}", main as fn());
} works for me and prints
What is the exact issue you have? |
The issue is that for the same use case, I am getting two different return address when I should get the same on both C++ and Rust. Same code, same hooking method, different result. I think that for my use case there is something more complex going on with LLVM, is your exemple this is a plain standard function in Rust, so you are getting the return address correctly. In my case, I am calling a detoured function. I think I should try to compile C++ code with Clang/LLVM and see if this is different too. So many question now.., are llvm.returnaddress and _ReturnAddress intrinsics supposed to have the same behavior? |
I tried both |
@bjorn3 I just want to confirm (after a lot of testing) that everything works great :), the issue was the hooking method, I switched from Microsoft Detours to a custom minhook implementation, and it is now working as intended 😄. |
Tracks
stabilization forthelink_llvm_intrinsics
feature, used via#[link_name="llvm.*"]
.Edit: As this is obviously back-end specific, it will most likely never be stabilized.
The text was updated successfully, but these errors were encountered: