Bug 48465 - [4.6/4.7 Regression] undefined reference to std::basic_string::_S_compare(unsigned long, unsigned long)
Summary: [4.6/4.7 Regression] undefined reference to std::basic_string::_S_compare(uns...
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Not yet assigned to anyone
Keywords: link-failure, wrong-code
Depends on:
Reported: 2011-04-05 17:17 UTC by Zdenek Sojka
Modified: 2011-04-10 16:21 UTC (History)
4 users (show)

See Also:
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Known to work: 4.5.3, 4.6.1, 4.7.0
Known to fail: 4.6.0
Last reconfirmed: 2011-04-05 17:23:03

reduced testcase (166 bytes, text/plain)
2011-04-05 17:17 UTC, Zdenek Sojka

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2011-04-05 17:17:17 UTC
Created attachment 23883 [details]
reduced testcase

Compiler output:
$ g++ -finline-small-functions -O testcase.C --param=hot-bb-frequency-fraction=1
/tmp/ccRTQGpy.o: In function `foo(int, int, char*)':
testcase.C:(.text+0x70): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_compare(unsigned long, unsigned long)'
collect2: ld returned 1 exit status

Tested revisions:
r171979 - fail
4.6 r171597 - fail
4.5 r171597 - OK
Comment 1 Jonathan Wakely 2011-04-05 17:23:03 UTC
I can reproduce this, but I don't think it can be a libstdc++ bug when it depends on optimisation and --param=hot-bb-frequency-fraction=1
Comment 2 Zdenek Sojka 2011-04-05 21:47:55 UTC
The problem might be the combination of the fact that _S_compare is static, and  "extern template class basic_string < char >;" declaration.
Comment 3 Paolo Carlini 2011-04-05 23:27:06 UTC
Right now I'm traveling and I have trouble working on this issue. Anyway, if the only problem is the undefined symbol, we could as well export it and be done. Looks like we are also in the pretty lucky situation that 4.6.0 just came out and 4.5 was ok, thus we can have the fix in 4.6.1 and mainline without special problems with the exports, we have just to add the export at a new minor version.

To be safe, I'm adding Honza in CC (would not be the first time a spurious undefined symbol turned out not to be a library issue ;) and I'm not sure to understand the --param at issue well enough to exclude that possibility)

In any case, let's make sure we resolve this in time for 4.6.1.
Comment 4 Jan Hubicka 2011-04-06 08:28:15 UTC
 --param=hot-bb-frequency-fraction=1 will effectively disable inlining within BBs that are not always executed when function is invoked. So the question is if the function in question is static within unit and should then be output as offline copy or there is just a bug in libstdc++ exported symbols.
Comment 5 Richard Biener 2011-04-06 09:51:40 UTC
The function is static and thus should be output as offline copy.  This doesn't
look like a libstdc++ bug.
Comment 6 Jonathan Wakely 2011-04-06 11:08:40 UTC
Adding these exports to libstdc++ does fix it though:

GLIBCXX_3.4.16 {
} GLIBCXX_3.4.15;
Comment 7 Jakub Jelinek 2011-04-06 11:45:42 UTC
Note that for i686 it isn't *mm, but *jj, so I think you want to:
GLIBCXX_3.4.16 {
} GLIBCXX_3.4.15;
Comment 8 Richard Biener 2011-04-06 13:00:28 UTC
If the class is explicitly instantiated we probably do not emit an out-of-line
copy of the static (dependent) function.  And I see

  extern template class basic_string<char>;

in bits/basic_string.tcc, so it seems to be a library bug after all.
Comment 9 Paolo Carlini 2011-04-06 14:45:36 UTC
Jon, if you could run the patchlet (as tweaked by Jakub) through the testsuite, and apply it, it would be great. I'm still traveling and trying to find the time to work on the std::tuple issues over the next days.
Comment 10 Jonathan Wakely 2011-04-06 14:59:03 UTC
ok, will do
Comment 11 Paolo Carlini 2011-04-06 17:02:30 UTC
Comment 12 Jonathan Wakely 2011-04-10 16:19:46 UTC
Author: redi
Date: Sun Apr 10 16:19:41 2011
New Revision: 172240

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172240
2011-04-10  Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/48465
	* configure.ac (libtool_VERSION): Bump library version to 6:16:0.
	* configure: Regenerate.
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.16): Export missing symbols.
	* testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.16.

Comment 13 Jonathan Wakely 2011-04-10 16:20:50 UTC
Author: redi
Date: Sun Apr 10 16:20:42 2011
New Revision: 172241

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172241
2011-04-10  Jonathan Wakely  <jwakely.gcc@gmail.com>

	PR libstdc++/48465
	* configure.ac (libtool_VERSION): Bump library version to 6:16:0.
	* configure: Regenerate.
	* config/abi/pre/gnu.ver (GLIBCXX_3.4.16): Export missing symbols.
	* testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.16.

Comment 14 Jonathan Wakely 2011-04-10 16:21:48 UTC
fixed for 4.6.1