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++'
we might need an explicit instantiation of that type in libstdc++.so, I'll investigate
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.
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
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)
(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.
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?
Looks as though it also needs template class function<bool (__regex::_PatternCursor const&)>;
(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...)
AIX used to be even more special about this...
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
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.
(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.
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.
OK, I'll deal with it asap. I have quite a queue of patches to test and commit at present though.
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.
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.
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.
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.
See also bug 53713. Hasn't been marked as a dup yet.
*** Bug 53713 has been marked as a duplicate of this bug. ***
(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
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.
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.
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.
The instantiations definitely should be in libstdc++-v3/src/c++11/regex.cc in the GCC 4.7 release branch.
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
Should be fixed, please reopen if not.
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.