Linux 64bit Calling Convention
    Maxime Chevalier 
    maximechevalierb at gmail.com
       
    Wed Feb 27 16:42:49 PST 2013
    
    
  
I'm implementing a JIT compiler and having to call into D 
functions from machine code I generated. Unfortunately, I seem to 
be experiencing a problem where the arguments are passed in the 
reverse order of what I would expect.
The functions I'm calling are global functions with 2 class 
pointer arguments. E.g.:
void foo(ClassA ptrA, ClassB ptrB) { ... }
The ABI page on dlang.org seems to imply that D uses the C 
calling convention on Linux. Now, using the C convention on 
64-bit linux, this should mean that the first class pointer 
(ptrA) get passed in register RDI, and the second one (ptrB) in 
RSI. This is what I would expect but when I actually call a D 
function, the two arguments are reversed.
I understand that this isn't necessarily super clear without 
looking at code, but I just wanted to know if there was something 
obvious I might be overlooking with regards to the D calling 
convention on Linux/AMD64.
Is it because ptrA automatically gets treated as a "this" 
pointer, as if the function were a method of ClassA?
    
    
More information about the Digitalmars-d
mailing list