$ cat x.cc #include <iostream> int main() { std::cout << "hello\n"; } $ gcc x.cc -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic /usr/bin/ld: a.out: No symbol version section for versioned symbol `_ZSt15future_category@@GLIBCXX_3.4.14' /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status or $ g++ x.cc -static-libstdc++ /usr/bin/ld: a.out: No symbol version section for versioned symbol `_ZSt15future_category@@GLIBCXX_3.4.14' /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status $ ld --version GNU ld (GNU Binutils for Ubuntu) 2.21.53.20110810
Looks like you have an old stale version in your path somewhere. What does: $ find /usr/lib -name "libstdc++.a" show?
$ find /usr/lib -name "libstdc++.a" /usr/lib/gcc/x86_64-linux-gnu/4.6/32/libstdc++.a /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a /usr/lib/gcc/x86_64-linux-gnu/4.5/libstdc++.a However, these old libstdc++.a files are NOT used: g++ -Wl,--verbose x.cc -static-libstdc++ GNU ld (GNU Binutils for Ubuntu) 2.21.53.20110810 ... attempt to open /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/crtbegin.o succeeded /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/crtbegin.o attempt to open /home/jmaurer/tmp/cc0s7Nqc.o succeeded /home/jmaurer/tmp/cc0s7Nqc.o attempt to open /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/libstdc++.a failed attempt to open /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/libstdc++.a succeeded (/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/libstdc++.a)globals_io.o ... The libstdc++.a file used is the one installed today: $ ls -lL /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/libstdc++.a -rw-r--r-- 1 root root 16227426 2012-03-23 13:31 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/libstdc++.a
In case it matters, here's the "configure" info etc: $ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-4.7.0/configure -enable-languages=c,c++ --prefix=/usr/local --enable-shared --enable-linker-build-id --with-system-zlib --without-included-gettext --enable-threads=posix --enable-lto Thread model: posix gcc version 4.7.0 (GCC)
Please run: $ nm /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/libstdc++.a | grep GLIBCXX_3.4.14 and paste the output here.
It looks like a linker bug. I was able to reproduce the issue with Fedora17. $ ld -v GNU ld version 2.22.52.0.1-10.fc17 20120131 $ g++ x.cc -static-libstdc++ /usr/bin/ld: a.out: No symbol version section for versioned symbol `_ZSt15future_category@@GLIBCXX_3.4.14' /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: error: ld returned 1 exit status Gold is fine: $ sudo ln -f /bin/ld.gold /bin/ld $ g++ x.cc -static-libstdc++ $
$ nm /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/libstdc++.a | grep GLIBCXX_3.4.14 0000000000000000 B _ZSt15future_category@@GLIBCXX_3.4.14
I've opened a bug for Fedora17 here: https://bugzilla.redhat.com/show_bug.cgi?id=806598 Maybe you could do the same thing for Ubuntu? BTW the current vanilla git ld.bfd also links without problems. So vendor specific binutils patches may be responsible for this bug.
This is a libstdc++ bug, caused by the libstdc++ directory reorganization and introduction of the convenience libraries. The various source files in libstdc++ that use .symver directives were written with the assumption that libtool builds things twice, once without -DPIC for libstdc++.a and once with -DPIC for libstdc++.so.6. The compatibility stuff with symbol versions only belongs to libstdc++.so.6 obviously, otherwise you get the errors you are getting and gold is broken if it doesn't error out on that. Unfortunately the convenience libraries contain solely -DPIC code (-fPIC isn't a big deal, but -DPIC is here), so everything is compiled just once and libstdc++.a (incorrectly) as well as libstdc++.so.6 (correctly) is built with the .symver stuff in the objects.
Author: bkoz Date: Thu Mar 29 06:14:32 2012 New Revision: 185950 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185950 Log: 2012-03-28 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/52689 * libsupc++/Makefile.am (LTCXXCOMPILE, CXXLINK): Tweak. * libsupc++/Makefile.in: Regenerated. * src/Makefile.am (LTCXXCOMPILE, CXXLINK): Tweak. (libstdc___la_SOURCES): Add in compatiblity files, with content that varies with -DPIC. * src/Makefile.in: Regenerated. * src/c++11/Makefile.am (LTCXXCOMPILE, CXXLINK): Tweak. * src/c++11/Makefile.in: Regenerated. * src/c++11/compatibility-atomic-c++0x.cc: Guard with PIC. * src/c++11/compatibility-c++0x.cc: Same. * src/c++11/future.cc: Consolidate compatibility bits into.. * src/c++11/mutex.cc: Consolidate compatibility bits into.. * src/c++11/compatibility-thread-cxx0x.cc: ...here. New. * src/c++98/Makefile.am (LTCXXCOMPILE, CXXLINK): Tweak. * src/c++98/Makefile.in: Regenerated. * src/c++98/compatibility-ldbl.cc: Guard with PIC * src/c++98/compatibility-list-2.cc: Same. * src/c++98/compatibility-list.cc: Same. * src/c++98/compatibility.cc: Tweak comments. Added: trunk/libstdc++-v3/src/c++11/compatibility-thread-c++0x.cc - copied, changed from r185946, trunk/libstdc++-v3/src/c++11/mutex.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/libsupc++/Makefile.am trunk/libstdc++-v3/libsupc++/Makefile.in trunk/libstdc++-v3/src/Makefile.am trunk/libstdc++-v3/src/Makefile.in trunk/libstdc++-v3/src/c++11/Makefile.am trunk/libstdc++-v3/src/c++11/Makefile.in trunk/libstdc++-v3/src/c++11/compatibility-atomic-c++0x.cc trunk/libstdc++-v3/src/c++11/compatibility-c++0x.cc trunk/libstdc++-v3/src/c++11/future.cc trunk/libstdc++-v3/src/c++11/mutex.cc trunk/libstdc++-v3/src/c++98/Makefile.am trunk/libstdc++-v3/src/c++98/Makefile.in trunk/libstdc++-v3/src/c++98/compatibility-ldbl.cc trunk/libstdc++-v3/src/c++98/compatibility-list-2.cc trunk/libstdc++-v3/src/c++98/compatibility-list.cc trunk/libstdc++-v3/src/c++98/compatibility.cc
Unfortuntately, the fix causes link failures during mainline bootstrap on Solaris: I'm using a static g++ 4.4 built libppl_c.a, which contains references to Undefined first referenced symbol in file _ZNSt15_List_node_base4swapERS_S0_ /vol/gcc/lib/libppl_c.a(ppl_c_Pointset_Powerset_C_Polyhedron.o) _ZNSt15_List_node_base4hookEPS_ /vol/gcc/lib/libppl_c.a(ppl_c_Polyhedron.o) _ZNSt15_List_node_base6unhookEv /vol/gcc/lib/libppl_c.a(ppl_c_Pointset_Powerset_C_Polyhedron.o) _ZNSt15_List_node_base8transferEPS_S0_ /vol/gcc/lib/libppl_c.a(ppl_c_Pointset_Powerset_C_Polyhedron.o) ld: fatal: symbol referencing errors. No output written to go1 These references are now unresolved. It could be considered a build bug since the just build libstdc++.a is searched before the gcc 4.4 libstdc++.a specified via -L/vol/gcc-4.4/lib. Whether it is considered an accident or not that this worked so far is the question. Rainer
This fix also causes following testsuite failure on alphaev68-pc-linux-gnu: Running target unix FAIL: libmudflap.c++/pass41-frag.cxx (-static) (test for excess errors) WARNING: libmudflap.c++/pass41-frag.cxx (-static) compilation failed to produce executable From the testsuite log: Executing on host: /home/uros/gcc-build/./gcc/g++ -shared-libgcc -B/home/uros/gcc-build/./gcc -nostdinc++ -L/home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src -L/home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/.libs -B/usr/local/alphaev68-unknown-linux-gnu/bin/ -B/usr/local/alphaev68-unknown-linux-gnu/lib/ -isystem /usr/local/alphaev68-unknown-linux-gnu/include -isystem /usr/local/alphaev68-unknown-linux-gnu/sys-include -ggdb3 -DDEBUG_ASSERT -D_GLIBCXX_ASSERT -fmessage-length=0 -ffunction-sections -fdata-sections -g -O2 -D_GNU_SOURCE -mieee -I/home/uros/gcc-svn/trunk/libmudflap/testsuite -I/home/uros/gcc-svn/trunk/libmudflap/testsuite/.. -I.. -nostdinc++ -I/home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/include/alphaev68-unknown-linux-gnu -I/home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/include -I/home/uros/gcc-svn/trunk/libstdc++-v3/libsupc++ -I/home/uros/gcc-svn/trunk/libstdc++-v3/include/backward -I/home/uros/gcc-svn/trunk/libstdc++-v3/testsuite/util -L/home/uros/gcc-build/alphaev68-unknown-linux-gnu/./libmudflap/.libs /home/uros/gcc-svn/trunk/libmudflap/testsuite/libmudflap.c++/pass41-frag.cxx -static -fmudflap -lmudflap -L/home/uros/gcc-build/alphaev68-unknown-linux-gnu/./libmudflap/testsuite -ldl -lm -o ./pass41-frag.exe (timeout = 300) spawn /home/uros/gcc-build/./gcc/g++ -shared-libgcc -B/home/uros/gcc-build/./gcc -nostdinc++ -L/home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src -L/home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/.libs -B/usr/local/alphaev68-unknown-linux-gnu/bin/ -B/usr/local/alphaev68-unknown-linux-gnu/lib/ -isystem /usr/local/alphaev68-unknown-linux-gnu/include -isystem /usr/local/alphaev68-unknown-linux-gnu/sys-include -ggdb3 -DDEBUG_ASSERT -D_GLIBCXX_ASSERT -fmessage-length=0 -ffunction-sections -fdata-sections -g -O2 -D_GNU_SOURCE -mieee -I/home/uros/gcc-svn/trunk/libmudflap/testsuite -I/home/uros/gcc-svn/trunk/libmudflap/testsuite/.. -I.. -nostdinc++ -I/home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/include/alphaev68-unknown-linux-gnu -I/home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/include -I/home/uros/gcc-svn/trunk/libstdc++-v3/libsupc++ -I/home/uros/gcc-svn/trunk/libstdc++-v3/include/backward -I/home/uros/gcc-svn/trunk/libstdc++-v3/testsuite/util -L/home/uros/gcc-build/alphaev68-unknown-linux-gnu/./libmudflap/.libs /home/uros/gcc-svn/trunk/libmudflap/testsuite/libmudflap.c++/pass41-frag.cxx -static -fmudflap -lmudflap -L/home/uros/gcc-build/alphaev68-unknown-linux-gnu/./libmudflap/testsuite -ldl -lm -o ./pass41-frag.exe^M /home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.a(locale.o): In function `std::locale::id::_M_id() const':^M /home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/c++98/../../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/locale.cc:423: undefined reference to `std::num_get<char, std::istreambuf_iterator<char, std::char_traits<char> > >::id'^M /home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/c++98/../../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/locale.cc:424: undefined reference to `std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::id'^M /home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/c++98/../../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/locale.cc:425: undefined reference to `std::money_get<char, std::istreambuf_iterator<char, std::char_traits<char> > >::id'^M /home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/c++98/../../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/locale.cc:426: undefined reference to `std::money_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::id'^M /home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/c++98/../../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/locale.cc:428: undefined reference to `std::num_get<wchar_t, std::istreambuf_iterator<wchar_t, std::char_traits<wchar_t> > >::id'^M /home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/c++98/../../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/locale.cc:429: undefined reference to `std::num_put<wchar_t, std::ostreambuf_iterator<wchar_t, std::char_traits<wchar_t> > >::id'^M /home/uros/gcc-build/alphaev68-unknown-linux-gnu/libstdc++-v3/src/c++98/../../../../../gcc-svn/trunk/libstdc++-v3/src/c++98/locale.cc:430: undefined reference to `std::money_get<wchar_t, std::istreambuf_iterator<wchar_t, std::char_traits<wchar_t> > >::id'^M This happens in #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT protected code.
(In reply to comment #11) > This fix also causes following testsuite failure on alphaev68-pc-linux-gnu: > > Running target unix > FAIL: libmudflap.c++/pass41-frag.cxx (-static) (test for excess errors) > WARNING: libmudflap.c++/pass41-frag.cxx (-static) compilation failed to produce > executable Reverting: * src/c++98/compatibility-ldbl.cc: Guard with PIC fixes the failure. Based on this, does following patch looks OK: --cut here-- Index: src/c++98/compatibility-ldbl.cc =================================================================== --- src/c++98/compatibility-ldbl.cc (revision 186092) +++ src/c++98/compatibility-ldbl.cc (working copy) @@ -27,8 +27,6 @@ #include <cmath> #include <tr1/functional> -#ifdef PIC - #ifdef _GLIBCXX_LONG_DOUBLE_COMPAT #ifdef __LONG_DOUBLE_128__ @@ -80,5 +78,3 @@ __attribute__((alias ("_ZNKSt3tr14hashIeEclEe"))); #endif - -#endif --cut here--
> --- Comment #12 from Uros Bizjak <ubizjak at gmail dot com> 2012-04-03 08:56:13 UTC --- > Reverting: > > * src/c++98/compatibility-ldbl.cc: Guard with PIC > > fixes the failure. Based on this, does following patch looks OK: I need this patch diff --git a/libstdc++-v3/src/c++98/compatibility-list.cc b/libstdc++-v3/src/c++98/compatibility-list.cc --- a/libstdc++-v3/src/c++98/compatibility-list.cc +++ b/libstdc++-v3/src/c++98/compatibility-list.cc @@ -24,8 +24,6 @@ #include <bits/move.h> -#ifdef PIC - #ifndef _GLIBCXX_BEGIN_NAMESPACE_COMPAT # define _GLIBCXX_BEGIN_NAMESPACE_COMPAT #endif @@ -146,5 +144,3 @@ _GLIBCXX_BEGIN_NAMESPACE_COMPAT _GLIBCXX_END_NAMESPACE_COMPAT } // namespace std - -#endif to allow go1 to build on Solaris. Rainer
Patch in comment #12 is ok to check in. Thanks!
Patch in comment #13 is ok to check in, sadly.
Author: uros Date: Wed Apr 4 17:25:27 2012 New Revision: 186142 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186142 Log: Partially revert: 2012-03-28 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/52689 * src/c++98/compatibility-ldbl.cc: Guard with PIC Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/src/c++98/compatibility-ldbl.cc
Author: bkoz Date: Tue Apr 17 00:19:12 2012 New Revision: 186517 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186517 Log: 2012-04-16 Bernhard Reutner-Fischer <aldot@gcc.gnu.org> PR bootstrap/52840 * src/Makefile.am (build-debug): Do not adjust vpath dir, remove Makefile.tmp * src/Makefile.in: Adjust as per above. 2012-04-16 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/52689 * libsupc++/Makefile.am (LTCXXCOMPILE, CXXLINK): Tweak. * libsupc++/Makefile.in: Regenerated. * src/Makefile.am (LTCXXCOMPILE, CXXLINK): Tweak. (libstdc___la_SOURCES): Add in compatiblity files, with content that varies with -DPIC. * src/Makefile.in: Regenerated. * src/c++11/Makefile.am (LTCXXCOMPILE, CXXLINK): Tweak. * src/c++11/Makefile.in: Regenerated. * src/c++11/compatibility-atomic-c++0x.cc: Guard with PIC. * src/c++11/compatibility-c++0x.cc: Same. * src/c++11/future.cc: Consolidate compatibility bits into.. * src/c++11/mutex.cc: Consolidate compatibility bits into.. * src/c++11/compatibility-thread-cxx0x.cc: ...here. New. * src/c++98/Makefile.am (LTCXXCOMPILE, CXXLINK): Tweak. * src/c++98/Makefile.in: Regenerated. * src/c++98/compatibility-list-2.cc: Guard with PIC. * src/c++98/compatibility.cc: Tweak comments. Added: branches/gcc-4_7-branch/libstdc++-v3/src/c++11/compatibility-thread-c++0x.cc Modified: branches/gcc-4_7-branch/libstdc++-v3/ChangeLog branches/gcc-4_7-branch/libstdc++-v3/libsupc++/Makefile.am branches/gcc-4_7-branch/libstdc++-v3/libsupc++/Makefile.in branches/gcc-4_7-branch/libstdc++-v3/src/Makefile.am branches/gcc-4_7-branch/libstdc++-v3/src/Makefile.in branches/gcc-4_7-branch/libstdc++-v3/src/c++11/Makefile.am branches/gcc-4_7-branch/libstdc++-v3/src/c++11/Makefile.in branches/gcc-4_7-branch/libstdc++-v3/src/c++11/compatibility-atomic-c++0x.cc branches/gcc-4_7-branch/libstdc++-v3/src/c++11/compatibility-c++0x.cc branches/gcc-4_7-branch/libstdc++-v3/src/c++11/future.cc branches/gcc-4_7-branch/libstdc++-v3/src/c++11/mutex.cc branches/gcc-4_7-branch/libstdc++-v3/src/c++98/Makefile.am branches/gcc-4_7-branch/libstdc++-v3/src/c++98/Makefile.in branches/gcc-4_7-branch/libstdc++-v3/src/c++98/compatibility-ldbl.cc branches/gcc-4_7-branch/libstdc++-v3/src/c++98/compatibility-list-2.cc branches/gcc-4_7-branch/libstdc++-v3/src/c++98/compatibility-list.cc branches/gcc-4_7-branch/libstdc++-v3/src/c++98/compatibility.cc
Patch plus revisions in gcc-4_7-branch.
Author: bkoz Date: Wed Apr 25 01:17:57 2012 New Revision: 186794 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186794 Log: 2012-04-24 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/52689 * testsuite/17_intro/static.cc: New. Added: trunk/libstdc++-v3/testsuite/17_intro/static.cc Modified: trunk/libstdc++-v3/ChangeLog
Fixed for 4.7.1
Author: bkoz Date: Wed Apr 25 22:47:52 2012 New Revision: 186845 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186845 Log: 2012-04-25 Benjamin Kosnik <bkoz@redhat.com> PR libstdc++/52689 * testsuite/17_intro/static.cc: Fix. * testsuite/lib/dg-options.exp (dg-require-static-libstdcxx): New. Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/testsuite/17_intro/static.cc trunk/libstdc++-v3/testsuite/lib/dg-options.exp trunk/libstdc++-v3/testsuite/lib/libstdc++.exp
Fixed.
*** Bug 53680 has been marked as a duplicate of this bug. ***