Skip to content

Argument size computation for foreign ffi exports is likely wrong.

Summary

In GHC.HsToCore.Foreign.C:mkFExportCBits we compute the size of arguments like this:

aug_arg_size = sum [ widthInBytes (typeWidth rep) | (_,_,_,rep) <- aug_arg_info]

While this is accurate as far as I can tell the only thing we use this for is if we use stdcall foreign exports we annotate the function with the argument size. I believe stdcall expects arguments to be padded to multiples of the platforms word size, however the current code will give the exact size. So there might be a missmatch.

However as I understand it:

  • stdcall is only a thing on 32bit
  • It's basically only a thing on windows
  • It's not the default calling convention
  • I'm not sure the annotation is actually used/relevant for resolving symbols.
  • If someone uses it they should easily be able to swap to another calling convention.

So I don't think it's worth investigating it further, but I figured I would document it in case anyone comes across this issue.

Edited by Andreas Klebinger
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information