Binary size optimization

Imperatorn johan_forsberg_86 at hotmail.com
Thu Sep 28 08:38:42 UTC 2023


Today I randomly tried compiling a hello world using DMD, LDC and 
gcc (yes, not gdc)

I compared binary sizes and something looked off. The D ones were 
much larger.

Sometimes 10x, with some optimizations still about 2x.

But, then I tried using shared default lib and the size is even 
smaller than the one produced by gcc -Os!

I just did two versions, one with betterC with extern(C) and one 
with std.stdio : printf
(I didn't try dmd since I couldn't figure out easily how to share 
lib)

[1] ldc2 -O -release -link-defaultlib-shared -betterC app.d
[2] ldc2 -O -release -link-defaultlib-shared app.d

Both are smaller than the gcc-version.

How is this possible? What are the consequences and trade-offs?

Maybe this should have been posted in Learn instead, but idk.

Thanks


More information about the Digitalmars-d-learn mailing list