Skip to content

Use cfi_encoding instead of name in abi checking in miri - #164739

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
hkalbasi:cfi_encoding_miri
Oct 24, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
hkalbasi:cfi_encoding_miri

Conversation

@hkalbasi

Copy link
Copy Markdown
Member

Based on rust-lang/unsafe-code-guidelines#626 I think this patch helps in reflecting the current reality around abi compatibility and cfi better.

@rustbot

rustbot commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

@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 Oct 22, 2026
@rustbot

rustbot commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, mir
  • compiler, mir expanded to 77 candidates
  • Random selection from 20 candidates

Comment on lines +89 to +90
#[cfi_encoding = "CfiEncoded"]
pub struct CfiEncoded1 {

@Darksonn Darksonn Oct 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CFI encodings are prefixed with the length of the tag.

Suggested change
#[cfi_encoding = "CfiEncoded"]
pub struct CfiEncoded1 {
#[cfi_encoding = "10CfiEncoded"]
pub struct CfiEncoded1 {

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One has to do that manually...? What happens if I don't?

I thought this was just the tag so we don't have to worry about the rest of the encoding.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All that happens is that it's only compatible with other structs also missing the integer prefix in the encoding.

I think it was done this way to also allow specifying the cfi encoding of e.g. a specific integer type, which do not have the integer prefix, putting them in a different "namespace" than structs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh so this can make a type look like an integer? Then I misunderstood what you said in rust-lang/unsafe-code-guidelines#626.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So for this PR it doesn't really matter then. The logic in compiler/rustc_const_eval/src/interpret/call.rs is fine. Just the test is probably a bad example for how to use the attribute which ideally we should avoid.

Suggested change
#[cfi_encoding = "CfiEncoded"]
pub struct CfiEncoded1 {
#[cfi_encoding = "10CfiEncoded"] // CFI encodings say that we should prefix the struct tag with its length
pub struct CfiEncoded1 {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed the call.rs logic, to handle cases when a #[cfi_encoding] struct is matched with a normal struct. It's sad that call.rs should contain cfi specific logic, ideally we should have #[repr(C, tag = "CfiEncoded")] or something like that, but for now the new call.rs looks more correct to me than the previous one. An alternative is to reject compatibility between normal and #[cfi_encoding] structs, I can do that instead, if desired.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An alternative is to reject compatibility between normal and #[cfi_encoding] structs, I can do that instead, if desired.

I'd prefer that TBH. That attribute seems quite cursed in its current behavior, good thing that it is still unstable.

@RalfJung

Copy link
Copy Markdown
Member

r? me

@RalfJung

Copy link
Copy Markdown
Member

@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 Oct 23, 2026
@hkalbasi

Copy link
Copy Markdown
Member Author

@rustbot review

@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 Oct 23, 2026
@RalfJung

Copy link
Copy Markdown
Member

@bors r+
Looks good, thanks :)

@rust-bors

rust-bors Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4b535e4 has been tentatively approved by RalfJung

It will be put into the queue for this repository once PR CI succeeds.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 23, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #163743 (std: simplify the miri bypass of the stack overflow detection logic)
 - #164474 (core: implement `char::is_xid_{start|continue}`)
 - #164643 (Const-stabilize `{BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque)::{len, is_empty}`)
 - #164739 (Use cfi_encoding instead of name in abi checking in miri)
 - #162927 (stabilize ptr_cast_slice)
 - #163372 (Restrict `PartialEq` and `PartialOrd` documentation to thin pointers)
 - #164261 (Simplify MSYS check in is_terminal on Windows)
 - #164698 (Remove FCP from libs tracking checklist)
 - #164810 (Don't prioritize issues that require internal features)
@rust-bors
rust-bors Bot merged commit f7cc873 into rust-lang:main Oct 24, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 24, 2026
Rollup merge of #164739 - hkalbasi:cfi_encoding_miri, r=RalfJung

Use cfi_encoding instead of name in abi checking in miri

Based on rust-lang/unsafe-code-guidelines#626 I think this patch helps in reflecting the current reality around abi compatibility and cfi better.
programskillforverification pushed a commit to programskillforverification/miri that referenced this pull request Oct 24, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#163743 (std: simplify the miri bypass of the stack overflow detection logic)
 - rust-lang/rust#164474 (core: implement `char::is_xid_{start|continue}`)
 - rust-lang/rust#164643 (Const-stabilize `{BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque)::{len, is_empty}`)
 - rust-lang/rust#164739 (Use cfi_encoding instead of name in abi checking in miri)
 - rust-lang/rust#162927 (stabilize ptr_cast_slice)
 - rust-lang/rust#163372 (Restrict `PartialEq` and `PartialOrd` documentation to thin pointers)
 - rust-lang/rust#164261 (Simplify MSYS check in is_terminal on Windows)
 - rust-lang/rust#164698 (Remove FCP from libs tracking checklist)
 - rust-lang/rust#164810 (Don't prioritize issues that require internal features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants