lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 15 February 2018 at 07:33, KHMan <keinhong@gmail.com> wrote:
> On 2/15/2018 3:01 PM, Dibyendu Majumdar wrote:
>>
>> On 15 February 2018 at 06:40, Thomas Buergel wrote:
>>>>
>>>> Looks like there was a bug in luaffi when passing parameters to
>>>> functions on the stack on x86-64 platform. I have not found definitive
>>>> documentation clarifying this (if anyone can provide a reference that
>>>> would be very helpful) but it seems that stack arguments must be at 8
>>>> byte boundaries.
>>>
>>>
>>> The two dominant x86-64 calling conventions in an overview:
>>>
>>> https://en.wikipedia.org/wiki/X86_calling_conventions#x86-64_calling_conventions
>>>
>>> For once, the one used on Windows is simpler:
>>> https://docs.microsoft.com/en-us/cpp/build/calling-convention
>>>
>>> Especially varargs can be a challenge on the SysV x86-64 ABI:
>>> https://blog.nelhage.com/2010/10/amd64-and-va_arg/
>>>
>>
>>
>> Thank you - I was aware of the first two references but there doesn't
>> seem to be a discussion on the requirements of size/alignment of
>> arguments passed on the stack.
>>
>> I found following:
>>
>>
>> https://stackoverflow.com/questions/32614007/size-and-alignment-of-x64-stack-arguments
>>
>> And:
>>
>> http://refspecs.linuxfoundation.org/elf/x86_64-abi-0.99.pdf
>>
>> Above says:
>>
>> The size of each argument gets rounded up to eightbytes
>
>
> Don't forget Agner Fog (I guess he's more familiar to older folks), see the
> doc on calling conventions:
>
> http://www.agner.org/optimize/
>

Thank you, the calling conventions document appears quite detailed. It
confirms above, as:

The 64 bit systems keep the stack aligned by 16. The stack word size
is 8 bytes, but the stack must be aligned by 16 before any call
instruction.

Each parameter must take a whole number of stack entries. If a
parameter is smaller than the stack word size then the rest of that
stack entry is unused.


Regards