* Win32 issues with Templates and Libs *

Daniel Keep daniel.keep.lists at gmail.com
Tue Feb 20 05:29:53 PST 2007


Mmm... yummy technical details :P

There seem to be quite a few problems/annoyances due to limitations in
the object file formats.  It makes one wonder whether it wouldn't be a
good idea to simply make a new one that properly supported D's feature
set...

Of course, that would involve touching OPTLINK, something I gather no
one is particularly keen on :P

	-- Daniel

Walter Bright wrote:
> The problem is that one of two kinds of COMDAT sections can be generated:
> 
> 1) Only one COMDAT with a particular name may appear
> 2) Any number of COMDATs with the same name may appear, pick one and
> discard the others
> 
> Instantiating a template produces a COMDAT section. Since multiple
> modules may instantiate a template with the same arguments, without
> knowing about each other, option (2) is used.
> 
> When a module is put into a library, a dictionary is created for the
> library, essentially an associative array of object modules indexed by
> symbol names. COMDATs of option (1) get put into the dictionary, ones of
> option (2) do not. Why not? Because if there's more than one of (2),
> which object module do you pull in? No way to tell.
> 
> Thus, the problem you're seeing. The solution is:
> 
> 1) have another global in module test that gets pulled in, thus also
> pulling the COMDAT along with it, and resolving the symbol.
> 
> 2) explicitly link in module test
> 
> So, you might ask, why not just regenerate the template instantiation
> every time you use it? Because it would lead to a lot of object file bloat.

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list