Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for clobber_abi to asm! #87581

Merged
merged 3 commits into from
Aug 15, 2021
Merged

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Jul 29, 2021

This PR adds the clobber_abi feature that was proposed in #81092.

Fixes #81092

cc @rust-lang/wg-inline-asm

r? @nagisa

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 29, 2021
@Amanieu Amanieu marked this pull request as draft July 30, 2021 16:27
@Amanieu Amanieu marked this pull request as ready for review July 31, 2021 19:24
Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

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

Seems reasonable enough, though some integration with existing abi machinery in rustc would be ideal. For example I could see adjust_cabi being changed so that is converts C to win64 or sysv64 or vice versa on the relevant systems.

src/doc/unstable-book/src/library-features/asm.md Outdated Show resolved Hide resolved
arch: InlineAsmArch,
target: &Target,
name: Symbol,
) -> Result<Self, &'static [&'static str]> {
Copy link
Member

Choose a reason for hiding this comment

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

I think it is somewhat important that we utilize Target::adjusted_abi here so that e.g. ABIs such as system and efiapi work out of the box here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried using Abi directly but the code got a bit messy. In any case we only support a small subset of ABIs for clobber_abi, I'm not sure if it makes sense to use the existing ABI machinery.

_ => Err(&["C", "aapcs"]),
},
InlineAsmArch::AArch64 => match name {
"C" => Ok(InlineAsmClobberAbi::AArch64),
Copy link
Member

Choose a reason for hiding this comment

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

Why do we handle aapcs for ARM but not aarch64?

Copy link
Member

Choose a reason for hiding this comment

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

On AArch64

pub extern "aapcs" fn aapcs_func() {}

results in:

LLVM ERROR: Unsupported calling convention.

Copy link
Member Author

Choose a reason for hiding this comment

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

aapcs is only a valid calling convention on ARM, not AArch64.

let name = &*name.as_str();
match arch {
InlineAsmArch::X86 => match name {
"C" | "cdecl" | "stdcall" | "fastcall" => Ok(InlineAsmClobberAbi::X86),
Copy link
Member

Choose a reason for hiding this comment

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

Can you handle the "system" abi on all archs too? This matches whatever abi is used on the respective platform to call into system libraries, so the same as the "C" abi on most targets, but on 32bit x86 windows it is the stdcall calling convention.

Copy link
Member Author

@Amanieu Amanieu Aug 6, 2021

Choose a reason for hiding this comment

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

Sure, I can add "system" (and even "efiapi") to this list. It makes no difference in terms of which registers are actually clobbered since cdecl and stdcall clobber the same set of registers, and on other arches they are identical to "C".

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@nagisa
Copy link
Member

nagisa commented Aug 14, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Aug 14, 2021

📌 Commit 3fd463a has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2021
@bors
Copy link
Contributor

bors commented Aug 14, 2021

⌛ Testing commit 3fd463a with merge 85109e2...

@bors
Copy link
Contributor

bors commented Aug 15, 2021

☀️ Test successful - checks-actions
Approved by: nagisa
Pushing 85109e2 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 15, 2021
@bors bors merged commit 85109e2 into rust-lang:master Aug 15, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

asm! needs a better way of specifying clobbers
7 participants