[M3devel] small structs

Jay K jayk123 at hotmail.com
Mon Jun 26 08:39:08 CEST 2017


Which backend?

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?

- Jay
________________________________
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
To: m3devel
Subject: [M3devel] small structs

Hey,
  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.

  Any thoughts?

Regards Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20170626/9a246729/attachment.html>


More information about the M3devel mailing list