This is the mail archive of the binutils@sources.redhat.com 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]

C++ template instantiation aliasing problem


If a (seemingly local) structure is defined differently in two different
C++ modules, LD will select one instantiation of a templated function
and apply it both modules, even if the instantiations differ. 

The problem is in how multiply defined symbols are handled.
Traditionally with C, an error message would be generated. But with C++,
it is desirable to merge template instantiations to reduce overall code
size, so the first instantiation found is selected and the others are
discarded. The problem is that there is another instantiation that is
(and should be!) different and distinct. 

To solve this, the linker should
  -- Issue a warning when multiply defined symbols do not map to
identical code
  -- (possibly) maintain multiple distinct versions in the generated
binary

I am using binutils-2.10.91.0.2-3 (RH 7.2) 
I have attached a testcase (tmpl_alias.tar.gz, 739 bytes) that
demonstrates this problem. 

'make test' demonstrates the testcase. 
I should note that adding the 'static' keyword to the template
definition in linkbug.h works around the problem. Nevertheless, given
the subtlety of the problem and the difficulty of tracking it down, a
warning message is warranted. 
	Steve Holland
sdh4 a t cornell d o t edu

Attachment: tmpl_alias.tar.gz
Description: application/compressed-tar


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