[PATCH] Fix and simplify (Re: Fix libbacktrace -fPIC breakage from "Use libbacktrace in libgfortran")

Ulrich Weigand uweigand@de.ibm.com
Wed Aug 26 15:37:00 GMT 2015


Hans-Peter Nilsson wrote:

> I don't feel very confused, but I understand you've investigated
> things down to a point where we can conclude that libtool can't
> do what SPU needs without also at least fiddling with
> compilation options.

Well, looks like I was confused after all.  I missed one extra
feature of libtool that does indeed just make everything work
automatically: if a library is set up using the "noinst" flag,
libtool considers it a "convenience library" and will never
create a shared library in any case; but it will create two
sets of object files, one suitable for linking into a static
library and one suitable for linking into a shared library,
and will automatically use the correct set when linking any
other library against the "convenince library".

This is exactly what we want to happen for libbacktrace.  And
in fact, it is *already* set up as convenience library:
noinst_LTLIBRARIES = libbacktrace.la

This means the only thing we need to do is simply remove all
the special code: no more "disable-shared" and no more fiddling
with -fPIC (except for the --enable-host-shared case, which
remains special just like it does in all other libraries).

I've verified that this works on x86_64: the resulting
libgfortran.so uses the -fPIC version of the libbacktrace
object, while libgfortran.a uses the non-PIC versions.

On SPU, libtool will now automatically only generate the
non-PIC versions since the target does not support shared
library.  So everything works as expected.

OK for mainline?

Bye,
Ulrich

Index: libbacktrace/configure.ac
===================================================================
--- libbacktrace/configure.ac	(revision 227217)
+++ libbacktrace/configure.ac	(working copy)
@@ -79,7 +79,7 @@ case "$AWK" in
 "") AC_MSG_ERROR([can't build without awk]) ;;
 esac
 
-LT_INIT([disable-shared])
+LT_INIT
 AM_PROG_LIBTOOL
 
 backtrace_supported=yes
@@ -161,22 +161,11 @@ else
   fi
 fi
 
-# When building as a target library, shared libraries may want to link
-# this in.  We don't want to provide another shared library to
-# complicate dependencies.  Instead, we just compile with -fPIC, if
-# the target supports compiling with that option.
-PIC_FLAG=
-if test -n "${with_target_subdir}"; then
-  ac_save_CFLAGS="$CFLAGS"
-  CFLAGS="$CFLAGS -fPIC"
-  AC_TRY_COMPILE([], [], [PIC_FLAG=-fPIC])
-  CFLAGS="$ac_save_CFLAGS"
-fi
-# Similarly, use -fPIC with --enable-host-shared:
+# Enable --enable-host-shared.
 AC_ARG_ENABLE(host-shared,
 [AS_HELP_STRING([--enable-host-shared],
 		[build host code as shared libraries])],
-[PIC_FLAG=-fPIC], [])
+[PIC_FLAG=-fPIC], [PIC_FLAG=])
 AC_SUBST(PIC_FLAG)
 
 # Test for __sync support.

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com



More information about the Gcc-patches mailing list