Why doesn't DMD create any redundant symbols?
Gregor Richards
Richards at codu.org
Tue Aug 28 09:57:16 PDT 2007
This is a problem that comes up for me again and again in making DSSS
work everywhere. When DMD is being used to compile several modules with
-c, it never creates any redundant data, and it also doesn't mark any
data which could be redundant as common as far as I can tell. This means
that DSSS has to build one file at a time with DMD. This makes certain
obnoxious people complain about DSSS being slow, because it takes an
incredible ten seconds to compile a fairly large library. When I
switched it to compiling multiple files simultaneously, it takes <1
second, but was wrong for reasons that will be described below.
When DMD comes over typeinfo (for example), it only puts the typeinfo
symbol into one .o file it is generating, even if it's used within
several. On the surface, this seems like a good idea, but in reality it
causes a whole slew of problems with bogus intermodule dependencies.
With this, foo.io.output could arbitrarily depend on foo.net.ipvsix.udp,
because some piece of typeinfo was put there.
First, libraries. I don't know precisely how .lib files work on Windows,
but linking .a files will pick-and-choose only those .o files that are
used. With these bogus inter-module dependencies, it will often be
forced to drag in the whole library, even though only a small chunk of
it is actually necessary. This just causes big binaries, except when
libraries have conditional dependencies - if foo.a depends on another
library, but foo.b does not, it is now unpredictable what libraries are
necessary. Oof.
Second, incremental compilation. This is one I didn't realize was a
problem until recently. DSSS will perform incremental compilation when
only one file has changed by only compiling that file. However, that
causes more issues with these common data problems. Now, typeinfo could
be doubly defined but not marked common, or (by means I don't quite
understand) not defined at all. So, I now have to compile one file at a
time, even when building binaries.
The solution to all of this is simple: Create redundant symbols in the
object files, marked as common. I know this can be done because it's
done properly with one file at a time. This increases the size of the
object files, but since it reduces bogus intermodule dependencies and
sections marked as common will be merged anyway, it actually reduces the
size of produced binaries, as well as making linking a significantly
less complex problem.
I have to assume there's a reason for this, so, to summarize: Why
doesn't DMD create any redundant symbols in .o files?
- Gregor Richards
More information about the Digitalmars-d
mailing list