-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
The sparc64, riscv64, loongarch64 extern "C" fn ABIs are all wrong when aligned/packed structs are involved #115609
Copy link
Copy link
Open
Labels
A-ABIArea: Concerning the application binary interface (ABI)Area: Concerning the application binary interface (ABI)A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-SPARCTarget: SPARC processorsTarget: SPARC processorsO-loongarchTarget: LoongArch (LA32R, LA32S, LA64)Target: LoongArch (LA32R, LA32S, LA64)O-riscvTarget: RISC-V architectureTarget: RISC-V architectureP-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-ABIArea: Concerning the application binary interface (ABI)Area: Concerning the application binary interface (ABI)A-FFIArea: Foreign function interface (FFI)Area: Foreign function interface (FFI)I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-SPARCTarget: SPARC processorsTarget: SPARC processorsO-loongarchTarget: LoongArch (LA32R, LA32S, LA64)Target: LoongArch (LA32R, LA32S, LA64)O-riscvTarget: RISC-V architectureTarget: RISC-V architectureP-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
All of these ABIs have in common that they are looking at
layout.fieldsto compute the ABI for the function, and they are all getting it wrong, in various different ways. (I previously reported bugs against all of these becauserepr(transparent)is not properly respected; those bugs have the same cause -- relying onlayout.fields-- but they are orthogonal.)For instance, this type
on riscv64 gets a PassMode::Cast of
which gets translated to the LLVM type
{ i8, f32 }, and that's a non-packed LLVM struct. On a call,Pgets transmuted to that LLVM type, which obviously produces garbage since the fields are at different offsets.On sparc64, the type translates into
{ i32, f32 }which is wrong as well.As another example, this type
on loongarch64 gets a PassMode::Cast of
which is the LLVM type
{ i32, f32 }, and that's obviously not the right type forS2.(Caveat: I can't actually run code on these targets, so there's a small chance that I am completely misinterpreting what these
PassModemean. I hope that's not the case...)I don't know what the C ABI on those platforms has to say about packed and aligned structs. Currently, we don't even provide ABIs a way to generate a packed LLVM struct for the arguments --
PassMode::Castalways uses an un-packed LLVM struct.Updates: