diff --git a/text/0000-extern-custom.md b/text/3980-extern-custom.md similarity index 94% rename from text/0000-extern-custom.md rename to text/3980-extern-custom.md index af1e05fbbe9..ee4cb361231 100644 --- a/text/0000-extern-custom.md +++ b/text/3980-extern-custom.md @@ -1,9 +1,9 @@ - Feature Name: `abi_custom` - Start Date: 2026-07-01) -- RFC PR: [rust-lang/rfcs#0000](https://github.com/rust-lang/rfcs/pull/0000) +- RFC PR: [rust-lang/rfcs#3980](https://github.com/rust-lang/rfcs/pull/3980) - Rust Issue: [rust-lang/rust#140829)](https://github.com/rust-lang/rust/issues/140829) -# Summary +## Summary [summary]: #summary An `extern "custom" fn` is a function with a custom ABI that is unknown to rust. Often these are low-level functions that pass arguments in different registers than any standard calling convention, so using this helps rustc block you from using this in any place where rustc would need to understand that calling convention. @@ -40,14 +40,14 @@ unsafe extern "custom" { * https://github.com/rust-lang/rust/pull/140770 * https://github.com/rust-lang/rust/pull/158504 -# Motivation +## Motivation [motivation]: #motivation In some low-level scenarios we must define naked functions with a custom ABI. This comes up in `rust-lang/compiler-builtins` (e.g. for `__rust_probestack` and `__aeabi_uidivmod`), and also in systems programming (e.g. when defining `__fentry__`, a symbol used the mcount mechanism). The current solution is often to use `extern "C"`, but that is misleading: the function does not use the C calling convention, and calling it as if it were is almost certainly causing UB. -# Guide-level explanation +## Guide-level explanation [guide-level-explanation]: #guide-level-explanation Because rust doesn't know what calling convention to use, an `extern "custom"` function can only be called via inline assembly or FFI. @@ -125,24 +125,24 @@ help: remove the parameters and return type | ``` -# Reference-level explanation +## Reference-level explanation [reference-level-explanation]: #reference-level-explanation See https://github.com/rust-lang/reference/pull/2300. -# Drawbacks +## Drawbacks [drawbacks]: #drawbacks No specific drawback. -# Rationale and alternatives +## Rationale and alternatives [rationale-and-alternatives]: #rationale-and-alternatives https://github.com/rust-lang/rust/issues/140566 The name has already been debated. The name `unknown` has been mentioned, but to write the implementation you really do need to know the ABI. It is custom in the sense that rustc does not know about it, but the author definitely does. -# Prior art +## Prior art [prior-art]: #prior-art https://github.com/rust-lang/rust/issues/140566#issuecomment-2846205457 @@ -154,12 +154,12 @@ We do have some other calling conventions that cannot be called using rust's fun Those however do have a known ABI, it's just that semantically it does not make sense to call them from a rust program. -# Unresolved questions +## Unresolved questions [unresolved-questions]: #unresolved-questions None currently. -# Future possibilities +## Future possibilities [future-possibilities]: #future-possibilities None currently.