LDC calling convention

Alexandru Militaru alexandru.cmilitaru at gmail.com
Tue Apr 9 08:58:00 UTC 2019


Hello!

I am trying to port a kernel module to D and I am using LDC to 
compile the code. I want to call a function with 7 arguments and 
after some debugging sessions I’ve observed that the second 
argument has a different value in the callee function than the 
one I am passing in the caller function. After I’ve inspected 
with objdump the kernel module it seems to me that the LDC places 
the parameters in registers in a weird order. Note that the 
calling convention was fine until now and everything worked. 
Maybe the problem is that the function has 7 arguments. In the 
kernel, the calling convention is: first 6 arguments in rdi, rsi, 
rdx, rcx, r8, r9 and then on the stack.

Here is an image with the assembly code generated: in the left, 
the instructions generated by GCC for the kernel, in the right, 
the instructions generated by LDC. The parameters are, in this 
order: 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16. Can someone 
explain to me why this is happening and how to solve it?

https://imgur.com/6sSMWIY


More information about the digitalmars-d-ldc mailing list