-
Notifications
You must be signed in to change notification settings - Fork 13.3k
aarch64-apple-ios: Returning structs by value in extern "C" functions uses wrong calling convention #24154
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
Comments
Reading the calling conventions for AArch64, I believe the Xcode version is correct and Rust is incorrect. According to section 5.4 rule C.2, since |
Sorry, one last note. It looks like writing Rust code to take a struct by value has the same problem. This rust function: #[no_mangle]
pub extern "C" fn sum_point(p: Point) -> f32 {
p.x + p.y
} compiles to this assembly:
but the equivalent C function compiled in Xcode produces:
|
@steveklabnik I'd say 'A-iOS' is incorrect label as this is related to Aarch64 in general and can happen on Android too. |
@vhbit (to be fair i suspect @steveklabnik was working from the description in the title) |
@steveklabnik, may I ask you also to cc me on issues which you mark with iOS label - till today I didn't know it exists at all as I don't track issues. |
@pnkfelix I didn't mean to offense anyone, I apologize if that sounded like that - my intention was just to clarify issue |
Yeah, I just try to ensure each issue has at least one label, but I'm not always perfect with them. @vhbit I can try to remember :) |
@steveklabnik do you know if there is a way to utilize the github's API so that someone could register to receive notices of such labels? |
Not off the top of my head. https://developer.github.com/v3/issues/labels/ could probably make it work, I'd bet. |
I doubt this PR is ready to merge as-is, for a couple reasons: * There are no tests for this change. I'm not sure how to add tests for this change, as it modifies the C ABI for a cross-compilation target. Anecdotally, I have an iOS library I've been working on, and before this change, it crashes running on an arm64 device due to bad calling conventions (a simplified example is in #24154), and after this change, it runs correctly. * This is my first foray into LLVM. I did my best to reimplement what Clang does for AArch64 codegen (https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/TargetInfo.cpp), particularly in `ABIInfo::isHomogeneousAggregate`, `AArch64ABIInfo::isHomogeneousAggregateBaseType`, and `AArch64ABIInfo::isHomogeneousAggregateSmallEnough`, but I'm not confident I got a complete translation, particularly because Clang includes a lot of checks that I don't believe are necessary for rustc. Fixes #24154.
Creating an extern C function like this:
and compiling using
cargo build --target aarch64-apple-ios --release
, the assembly produced forget_point
is:My ARM assembly is a little rusty, but I believe this is expecting the caller to pass in the address of a
Point
inx0
, and then the function fills it in.However, this C code, which should be equivalent:
compiles to the following assembly in Xcode 6.2 targeting arm64:
which is returning the two struct fields in the SIMD registers.
Is this an issue of how aarch64 is defined or configured, maybe?
The text was updated successfully, but these errors were encountered: