[resend] PE/COFF (and ELF) Template bugs (const & static init data members)

Mumit Khan khan@xraylith.wisc.edu
Thu May 14 14:34:00 GMT 1998


I'm resending a bug report that I had submitted back in Feb 17 that deals
with bugs in explicit template instantiation on PE/COFF systems. This
particular bug makes the C++ side unusable on Win32 (eg., can't link with
string class), so I really would like to see a fix (or pointer to how I
can fix it). I'm editing the origina slightly to take out the part that 
was due to the the linker.

This bug also affects Linux/ELF, but only shows up when *all* the copies of
the template class are explicitly instantiated!

Regards,
Mumit -- khan@xraylith.wisc.edu

------- Forwarded Message

Date:    Tue, 17 Feb 1998 13:01:51 -0600
From:    Mumit Khan <khan@cygnus.com>
Subject: (1.0.2) Win32 Template bugs (const & static init data members)

The following is a short analysis of a template bug that afflicts PE-COFF,
which supports LINKONCE sections to discard duplicate template instances. 
The problems shows up if an explicitly instantiated template class has 
either/both of the following members:

  - STATIC CONST DATA, and/or
  - STATIC INITIALIZED DATA

Bug 1: EXPLICIT INSTANTIATION: C++ front does not put the explicitly
  instantiated copies of either in LINKONCE sections. This causes 
  problems with library classes such as "string" (nilRep and npos), esp
  since the recent (mainline on Jan 25, egcs-1.0.2 on Feb 10) change to 
  libstdc++/std/bastring.h.

BUG 2: [Can't load .... bug -- ALREADY FIXED IN BINUTILS]

Consider the following code:

  template <class T>
  class Template 
  {
    public:
      static int static_data;
      static int static_initialized_data;
      static const int static_const_data = 5;
  };

  template <class T> int
  Template<T>::static_data;

  template <class T> int
  Template<T>::static_initialized_data = 0;

  template <class T> const int
  Template<T>::static_const_data;

BUG 1: EXPLICIT INSTANTIATION OF STATIC INITIALIZED and STATIC CONST DATA
  MEMGBERS.

Now we explicitly instantiate 'Template<int>' in some compilation unit:
  
  template class Template<int>;

And egcs produces the following symbols:

  00000004 C Template<int>::static_data			<< 1 
  00000000 D Template<int>::static_initialized_data	<< 2
  00000000 T Template<int>::static_const_data		<< 3

Note the following:
  1. static_data is *correctly* emitted as common symbol.
  2. static_initialized_data *should've* gone in the linkonce section.
  3. Likewise for static_const_data. ALSO, Why is it in the text segement, 
     as opposed to the read-only data ("R") section?

The problem seems to in the use of make_decl_one_only() in cp/
pt.c (mark_decl_instantiated) to provide the appropriate linkage
of explicitly instantiated templates, and somehow the static
const and static initialized data members are not getting the right
attributes (DECL_ONE_ONLY?). 

BUG 2: [FIXED IN BINUTILS]

Regards,
Mumit -- khan@xraylith.wisc.edu
http://www.xraylith.wisc.edu/~khan/

------- End of Forwarded Message




More information about the Gcc-bugs mailing list