-
-
Notifications
You must be signed in to change notification settings - Fork 16.8k
Lang proposal: extern "unspecified" for naked functions with arbitrary ABI #140566
Copy link
Copy link
Closed
Labels
A-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.F-abi_custom`#![feature(abi_custom)]``#![feature(abi_custom)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Description
Activity
Metadata
Metadata
Assignees
Labels
A-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.F-abi_custom`#![feature(abi_custom)]``#![feature(abi_custom)]`I-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
View all comments
Background
One of the uses of naked functions is to implement custom calling conventions. We have some code in compiler-builtins like this:
The ABI needs to be specified, so
extern "C"is used. However, this is misleading as the function does not actually use the C calling convention.Correct ABI would be considered part of the preconditions for this function and it would only be callable inside an
unsafeblock, but Rust has no way to call the function correctly so it seems like we should prevent this.Proposal
Add a new "unspecified" ABI that may be used with naked functions. Rust will error on attempts to call them.
Proposed rules:
extern "unspecified"can only be used with naked functions orexternblocksextern "unspecified". It can still be passed as a function pointer, and it can be asymin an asm block.extern "unspecified"functions must be markedunsafe, and cannot besafe fnwith anexternblock. This is a hard error. (I'm less certain about this rule since unsafety doesn't mean much if you can't call it. Proposed because it seems consistent with how it must be used, given the function still has preconditions, and it's probably makes sense to treat them asunsafein the compiler.)Questions:
cc @rust-lang/lang, @folkertdev, @Amanieu
(currently empty) thread for discussion on Zulip: https://rust-lang.zulipchat.com/#narrow/channel/216763-project-inline-asm/topic/.60extern.20.22unspecified.22.60.20for.20naked.20functions/with/515596073