This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add missing explicit instantiation for std::lower_bound template
- From: Benjamin De Kosnik <bkoz at redhat dot com>
- To: Dodji Seketeli <dodji at redhat dot com>
- Cc: Paolo Carlini <paolo dot carlini at oracle dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>, FranÃois Dumont <fdumont at gcc dot gnu dot org>, Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Date: Mon, 11 Feb 2013 16:55:25 -0800
- Subject: Re: [PATCH] Add missing explicit instantiation for std::lower_bound template
- References: <8738xcm5xc.fsf@redhat.com> <51112F05.2070404@oracle.com> <87y5f1alj5.fsf@redhat.com>
> >> 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
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