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.


Ian Lance Taylor wrote:
> 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

The reason I ask, is that my project uses a modified GCC to generate
information about exceptions and callgraph information and then i have a
post processing tool that looks over all the information generated and
merges it together from the various translation units. This post
processing tool operates kind of similar to a linker.

In the merge process I have been requiring that if multiple
implementations of the same function are found that they must have the
same function calls and exceptions thrown etc. So where the linker was
working fine in the code mentioned before, my post processing tool was
emitting an error and failing.

Thanks for the information now that I know it is valid. I will just make
sure i take vague linkage into account and try to behave similar to the
way i see the linker behaving by only including the first implementation
found.

I may actually emit a warning too, just in case people want to know why
something strange seems to be happening...

Brendon.


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