Patchwork [google] remove versioned symbols from libstdc++.a

login
register
mail settings
Submitter Ollie Wild
Date Sept. 6, 2012, 1:26 a.m.
Message ID <CAFOgFcR0rYUJRm3BN9hp-Ae8ufSA-wq3vEWPa-i3ped2cNKuJQ@mail.gmail.com>
Download mbox | patch
Permalink /patch/181990/
State New
Headers show

Comments

Ollie Wild - Sept. 6, 2012, 1:26 a.m.
This is a Google-local fix to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54482.

When configured with --with-pic, libstdc++.a includes versioned
symbols, preventing it from being linked into shared libraries.  The
ultimate cause of this is a misuse of -DPIC as a proxy for, "I'm being
compiled into a shared library."  Unfortunately, there is no obvious
alternative without first patching libtool.

This patch provides a temporary workaround for the google/* branches.
It creates new libtool options, -Xcompiler-static and
-Xcompiler-shared, which pass flags only when compiling static or
shared libraries, respectively.  I then use the new machinery to pass
-UPIC to the static library compilations.  This has the effect of
tricking libstdc++ into behaving properly.

Ideally, a new macro should be used, since there are legitimate cases
when PIC could be useful (e.g. in selecting between alternate assembly
implementations).  However, the current approach is less likely to
break under future merge activity, since any new compatibility changes
should "just work."

Long term, the correct solution is to: (a) convert this to a suitable
libtool patch and push that upstream, (b) update GCC's libtool
version, and (c) rework the libstdc++ source files to key off a more
appropriate macro (e.g. SHARED_LIB).  That's going to take some time,
though, especially since upgrading libtool is a major (and rare)
event.

Okay for google/integration and google/gcc-4_7?

Thanks,
Ollie


2012-09-05  Ollie Wild  <aaw@google.com>

        * ltmain.sh (func_mode_compile): Add -Xcompiler-shared and
        -Xcompiler-static options.
        (func_mode_help): Document new options.
        * libstdc++/src/Makefile.am (LTCXXCOMPILE): Pass -UPIC when compiling
        static libraries.
        * libstdc++/src/Makefile.in: Regenerate.
commit 7208cb10bcf3f1bfab77aa6756fc0b2672bd39fa
Author: Ollie Wild <aaw@google.com>
Date:   Tue Sep 4 14:35:19 2012 -0500

    Add new libtool options -Xcompiler-shared and -Xcompiler-static.
    
    Use this to remove versioned symbols from libstdc++.a when configured with
    --with-pic.
    
    Google ref b/7088884
    
    2012-09-05  Ollie Wild  <aaw@google.com>
    
    	* ltmain.sh (func_mode_compile): Add -Xcompiler-shared and
    	-Xcompiler-static options.
    	(func_mode_help): Document new options.
    	* libstdc++/src/Makefile.am (LTCXXCOMPILE): Pass -UPIC when compiling
    	static libraries.
    	* libstdc++/src/Makefile.in: Regenerate.
Paul Pluzhnikov - Sept. 6, 2012, 3:50 a.m.
On Wed, Sep 5, 2012 at 6:26 PM, Ollie Wild <aaw@google.com> wrote:

> Okay for google/integration and google/gcc-4_7?

Approved for google/* branches.

Thanks,
Ollie Wild - Sept. 6, 2012, 3:58 a.m.
Commited as r191006 and r191007.

Ollie

On Wed, Sep 5, 2012 at 10:50 PM, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:
> On Wed, Sep 5, 2012 at 6:26 PM, Ollie Wild <aaw@google.com> wrote:
>
>> Okay for google/integration and google/gcc-4_7?
>
> Approved for google/* branches.
>
> Thanks,
> --
> Paul Pluzhnikov

Patch

diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index a1eb04d..d166155 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -147,7 +147,8 @@  LTCXXCOMPILE = \
 	$(LIBTOOL) --tag CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
 	--mode=compile $(CXX) $(INCLUDES) \
-	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) \
+	-Xcompiler-static -UPIC
 
 LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 
diff --git a/libstdc++-v3/src/Makefile.in b/libstdc++-v3/src/Makefile.in
index b10d853..e0578a2 100644
--- a/libstdc++-v3/src/Makefile.in
+++ b/libstdc++-v3/src/Makefile.in
@@ -406,7 +406,8 @@  LTCXXCOMPILE = \
 	$(LIBTOOL) --tag CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
 	--mode=compile $(CXX) $(INCLUDES) \
-	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) \
+	-Xcompiler-static -UPIC
 
 LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 
diff --git a/ltmain.sh b/ltmain.sh
index 6428631..3aac68f 100644
--- a/ltmain.sh
+++ b/ltmain.sh
@@ -1280,6 +1280,8 @@  func_mode_compile ()
     $opt_debug
     # Get the compilation command and the source file.
     base_compile=
+    shared_compile=
+    static_compile=
     srcfile="$nonopt"  #  always keep a non-empty value in "srcfile"
     suppress_opt=yes
     suppress_output=
@@ -1303,6 +1305,20 @@  func_mode_compile ()
 	continue
 	;;
 
+      xcompiler-shared )
+        arg_mode=normal
+	func_quote_for_eval "$arg"
+	shared_compile="$shared_compile $func_quote_for_eval_result"
+	continue
+	;;
+
+      xcompiler-static )
+        arg_mode=normal
+	func_quote_for_eval "$arg"
+	static_compile="$static_compile $func_quote_for_eval_result"
+	continue
+	;;
+
       normal )
 	# Accept any command-line options.
 	case $arg in
@@ -1333,6 +1349,18 @@  func_mode_compile ()
 	  continue      #  The current "srcfile" will either be retained or
 	  ;;            #  replaced later.  I would guess that would be a bug.
 
+	-Xcompiler-shared)
+	  arg_mode=xcompiler-shared  #  the next one goes into the
+	                             #  "shared_compile" arg list
+	  continue
+	  ;;
+
+	-Xcompiler-static)
+	  arg_mode=xcompiler-static  #  the next one goes into the
+	                             #  "static_compile" arg list
+	  continue
+	  ;;
+
 	-Wc,*)
 	  func_stripname '-Wc,' '' "$arg"
 	  args=$func_stripname_result
@@ -1516,10 +1544,10 @@  compiler."
       fbsd_hideous_sh_bug=$base_compile
 
       if test "$pic_mode" != no; then
-	command="$base_compile $qsrcfile $pic_flag"
+	command="$base_compile $qsrcfile $pic_flag $shared_compile"
       else
 	# Don't build PIC code
-	command="$base_compile $qsrcfile"
+	command="$base_compile $qsrcfile $shared_compile"
       fi
 
       func_mkdir_p "$xdir$objdir"
@@ -1568,9 +1596,9 @@  compiler."
     if test "$build_old_libs" = yes; then
       if test "$pic_mode" != yes; then
 	# Don't build PIC code
-	command="$base_compile $qsrcfile$pie_flag"
+	command="$base_compile $qsrcfile$pie_flag $static_compile"
       else
-	command="$base_compile $qsrcfile $pic_flag"
+	command="$base_compile $qsrcfile $pic_flag $static_compile"
       fi
       if test "$compiler_c_o" = yes; then
 	command="$command -o $obj"
@@ -1664,6 +1692,12 @@  This mode accepts the following additional options:
   -shared           do not build a \`.o' file suitable for static linking
   -static           only build a \`.o' file suitable for static linking
   -Wc,FLAG          pass FLAG directly to the compiler
+  -Xcompiler-shared FLAG
+                    pass FLAG directly to the compiler when compiling shared
+		    libraries
+  -Xcompiler-static FLAG
+                    pass FLAG directly to the compiler when compiling static
+		    libraries
 
 COMPILE-COMMAND is a command to be used in creating a \`standard' object file
 from the given SOURCEFILE.