September 01, 2014
Jacob Carlborg <doob@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 :-(
September 01, 2014
On Monday, 1 September 2014 at 17:23:03 UTC, Dan Olson wrote:
> Jacob Carlborg <doob@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

This was supposed to be enabled by default in 0.14.0 (it is exactly what ld --gc-sections does). Probably some issue with ld argument wrapper for whatever lines OSX uses?
September 01, 2014
On 2014-09-01 19:28, Dicebot wrote:

> This was supposed to be enabled by default in 0.14.0 (it is exactly what
> ld --gc-sections does). Probably some issue with ld argument wrapper for
> whatever lines OSX uses?

It only works for Linux.

-- 
/Jacob Carlborg
September 01, 2014
On 2014-09-01 19:23, Dan Olson wrote:

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

It will probably clean out TLS, module info and similar data which is not reachable from the main function.

-- 
/Jacob Carlborg
September 01, 2014
On Monday, 1 September 2014 at 17:46:11 UTC, Jacob Carlborg wrote:
> On 2014-09-01 19:28, Dicebot wrote:
>
>> This was supposed to be enabled by default in 0.14.0 (it is exactly what
>> ld --gc-sections does). Probably some issue with ld argument wrapper for
>> whatever lines OSX uses?
>
> It only works for Linux.

Any reason why it can't work for OSX in a same way? Assuming LDC does emit ModuleInfo & Co sections the same way it does on Linux, using OSX specific alternative to --gc-sections should "just work".
September 01, 2014
First: thanks to Joakim and yourself for all the recent replies.


> unnecessary symbols are not stripped.

I think that`s the most essential part of why "Hello world" came out so big for me.


> LDC has the --gc-sections flag, enabled by default. This will significantly reduce the since of the binary.

Thanks to both you and Joakim for that.

Do you guys — or anybody else — know what the situation is with GDC?  Does it strip out unneeded sections/symbols/both, or is it just dumping everything into the executable like DMD-on-Mac-OS-X seems to do?

— Abe
September 01, 2014
On Monday, 1 September 2014 at 18:33:44 UTC, Dicebot wrote:
> Any reason why it can't work for OSX in a same way? Assuming LDC does emit ModuleInfo & Co sections the same way it does on Linux, using OSX specific alternative to --gc-sections should "just work".

The reason we don't enable the -dead_strip option of ld64 is simply because nobody had time to make sure it works as intended. For Linux, I made the necessary adjustments to get --gc-sections to function correctly while I was working on the related code for runtime loading anyway.

David
September 02, 2014
On Monday, 1 September 2014 at 22:17:13 UTC, Abe wrote:
> Do you guys — or anybody else — know what the situation is with GDC?  Does it strip out unneeded sections/symbols/both, or is it just dumping everything into the executable like DMD-on-Mac-OS-X seems to do?

GDC does not strip unneeded stuff by default on any OS, and generates by far the biggest executables in my experience (though some of it is due to druntime/Phobos debug info which you can manually strip out afterwards).

David
September 02, 2014
On 01/09/14 20:33, Dicebot wrote:

> Any reason why it can't work for OSX in a same way? Assuming LDC does
> emit ModuleInfo & Co sections the same way it does on Linux, using OSX
> specific alternative to --gc-sections should "just work".

It does not emit these sections the same way, at least not on DMD.

-- 
/Jacob Carlborg
September 02, 2014
On Tuesday, 2 September 2014 at 06:18:27 UTC, Jacob Carlborg
wrote:
> On 01/09/14 20:33, Dicebot wrote:
>
>> Any reason why it can't work for OSX in a same way? Assuming LDC does
>> emit ModuleInfo & Co sections the same way it does on Linux, using OSX
>> specific alternative to --gc-sections should "just work".
>
> It does not emit these sections the same way, at least not on DMD.

Well I am speaking about LDC ;) --gc-sections don't work with
Linux DMD either.