DMD compiler switch to set default extern() linkage?

Alex Rønne Petersen xtzgzorex at gmail.com
Thu Apr 5 03:10:05 PDT 2012


On 05-04-2012 12:02, deadalnix wrote:
> Le 05/04/2012 11:49, Alex Rønne Petersen a écrit :
>> Hi,
>>
>> It is no secret that DMD is the only compiler in existence that follows
>> the "D" calling convention (and even then, only on some platforms,
>> seemingly?). Both GDC and LDC use the C calling convention of the
>> platform by default (and don't even have options to use the "D" calling
>> convention because their back ends don't support it at all).
>>
>> I'm writing a virtual machine. As far as I am concerned, the "D" calling
>> convention adds nothing but complexity to the configuration support
>> matrix. The calling convention situation across platforms is already
>> utterly insane enough as it is. I would not have a problem with
>> supporting the "D" calling convention if all compilers followed it. But
>> they don't. And it is only specified for x86. Even in an ideal world,
>> the "D" calling convention won't exist everywhere because it isn't
>> intended to.
>>
>> So yes, we could just say "but eventually, those compilers should
>> support it!". But realistically, it is not going to happen. Those
>> compilers have no reason to implement yet another calling convention
>> that is entirely specific to x86.
>>
>> I don't think it's good that DMD forces all functions to use the "D"
>> calling convention by default. However, I accept that it is an
>> established situation, and changing is now is not an option.
>>
>> That said, I believe a compiler switch to set the default extern()
>> linkage is not an unreasonable thing to ask for, e.g.: dmd -extern=C
>> foo.d
>>
>> Thoughts?
>>
>
> Extern(XXX) change the calling convention, but also the mangling.
> Setting it by default would create a huge mess. It is, for example, sure
> to create massive mangled name collision if extern(C) is applied by
> default (C doesn't mangle argument types and doesn't support modules).
>
> I understand the issue, but the solution would be a switch to force ABI,
> not extern.

OK, so what we really want is an option to specify what calling 
convention to use when extern(D) is used. Something like: dmd -cc=C/D foo.d

-- 
- Alex


More information about the Digitalmars-d mailing list