Skip to content

Support using const pointers in asm const operand#138618

Open
nbdd0121 wants to merge 10 commits intorust-lang:mainfrom
nbdd0121:asm_const_ptr
Open

Support using const pointers in asm const operand#138618
nbdd0121 wants to merge 10 commits intorust-lang:mainfrom
nbdd0121:asm_const_ptr

Conversation

@nbdd0121
Copy link
Member

@nbdd0121 nbdd0121 commented Mar 17, 2025

View all comments

Implements RFC#3848 with tracking issue #128464

This adds support of const pointers for asm const in addition to plain integers.

The inline asm! support is implemented using i constraint, and the global_asm! and naked_asm! support is implemented by inserting symbol + offset and make symbol compiler-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.

@rustbot
Copy link
Collaborator

rustbot commented Mar 17, 2025

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 17, 2025
@fmease
Copy link
Member

fmease commented Mar 17, 2025

r? codegen

@rustbot rustbot assigned workingjubilee and unassigned fmease Mar 17, 2025
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Contributor

r? compiler-errors

@rustbot
Copy link
Collaborator

rustbot commented Apr 10, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

out_place: Option<PlaceRef<'tcx, B::Value>>,
},
Const {
Interpolate {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more doc comment explaining the significance of the difference between Interpolate and Const for backends. It begs the question for why we ever turn const operands into strings, for example.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some explaination. Technically we should be able to use Const for integers, although I am a bit conservative here and don't want to change how existing things work.

This might also be useful to have in the future if we decided to add interpolate "some CTFE string to be interpolated" new type of operand.

@bors
Copy link
Collaborator

bors commented Apr 29, 2025

☔ The latest upstream changes (presumably #140415) made this pull request unmergeable. Please resolve the merge conflicts.

@traviscross
Copy link
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 4, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented May 13, 2025

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@bors
Copy link
Collaborator

bors commented May 28, 2025

☔ The latest upstream changes (presumably #141668) made this pull request unmergeable. Please resolve the merge conflicts.

// and on x86 PIC symbol can't be constant.
// x86_64-LABEL: const_ptr:
// x86_64: #APP
// x86_64: mov al, byte ptr [{{.*}}anon{{.*}}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// x86_64: mov al, byte ptr [{{.*}}anon{{.*}}]

What was the expansion you observed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mov al, byte ptr [.Lanon.2e8c0013b01edcd3779e8174c2338a00.0]

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 19, 2025
@rust-log-analyzer

This comment has been minimized.

@nbdd0121
Copy link
Member Author

@rustbot ready

@nbdd0121
Copy link
Member Author

r? @rust-lang/compiler

@BoxyUwU
Copy link
Member

BoxyUwU commented Dec 29, 2025

for the future you can just write r? compiler you dont have to ping the whole compiler team :3

@nbdd0121
Copy link
Member Author

Oops, sorry!

@bors
Copy link
Collaborator

bors commented Jan 1, 2026

☔ The latest upstream changes (presumably #150559) made this pull request unmergeable. Please resolve the merge conflicts.

@wesleywiser
Copy link
Member

r? rust-lang/compiler

@rustbot rustbot assigned chenyukang and unassigned SparrowLii Mar 5, 2026
@saethlin saethlin assigned saethlin and unassigned chenyukang Mar 6, 2026
@saethlin
Copy link
Member

saethlin commented Mar 6, 2026

@nbdd0121 I've self-assigned this because I'm going to delta-review it this weekend, so it would be worth fixing the merge conflicts whenever convenient.

nbdd0121 added 10 commits March 6, 2026 11:53
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 removed, as it supports `#[thread_local]`
statics where CTFE does not.
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.
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.