-
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
inline ASM requires target features on some targets #112709
Comments
We did observe that setting Note that the code involved here is attempting to leverage runtime CPU feature detection (on aarch64, by querying the relevant OS-specific APIs) and so the relevant On |
This seems to fix the build failures we were experiencing here: rust-lang/rust#112709
This seems to fix the build failures we were experiencing here: rust-lang/rust#112709
I guess you have to add Details: First, aarch64-unknown-linux-gnu does not assume that AES instructions are always available, and attempting to use AES instructions in an inline assembly without enabling the However, this error is usually reported by LLVM after the inline assembly is actually passed to LLVM. For example, if there is an inline attribute, the function is not actually called, or if you are using cargo check instead of cargo build, this error may not yet appear: https://godbolt.org/z/6cdnhWTGc In your case, I guess that the error occurred because the As for performance degradation, I would suggest checking to see if it still occurs when In any case, this does not seem to be a compiler bug. Footnotes
|
@TAKI-E I actually came across that solution a few minutes before your response and it seems to be working: RustCrypto/block-ciphers@c7fe62e I'm willing to accept this is a legitimate bug in the original code, but it would be nice if there were diagnostics which reported the call sites as the error, rather than the inner function. I'm not sure if that deserves a separate issue or where to go from here. |
Hmm, the actual error is generated by LLVM, not rustc, so I'm not sure how realistic it would be to improve the diagnostics on rustc end. Also, when the problem is only the lack of target features, it may be reasonable to indicate that the problem is in the caller not using (BTW, LLVM intrinsics have similar issues, and stdarch has been switched from |
Interesting, I guess we should follow suit with Going to close this then. |
I don't think it's documented anywhere in Rust resources? It would be nice to have a mention about it in the reference at the very least. |
This seems surprising to me; shouldn't programmers be allowed to use "extra knowledge" about which instructions are available in an inline asm block, even if the compiler may not be aware that they are available here? And indeed this should definitely at the very least be documented. But IMO, we'd ideally get LLVM to stop doing this. The error does seem to also arise without |
inline(always)
fn
@RalfJung You can use "extra knowledge" in inline asm, but then you also need to annotate it accordingly. You should be able to replace |
I checked, and it does work fine: https://godbolt.org/z/1EY6MW7e5 |
But why is such an annotation required? The main point of Also, there's still the bug that this isn't documented anywhere on https://doc.rust-lang.org/nightly/reference/inline-assembly.html. |
@nikic oh nice, does that eliminate the need for the corresponding For example we just ran into that trying to add VAES support to the |
I agree with @RalfJung, to me the need for |
I can only guess, but presumably it's to prevent accidental use of instructions that are not supported on the target. To be clear, this behavior is not an LLVM invention, it's general assembler behavior for that target. You'll see exactly the same thing if you don't use the integrated assembler and use e.g. binutils instead: https://asm.godbolt.org/z/Mxa1YbnYd
Yes, as this is part of the assembly string, it's not subject to rustc's stability checks. |
What are potential drawbacks of enabling all available extensions automatically? I can understand why this feature was historically introduced (after all you need assembler plugins to know how to translate new instructions to binary code), but I am not sure if it's worth to require an explicit opt-in for it in Rust assembler. |
@nikic sorry for the sidebar, but is this error possible to resolve by providing an appropriate
|
@tarcieri That would require stabilization. It's enforced by rustc, not by LLVM. |
I have code that, for whatever reason, will compile on
aarch64-apple-darwin
but not onaarch64-unknown-linux-gnu
. It's asking me to enabletarget_feature
s on a function that's annotatedinline(always)
(which, in and of itself, does not seem to make sense).A minimal reproduction is also elusive in that everything I've tried so far compiles. I'm wondering if this is some kind of bug related to the inliner.
To start with, here are the functions it's complaining about:
These compile fine in and of themselves. In fact trying to put together a minimal repro I haven't been able to reproduce the compile error, even with quite a bit of the related code in place: https://godbolt.org/z/P7h8KsaMG
So it seems like some strange interactions in more complicated code, possibly related to inlining.
It's easily reproducible, but unfortunately the only repro I have to offer is the following commit of this PR: RustCrypto/block-ciphers@7818f35
The compile error is as follows (which I've reproduced locally): https://github.com/RustCrypto/block-ciphers/actions/runs/5283017067/jobs/9558698657
One more odd observation, the compile error can be "solved" by replacing
#[inline(always)]
with#[target_feature(enable = "aes")]
, as in here: RustCrypto/block-ciphers@10debe5However, this solution seemed to cause massive performance degradation with spooky-action-at-a-distance impacts on seemingly unrelated code (although code that was using the same CPU instruction): RustCrypto/block-ciphers#365 (comment)
Meta
This reproduces on all versions of rustc I've tried, including the latest nighty. The code in question is targeting an MSRV of 1.61, where the error also occurs.
The text was updated successfully, but these errors were encountered: