Bug 52887 - Bootstrap on AIX failure: Undefined symbol: .std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)>::function(std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)> const&)
Summary: Bootstrap on AIX failure: Undefined symbol: .std::function<void (std::__regex...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: bootstrap (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 53713 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-04-06 15:36 UTC by Daniel Richard G.
Modified: 2013-02-11 23:53 UTC (History)
5 users (show)

See Also:
Host: powerpc-ibm-aix5.3.0.0
Target: powerpc-ibm-aix5.3.0.0
Build: powerpc-ibm-aix5.3.0.0
Known to work:
Known to fail:
Last reconfirmed: 2012-06-19 00:00:00


Attachments
Workaround to provide the two missing symbols (321 bytes, text/x-csrc)
2012-05-10 15:04 UTC, Daniel Richard G.
Details
Fix for undefined references (260 bytes, patch)
2012-06-18 09:44 UTC, Jörg Richter
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Richard G. 2012-04-06 15:36:57 UTC
Bootstrapping GCC 4.7.0 on an AIX 5.3 system fails with

/tmp/gcc-4.7.0-build/./prev-gcc/g++ -B/tmp/gcc-4.7.0-build/./prev-gcc/ -B/opt/tg/powerpc-ibm-aix5.3.0.0/bin/ -nostdinc++ -B/tmp/gcc-4.7.0-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/src/.libs -B/tmp/gcc-4.7.0-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/libsupc++/.libs -I/tmp/gcc-4.7.0-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/include/powerpc-ibm-aix5.3.0.0 -I/tmp/gcc-4.7.0-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/include -I/home/src/gcc-4.7.0/libstdc++-v3/libsupc++ -L/tmp/gcc-4.7.0-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/src/.libs -L/tmp/gcc-4.7.0-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/libsupc++/.libs   -g -O2 -DIN_GCC   -fno-exceptions -fno-rtti -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc -Wl,-bbigtoc -Wl,-bmaxdata:0x40000000 -o cc1 c-lang.o c-family/stub-objc.o attribs.o c-errors.o c-decl.o c-typeck.o c-convert.o c-aux-info.o c-objc-common.o c-parser.o tree-mudflap.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o default-c.o rs6000-c.o \
          cc1-checksum.o main.o  libbackend.a libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a   ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a    -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -lmpc -lmpfr -lgmp   -L../zlib -lz
ld: 0711-317 ERROR: Undefined symbol: .std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)>::function(std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)> const&)
ld: 0711-317 ERROR: Undefined symbol: .std::function<bool (std::__regex::_PatternCursor const&)>::function(std::function<bool (std::__regex::_PatternCursor const&)> const&)
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: error: ld returned 8 exit status
gmake[3]: *** [cc1] Error 1
gmake[3]: Leaving directory `/tmp/gcc-4.7.0-build/gcc'
gmake[2]: *** [all-stage2-gcc] Error 2
gmake[2]: Leaving directory `/tmp/gcc-4.7.0-build'
gmake[1]: *** [stage2-bubble] Error 2
gmake[1]: Leaving directory `/tmp/gcc-4.7.0-build'
gmake: *** [bootstrap-lean] Error 2


The build tree was configured with

'--prefix=/opt/tg' '--disable-dependency-tracking' '--disable-maintainer-mode' '--program-prefix=tg-' '--disable-shared' '--disable-nls' '--enable-version-specific-runtime-libs' '--with-pic' '--with-mpc=/usr/local' '--with-mpfr=/usr/local' '--with-gmp=/usr/local' 'CC=tg-gcc -mminimal-toc' 'CXX=false' '--enable-languages=c,c++'
Comment 1 Jonathan Wakely 2012-04-10 09:12:39 UTC
we might need an explicit instantiation of that type in libstdc++.so, I'll investigate
Comment 2 Daniel Richard G. 2012-05-10 13:54:12 UTC
I can avoid this error during bootstrap by configuring with --disable-build-poststage1-with-cxx, but then I get the same link error when building regular C++ programs with the newly-built compiler.
Comment 3 Jonathan Wakely 2012-05-10 14:57:02 UTC
does adding this instantiation to libstdc++-v3/src/c++11/regex.cc help?


--- r	2012-05-10 16:56:35.252128466 +0200
+++ regex.cc	2012-05-10 16:56:39.412128415 +0200
@@ -34,5 +34,7 @@
 
   regex_error::~regex_error() throw() { }
 
+  template class function<void (__regex::_PatternCursor const&, __regex::_Results&)>;
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
Comment 4 Daniel Richard G. 2012-05-10 15:04:22 UTC
Created attachment 27364 [details]
Workaround to provide the two missing symbols

I needed a working 4.7.0, and don't use the STL, so I put together a small workaround for this bug. Compile this source file, and add the object to the appropriate libstdc++.a library. More details in the file.

(Note that I build GCC with --disable-shared; "fixing" a shared libstdc++ would be a bit more involved)
Comment 5 Daniel Richard G. 2012-05-10 22:04:26 UTC
(In reply to comment #3)
> does adding this instantiation to libstdc++-v3/src/c++11/regex.cc help?

Apologies Jonathan, I didn't see your comment before submitting my attachment.

Preliminary results are that the instantiation allows the link to proceed. This was in a tree where the error had already occurred, however, so not the best test. I've started a new build, with the change in from the beginning, that should hopefully answer the question definitively by tomorrow.
Comment 6 Daniel Richard G. 2012-05-11 17:05:57 UTC
With the new build, I now see one missing symbol instead of two. (Not sure why the earlier hacked build went through):

gmake[3]: Entering directory `/tmp/gcc-4.7.0/_build/gcc'
/tmp/gcc-4.7.0/_build/./prev-gcc/g++ -B/tmp/gcc-4.7.0/_build/./prev-gcc/ -B/opt/tg/powerpc-ibm-aix5.3.0.0/bin/ -nostdinc++ -B/tmp/gcc-4.7.0/_build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/src/.libs -B/tmp/gcc-4.7.0/_build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/libsupc++/.libs -I/tmp/gcc-4.7.0/_build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/include/powerpc-ibm-aix5.3.0.0 -I/tmp/gcc-4.7.0/_build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/include -I/tmp/gcc-4.7.0/libstdc++-v3/libsupc++ -L/tmp/gcc-4.7.0/_build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/src/.libs -L/tmp/gcc-4.7.0/_build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/libsupc++/.libs   -g -O2 -DIN_GCC   -fno-exceptions -fno-rtti -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc -Wl,-bbigtoc -Wl,-bmaxdata:0x40000000 -o cc1 c-lang.o c-family/stub-objc.o attribs.o c-errors.o c-decl.o c-typeck.o c-convert.o c-aux-info.o c-objc-common.o c-parser.o tree-mudflap.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/c-gimplify.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o default-c.o rs6000-c.o \
          cc1-checksum.o main.o  libbackend.a libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a   ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a    -L/tg/freeport/arch/aix64/lib -L/tg/freeport/arch/aix64/lib -L/tg/freeport/arch/aix64/lib -lmpc -lmpfr -lgmp   -L../zlib -lz
