stabilize c_variadic_naked_functions - #159746
Conversation
| /// of such functions via `extern` blocks and definition via naked functions; there's a | ||
| /// separate check during AST construction guarding *definitions* of variadic functions. |
There was a problem hiding this comment.
in the reference we now have to differentiate between naked and non-naked (clothed?) definitions. I guess we'll figure out some terminology in the reference PR.
|
The reference PR for c-variadic is still in flight, but it would be neat if |
|
r? @tiif rustbot has assigned @tiif. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Thanks @folkertdev. @rfcbot fcp merge lang |
|
@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
@rfcbot reviewed |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
|
I think it would make sense to stabilize this feature in the same release that stabilizes c-variadic definitions, 1.99.0. The cutoff for that is close though. The only remaining blocker is an accepted reference PR. I think it makes sense to have this ride along on the existing one for c-variadic definitions. Is that OK? We can of course request a beta-backport if this doesn't quite make it in before the cutoff. |
|
Now that we have an approved reference PR @bors r=tiif |
…ked-functions, r=tiif stabilize `c_variadic_naked_functions` tracking issue: rust-lang#148767 reference PR: rust-lang/reference#2321 # Stabilization report ## Summary Stabilize the ability to use `#[unsafe(naked)]` functions to define c-variadic functions. These c-variadic naked functions accept the same set of ABIs as c-variadic foreign functions, this set is larger than what we currently accept for c-variadic definitions. ```rust #[unsafe(naked)] unsafe extern "aapcs" fn variadic_aapcs(_: f64, _: ...) -> f64 { core::arch::naked_asm!( r#" sub sp, sp, rust-lang#12 stmib sp, {{r2, r3}} vmov d0, r0, r1 add r0, sp, rust-lang#4 vldr d1, [sp, rust-lang#4] add r0, r0, rust-lang#15 bic r0, r0, rust-lang#7 vadd.f64 d0, d0, d1 add r1, r0, rust-lang#8 str r1, [sp] vldr d1, [r0] vadd.f64 d0, d0, d1 vmov r0, r1, d0 add sp, sp, rust-lang#12 bx lr "#, ) } ``` ## Accepted ABIs The set of accepted ABIs is the same as for c-variadic foreign functions, defined as rule [`items.extern.variadic.conventions`](https://doc.rust-lang.org/nightly/reference/items/external-blocks.html?highlight=externblo#r-items.extern.variadic.conventions): - `"aapcs"` - `"C"` - `"cdecl"` - `"efiapi"` - `"system"` - `"sysv64"` - `"win64"` And their corresponding `-unwind` variants. Given that naked functions desugar to a block of module assembly and a foreign definition, it makes sense to support the same set as source-level foreign definitions. For c-variadic definitions we only accept `"C"` and `"C-unwind"`. ## Multiple c-variadic ABIs in the same program LLVM supports c-variadic calls of different ABIs in the same program. We test both an arm and x86 configuration - https://github.com/rust-lang/rust/blob/771916f9028e7fe56d2685f2c4f698de5d7d6a45/tests/ui/c-variadic/same-program-multiple-abis-arm.rs - https://github.com/rust-lang/rust/blob/771916f9028e7fe56d2685f2c4f698de5d7d6a45/tests/ui/c-variadic/same-program-multiple-abis-x86_64.rs Note that GCC, Clang and LLVM do not support c-variadic definitions of multiple ABIs: the `va_start`, `va_arg` etc. macros are always expanded using the default C calling convention. Clang and GCC reject a variable argument list on definitions that use a non-default calling convention. ## History - [#t-lang > C-variadic naked functions](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/C-variadic.20naked.20functions/with/554593886) - rust-lang#148770 The stabilization report of `feature(c_variadic)` mentions this feature: - rust-lang#155697 ## Unresolved questions None.
…uwer Rollup of 9 pull requests Successful merges: - #160782 (rustc_attr_ir: fix up `lang_items` imports) - #159746 (stabilize `c_variadic_naked_functions`) - #160141 (Refactor tidy detection of stability attribute) - #160744 (make more diagnostic structs pub(crate)) - #160778 (Add regression test for cycle error on guaranteed unsized self type) - #160779 (arm64ec: `f128` is supported since LLVM 23) - #160781 (Add regression test for save temps ICE on incremental recompile) - #160792 (User facing .expect now follows “expect as precondition" style) - #160796 (Change .expect message to follow precondition style)
Rollup merge of #159746 - folkertdev:stabilize-c-variadic-naked-functions, r=tiif stabilize `c_variadic_naked_functions` tracking issue: #148767 reference PR: rust-lang/reference#2321 # Stabilization report ## Summary Stabilize the ability to use `#[unsafe(naked)]` functions to define c-variadic functions. These c-variadic naked functions accept the same set of ABIs as c-variadic foreign functions, this set is larger than what we currently accept for c-variadic definitions. ```rust #[unsafe(naked)] unsafe extern "aapcs" fn variadic_aapcs(_: f64, _: ...) -> f64 { core::arch::naked_asm!( r#" sub sp, sp, #12 stmib sp, {{r2, r3}} vmov d0, r0, r1 add r0, sp, #4 vldr d1, [sp, #4] add r0, r0, #15 bic r0, r0, #7 vadd.f64 d0, d0, d1 add r1, r0, #8 str r1, [sp] vldr d1, [r0] vadd.f64 d0, d0, d1 vmov r0, r1, d0 add sp, sp, #12 bx lr "#, ) } ``` ## Accepted ABIs The set of accepted ABIs is the same as for c-variadic foreign functions, defined as rule [`items.extern.variadic.conventions`](https://doc.rust-lang.org/nightly/reference/items/external-blocks.html?highlight=externblo#r-items.extern.variadic.conventions): - `"aapcs"` - `"C"` - `"cdecl"` - `"efiapi"` - `"system"` - `"sysv64"` - `"win64"` And their corresponding `-unwind` variants. Given that naked functions desugar to a block of module assembly and a foreign definition, it makes sense to support the same set as source-level foreign definitions. For c-variadic definitions we only accept `"C"` and `"C-unwind"`. ## Multiple c-variadic ABIs in the same program LLVM supports c-variadic calls of different ABIs in the same program. We test both an arm and x86 configuration - https://github.com/rust-lang/rust/blob/771916f9028e7fe56d2685f2c4f698de5d7d6a45/tests/ui/c-variadic/same-program-multiple-abis-arm.rs - https://github.com/rust-lang/rust/blob/771916f9028e7fe56d2685f2c4f698de5d7d6a45/tests/ui/c-variadic/same-program-multiple-abis-x86_64.rs Note that GCC, Clang and LLVM do not support c-variadic definitions of multiple ABIs: the `va_start`, `va_arg` etc. macros are always expanded using the default C calling convention. Clang and GCC reject a variable argument list on definitions that use a non-default calling convention. ## History - [#t-lang > C-variadic naked functions](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/C-variadic.20naked.20functions/with/554593886) - #148770 The stabilization report of `feature(c_variadic)` mentions this feature: - #155697 ## Unresolved questions None.
tracking issue: #148767
reference PR: rust-lang/reference#2321
Stabilization report
Summary
Stabilize the ability to use
#[unsafe(naked)]functions to define c-variadic functions. These c-variadic naked functions accept the same set of ABIs as c-variadic foreign functions, this set is larger than what we currently accept for c-variadic definitions.Accepted ABIs
The set of accepted ABIs is the same as for c-variadic foreign functions, defined as rule
items.extern.variadic.conventions:"aapcs""C""cdecl""efiapi""system""sysv64""win64"And their corresponding
-unwindvariants. Given that naked functions desugar to a block of module assembly and a foreign definition, it makes sense to support the same set as source-level foreign definitions.For c-variadic definitions we only accept
"C"and"C-unwind".Multiple c-variadic ABIs in the same program
LLVM supports c-variadic calls of different ABIs in the same program. We test both an arm and x86 configuration
Note that GCC, Clang and LLVM do not support c-variadic definitions of multiple ABIs: the
va_start,va_argetc. macros are always expanded using the default C calling convention. Clang and GCC reject a variable argument list on definitions that use a non-default calling convention.History
feature(c_variadic_naked_functions)#148770The stabilization report of
feature(c_variadic)mentions this feature:Unresolved questions
None.