-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Support for pointers with asm_const #128464
Comments
I think this is at least blocked on #125558 right now (which is done but runs into an error message ordering difference between CI and local that we don't know how to fix). |
First of all, it doesn't make sense to pass a pointer as a Secondly, what you are actually proposing is a generalization of sym, where rather than only supporting |
I understand that |
Indeed. Note that in my real use-case |
Everywhere else in the language, we do support pointers as "constants", and our backends do the right thing. You can use pointers as initial values for |
That may indicate that
Which doesn't really make sense for relocatable constants. The whole point of It's really more of a |
So then what is the right name for something in inline asm that can evaluate to a relocation with offset? "sym" does not seem right either, since the offset makes it not a symbol.
What does this look like in C?
Would it be a problem to use "const" even when the result is a relocation? This shod not be too surprising since it is how "const" works everywhere else in Rust. For int-typed consts we would still guarantee that the result is bare assembly without linker involvement.
|
@rustbot label A-rust-for-linux |
Nominating this for lang to discuss the question of whether we should support use of @Amanieu, any input you'd like to provide would be helpful. |
After thinking about it a bit, I think it's probably fine to add this functionality to |
As |
One issue is that this conflicts with another proposal that has been discussed on Zulip about having |
Interpolating string constant with |
@Amanieu The link is two years ago, so I guess we could discuss it here? I don't understand why accepting |
It was a while and I remember having a more in-depth discussion about it, but I can't find it (it may have been an in-person discussion). The basic problem is that this issue is about inserting a symbol pointing to a constant into assembly code. The other proposal is about taking a Both are reasonable ways in which the current |
The |
I would say this is about inserting the value of the constant into assembly code. A constant of type It's a bit like formatting: given the const value, how is it to be put into the assembly? For integer-typed constants, there's only really one option. For raw pointers, there's also really only one option. For references, we have the usual choice of either putting in the pointer value of the reference, or putting in the value that the reference points to. |
OK I think I understand. By saying "conflict", it is how the pointer is dealt with as inline assembly operand that is conflict. I agree that using another "keyword" like "interpolate" instead of reusing the "const" operand to format the |
We discussed this in the @rust-lang/lang triage meeting today. Meeting consensus was
Is there an implementation of this already or would that need to be done? |
@rustbot labels +I-lang-nominated I am nominating this issue for lang team discussion. The proposal is to extend trait Helper {
const MY_PTR: *const c_void;
}
fn my_asm_wrapper<T: Helper>() {
unsafe { asm!("mov {},eax", const T::MY_PTR) };
} as well as constants like the address of a particular field. This is needed by Rust For Linux. The question I would like answered is procedural: is this a small enough extension that we should simply "rfcbot fcp merge" in place, or would it better to have an RFC? It seems like a fairly minimal extension, but it also sets a bit of a precedent that I would expect to stabilize a minimal version of the feature as a starting point, accepting only raw pointers for example, and only thin ones. (References might be ok, too.) |
We still need to precisely specify how the constant reference is rendered as a string in the asm code. The most obvious form would be an assembler expression of the form |
@Amanieu are you suggesting that some constants may have be renderable at all on some targets? I would assume that this rendering is target specific. |
It's fine for the rendering to be target-specific, however we do need to document the rendering in the reference. |
Inline assembly supports an unstable feature called asm_const with tracking issue #93332 that lets you pass constants to inline assembly. However, it only supports integer types. This issue is a feature request to support raw pointers with asm_const.
This would enable code such as the following:
Currently, the above code would require you to convert
my_asm_wrapper
into amacro_rules!
so that you can write out the path to the global using thesym
operand. Supporting this would be useful for the Rust for Linux project, as implementing support for static keys requires a long list of workarounds at the moment.cc @Amanieu @oli-obk
The text was updated successfully, but these errors were encountered: