View Issue Details

IDProjectCategoryView StatusLast Update
0037266FPCDocumentationpublic2020-09-04 18:44
ReporterKai Burghardt Assigned ToMichael Van Canneyt  
Status resolvedResolutionfixed 
Product Version3.0.4 
Fixed in Version3.3.1 
Summary0037266: Reference Guide erroneously claims EAX, ECX, EDX were used for the first three parameters in `register` calling convention
DescriptionIt should be EDI, ESI, EDX instead.
Additional InformationJust delete the claim.
TagsNo tags attached.
Fixed in Revision1748
Attached Files


Kai Burghardt

2020-06-26 11:47


ref.tex.patch (648 bytes)   
--- ref.tex~	2020-06-26 09:45:00.171076316 +0000
+++ ref.tex	2020-06-26 09:45:00.171076316 +0000
@@ -11527,8 +11527,7 @@
 The \var{register} keyword is used for compatibility with Delphi. In
 version 1.0.x of the compiler, this directive has no effect on the
-generated code. As of the 1.9.X versions, this directive is supported. The
-first three arguments are passed in registers EAX, ECX and EDX.
+generated code. As of the 1.9.X versions, this directive is supported.
ref.tex.patch (648 bytes)   

Max Nazhalov

2020-06-26 13:11

reporter   ~0123599

Last edited: 2020-06-26 21:10

View 3 revisions

The claim is (almost) correct for x86-32-bit: register calling convention uses EAX EDX ECX as first 3 parameters, in that order.
For 64-bit [as you've tagged your report x86_64 GNU/Linux] RDI, RSI et al are used, NOT EDI ESI etc,

Sven Barth

2020-06-26 16:32

manager   ~0123601

> For 64-bit RDI, RSI et al are used, NOT EDI ESI etc,

For x86_64 the "register" calling convention does not exist as a separate calling convention instead the platform's default calling convention is used (Win64 vs. non-Win64). On non-Win64 it is indeed RDI and RSI that are used (amongst others), but for Win64 it would RCX, RDX, R8 and R9.

@Michael: it might be best to document that the "register" calling convention as such exists only on specific platforms (currently i386 and m68k) otherwise the default will be used.

Kai Burghardt

2020-06-27 09:02

reporter   ~0123610

OK, thanks for the clarification.

I’d still delete the claim though, in the spirit of 0035867:0117336 “It does not make sense to reproduce the ABIs of every supported platform in our own documentation.”

Sven Barth

2020-06-27 10:30

manager   ~0123611

Last edited: 2020-06-27 10:31

View 2 revisions

For the register calling convention it does make sense though, because it is not part of the platform ABI and in those cases where it doesn't match the platform ABI (namely i386, i8086 and m68k) the users should know which registers to use for assembly routines.

Serge Anvarov

2020-06-27 12:32

reporter   ~0123614

I understand that this will require further development in the future, but it might be better to specify a table where for each platform to specify which registers are used?

Kai Burghardt

2020-06-28 15:14

reporter   ~0123648

OK, but then please move it to the “Programmer’s guide.“ The “Reference guide” is, as far as I understand, about the Language, while the Programmer’s guide explains issues concerning this particular compiler, FPC.

(In § “Calling mechanism” (of the Programmer’s guide) there is already a statement, quote, “The list of registers that are modified is highly dependent on the processor, calling convention and ABI of the target platform.”)

Michael Van Canneyt

2020-09-04 14:07

administrator   ~0125358

Last edited: 2020-09-04 14:08

View 2 revisions

Corrected order of registers, added remark that this is only valid on i386, and added a remark you should not use this calling convention to begin with.
It's a remnant of Delphi/TP from ancient MS-DOS times.

Sven Barth

2020-09-04 17:06

manager   ~0125372

@Michael: it's wrong to say that the use of this directive is discouraged, because on i386, i8086 and m68k it's the default calling convention for FPC used by anything that doesn't declare a specific one. So if you have a unit where you change the default calling convention using $Calling, but need to mark a single function using the global default calling convention this would be a valid use case.

Michael Van Canneyt

2020-09-04 18:44

administrator   ~0125375

"Is not recommended" means 'don't use unless you know what you're doing'.

So I added 'unless you know what you're doing'.

In an ideal world, the calling conventions modifiers simply would not have to exist.

Issue History

Date Modified Username Field Change
2020-06-26 11:47 Kai Burghardt New Issue
2020-06-26 11:47 Kai Burghardt Status new => assigned
2020-06-26 11:47 Kai Burghardt Assigned To => Michael Van Canneyt
2020-06-26 11:47 Kai Burghardt File Added: ref.tex.patch
2020-06-26 13:11 Max Nazhalov Note Added: 0123599
2020-06-26 13:13 Max Nazhalov Note Edited: 0123599 View Revisions
2020-06-26 16:32 Sven Barth Note Added: 0123601
2020-06-26 21:10 Max Nazhalov Note Edited: 0123599 View Revisions
2020-06-27 09:02 Kai Burghardt Note Added: 0123610
2020-06-27 10:30 Sven Barth Note Added: 0123611
2020-06-27 10:31 Sven Barth Note Edited: 0123611 View Revisions
2020-06-27 12:32 Serge Anvarov Note Added: 0123614
2020-06-28 15:14 Kai Burghardt Note Added: 0123648
2020-09-04 14:07 Michael Van Canneyt Status assigned => resolved
2020-09-04 14:07 Michael Van Canneyt Resolution open => fixed
2020-09-04 14:07 Michael Van Canneyt Fixed in Version => 3.3.1
2020-09-04 14:07 Michael Van Canneyt Fixed in Revision => 1748
2020-09-04 14:07 Michael Van Canneyt FPCTarget => 3.2.2
2020-09-04 14:07 Michael Van Canneyt Note Added: 0125358
2020-09-04 14:08 Michael Van Canneyt Note Edited: 0125358 View Revisions
2020-09-04 17:06 Sven Barth Status resolved => feedback
2020-09-04 17:06 Sven Barth Resolution fixed => open
2020-09-04 17:06 Sven Barth Note Added: 0125372
2020-09-04 18:44 Michael Van Canneyt Status feedback => resolved
2020-09-04 18:44 Michael Van Canneyt Resolution open => fixed
2020-09-04 18:44 Michael Van Canneyt Note Added: 0125375