This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Linking template instanciations in multiple translation units.
- From: Ian Lance Taylor <iant at google dot com>
- To: Brendon Costa <brendon at christian dot net>
- Cc: binutils at sourceware dot org
- Date: 01 Dec 2006 16:12:05 -0800
- Subject: Re: Linking template instanciations in multiple translation units.
- References: <4570C269.5030807@christian.net>
Brendon Costa <brendon@christian.net> writes:
> I understand that GCC emits a separate instance of the template in each
> translation unit it is required in and flags it so that the linker
> should then handle the multiple implementations. Usually these template
> implementations should be the same, however I came across this one that
> was not. Should the linker check to see if the implementations that it
> "merges" are the same or is this not possible or not meeting a
> particular requirement?
It's difficult. You can't assume that the same template source
compiles into the same machine code in two different .o files, because
the .o files might have been compiled with different options, and they
might see different inline functions. That is legal C++, and the
linker should not reject it.
One approach which would detect most such cases would be to use the
debugging information to identify the source of the code. If two
template instantiations with the same name come from different source
files, then there is probably a problem.
I can't think of any other approach which would work, short of a
compiler change to record the source code in some way.
Ian