Skip to content

AAPCS ABI is accepted for x86 target #57182

Description

@nagisa

Currently the following code compiles fine when targetting x86_64.

pub extern "aapcs" fn  foo() {}

This code is non-sensical because AAPCS calling convention is only defined for ARM. An example of non-sensical ABI being disallowed is

pub extern "fastcall" fn  foo() {}

when compiling with --target=armv7-unknown-linux-gnueabihf which fails with:

error[E0570]: The ABI `"fastcall"` is not supported for the current target
 --> <source>:6:1
  |
6 | / extern "fastcall" fn foo() { 
7 | | }
  | |_^

Targets should be reviewed for such nonsensical ABIs and their blacklists updated. I feel that to avoid this issue in the future we should rather prefer a whitelist of ABIs, rather than a blacklist, and by default put no ABIs, so that the compilation fails until the ABI list is properly populated for the target.

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-target-specsArea: Compile-target specifications
    on Dec 28, 2018
  2. nagisa commented on Dec 28, 2018

    @nagisa
    MemberAuthor

    Compiling extern "aapcs" on aarch64 will explode in LLVM with LLVM ERROR: Unsupported calling convention..

  3. added
    C-bugCategory: This is a bug.
    A-FFIArea: Foreign function interface (FFI)
    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
    on Oct 16, 2019
  4. gnzlbg commented on Oct 16, 2019

    @gnzlbg
    Contributor

    I ran into these same issues in #65443 .

    One thing that I mentioned there, that is not mentioned here, is that because these errors can happen on stable safe Rust code, this is actually a soundness bug (safe Rust code has UB). Note also that for some ABIs, like stdcall, we don't error on tier-1 targets.

    I feel that to avoid this issue in the future we should rather prefer a whitelist of ABIs, rather than a blacklist, and by default put no ABIs, so that the compilation fails until the ABI list is properly populated for the target.

    I agree. There are some ABIs that the reference says are available on all targets (e.g. "C", "system", "Rust", etc.) but except for those, each target should have a white-list that explicitly allows using an ABI on the target.

  5. added a commit that references this issue on Jul 6, 2021
    8240e7a
  6. added a commit that references this issue on Jul 6, 2021
    b09dad3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-target-specsArea: Compile-target specificationsC-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions