Lib change leads to larger executables
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Thu Feb 22 13:00:37 PST 2007
jcc7 wrote:
> Frits van Bommel (fvbommel at REMwOVExCAPSs.nl) wrote:
>> jcc7 wrote:
>>> Surely, the compiler can figure out which TypeInfo's it needs at
>>> the point of compiling an .exe or .dll.
>> Not necessarily. Any modules that are linked in but not called by
>> other modules (e.g. code only reachable from static constructors
>> and/or static destructors) may not be seen when main/DllMain is
>> compiled, if there even is one of these (see above point about
>> DllMain being optional).
>
> I don't see how static constructors and/or destructors interferes with the
> compiler detecting which TypeInfo's would be necessary, but I don't think such a
> problem would be insurmountable.
How static constructors could interfere:
---
module selfcontained;
static this() {
// some code that requires TypeInfo not used in other modules
// (including Phobos), perhaps for a type defined in this module.
}
---
(Change 'static this' to 'static ~this' or 'unittest' for similar problems)
If this module isn't imported (directly or indirectly) from the file
defining main() the compiler can't possibly know what TypeInfo needs to
be generated for it when compiling main(), simply because it doesn't
parse that file when pointed at the file containing main().
Yes, this could be "fixed" by having the module containing main() import
all such modules, but it shouldn't have to. We shouldn't need to work
around toolchain limitations, especially if there's a way to make it
Just Work(TM).
> Perhaps, it'd be a question of "Is it worth the
> effort?".
It'll be worth the effort when one of _your_ projects fail to compile
because of it :P.
> But then again, I don't know much about what the compiler and linker do "under the
> hood". It's mostly a black box for me. But from reading Walter and Kris discuss
> the issues involved, I'm convinced there has to be a less haphazard way for DMD
> and optlink to interact.
Like I've mentioned earlier: I'm pretty sure this problem would go away
entirely if the compiler simply generated all TypeInfo used in the
module. If that generates larger intermediate object files I'm okay with
that. In fact, that was how I thought it worked until I started reading
about this problem...
>>> If not, even if we have to wait for linker to spit out
>>> a list of missing TypeInfo's and then generate the TypeInfo
>>> (trial-and-error), I think that would be a small price to pay for
>>> eliminating all of this bloat of unneeded module that Kris has
>>> discovered.
>> This would mean you can't "manually" link stuff together, using
>> optlink/ld/whatever directly. I don't know how many people want to
>> do this, but Walter has made it pretty clear he wants to be able to
>> use a generic linker[1] (i.e. one that doesn't require specialized
>> knowledge of D) and I agree with that.
>
> Isn't there still a question of whether anyone has found a "generic linker" for
> OMF (other than OptLink) that can work with DMD anyway?
I believe I mentioned that a bit later ;).
[snip special linker discussion]
>> Though arguably the situation with DMD/Windows is already worse when
>> it comes to that, since almost nobody else uses OMF anymore...
>
> Right. We seem to be on our own when it comes to using OMF.
Well, it seems OpenWatcom supports it. From what I've read here the
linker doesn't like DMD object files though. Walter claims it's buggy. I
don't know enough about OMF to say one way or the other.
> I think we're mostly trying to find a fix for the problem with the OMF files
> generated by DMD right now. Apparently, GDC doesn't have these same problems (or
> if GDC does have linker problems, Walter isn't the one responsible for fixing
> them). So I think the problem is limited to using DMD's OMF files on Windows.
> (Doesn't DMD on Linux use ELF? I think that's the case.)
Yes, DMD/Linux uses ELF. It just calls ld (through gcc) to link instead
of using optlink.
I'm not sure if ld (or the mingw port of it) can use ELF to create
Windows executables, but if it can that may be an option: just switch to
ELF entirely and trash optlink. (this paragraph wasn't entirely serious,
in case you hadn't noticed :P)
More information about the Digitalmars-d
mailing list