[fpc-devel]Again about calling conventions and name mangling
Pavel V. Ozerski
pavel at insect.ief.spb.su
Thu Oct 18 14:52:27 CEST 2001
Hello Peter and all FPC team,
Did you look at my $calling patch?
Maybe, I should fix or improve something in it? Or you needs some my
Btw, I'm not sure that general parsing of procedure directives in FPC
is good. There are exist also some differences between FPC and Delphi.
This example can be compiled with Delphi 3 but not with FPC:
FPC 1.1 gives an error message:
test.pp(4,42) Error: Procedure directive "PASCAL" has conflicts with other directives
test.pp(4,42) Fatal: Syntax error, "BEGIN" expected but "identifier PASCAL" found
Delphi 3 compiles this sample successfully, I assume that last calling
convention directive overlaps all previous.
I think, Delphi behavior must at least be supported in $delphi mode of
FPC. Additionally, I think, procedure directives must be sorted into
groups to simplify and improve solving conflicts and overlapping.
1) introduce new type tProcDirKind=(pdk_Mangling, pdk_CallConv... etc;
2) add to proc_dir_rec type (unit pdecsub.pas) a new field, kind:
3) differently check conflicts between directives for every kind;
4) separate handling of calling conventions from handling of name
mangling. This solution can seem to be painful, because can disturb
compatibility with older FPC versions, but I think, it is necessary.
New keywords like "cmangled", "cppmangled" etc must be introduced,
default using of calling conventions-related directives must cause no
changes in names mangling. Btw, relationships between name mangling and
calling conventions is not only strange but also somewhere wrong now. For
example, function TheFunc(x1:pchar;x2:longint):longint;stdcall;
now will be mangled in FPC to _THEFUNC$PCHAR$LONGINT but C/C++
compilers will mangle this stdcall function to _TheFunc at 8 .
That's not logical, to emulate C/C++ name mangling only for a part of common
Another problem which is caused with the unasked name mangling
changes: A small demo which includes 2 units and one program which
used these units:
Try to build this project without changes in sources!
I got problems at linking stage because both cdecl procedures in
different units have the same mangled name! This example demonstrates
that non-FPC name mangling must be used very carefully, but now it is
applying in very common cases. Btw, IMHO, even if the "automatic"
C-like name mangling would be excluded from FPC, the compiler became
not very less flexible because there are exist also syntax constructions
procedure TheProc(x1:pchar);stdcall;external name '_TheProc at 4';
for import and
procedure TheProc(x1:pchar);stdcall;[public,alias:'_TheProc at 4'];
I could also try to solve some these problems but I could know the
lot of my $calling patch, because solving ways depend on it.
Pavel mailto:pavel at insect.ief.spb.su
More information about the fpc-devel