http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54482

             Bug #: 54482
           Summary: catch-22 in static linking with libstdc++ fails
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: sim...@google.com


Libstdc++ uses '#ifdef PIC' as a proxy for deciding when to include versioned
symbols.

However, libtool will set -DPIC if -fPIC, even if the code being built is not
destined for a shared library.  This leads to versioned symbols being compiled
into libstdc++.a, and the resulting static libstdc++ can then fail to link. 
Can be triggered by 'configure --with-pic=yes ...' recommended by
__cxxabiv1::__forced_unwind.

See also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28811#c19

Example, using current 4.8 head at r190920:

$ cat /tmp/hello-world.cc
#include <iostream>
void func() {
  std::cout << "Hello, world" << std::endl;
}

$ configure --disable-bootstrap --enable-languages=c,c++
--build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu
--target=x86_64-unknown-linux-gnu
$ make..., make install...
g++ -shared -fPIC -static-libstdc++ -Wl,-whole-archive -o /dev/null
/tmp/hello-world.cc
/usr/bin/ld:
/usr/local/google/home/simonb/install_clean/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../lib64/libstdc++.a(compatibility.o):
relocation R_X86_64_32 against `_ZTIN10__cxxabiv115__forced_unwindE' can not be
used when making a shared object; recompile with -fPIC

$ configure --with-pic=yes --disable-bootstrap --enable-languages=c,c++
--build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu
--target=x86_64-unknown-linux-gnu
$ make..., make install...
$ ../install/bin/g++ -shared -fPIC -static-libstdc++ -Wl,-whole-archive -o
/dev/null /tmp/hello-world.cc
/usr/bin/ld: /dev/null: version node not found for symbol
_ZNKSt14basic_ifstreamIcSt11char_traitsIcEE7is_openEv@GLIBCXX_3.4

Reply via email to