gdc or ldc for faster programs?
Ali Çehreli
acehreli at yahoo.com
Thu Jan 27 16:46:59 UTC 2022
On 1/26/22 11:07, Siarhei Siamashka wrote:
> On Wednesday, 26 January 2022 at 18:41:51 UTC, Iain Buclaw wrote:
>> The D language shot itself in the foot by requiring templates to have
>> weak semantics.
>>
>> If DMD and LDC inline weak functions, that's their bug.
>
> As I already mentioned in the bugzilla, it would be really useful to see
> a practical example of DMD and LDC running into troubles because of
> mishandling weak templates.
I am not experienced enough to answer but the way I understand weak
symbols, it is possible to run into trouble but it will probably never
happen. When it happens, I suspect people can find workarounds like
disabling inlining.
> I was never able to find anything about
> "requiring templates to have weak semantics" anywhere in the Dlang
> documentation or on the Internet.
The truth is some part of D's spec is the implementation. When I compile
the following program (with dmd)
void foo(T)() {}
void main() {
foo!int();
}
I see that template instantiations are linked through weak symbols:
$ nm deneme | grep foo
[...]
0000000000021380 W _D6deneme__T3fooTiZQhFNaNbNiNfZv
What I know is that weak symbols can be overridden by strong symbols
during linking. Which means, if a function body is inlined which also
has a weak symbol, some part of the program may be using the inlined
definition and some other parts may be using the overridden definition.
Thanks to separate compilation, they need not match hence the violation
of the one-definition rule (ODR).
Ali
More information about the Digitalmars-d-learn
mailing list