why does DMD compile "hello world" to about 500 _kilobytes_ on Mac OS X [x86_64]?!?

Dan Olson via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 1 10:23:02 PDT 2014


Jacob Carlborg <doob at me.com> writes:

> On 01/09/14 01:51, Abe wrote:
>
>> The question: why is Hello World so frickin` huge?!?
>
> The runtime and standard library is statically linked, compared to C
> where it's dynamically linked. Also unnecessary symbols are not
> stripped. DMD on OS X doesn't currently support dynamic libraries. LDC
> has the --gc-sections flag, enabled by default. This will
> significantly reduce the since of the binary.

Another option you can use today with OS X is pass in -dead_strip linker
option to get rid of unreachable symbols. It works good with LDC.

using LDC - the LLVM D compiler (0.14.0):
  based on DMD v2.065 and LLVM 3.4.2

$ ldc2 -L-dead_strip hello.d
$ ls -lh hello
-rwxr-xr-x  1 dan  staff   305K Sep  1 10:01 hello
$ strip hello
$ ls -lh hello
-rwxr-xr-x  1 dan  staff   228K Sep  1 10:01 hello

A version using puts instead of writeln shrinks more.

ldc2 helloputs -L-dead_strip
$ ldc2 -L-dead_strip helloputs.d
$ ls -lh helloputs
-rwxr-xr-x  1 dan  staff   243K Sep  1 10:01 helloputs
$ strip helloputs
$ ls -lh helloputs
-rwxr-xr-x  1 dan  staff   181K Sep  1 10:01 helloputs

Otherwise LDC makes really big binaries:

$ ldc2 hello.d
$ ls -lh hello
-rwxr-xr-x  1 dan  staff   2.2M Sep  1 10:01 hello
$ strip hello
$ ls -lh hello
-rwxr-xr-x  1 dan  staff   1.9M Sep  1 10:01 hello

When I try -dead_strip with DMD, I get runtime SEGV with simple writeln
hello world :-(


More information about the Digitalmars-d mailing list