[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #10 from bangerth at gmail dot com 2009-01-30 15:37 --- (In reply to comment #9) Following the twisted maze that is BOOST_CLASS_EXPORT() leads me to think that it is (very) roughly equivalent to this: void dummy(boost::archive::xml_iarchive ar, A a, B b) { boost::serialization::serialize(ar, a, 0); boost::serialization::serialize(ar, b, 0); } Indeed, replacing my BOOST_CLASS_EXPORT() calls with this, I get the same effect (disappearing symbols with -O2). At this point, my question is: is triggering template instantiations in this way supposed to be equivalent to explicit instantiations (as in comment #8) with respect to symbols exposed to the outside? If the answer is no, thank you very much for your help and sorry for the trouble. The answer is no. The code requires the *implicit* instantiation of some code but the compiler only needs to instantiate whatever it needs and is free to eliminate what it doesn't. In fact, there is no guarantee that any code visible outside this one object file is generated at all. W. -- bangerth at gmail dot com changed: What|Removed |Added CC||bangerth at gmail dot com Status|WAITING |RESOLVED Resolution||INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #8 from ronan dot lehy at probayes dot com 2009-01-15 15:13 --- If I add simple explicit instantiations in place or in addition to the BOOST_CLASS_EXPORT() calls, all symbols are correctly exposed in all cases : namespace boost { namespace serialization { template void serializeboost::archive::xml_iarchive(boost::archive::xml_iarchive , A , unsigned int); template void serializeboost::archive::xml_iarchive(boost::archive::xml_iarchive , B , unsigned int); } } Therefore, there may be a problem related to the way BOOST_CLASS_EXPORT() instantiates serialize(). BOOST_CLASS_EXPORT(A) expands to: namespace boost { namespace archive { namespace detail { template const guid_initializer A guid_initializer A ::instance(A); template std::pair const export_generator A, boost::archive::detail::known_archive_types::type *, const guid_initializer A * export_archives_invoke A, boost::archive::detail::known_archive_types::type (A , boost::archive::detail::known_archive_types::type ); } } }; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #9 from ronan dot lehy at probayes dot com 2009-01-15 16:12 --- Following the twisted maze that is BOOST_CLASS_EXPORT() leads me to think that it is (very) roughly equivalent to this: void dummy(boost::archive::xml_iarchive ar, A a, B b) { boost::serialization::serialize(ar, a, 0); boost::serialization::serialize(ar, b, 0); } Indeed, replacing my BOOST_CLASS_EXPORT() calls with this, I get the same effect (disappearing symbols with -O2). At this point, my question is: is triggering template instantiations in this way supposed to be equivalent to explicit instantiations (as in comment #8) with respect to symbols exposed to the outside? If the answer is no, thank you very much for your help and sorry for the trouble. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #6 from ronan dot lehy at probayes dot com 2009-01-14 09:11 --- Thanks a lot for considering this report! (In reply to comment #5) Also since it is not explicitly instatinated, the template does not need to be in the object file really. I believe this is instantiated with Archive = boost_xml_iarchive by the BOOST_EXPORT macro. (In reply to comment #5) serialize with an empty body is a pure function so it will be can be optimized away without any effects. I don't see the issue here really. But this function (as instantiated with Archive = boost_xml_iarchive by BOOST_EXPORT) can be called from other .o files. Actually, it is, and linking the .o files together into a shared library then fails. Can you give a better example of why do you think this is wrong besides a nm testcase? I could show you how mylib1.o and mylib2.o fail to link into libmylib.so, since serializeboost_xml_iarchive(boost_xml_iarchive, A, unsigned int) is referenced by mylib2.o, and should be defined in mylib1.o, but is not. Do you want that ? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #7 from ronan dot lehy at probayes dot com 2009-01-14 09:14 --- (In reply to comment #6) I believe this is instantiated with Archive = boost_xml_iarchive by the BOOST_EXPORT macro. I mean BOOST_CLASS_EXPORT(), of course, sorry. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #1 from ronan dot lehy at probayes dot com 2009-01-13 16:35 --- Created an attachment (id=17088) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17088action=view) Preprocessed source -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #2 from ronan dot lehy at probayes dot com 2009-01-13 16:39 --- (In reply to comment #1) Created an attachment (id=17088) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17088action=view) I had to trim a bit the source to be make the preprocessed source fit into 1000 ko. With it, the expected nm output (-O2 -fno-inline-small-functions) is: W void boost::serialization::serializeboost::archive::xml_iarchive(boost::archive::xml_iarchive, A, unsigned int) W void boost::serialization::serializeboost::archive::xml_iarchive(boost::archive::xml_iarchive, B, unsigned int) And the one with missing symbols (-O2) is: W void boost::serialization::serializeboost::archive::xml_iarchive(boost::archive::xml_iarchive, B, unsigned int) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #3 from ronan dot lehy at probayes dot com 2009-01-13 16:42 --- Created an attachment (id=17089) -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17089action=view) Original source (#includes Boost headers). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #4 from pinskia at gcc dot gnu dot org 2009-01-13 20:43 --- serialize with an empty body is a pure function so it will be can be optimized away without any effects. I don't see the issue here really. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828
[Bug c++/38828] g++ 4.3.2: -O2 without -fno-inline-small-functions makes some template instantiations disappear
--- Comment #5 from pinskia at gcc dot gnu dot org 2009-01-13 20:46 --- Also since it is not explicitly instatinated, the template does not need to be in the object file really. Can you give a better example of why do you think this is wrong besides a nm testcase? It might be due to that you are defining the template specialization in the other TUs in which case, the code is invalid. -- pinskia at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |WAITING http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38828