Support using const pointers in asm const operand#138618
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
r? codegen |
This comment has been minimized.
This comment has been minimized.
|
r? compiler-errors |
|
Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_gcc |
|
☔ The latest upstream changes (presumably #140415) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
|
☔ The latest upstream changes (presumably #141668) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
| // current codegen unit | ||
| tcx.symbol_name(instance) | ||
| } | ||
| GlobalAlloc::Static(def_id) => { |
There was a problem hiding this comment.
What is the difference between GlobalAsmOperandRef::Const with a static and GlobalAsmOperandRef::SymStatic?
There was a problem hiding this comment.
#[thread_local] works with sym STATIC today, but it cannot be referenced in CTFE. I would actually be in favour of removing that feature.
There was a problem hiding this comment.
I would tend to agree with removing #[thread_local] support for sym STATIC. On some platforms (cough Windows cough) #[thread_local] accesses go through a function shim to ensure cross-dylib accesses work, so sym STATIC would probably already be broken for those platforms.
There was a problem hiding this comment.
Rename GlobalAsmOperandRef::SymStatic to SymThreadLocalStatic
|
I think the approach I use in rustc_codegen_gcc to avoid symbol name collision when a const is generated multiple times doesn't work if multiple CGUs decide to codegen the same symbol for a promoted constant. The proper fix I think is to let backend mint new symbol names, rather than construct a fake |
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
This comment has been minimized.
This comment has been minimized.
This is currently a no-op, but will be useful when const in `global_asm!` can be pointers.
Currently global_asm already have symbol names when using v0 scheme, this makes them obtain symbols with legacy scheme too.
This gives the asm-const code the basic ability to deal wiht pointer and provenances, which lays the ground work for asm_const_ptr. Note that `SymStatic` is not fully removed, a specialized is kept and renamed as `SymThreadLocalStatic`, for `#[thread_local]` statics where CTFE does not support naming. The `#[thread_local]` is unstable feature and it's not clear if we want to support this in `sym`, but removal of it should be a separate PR.
With the previous commit, now we can see there are some code duplication for the handling of `GlobalAlloc` inside backends. Do some clean up to unify them.
CTFE pointers created via type ID, `without_provenance` or pointers to const ZSTs can now be codegenned with all 3 backends. These pointers are generated in the same way as integers.
The backend now fully supports codegen of const pointers, remove the block inside typeck behind a new feature gate. Tests are also added.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I've reworked how symbol name is generated and stop using the mangled name of the const, due to the outlined symbol name conflict issue above. This also resolves the concern #138618 (comment). The new approach generates an unique symbol name prefix for each CGU, and then the codegen backends can use this symbol prefix to create helper symbols that they need internally. I think this can be useful longer term as well. The generated prefix is demangled to something like EDIT: Due to two pushes the range-diff above is not the full picture, this is the full range diff. |
|
Is the cgu index still included in the symbol name when the number of cgus is 1? |
|
It'll still demangle to things like |
|
@rustbot ready |
View all comments
Implements RFC#3848 with tracking issue #128464
This adds support of const pointers for asm
constin addition to plain integers.The inline
asm!support is implemented usingiconstraint, and theglobal_asm!andnaked_asm!support is implemented by insertingsymbol + offsetand makesymbolcompiler-used. For unnamed consts, it will create additional internal & hidden symbols so that they can be referenced by global_asm.The feature is also implemented for GCC backend but it's untested.Tested now.