public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "simonb at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/54482] New: catch-22 in static linking with libstdc++ fails
Date: Tue, 04 Sep 2012 16:51:00 -0000	[thread overview]
Message-ID: <bug-54482-4@http.gcc.gnu.org/bugzilla/> (raw)

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: unassigned@gcc.gnu.org
        ReportedBy: simonb@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	other threads:[~2012-09-04 16:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-04 16:51 simonb at google dot com [this message]
2012-09-06 14:52 ` [Bug libstdc++/54482] failures in static linking with libstdc++, due to versioned symbols aaw at gcc dot gnu.org
2012-09-12  3:26 ` bkoz at gcc dot gnu.org
2012-09-12  4:58 ` aaw at gcc dot gnu.org
2012-09-20  2:11 ` bkoz at gcc dot gnu.org
2012-11-05 23:42 ` bkoz at gcc dot gnu.org
2014-05-21 13:35 ` redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-54482-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).