ld: 0711-317 ERROR: Undefined symbol: .std::function<bool (std::__regex::_PatternCursor const&)>::function(std::function<bool (std::__regex::_PatternCursor const&)> const&)
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: error: ld returned 8 exit status
gmake[3]: *** [cc1] Error 1
gmake[3]: Leaving directory `/tmp/gcc-4.7.0/_build/gcc'
gmake[2]: *** [all-stage2-gcc] Error 2
gmake[2]: Leaving directory `/tmp/gcc-4.7.0/_build'
gmake[1]: *** [stage2-bubble] Error 2
gmake[1]: Leaving directory `/tmp/gcc-4.7.0/_build'
gmake: *** [bootstrap] Error 2


Perhaps one more instantiation is needed?
Comment 7 Jonathan Wakely 2012-05-11 18:34:59 UTC
Looks as though it also needs

template class function<bool (__regex::_PatternCursor const&)>;
Comment 8 Daniel Richard G. 2012-05-12 05:09:15 UTC
(In reply to comment #7)
> Looks as though it also needs
> template class function<bool (__regex::_PatternCursor const&)>;

I added that, and with the two instantiations, bootstrap completes successfully.

(I don't suppose that's the fix, however, given that other systems don't need this...)
Comment 9 Paolo Carlini 2012-05-12 08:35:05 UTC
AIX used to be even more special about this...
Comment 10 Jörg Richter 2012-06-18 09:44:30 UTC
Created attachment 27649 [details]
Fix for undefined references

Patch for 4.7.1 with the two missing instantiations.
Works for me.  Not tested with GCC testsuite.
Please consider this for 4.7.2
Comment 11 Jonathan Wakely 2012-06-18 15:26:03 UTC
We know the instantiations that are needed, but I don't want to define them for all platforms if they're not needed elsewhere. I also have no way of testing on AIX, so someone needs to run the teststuite with the changes.
Comment 12 Daniel Richard G. 2012-06-18 16:56:42 UTC
(In reply to comment #11)
> We know the instantiations that are needed, but I don't want to define them for
> all platforms if they're not needed elsewhere. I also have no way of testing on
> AIX, so someone needs to run the teststuite with the changes.

I can do the testing, but is this really the solution? Why would AIX (and not even all versions of AIX) need these instantiations, how is it doing things differently from other systems?

This is fine as a workaround, but I'm presuming the real fix is to get GCC on AIX working again the same way as it does elsewhere.
Comment 13 David Edelsohn 2012-06-19 23:21:27 UTC
I successfully bootstrap on AIX 5.3 multiple times per week with the need of the additional instantiations. This may be due to different versions of the AIX assembler. The system I am using has bos.adt.base level 5.3.7.0 installed. I also do not use many of the additional configure options.

--disable-shared probably is a bad choice.

The file format used on AIX is XCOFF. The file format used on most other systems is ELF. ELF provides a richer set of features for symbols and sections that GCC implicitly assumes to support C++ features.

Additionally, SVR4/ELF semantics allows linkers to play a little more "fast and loose". Basically, SVR4/ELF lazy binding allows libraries to omit symbol definitions if they never are used. I suspect that the instantiations that Jonathan is adding truly are needed and should be defined for all systems, but the other systems silently ignore the error.

And this probably works on my builds of AIX because I build shared libraries with an option for SVR4-like semantics that allows link-time errors during shared library creation.

So the real answer probably is that the instantiations are necessary and libstdc++ really has a latent bug that is not visible on other systems.
Comment 14 Jonathan Wakely 2012-06-20 01:35:58 UTC
OK, I'll deal with it asap.  I have quite a queue of patches to test and commit at present though.
Comment 15 Daniel Richard G. 2012-06-20 04:10:28 UTC
David, thank you for commenting; I have a better appreciation now of how AIX is a different animal from most, and indeed may be doing things more correctly than other systems on this one point.

I'd also like to bring attention to a seemingly similar issue I've encountered when bootstrapping on AIX 4.3:

    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53238#c11

That one is less straightforward, however, because (as reported a couple comments further down) it only occurs when bootstrapping. If I build GCC with a C-only GCC of the same version and --disable-bootstrap, there's no error.
Comment 16 Jonathan Wakely 2012-06-20 08:50:25 UTC
Whether or not it's more correct, the <regex> code is non-functional and so needing to add symbols to the .so to support broken code noone uses or can use is rather unfortunate.
Comment 17 David Edelsohn 2012-06-20 13:25:31 UTC
Another feature of AIX is its garbage-collecting linker. The very first implementation of GCC for AIX was forced to emit an extra symbol to tie the text section to the data section to prevent the linker from garbage collecting a related section that did not have an obvious reference. This introduces an extra dependency and may pull in unreferenced data sections from object files. libstdc++ is built with --function-sections and --data-sections, which should minimize this, but, again, if an application is relying upon the linker to ignore missing definitions of symbols, it may behave differently on AIX.
Comment 18 David Edelsohn 2012-06-20 21:14:36 UTC
Strangely, someone else is reporting a runtime error with the same symbol:

exec(): 0509-036 Cannot load program a.out because of the following errors:
rtld: 0712-001 Symbol
_ZNSt8functionIFvRKNSt7__regex14_PatternCursorERNS0_8_ResultsEEEC1ERKS7_
was referenced from module
/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.7.1/ppc64/libstdc++.a(libstdc++.so.6),
but a runtime definition of the symbol was not found.
rtld: 0712-001 Symbol
_ZNSt8functionIFbRKNSt7__regex14_PatternCursorEEEC1ERKS5_ was
referenced from module
/opt/freeware/lib/gcc/powerpc-ibm-aix6.1.0.0/4.7.1/ppc64/libstdc++.a(libstdc++.so.6),
but a runtime definition of the symbol was not found.
rtld: 0712-002 fatal error: exiting.

Maybe the <regex> code is non-functional, but *something* is referencing the symbol under certain circumstances. The kludge patch fixes it, so the missing instantiation is a problem. In the shared library case, if the symbol really is referenced, I don't know how this is working on GNU/Linux.
Comment 19 Jörg Richter 2012-06-21 06:58:13 UTC
See also bug 53713.  Hasn't been marked as a dup yet.
Comment 20 Jonathan Wakely 2012-06-21 08:23:56 UTC
*** Bug 53713 has been marked as a duplicate of this bug. ***
Comment 21 Daniel Richard G. 2012-07-25 03:18:32 UTC
(In reply to comment #18)
> Maybe the <regex> code is non-functional, but *something* is referencing the
> symbol under certain circumstances.

I figure this is a question worth answering. Repeating the failed link with -Wl,-bnoquiet gives some helpful information:

ld: 0711-318 ERROR: Undefined symbols were found.
        The following symbols are in error:
 Symbol                    Inpndx  TY CL Source-File(Object-File) OR Import-File{Shared-object}
                              RLD: Address  Section  Rld-type Referencing Symbol
 ----------------------------------------------------------------------------------------------
 .std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)>::function(std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)> const&) [146]   ER PR /home/src/gcc-4.7.1/libstdc++-v3/src/c++11/regex.cc(/tmp/gcc-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/src/.libs/libstdc++.a[regex.o])
                                   00002918 .text    R_RBR    [3582]  .std::__regex::_State::_State(std::__regex::_State const&)
 .std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)>::function(std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)> const&) [276]   ER PR /home/src/gcc-4.7.1/libstdc++-v3/src/c++11/functexcept.cc(/tmp/gcc-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/src/.libs/libstdc++.a[functexcept.o])
                                   00003e18 .text    R_RBR    [4312]  .std::__regex::_State::_State(std::__regex::_State const&)
 .std::function<bool (std::__regex::_PatternCursor const&)>::function(std::function<bool (std::__regex::_PatternCursor const&)> const&) [148]   ER PR /home/src/gcc-4.7.1/libstdc++-v3/src/c++11/regex.cc(/tmp/gcc-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/src/.libs/libstdc++.a[regex.o])
                                   00002938 .text    R_RBR    [3582]  .std::__regex::_State::_State(std::__regex::_State const&)
 .std::function<bool (std::__regex::_PatternCursor const&)>::function(std::function<bool (std::__regex::_PatternCursor const&)> const&) [278]   ER PR /home/src/gcc-4.7.1/libstdc++-v3/src/c++11/functexcept.cc(/tmp/gcc-build/prev-powerpc-ibm-aix5.3.0.0/libstdc++-v3/src/.libs/libstdc++.a[functexcept.o])
                                   00003e38 .text    R_RBR    [4312]  .std::__regex::_State::_State(std::__regex::_State const&)
ER: The return code is 8.
ld: 0711-317 ERROR: Undefined symbol: .std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)>::function(std::function<void (std::__regex::_PatternCursor const&, std::__regex::_Results&)> const&)
ld: 0711-317 ERROR: Undefined symbol: .std::function<bool (std::__regex::_PatternCursor const&)>::function(std::function<bool (std::__regex::_PatternCursor const&)> const&)
collect2: error: ld returned 8 exit status
Comment 22 Jörg Richter 2012-09-14 07:58:16 UTC
I have reduced a real live case. But still using <vector>.

$ cat t.cc
#include <vector>
struct ClassicUpdate
{
    ClassicUpdate();
};
typedef std::vector<ClassicUpdate> ClassicUpdates;
struct UpdateData
{
    ClassicUpdates classicUpdates;

    UpdateData( ClassicUpdates const& classicUpdates )
      : classicUpdates( classicUpdates )
    {}
};
int main()
{}

$ g++ -std=gnu++0x -o mm t.cc -save-temps

$ grep Construct.*ClassicUpdate *.s
        .weak   _ZSt10_ConstructI13ClassicUpdateIRKS0_EEvPT_DpOT0_[DS]
  ...

This should demostrate that GCC compiles a symbol referencing ClassicUpdate into the executable. When the AIX linker decides to use that symbol you get 
an undefined reference error. This is not the case here. But the unreduced 
source has the problem.

GCC 4.6.3 doesn't do this. And removing -std=gnu++0x works too.

So it seems this is not regex-related but a deeper bug in GCC 4.7 that emits 
functions that are never called.
Comment 23 David Edelsohn 2012-09-16 02:36:27 UTC
I do not see the extraneous symbols using the example in comment #22 when compiling with trunk.  Also, the example G++ invocation does not enable any optimizations.
Comment 24 Gilles Pion 2012-11-21 08:02:41 UTC
I have the exact same problem on AIX 5.3 trying to bootstrat GCC but with version 4.7.2. in my case

I have to admit that I don't understand all the issues described here but since I've been able to bootstrap 7.2.1 without any problem I'm a bit surprised.
Comment 25 David Edelsohn 2012-11-26 02:50:22 UTC
The instantiations definitely should be in libstdc++-v3/src/c++11/regex.cc in the GCC 4.7 release branch.
Comment 26 Jonathan Wakely 2013-01-17 01:39:52 UTC
Author: redi
Date: Thu Jan 17 01:39:46 2013
New Revision: 195258

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195258
Log:
	PR libstdc++/52887
	* src/c++11/regex.cc: Add instantiations for AIX.

Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/src/c++11/regex.cc
Comment 27 Jonathan Wakely 2013-01-17 01:41:06 UTC
Should be fixed, please reopen if not.
Comment 28 Benjamin Kosnik 2013-02-11 23:53:30 UTC
FWIW, I think the real fix here is to compile regex.cc with -fimplicit-templates. I suspect that different things are being inlined on AIX than on linux/ELF, there is an assumed implicit instantiation on AIX for this symbol that is currently being supressed via -fno-implicit-templates.