Modern C++ Lamentations

H. S. Teoh hsteoh at
Mon Dec 31 15:51:50 UTC 2018

On Sun, Dec 30, 2018 at 02:37:59PM -0800, Walter Bright via Digitalmars-d wrote:
> On 12/30/2018 6:27 AM, H. S. Teoh wrote:
> > Recently I noticed that LDC now compiles every function into their
> > own section
> DMD has always done that.

Then it must be doing something wrong, since running dmd with
-L-gc-sections produces a 2 MB executable, but running ldc2 (without any
special options) produces a 456 KB executable. Exactly the same set of
source files. No dependencies on compiler-specific features in the code.

To put this more in perspective, I re-tested this with a trivial Hello
World program:

	import std.stdio;
	void main() {
		writeln("Hello world");

Compile this with dmd:

	$ dmd -L--gc-sections test.d
	$ ls -l test
	-rwxrwxr-x 1 hsteoh hsteoh 967416 Dec 31 07:43 test

Compile this with ldc2:

	$ ldc2 test.d
	hsteoh at crystal:/tmp$ \ls -l test
	-rwxrwxr-x 1 hsteoh hsteoh 24632 Dec 31 07:44 test

Note the order of magnitude difference in size, and that ldc2 achieves
this by default, with no additional options needed.

How do you make dmd produce the same (or comparable) output?

> > and runs LTO, including GC of unreferenced sections, by default.
> I've tried using the GC feature of ld, but it would produce
> executables that crashed.
> But that was years ago, perhaps ld has improved. If someone would like
> to turn that on with dmd, it would be a worthwhile experiment.

Maybe it's because certain required sections need to be marked in some
way so that the linker doesn't discard them?


The irony is that Bill Gates claims to be making a stable operating system and Linus Torvalds claims to be trying to take over the world. -- Anonymous

More information about the Digitalmars-d mailing list