ldc-developers/ldc — Issue #48: Bad/No Dead Code Elimination
Author: dsimcha
Created: 2011-12-11 18:29:03+00:00
State: open

LDC and/or the linker options it uses do a terrible job of eliminating dead code. This results in two annoying problems:

1. Linker `undefined reference` errors for symbols that are only referred to from dead code.

2. Huge binaries.

Example:

// lib/file1.d:
int doNothing();

void callDoNothing() {
doNothing();
}

// lib/file2.d:
module lib.file2;

import std.stdio;

void sayHello() {
writeln("Hello, world.");
}

// main.d:
import lib.file2;

void main() {
sayHello();
}

$ ldmd2 -lib -ofliblib.a lib/*.d
$ ldmd2 main.d -Lliblib.a
liblib.a(liblib.o): In function `_D5file113callDoNothingFZv':
file1:(.text+0x2): undefined reference to `_D5file19doNothingFZi'
collect2: ld returned 1 exit status
Error: linking failed:
status: 1

When I do the same thing with GDC or DMD, the linker recognizes that `doNothing()` is only referred to from dead code, doesn't complain about the fact that the reference isn't defined, and presumably removes the dead code referring to `doNothing()` from the executable.