This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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: [C++] GCC tree linkage types


On Mon, 27 Oct 2003, Chris Lattner wrote:

> On Sun, 26 Oct 2003, Richard Henderson wrote:

> Ok, it looks like my problems are due to a combination of explicitly
> instantiated templates and "external" templates.  It looks like I need to
> be able to tell when a DECL_ONE_ONLY function is part of an explicit
> template instantiation of an external template.  (gack)!
>
> For example, take this translation unit:
> ---
> template<class T>
> struct Test {
>   void func() {}
> };
>
> extern template class Test<int>;
> template struct Template<int>;
> ---
>
> Here we recognize that we have to emit the function in this translation
> unit, but DECL_ONE_ONLY is set on the function, so it is marked
> link-once, and deleted by the LLVM optimizer (it is not used in this
> translation unit).

Ok, I think that I have found a "solution" to my problem, but I want to
check with some C++ people to make sure that it is kosher.  I tracked this
down to this fragment of cp/pt.c:mark_decl_instantiated:

      /* Always make artificials weak.  */
      if (DECL_ARTIFICIAL (result) && flag_weak)
	comdat_linkage (result);
      /* For WIN32 we also want to put explicit instantiations in
	 linkonce sections.  */
      else if (TREE_PUBLIC (result))
	maybe_make_one_only (result);

Specifically, if I comment out the maybe_make_one_only call, the function
ends up with strong external linkage, and solves my problem.  The question
is, however, what is the right solution to this?  Why does Win32 want
explicit instantiations in linkonce sections?  Can you have multiple
explicit instantiations of the same template in the same program?

Perhaps DECL_COMDAT is the right answer to this?

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/


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