-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
arm-none-eabi (etc) have incorrect repr(C) enum layout (AAPCS vs AAPCS-linux) #87917
Comments
I think this difference matches to the |
That comment has been unchanged since #9613 - I guess we don't do enough FFI testing? |
lol perhaps the fix is to make it u8 for |
Maybe we want to make it part of the target specification? Feels very wrong to have architecture names hardcoded in |
oh, we can just make it None |
Makes sense. Perhaps also a codegen flag. |
GCC uses the `-fshort-enums` ABI for arm-none and the `int`-sized enum ABI for arm-linux. Clang uses the `int`-sized enum ABI for all arm targets. Both options are permitted by AAPCS. Rust is matching GCC's behavior for these targets, as interop with code code compiled by GCC is desirable in the bare-metal context. See rust-lang#87917.
We're building code for a Cortex-M33 running FreeRTOS, and using C/Rust FFI.
The C code is being compiled with:
The rust code is being compiled with:
The following enum:
has a size of 4 on the rust side and 1 on the C side.
The specific choice of Cortex CPU is not relevant here, a reduce testcase that enables us to see the size in a compiler error (so we don't need to actually run the code) is as follows:
Produces the error:
error: invalid conversion from 'int' to 'char (*)[1]'
, whereas:Produces the error
expected an array with a fixed size of 4 elements, found one with 0 elements
This bug traces back to this comment:
rust/compiler/rustc_middle/src/ty/layout.rs
Lines 134 to 138 in ae90dcf
I am able to reproduce this for both thumb and non-thumb, with and without hard floats:
arm-none-eabi-g++ test.c
, regardless of the-mthumb
and-mfloat-abi=hard
flags, will always think the enum is of size 1, whereas I tried a bunch of ARM targets on the Rust side and they all think it is of size 4.arm-linux-gnueabi-g++
agrees with Rust about the size of the enum, so I think this has to do specifically with-none-eabi
and-none-eabihf
. I feel like we should either follow GCC's convention (which is presumably clang's convention), or expose a codegen flag that flips this.cc @joshtriplett @cuviper @japaric who typically care about stuff like this
The text was updated successfully, but these errors were encountered: