Patchwork Add missing explicit instantiation for std::lower_bound template

login
register
mail settings
Submitter Benjamin Kosnik
Date Feb. 12, 2013, 12:55 a.m.
Message ID <20130211165525.7e2a9fd0@oakwood>
Download mbox | patch
Permalink /patch/219713/
State New
Headers show

Comments

Benjamin Kosnik - Feb. 12, 2013, 12:55 a.m.
> >> Since commit r195676[1], it looks like
> >> libstdc++-v3/src/c++11/hashtable_c++0x.cc is missing an explicit
> >> instantiation for std::lower_bound. 
                                                               
it's missing an implicit instantiation of std::lower_bound.

>>This leads to libstdc++.so
> >> having the symbol for that (missing) instantiation be undefined,
> >> thus preventing executables from being linked with libstdc++.
> > Note that I can confirm this only if I build with less optimization
> > than the default -O2, say -O. That may explain why nobody noticed
> > earlier.

Yes, indeed.

Certainly, the explicit instantiation is ok for this non-usual -O
compile. The full instantiation set depends on specific flag and
perhaps platform. Let's not special case all of these, and instead just
allow implicit template instantiations via -fimplicit-templates. 

Thus, what is really needed (and also in cases like PR52887)
is to just allow implicit template instantiations. Done as attached.

-benjamin

tested x86/linux
tested x86/linux -O0
tested x86/linux -O

Patch

2013-02-11  Benjamin Kosnik  <bkoz@redhat.com>

	    * src/c++11/Makefile.am (hashtable_c++0x.lo, hashtable_c++0x.o):
	    Use -fimplicit-templates.
	    * src/c++11/Makefile.in: Regenerate.
	    * src/c++11/hashtable_c++0x.cc: Remove instantiation for
	    std::lower_bound template.


diff --git a/libstdc++-v3/src/c++11/Makefile.am b/libstdc++-v3/src/c++11/Makefile.am
index 89ee335..e7b48ac 100644
--- a/libstdc++-v3/src/c++11/Makefile.am
+++ b/libstdc++-v3/src/c++11/Makefile.am
@@ -60,6 +60,13 @@  vpath % $(top_srcdir)/src/c++11
 
 libc__11convenience_la_SOURCES = $(sources)  $(inst_sources)
 
+# Use special rules for the hashtable.cc file so that all
+# the generated template functions are also instantiated. 
+hashtable_c++0x.lo: hashtable_c++0x.cc
+	$(LTCXXCOMPILE) -fimplicit-templates -c $<
+hashtable_c++0x.o: hashtable_c++0x.cc
+	$(CXXCOMPILE) -fimplicit-templates -c $<
+
 # AM_CXXFLAGS needs to be in each subdirectory so that it can be
 # modified in a per-library or per-sub-library way.  Need to manually
 # set this option because CONFIG_CXXFLAGS has to be after
diff --git a/libstdc++-v3/src/c++11/hashtable_c++0x.cc b/libstdc++-v3/src/c++11/hashtable_c++0x.cc
index b6a56bc..7617c58 100644
--- a/libstdc++-v3/src/c++11/hashtable_c++0x.cc
+++ b/libstdc++-v3/src/c++11/hashtable_c++0x.cc
@@ -94,11 +94,4 @@  namespace __detail
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace __detail
-
- // Instantiations.
- template
- const unsigned long*
- lower_bound<const unsigned long*, size_t>(const unsigned long*,
-					   const unsigned long*,
-					   const size_t&);
 } // namespace std