This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Linking template instanciations in multiple translation units.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]