Skip to content

RISC-V: add note about target features vs. misa extensions - #2354

Open
TechnoPorg wants to merge 1 commit into
rust-lang:masterfrom
TechnoPorg:riscv-clarify-target-features
Open

RISC-V: add note about target features vs. misa extensions#2354
TechnoPorg wants to merge 1 commit into
rust-lang:masterfrom
TechnoPorg:riscv-clarify-target-features

Conversation

@TechnoPorg

Copy link
Copy Markdown

As per the discussion in rust-lang/rust#162552 and #t-compiler/risc-v > RISC-V extensions vs. Rust target features, this clarifies that enabling a target feature means the misa bit of the same name (if any) is assumed to always be set. Although this originally came up in the context of the M extension, it applies to many others as well, which are listed in the linked Machine ISA manual page.

cc @RalfJung

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Sep 11, 2026
Comment thread src/attributes/codegen.md
Comment on lines +566 to +571
> [!NOTE]
> Some RISC-V standard extensions can be enabled (1) or disabled (0) via their corresponding bits in the [Machine ISA][rv-machine] (`misa`) register.
> For example, the [A][rv-a] and [M][rv-m] bits being cleared means atomic instructions and integer multiplication/division instructions are unimplemented.
>
> Rust code compiled with a RISC-V target feature of the same name as an extension assumes the extension will always be available.
> It is undefined behaviour to execute it in an environment where the extension is disabled (bit is 0 in `misa`).

@RalfJung RalfJung Sep 12, 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.

I think a note (which is not normative) is not enough here. We need to say, normatively, that code compiled with a "single-letter target feature" (or whatever they are called) is UB to invoke unless the corresponding bit is actually set in the misa register.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Would that go in the same part of the document, just not as a note?

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.

I'm not sure -- @traviscross @ehuss

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

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants