RISC-V - Potential Interop Issues/Considerations #75619
Unanswered
tannergooding
asked this question in
General
Replies: 2 comments 3 replies
-
CC. @jkoritzinsky, @AaronRobinsonMSFT, @jkotas, @lambdageek Would appreciate your input on this and potential directions that should be considered here. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Moreover, the default can be modified using compiler switches ( LoongArch has this problem as well. @shushanhf Have you ever run into these sign mismatches in interop? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The signedness of
char
in C is implementation defined:This fine most of the time because the ABI for these scenarios only cares about the lowest 8 register-bits. The upper bits of the register are left undefined and the callee must explicitly zero or sign-extend the value itself.
On Unix RISC-V, it is also unsigned: [0, 255]. However, the ABI requires the caller to zero/sign-extend the type to fill the entire register instead and this represents a new consideration for interop code.
In particular, this means that all interop signatures must exactly match the signedness as defined by native code. If the underlying C API takes
uint
, then passing inint
is invalid and will cause downstream failures on 64-bit platforms. The same is true forshort
vsushort
orbyte
vssbyte
on 32-bit and 64-bit platforms.For a type like
char
where the signedness is not well-defined, this means that you can no longer define a single interop signature that works for all combinations of[Windows, Unix]
and[x86, x64, Arm32, Arm64, RISC-V]
.Given that there is some recent push from the community to add RISC-V support, this is going to become a more prevalent consideration for .NET both in the interop bindings exposed as well as in how to rationalize the handling of
C char
across platforms.Beta Was this translation helpful? Give feedback.
All reactions