Solutions to the TypeInfo dependency injection issue?

Sean Kelly sean at f4.ca
Sun Mar 11 18:09:47 PDT 2007


kris wrote:
> Walter Bright wrote:
>> kris wrote:
>>
>>> Walter Bright wrote:
>>>
>>>> kris wrote:
>>>>
>>>>> What about (c) how templates are affected at each step ?
>>>>
>>>>
>>>>
>>>> It's the same algorithm - nothing special about templates.
>>>
>>>
>>> Is it possible, do you think, to be just a little more forthcoming on 
>>> this?
>>>
>>> 1) when you batch-compile code with multiple references to a 
>>> template, there is just one instance generated.
>>
>>
>> Yes.
>>
>>> 2) when you compile the same code modules individually, there are 
>>> presumably multiple template instances generated?
>>
>>
>> Yes.
>>
>>> 3) how does the linker resolve the multiple template instances to 
>>> just one?
>>
>>
>> The template instantiations are put into COMDAT sections, and the 
>> linker discards redundant ones.
> 
> Thank you;
> 
> 4) all symbols required to represent typeinfo and templates are now 
> duplicated in each object file ?

My guess is separate compilation generates all TypeInfo and templates 
used by that module into the module's object file.  Which I believe is a 
"yes."

> 5) The linker does not have to search beyond the current object file for 
> instances of #4 (as suggested by larsivi) ?

Correct.

> 6) the result is a library with many more duplicate symbols than before, 
> but arranged in such a manner that persuades the linker to do the "right 
> thing" ?

Yes.

> 7) there is no possibility of the linker following a 'bad chain', and 
> thus linking in unused or otherwise redundant code ?

It certainly seems that way.  We get larger object files and libraries 
in exchange for smaller executables.  If any of the above is wrong, 
someone please correct me.


Sean



More information about the Digitalmars-d mailing list