[Bug libstdc++/54482] failures in static linking with libstdc++, due to versioned symbols

bkoz at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Sep 12 03:26:00 GMT 2012


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

Benjamin Kosnik <bkoz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bkoz at gcc dot gnu.org,
                   |                            |Ralf.Wildenhues at gmx dot
                   |                            |de

--- Comment #2 from Benjamin Kosnik <bkoz at gcc dot gnu.org> 2012-09-12 03:26:23 UTC ---
FYI this bug is a duplicate of 28811. The summary/diagnosis is wrong. It's not
about versioned symbols, at least not in 4.7.x and above (after fix of 52689).

The issue is that even for all libstdc++ sources that are destined for the
static library, ie libstdc++.a, compile flags should include -fPIC or
equivalent, so that -static-libstdc++ works.

These files are not compiled this way at the moment.

So, compat*.o files need to be compiled with -prefer-pic.

But, using that means that the delicate balance of the non-convenience library
files in src, ie compat*.cc files is disturbed.

At the moment, compat*.cc files are special, and have have code suitable for
static and shared libs, and some code intended only for shared libs. Right now,
the compile-time macro to designate these shared-only sections is PIC.

But, using libtool's -prefer-pic for the compat*.cc files means -fPIC -DPIC,
which messes up static/shared code paths. So, one solution may be to use
-prefer-pic when using libtool to create all object files, but to use another
macro, say _GLIBCXX_SHARED when compiling only shared code.

(Another solution is to make yet-another convenience libary, that is only
shared, and manually separate the source file dependencies. Let's try not to do
it this way.)

So, what is desired is a compile-time hook or flag into libtool that deals with
just the static or just the shared compiled objects. There are currently
configure-time hooks for this (--enable-shared/-static, etc).

One "hook"  is to create an override for libtool's pic_flag variable, using
CXX_pic_flag, that is special for libstdc++. 

ie, from the generated libtool:

from:
pic_flag=" -fPIC -DPIC"

to:
pic_flag="-D_GLIBCXX_SHARED  -fPIC -DPIC"

Sadly, I cannot figure out the correct way to do this, perhaps Ralf can help
me.

In the meantime:

A hacky way to do this in configure.ac:

# Use _GLIBCXX_SHARED as a compile-time switch just for libstdc++ to designate
# a shared-only codepath.
AC_CONFIG_COMMANDS([libtool-pic-patch],
[echo "config.status: patching libtool's pic_flag with -D_GLIBCXX_SHARED";
 sed < libtool > libtool.tmp 's/^pic_flag="/pic_flag="-D_GLIBCXX_SHARED /';
 mv libtool.tmp libtool;
 chmod 775 libtool;
])



More information about the Gcc-bugs mailing list