`VaList<'_>` does not carry its ABI in its type
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Consider the following code that will be valid with extended_varargs_abi_support and c_variadic:
unsafe extern "sysv64" {
fn nix_valist(vl: VaList<'_>);
}
unsafe extern "win64" {
fn win_valist(vl: VaList<'_>);
}
For VaList<'_>, part of the c_variadic feature, the type does not contain the ABI it is used with. However, if we want to support defining functions with ..., that use VaList<'_> internally, for every ABI that we would accept with declarations of functions that accept ..., like so:
unsafe extern "sysv64" fn nix_valist(vl: VaList<'_>) {
todo!()
}
unsafe extern "win64" fn win_valist(vl: VaList<'_>) {
todo!()
}
then we have two problems:
- We no longer can expand to the same type, as we currently assume a target can only have one
VaListimplementation, but in actuality it can have an implementation for each ABI it supports! - The
VaListthat we construct can now be passed to a function likevsnprintf(or the previousnix_valistandwin_valist) which accepts theVaListas a parameter. BecauseVaListdoes not include the ABI it is constructed with in its type, it is valid to pass it to a function that will assume it uses a different varargs ABI. This can cause incorrect behavior in programs that otherwise take sensible precautions with using variable arguments, like using other data to transfer argument counts and types.
While this is not yet decided as behavior we wish to support, and the relevant functions of VaList are currently unsafe, it may be wise to consider embedding the ABI in VaList to address these problems. The goal would be to have something equivalent to VaList<'_, extern "sysv64">.
@rustbot label: +F-c_variadic +T-lang +T-libs-api
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the VaList and c_variadic behavior described here, including the sysv64 and win64 extern declarations and definitions. Determine whether VaList should encode its ABI, then assess the effects on construction and passing values across ABI-specific functions; done means a decided, consistent design for the currently undecided behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100