Author
Topic: Linux 64bit calling convention (Read 1598 times)

I wrote quite a lot of assembler optimized functions for windows and now wanted to port it to Linux.The biggest problem I now encounter is that I learned that Linux uses a different callingconvention for 64bit than windows does. Actually it uses different registers for function calls and it would be a great deal of work to rename these registers or even clone and rewrite the calls.

Is there a way I can force the freepascal compiler to use the windows calling convention for 64bit?(I know for 32 bit I can force different conventions...)

You do not need to. Win64 has only one (1) calling convention (four register _fastcall) and that is selected by default for that platform.If you want you can select stdcall or winapi on linux too, I seem to remember stdcall on 64 bit is aliased to 4 register __fastcall, but imho makes not much sense, unless, indeed, it is for some of your own routines. So try stdcall on Linux. (which shouldn't be really stdcall,but the aliased __fastcall64). I am not absolutely sure, though.And may be FastCall simply works.

Yeah I know that - and that's the problem. My routines (40+) are implemented such that they depend on theregisters windows uses. The thing is that according to wiki there is also only one calling convention on Linux/Unixwhich is similar to win64 calling conventions but uses different param registers. The thing is I rely on these....

Afaik on the x86 side (32bit) there are many calling conventions but they are completely ignored for 64bit (at least on thewindows compiler side is the case)... so ... is there something similar I can do on the 64bit side?

The thing is that according to wiki there is also only one calling convention on Linux/Unixwhich is similar to win64 calling conventions but uses different param registers. The thing is I rely on these....

Well, then you have to change that. IFDEF the code to use one set of registers on Win64, and another set of registers on Linux64. Consolidate them into a single set of common registers, or stack space, or whatever, for the rest of the code to use without caring about the underlying platform.