[M3devel] small structs
jayk123 at hotmail.com
Mon Jun 26 08:39:08 CEST 2017
In any case I would recommend avoiding passing/returning structs/records by value across languages or even "major" compilers.
This is a somewhat unusual "corner" in some ABIs and there are often accidental mismatches.
I know the integrated NT386 backend has a problem and we workaround it.
There is approx. one Win32 API affected. We wrap it with a C wrapper that uses explicit record address instead of value.
Basically this is an area that 1. Has multiple obvious reasonable approaches and no clear tie breaker if you are the designer. 2. Is sometimes tweaked. Leaving intended clones not always matching.
For example I believe NT/amd64...I looked it up...structs of size 1, 2, 4, 8 are passed in registers (presumably only if in first 4 parameters). I didn't see how returned. Any other
in-between or larger size is passed differently. C does not allow zero-sized structs, I'm not sure of others.
This is something sort of fixed by generating C, but I've seen C compilers mismatch too (citation needed).
What is actual scenario?
From: M3devel <m3devel-bounces at elegosoft.com> on behalf of Peter McKinna <peter.mckinna at gmail.com>
Sent: Sunday, June 25, 2017 11:21:51 PM
Subject: [M3devel] small structs
I have a problem passing small structs by value to an external C function. If the size of the struct/record is less than 16 bytes there seems to be an ABI mismatch, at least on x86_64 not sure of other targets. If it's larger than 16 bytes the value is passed on the stack as usual and works fine otherwise it looks as if the fields of the struct are extracted and passed in registers.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the M3devel