Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

RalfJung
Copy link
Member

Fixes #1946.

Regarding ABI availability, this documents a post-rust-lang/rust#137018 world. Some of the combinations documented as "not available" here actually do get accepted but trigger a future-compat warning.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Jul 27, 2025
Copy link
Member

@joshtriplett joshtriplett left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me.

@ehuss
Copy link
Contributor

ehuss commented Aug 6, 2025

Is there somewhere in the compiler that we can easily see these defaults?

My understanding is that if the ABI is not specified, the default is always "C". Is there something that says "C" is equivalent to these various ABIs for different targets? Or am I misunderstanding what it means by default?

Is aapcs the default for softfloat arm32?

@RalfJung
Copy link
Member Author

RalfJung commented Aug 6, 2025

My understanding is that if the ABI is not specified, the default is always "C".

Correct. And "C" can be identical to other ABIs depending on the target. This PR documents my understanding of these equivalences. Cc @workingjubilee @Amanieu for people that know more about the nitty-gritty details.

Basically, extern "C" is always the default for C code on the current target, but some of these ABI strings (such as sysv64) let one use that ABI on other targets as well. On non-Windows x86_64, "C" and "sysv64" are equivalent, but on win64 they are not.

Is aapcs the default for softfloat arm32?

I would think so but I don't know.

@Amanieu
Copy link
Member

Amanieu commented Aug 7, 2025

Is aapcs the default for softfloat arm32?

Yes, "C" == "aapcs" on soft-float arm32.

@ehuss
Copy link
Contributor

ehuss commented Aug 9, 2025

So if I am understanding correctly, the only way to determine what the behavior of the "C" calling convention is to dig through LLVM source, and each target seems to implement it differently, is that correct? For example aarch32/aarch64 use a method called CCAssignFnForCall. And x86 doesn't have any single place, but has methods like isCallingConvWin64.

I'm not entirely clear for stdcall, it says "default for the Win32 API". Why does it explicitly say "API"? Is this saying, this is the default that Microsoft uses for the Win32 API functions but is not the default of "C". That is, on i686-pc-windows-msvc, "C" is different from "stdcall"? Is that correct?

"thiscall" is also confusing, as it uses the term "default" for "C++ member functions". So it's not the default for the "C" calling convention?

(I'm finding the wording of "default" here confusing, so I'm trying to get clarity here.)

@RalfJung
Copy link
Member Author

RalfJung commented Aug 14, 2025

I'm not entirely clear for stdcall, it says "default for the Win32 API". Why does it explicitly say "API"? Is this saying, this is the default that Microsoft uses for the Win32 API functions but is not the default of "C". That is, on i686-pc-windows-msvc, "C" is different from "stdcall"? Is that correct?

Yes, that is correct. The default for win32 in general ("C" on that target) is "cdecl".

(I'm finding the wording of "default" here confusing, so I'm trying to get clarity here.)

Yeah that's fair. I went for a most minimal edit here to correct some wrong information. This section could probably use a larger rewrite, but I'm not sure if/when I will have the time for that.

ehuss added a commit to ehuss/reference that referenced this pull request Sep 16, 2025
This specifies the restrictions on which targets specific ABIs are
available. These are defined in `rustc` in
[`is_abi_supported`](https://github.com/rust-lang/rust/blob/eec6bd9d69832f57341c6de6a93fa7b9f47e2111/compiler/rustc_target/src/spec/mod.rs#L2610-L2613)
and the associated `AbiMap`.

Some of these are currently only implemented as future-incompatible
warnings via `unsupported_calling_conventions`. I'm fine with just not
acknowledging that, and saying what the intent is.

This is split off from rust-lang#1948
with the intent of separating out the changes.
traviscross pushed a commit to ehuss/reference that referenced this pull request Sep 16, 2025
This specifies the restrictions on which target-specific ABIs are
available. These are defined in `rustc` in [`is_abi_supported`] and
the associated `AbiMap`.

Some of these are currently only implemented as future incompatibly
warnings via `unsupported_calling_conventions`. I'm fine with just not
acknowledging that and saying what the intent is.

This is split off from rust-lang#1948
with the intent of separating out the changes.

[`is_abi_supported`]: https://github.com/rust-lang/rust/blob/eec6bd9d69832f57341c6de6a93fa7b9f47e2111/compiler/rustc_target/src/spec/mod.rs#L2610-L2613

Edited-by: TC
@rustbot
Copy link
Collaborator

rustbot commented Sep 16, 2025

☔ The latest upstream changes (possibly 0275c80) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung
Copy link
Member Author

Looks like #2000 now landed almost everything I wrote here, except that the reference now still says that "aapcs" is the "default for ARM" which is not correct.

@ehuss
Copy link
Contributor

ehuss commented Sep 17, 2025

Yea, we split this up into multiple PRs to try to make it easier to merge (#2000, #2001, #2003).

"aapcs" is the "default for ARM" which is not correct.

Can you take a look at #2003 and see if that wording looks correct to you?

@RalfJung
Copy link
Member Author

Closing in favor of #2003.

@RalfJung RalfJung closed this Sep 25, 2025
@rustbot rustbot removed the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Description of "aapcs" ABI seems wrong
5 participants