Forum > Unix

Linux 64bit calling convention

(1/2) > >>

mikerabat:
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 calling
convention 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...)

kind regards
   Mike

Thaddy:
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.

mikerabat:
Yeah I know that - and that's the problem. My routines (40+) are implemented such that they depend on the
registers windows uses. The thing is that according to wiki there is also only one calling convention on Linux/Unix
which 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 the
windows compiler side is the case)... so ... is there something similar I can do on the 64bit side?

Remy Lebeau:

--- Quote from: mikerabat on July 04, 2017, 04:00:56 pm ---The thing is that according to wiki there is also only one calling convention on Linux/Unix
which is similar to win64 calling conventions but uses different param registers. The thing is I rely on these....

--- End quote ---

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.

mikerabat:
Alright... I managed to add a little asm prologue (interchanging registers) to all 64 bit routines so they now work properly.

Navigation

[0] Message Index

[#] Next page

Go to full version