Replies: 2 comments 6 replies
|
Thx for the topic; I've quickly experimented on Linux, and came up with #4258. You might be hitting a similar/identical issue, though it seems much worse on Mac here. |
|
Take the standard helloworld and compile it (macOS/Linux) using ldc2: //
// 5.8MB: ldc2 --release --O3 main.d
// 1.2MB: ldc2 --release --O3 -L=-dead_strip -L=-x -L=-S main.d
//
import std.stdio;
void main()
{
writeln("hello world!");
}Big executables. (I'm using macOS x64) Now recompile the D runtime libs using Copy the generated libs inside Recompile the helloworld above using the same flags, now you get better results: // 4.8MB: ldc2 --release --O3 main.d
// 728KB: ldc2 --release --O3 -L=-dead_strip -L=-x -L=-S main.dAdd the // 724KB: ldc2 --release --O3 -fvisibility=hidden -L=-dead_strip -L=-x -L=-S main.dActivating link-time-optimization (LTO) - (time for linking increases!): // 698KB: ldc2 --release --O3 --flto=full -fvisibility=hidden -defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L=-dead_strip -L=-x -L=-S main.dWith additional // 599KB: ldc2 --release --O3 --flto=full -fvisibility=hidden -defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L=-dead_strip -L=-x -L=-S -L=-lz main.dSame for Linux and other POSIX OS (FreeBSD?, Solaris?), only some linker flags could be slightly different. For example, The secret is to add the following compiler/linker options when compiling any static libs (like phobos2/druntime): And of course the stripping and dead code removal for final executables. |
Uh oh!
There was an error while loading. Please reload this page.
On my M1 Mac, building an empty program results in a 5.6MB executable.
results in an executable that is 5617396 bytes in size.
dmd produces a 778976 byte executable from the same program.
using target x86-64 produces a 5.9MB exe.
Is there any way to trim this down? It seems quite absurd for the floor executable size to be almost 6MB.
All reactions