diff mbox

RFC: [build, ada] Centralize PICFLAG configuration

Message ID yddy5yuftod.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth Aug. 15, 2011, 5:53 p.m. UTC
Paolo,

> On 08/10/2011 01:42 PM, Rainer Orth wrote:
>> * Centralize the determination of PICFLAG.  Currently, three libraries
>>    inside the gcc tree are built PIC without libtool: libgcc, libiberty,
>>    and libgnat/libgnarl.
>>
>>    libiberty/configure.ac has a hardcoded list of PICFLAG that could be
>>    moved to a toplevel config/picflag.m4.
>
> That's the simplest alternative.  It would need however a pass through the
> config/ directory for targets that are never used as hosts for GCC (and
> thus libiberty).
>
> Alternatively, the libtool code could be extracted to config/picflag.m4.

I've merged all three, and (as expected) found a couple of
inconsistencies.

* The general approach between libtool and libiberty differs.  Unless
  otherwise specified (PIC is the default or doesn't work for some
  reason), libtool defaults to -fPIC, while libiberty has a strange
  mixture of -fPIC/-fpic and nothing, without explanation and without a
  default.

* git libtool.m4 uses -fno-common on *-*-darwin.  No idea if this is
  required.

* For QNX, it uses -fPIC -shared, which may no longer be necessary and
  is claimed as a g++ workaround.

* For IA64 HP-UX, there's a claim that -fPIC is necessary despite PIC
  code being the default.  I could find no hint in trunk that this is
  true any longer.

* On a few targets (called out in config/picflag.m4), -fpic and -fPIC
  differ.  While libtool always uses -fPIC, libiberty/configure.ac
  preferred -fpic in a few cases.  No idea why.

* For sh*-*-linux* and sh*-*-netbsd*, -fpic is used in
  HOST_LIBGCC2_CFLAGS.  Again, no explanation.  Perhaps this
  could/should be done as a local override in libgcc instead?

* For SPARC, libiberty/configure.ac has

	case "${CFLAGS}" in
	    *-fpic*)
		PICFLAG=-fpic
		;;
	    *)
		PICFLAG=-fPIC
		;;
	esac ;;

  Why is this SPARC-specific?

* There are two platforms that specify -fpic where this doesn't make a
  difference from -fPIC: arm*-*-netbsdelf* and bfin*-elf*,
  bfin*-uclinux*, bfin*-linux-uclibc*.  I've omitted that setting.

>>    Alternatively, one could think about using libtool --config | grep
>>    pic_flag to determine the flag without actually using libtool.
>>
>>    Last, one completely could go for libtool, but I very much doubt such
>>    a suggestion would get much traction.
>>
>> My current plan is to merge the PICFLAG information from libiberty and
>> libgcc into picflag.m4 and use that.
>
> Yes, that needs to be done of course.  I'm not sure if we still support
> gnatlib_and_tools to build libada/gnattools.  If so, we would need the
> PICFLAG to be available somehow in the gcc Makefile (perhaps by providing
> GCC_TARGET_PICFLAG in addition to GCC_PICFLAG in picflag.m4).

The only trace I could find is in a install.texi reference to historical
practice.

The patch below has been tested as the previous submissions.

	Rainer


2011-07-31  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	config:
	* picflag.m4: New file.

	gcc/ada:
	* gcc-interface/Makefile.in (GNATLIBCFLAGS_FOR_C): Replace
	TARGET_LIBGCC2_CFLAGS by PICFLAG.
	(gnatlib-shared-default, gnatlib-shared-dual-win32,
	gnatlib-shared-win32, gnatlib-shared-darwin, gnatlib-shared,
	gnatlib-sjlj, gnatlib-zcx): Likewise.

	libada:
	* configure.ac: Include ../config/picflag.m4.
	(GCC_PICFLAG): Call it.
	Substitute.
	* configure: Regenerate.
	* Makefile.in (TARGET_LIBGCC2_CFLAGS): Replace by PICFLAG.
	(GNATLIBCFLAGS_FOR_C): Replace TARGET_LIBGCC2_CFLAGS by PICFLAG.
	(LIBADA_FLAGS_TO_PASS): Likewise.
	Don't include $(GCC_DIR)/libgcc.mvars.

	libiberty:
	* aclocal.m4: Include ../config/picflag.m4.
	* configure.ac (GCC_PICFLAG): Call it.
	(enable_shared): Clear PICFLAG unless shared.
	* configure: Regenerate.

Comments

Steve Ellcey Aug. 15, 2011, 6:05 p.m. UTC | #1
On Mon, 2011-08-15 at 19:53 +0200, Rainer Orth wrote:

> * For IA64 HP-UX, there's a claim that -fPIC is necessary despite PIC
>   code being the default.  I could find no hint in trunk that this is
>   true any longer.

Rainer,  If I recall correctly the issue for -fPIC on IA64 HP-UX is to
turn on flag_shlib.  If you don't use -fPIC, flag_shlib is not set and
function FOO in a shared library may get inlined into function BAR or
function BAR may generate a direct call to FOO that cannot be
overwritten by a definition of function FOO coming from outside the
shared library.  Setting flag_shlib should be the only difference
between using or not using -fPIC on IA64 HP-UX.

Steve Ellcey
sje@cup.hp.com
Paolo Bonzini Aug. 15, 2011, 6:08 p.m. UTC | #2
On 08/15/2011 10:53 AM, Rainer Orth wrote:
> * The general approach between libtool and libiberty differs.  Unless
>    otherwise specified (PIC is the default or doesn't work for some
>    reason), libtool defaults to -fPIC, while libiberty has a strange
>    mixture of -fPIC/-fpic and nothing, without explanation and without a
>    default.

I guess it's kind of historic, probably to produce smaller/faster code 
on PPC and SPARC which differentiate between -fPIC/-fpic.

In general I trust libtool more, but -fPIC/-fpic differences should be 
more or less harmless, and this:

> * For SPARC, libiberty/configure.ac has
>
> 	case "${CFLAGS}" in
> 	    *-fpic*)
> 		PICFLAG=-fpic
> 		;;
> 	    *)
> 		PICFLAG=-fPIC
> 		;;
> 	esac ;;

actually makes some sense---so the general approach in your patch is 
good.  The patch is okay.

>> Yes, that needs to be done of course.  I'm not sure if we still support
>> gnatlib_and_tools to build libada/gnattools.  If so, we would need the
>> PICFLAG to be available somehow in the gcc Makefile (perhaps by providing
>> GCC_TARGET_PICFLAG in addition to GCC_PICFLAG in picflag.m4).
>
> The only trace I could find is in a install.texi reference to historical
> practice.

Yes, but it also matters whether AdaCore is using it.  If so, I'd like 
also to understand why.

Paolo
Rainer Orth Aug. 16, 2011, 4:47 p.m. UTC | #3
Steve,

> On Mon, 2011-08-15 at 19:53 +0200, Rainer Orth wrote:
>
>> * For IA64 HP-UX, there's a claim that -fPIC is necessary despite PIC
>>   code being the default.  I could find no hint in trunk that this is
>>   true any longer.
>
> Rainer,  If I recall correctly the issue for -fPIC on IA64 HP-UX is to
> turn on flag_shlib.  If you don't use -fPIC, flag_shlib is not set and
> function FOO in a shared library may get inlined into function BAR or
> function BAR may generate a direct call to FOO that cannot be
> overwritten by a definition of function FOO coming from outside the
> shared library.  Setting flag_shlib should be the only difference
> between using or not using -fPIC on IA64 HP-UX.

I see.  I've missed that because I only looked in gcc/config/ia64 for
uses of flag_pic.

Thanks.
        Rainer
Rainer Orth Aug. 16, 2011, 4:53 p.m. UTC | #4
Paolo Bonzini <bonzini@gnu.org> writes:

> On 08/15/2011 10:53 AM, Rainer Orth wrote:
>> * The general approach between libtool and libiberty differs.  Unless
>>    otherwise specified (PIC is the default or doesn't work for some
>>    reason), libtool defaults to -fPIC, while libiberty has a strange
>>    mixture of -fPIC/-fpic and nothing, without explanation and without a
>>    default.
>
> I guess it's kind of historic, probably to produce smaller/faster code on
> PPC and SPARC which differentiate between -fPIC/-fpic.
>
> In general I trust libtool more, but -fPIC/-fpic differences should be more
> or less harmless, and this:

Maybe.  OTOH, we might get away with -fpic for smaller libraries like
libiberty (which isn't usually built PIC anyway) or libgcc, but might
run into trouble with libgnat, which is far larger.

>> * For SPARC, libiberty/configure.ac has
>>
>> 	case "${CFLAGS}" in
>> 	    *-fpic*)
>> 		PICFLAG=-fpic
>> 		;;
>> 	    *)
>> 		PICFLAG=-fPIC
>> 		;;
>> 	esac ;;
>
> actually makes some sense---so the general approach in your patch is good.

Indeed, but IMO it makes sense in general, not only for SPARC, but for
all targets that distinguish between -fpic and -fPIC.

> The patch is okay.

You mean as is, with all the FIXME comments and stuff?  (Modulo the
gcc/ada PICFLAG issue, of course.)

Thanks.
        Rainer
Paolo Bonzini Aug. 16, 2011, 7:02 p.m. UTC | #5
On 08/16/2011 09:53 AM, Rainer Orth wrote:
>> >  actually makes some sense---so the general approach in your patch is good.
> Indeed, but IMO it makes sense in general, not only for SPARC, but for
> all targets that distinguish between -fpic and -fPIC.
>
>> >  The patch is okay.
> You mean as is, with all the FIXME comments and stuff?  (Modulo the
> gcc/ada PICFLAG issue, of course.)

Actually, you need to change PICFLAG to PICFLAGS_FOR_TARGET in 
gcc/ada/gcc-interface, so the patch as is is not okay.  But yes, I'd 
leave the FIXMEs in as we aren't really 100% sure about most things. 
The only FIXME you can remove is perhaps the one in SPARC

+	# FIXME: This could be done everywhere -fpic and -fPIC differ.
+	case "${CFLAGS}" in
+	    *-fpic*)
+		PICFLAG=-fpic
+		;;
+	    *)
+		PICFLAG=-fPIC
+		;;
+	esac ;;

to do it for all targets (doesn't even need to be restricted to some of 
them).

Paolo
Mike Stump Aug. 17, 2011, 7:16 p.m. UTC | #6
On Aug 15, 2011, at 10:53 AM, Rainer Orth wrote:
> * git libtool.m4 uses -fno-common on *-*-darwin.  No idea if this is
>  required.

Yes, it is.
Rainer Orth Aug. 18, 2011, 5:03 p.m. UTC | #7
Mike Stump <mikestump@comcast.net> writes:

> On Aug 15, 2011, at 10:53 AM, Rainer Orth wrote:
>> * git libtool.m4 uses -fno-common on *-*-darwin.  No idea if this is
>>  required.
>
> Yes, it is.

Fine, thanks.  I was just confused by the fact that it isn't currently
used to build the shared libgcc.

	Rainer
Mike Stump Aug. 18, 2011, 9:58 p.m. UTC | #8
On Aug 18, 2011, at 10:03 AM, Rainer Orth wrote:
> Mike Stump <mikestump@comcast.net> writes:
> 
>> On Aug 15, 2011, at 10:53 AM, Rainer Orth wrote:
>>> * git libtool.m4 uses -fno-common on *-*-darwin.  No idea if this is
>>> required.
>> 
>> Yes, it is.
> 
> Fine, thanks.  I was just confused by the fact that it isn't currently
> used to build the shared libgcc.

Hum...  Truly odd.  Watch for fallout if you change it, I'd hate to be wrong.  I can't imagine there are any common symbols in there though.
diff mbox

Patch

# HG changeset patch
# Parent feb70952e84eb1f718614d90985c3291dd565baa
Centralize PICFLAG configuration

diff --git a/config/picflag.m4 b/config/picflag.m4
new file mode 100644
--- /dev/null
+++ b/config/picflag.m4
@@ -0,0 +1,80 @@ 
+AC_DEFUN([GCC_PICFLAG], [
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  # FIXME: Do we need something for CFLAGS below?
+
+case "${host}" in
+    # PIC is the default on some targets or must not be used.
+    *-*-darwin*)
+	# PIC is the default on this platform
+	# Common symbols not allowed in MH_DYLIB files
+	PICFLAG=-fno-common
+	;;
+    alpha*-dec-osf5*)
+	# PIC is the default.
+	;;
+    hppa*64*-*-hpux*)
+	# PIC is the default for 64-bit PA HP-UX.
+	;;
+    i[34567]86-*-cygwin* | i[34567]86-*-mingw* | x86_64-*-mingw*)
+	;;
+    i[34567]86-*-interix3*)
+	# Interix 3.x gcc -fpic/-fPIC options generate broken code.
+	# Instead, we relocate shared libraries at runtime.
+	;;
+    i[34567]86-*-nto-qnx*)
+	# QNX uses GNU C++, but need to define -shared option too, otherwise
+	# it will coredump.
+	PICFLAG='-fPIC -shared'
+	;;
+    i[34567]86-pc-msdosdjgpp*)
+	# DJGPP does not support shared libraries at all.
+	;;
+    ia64*-*-hpux*)
+	# On IA64 HP-UX, PIC is the default but the pic flag
+	# sets the default TLS model and affects inlining.
+	# FIXME: Still in gcc 4.7?
+	PICFLAG=-fPIC
+	;;
+    mips-sgi-irix6*)
+	# PIC is the default.
+	;;
+    rs6000-ibm-aix* | powerpc-ibm-aix*)
+	# All AIX code is PIC.
+	;;
+
+    # Some targets support both -fPIC and -fpic, but prefer the latter.
+    # FIXME: Why?
+    i[34567]86-*-* | x86_64-*-*)
+	PICFLAG=-fpic
+	;;
+    m68k-*-*)
+	PICFLAG=-fpic
+	;;
+    s390*-*-*)
+	PICFLAG=-fpic
+	;;
+    # FIXME: Override -fPIC default in libgcc only? 
+    sh-*-linux* | sh[2346lbe]*-*-linux*)
+	PICFLAG=-fpic
+	;;
+    # FIXME: Simplify to sh*-*-netbsd*?
+    sh-*-netbsdelf* | shl*-*-netbsdelf* | sh5-*-netbsd* | sh5l*-*-netbsd* | \
+      sh64-*-netbsd* | sh64l*-*-netbsd*)
+	PICFLAG=-fpic
+	;;
+    sparc*-*-*)
+	# FIXME: This could be done everywhere -fpic and -fPIC differ.
+	case "${CFLAGS}" in
+	    *-fpic*)
+		PICFLAG=-fpic
+		;;
+	    *)
+		PICFLAG=-fPIC
+		;;
+	esac ;;
+    # Default to -fPIC unless specified otherwise.
+    *)
+	PICFLAG=-fPIC
+	;;
+esac
+])
diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
--- a/gcc/ada/gcc-interface/Makefile.in
+++ b/gcc/ada/gcc-interface/Makefile.in
@@ -114,7 +114,7 @@  GNATLIBCFLAGS = -g -O2
 # Pretend that _Unwind_GetIPInfo is available for the target by default.  This
 # should be autodetected during the configuration of libada and passed down to
 # here, but we need something for --disable-libada and hope for the best.
-GNATLIBCFLAGS_FOR_C = $(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS) -fexceptions \
+GNATLIBCFLAGS_FOR_C = $(GNATLIBCFLAGS) $(PICFLAG) -fexceptions \
 	-DIN_RTS -DHAVE_GETIPINFO
 ALL_ADAFLAGS = $(CFLAGS) $(ADA_CFLAGS) $(ADAFLAGS)
 MOST_ADAFLAGS = $(CFLAGS) $(ADA_CFLAGS) $(SOME_ADAFLAGS)
@@ -2482,7 +2482,7 @@  gnatlib: ../stamp-gnatlib1-$(RTSDIR) ../
 gnatlib-shared-default:
 	$(MAKE) $(FLAGS_TO_PASS) \
              GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS)" \
+	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(PICFLAG)" \
 	     GNATLIBCFLAGS_FOR_C="$(GNATLIBCFLAGS_FOR_C)" \
 	     MULTISUBDIR="$(MULTISUBDIR)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
@@ -2490,14 +2490,14 @@  gnatlib-shared-default:
 	$(RM) $(RTSDIR)/libgna*$(soext)
 	cd $(RTSDIR); `echo "$(GCC_FOR_TARGET)" \
                 | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -shared $(GNATLIBCFLAGS) \
-		$(TARGET_LIBGCC2_CFLAGS) \
+		$(PICFLAG) \
 		-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
 		$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
 		$(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
 		$(MISCLIB) -lm
 	cd $(RTSDIR); `echo "$(GCC_FOR_TARGET)" \
                 | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -shared $(GNATLIBCFLAGS) \
-		$(TARGET_LIBGCC2_CFLAGS) \
+		$(PICFLAG) \
 		-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
 		$(GNATRTL_TASKING_OBJS) \
 		$(SO_OPTS)libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
@@ -2529,7 +2529,7 @@  gnatlib-shared-dual:
 gnatlib-shared-dual-win32:
 	$(MAKE) $(FLAGS_TO_PASS) \
              GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS)" \
+	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(PICFLAG)" \
 	     GNATLIBCFLAGS_FOR_C="$(GNATLIBCFLAGS_FOR_C)" \
 	     MULTISUBDIR="$(MULTISUBDIR)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
@@ -2552,7 +2552,7 @@  gnatlib-shared-dual-win32:
 gnatlib-shared-win32:
 	$(MAKE) $(FLAGS_TO_PASS) \
              GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS)" \
+	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(PICFLAG)" \
 	     GNATLIBCFLAGS_FOR_C="$(GNATLIBCFLAGS_FOR_C)" \
 	     MULTISUBDIR="$(MULTISUBDIR)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
@@ -2560,13 +2560,13 @@  gnatlib-shared-win32:
 	$(RM) $(RTSDIR)/libgna*$(soext)
 	cd $(RTSDIR); `echo "$(GCC_FOR_TARGET)" \
                 | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -shared -shared-libgcc \
-		$(TARGET_LIBGCC2_CFLAGS) \
+		$(PICFLAG) \
 		-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
 		$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
 		$(SO_OPTS)libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) $(MISCLIB)
 	cd $(RTSDIR); `echo "$(GCC_FOR_TARGET)" \
                 | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -shared -shared-libgcc \
-		$(TARGET_LIBGCC2_CFLAGS) \
+		$(PICFLAG) \
 		-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
 		$(GNATRTL_TASKING_OBJS) \
 		$(SO_OPTS)libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
@@ -2575,21 +2575,21 @@  gnatlib-shared-win32:
 gnatlib-shared-darwin:
 	$(MAKE) $(FLAGS_TO_PASS) \
 	     GNATLIBFLAGS="$(GNATLIBFLAGS)" \
-	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS)" \
+	     GNATLIBCFLAGS="$(GNATLIBCFLAGS) $(PICFLAG)" \
 	     GNATLIBCFLAGS_FOR_C="$(GNATLIBCFLAGS_FOR_C) -fno-common" \
 	     MULTISUBDIR="$(MULTISUBDIR)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
 	     gnatlib
 	$(RM) $(RTSDIR)/libgnat$(soext) $(RTSDIR)/libgnarl$(soext)
 	cd $(RTSDIR); `echo "$(GCC_FOR_TARGET)" \
-                | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -dynamiclib $(TARGET_LIBGCC2_CFLAGS) \
+                | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -dynamiclib $(PICFLAG) \
 		-o libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
 		$(GNATRTL_NONTASKING_OBJS) $(LIBGNAT_OBJS) \
 		$(SO_OPTS) \
 		-Wl,-install_name,@rpath/libgnat$(hyphen)$(LIBRARY_VERSION)$(soext) \
 		$(MISCLIB) -lm
 	cd $(RTSDIR); `echo "$(GCC_FOR_TARGET)" \
-                | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -dynamiclib $(TARGET_LIBGCC2_CFLAGS) \
+                | sed -e 's,\./xgcc,../../xgcc,' -e 's,-B\./,-B../../,'` -dynamiclib $(PICFLAG) \
 		-o libgnarl$(hyphen)$(LIBRARY_VERSION)$(soext) \
 		$(GNATRTL_TASKING_OBJS) \
 		$(SO_OPTS) \
@@ -2638,7 +2638,7 @@  gnatlib-shared:
 	     GNATLIBCFLAGS_FOR_C="$(GNATLIBCFLAGS_FOR_C)" \
 	     MULTISUBDIR="$(MULTISUBDIR)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
-	     TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" \
+	     PICFLAG="$(PICFLAG)" \
              $(GNATLIB_SHARED)
 
 gnatlib-sjlj:
@@ -2653,7 +2653,7 @@  gnatlib-sjlj:
 	     GNATLIBCFLAGS_FOR_C="$(GNATLIBCFLAGS_FOR_C)" \
 	     MULTISUBDIR="$(MULTISUBDIR)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
-	     TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" gnatlib
+	     PICFLAG="$(PICFLAG)" gnatlib
 
 gnatlib-zcx:
 	$(MAKE) $(FLAGS_TO_PASS) EH_MECHANISM="-gcc" \
@@ -2667,7 +2667,7 @@  gnatlib-zcx:
 	     GNATLIBCFLAGS_FOR_C="$(GNATLIBCFLAGS_FOR_C)" \
 	     MULTISUBDIR="$(MULTISUBDIR)" \
 	     THREAD_KIND="$(THREAD_KIND)" \
-	     TARGET_LIBGCC2_CFLAGS="$(TARGET_LIBGCC2_CFLAGS)" gnatlib
+	     PICFLAG="$(PICFLAG)" gnatlib
 
 # .s files for cross-building
 gnat-cross: force
diff --git a/libada/Makefile.in b/libada/Makefile.in
--- a/libada/Makefile.in
+++ b/libada/Makefile.in
@@ -1,5 +1,5 @@ 
 # Makefile for libada.
-#   Copyright 2003, 2004, 2009, 2010 Free Software Foundation, Inc.
+# Copyright 2003, 2004, 2009, 2010, 2011 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -56,15 +56,13 @@  LOOSE_WARN = -W -Wall -Wwrite-strings -W
 GCC_WARN_CFLAGS = $(LOOSE_WARN)
 WARN_CFLAGS = @warn_cflags@
 
-TARGET_LIBGCC2_CFLAGS=
+PICFLAG = @PICFLAG@
 GNATLIBCFLAGS= -g -O2
-GNATLIBCFLAGS_FOR_C = $(GNATLIBCFLAGS) $(TARGET_LIBGCC2_CFLAGS) -fexceptions \
+GNATLIBCFLAGS_FOR_C = $(GNATLIBCFLAGS) $(PICFLAG) -fexceptions \
 	-DIN_RTS @have_getipinfo@
 
-# Get target-specific overrides for TARGET_LIBGCC2_CFLAGS.
 host_subdir = @host_subdir@
 GCC_DIR=$(MULTIBUILDTOP)../../$(host_subdir)/gcc
-include $(GCC_DIR)/libgcc.mvars
 
 target_noncanonical:=@target_noncanonical@
 version := $(shell cat $(srcdir)/../gcc/BASE-VER)
@@ -83,7 +81,7 @@  LIBADA_FLAGS_TO_PASS = \
         "GNATLIBFLAGS=$(GNATLIBFLAGS) $(MULTIFLAGS)" \
         "GNATLIBCFLAGS=$(GNATLIBCFLAGS) $(MULTIFLAGS)" \
         "GNATLIBCFLAGS_FOR_C=$(GNATLIBCFLAGS_FOR_C) $(MULTIFLAGS)" \
-        "TARGET_LIBGCC2_CFLAGS=$(TARGET_LIBGCC2_CFLAGS)" \
+        "PICFLAG=$(PICFLAG)" \
         "THREAD_KIND=$(THREAD_KIND)" \
         "TRACE=$(TRACE)" \
         "MULTISUBDIR=$(MULTISUBDIR)" \
diff --git a/libada/configure.ac b/libada/configure.ac
--- a/libada/configure.ac
+++ b/libada/configure.ac
@@ -1,5 +1,5 @@ 
 # Configure script for libada.
-#   Copyright 2003, 2004, 2009 Free Software Foundation, Inc.
+#   Copyright 2003, 2004, 2009, 2011 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@ 
 sinclude(../config/acx.m4)
 sinclude(../config/multi.m4)
 sinclude(../config/override.m4)
+sinclude(../config/picflag.m4)
 sinclude(../config/unwind_ipinfo.m4)
 
 AC_INIT
@@ -118,6 +119,9 @@  esac
 ], [enable_shared=yes])
 AC_SUBST([enable_shared])
 
+GCC_PICFLAG
+AC_SUBST([PICFLAG])
+
 # These must be passed down, or are needed by gcc/libgcc.mvars
 AC_PROG_AWK
 AC_PROG_LN_S
diff --git a/libiberty/aclocal.m4 b/libiberty/aclocal.m4
--- a/libiberty/aclocal.m4
+++ b/libiberty/aclocal.m4
@@ -1,6 +1,7 @@ 
 sinclude(../config/acx.m4)
 sinclude(../config/no-executables.m4)
 sinclude(../config/override.m4)
+sinclude(../config/picflag.m4)
 sinclude(../config/warnings.m4)
 
 dnl See whether strncmp reads past the end of its string parameters.
diff --git a/libiberty/configure.ac b/libiberty/configure.ac
--- a/libiberty/configure.ac
+++ b/libiberty/configure.ac
@@ -191,6 +191,8 @@  if [[ -n "${frag}" ]]; then
   frag=${libiberty_topdir}/libiberty/config/$frag
 fi
 
+GCC_PICFLAG
+
 # If they didn't specify --enable-shared, don't generate shared libs.
 case "${enable_shared}" in
   yes) shared=yes ;;
@@ -198,27 +200,8 @@  case "${enable_shared}" in
   "") shared=no ;;
   *) shared=yes ;;
 esac
-if [[ "${shared}" = "yes" ]]; then
-  case "${host}" in
-    *-*-cygwin*)	;;
-    alpha*-*-linux*)	PICFLAG=-fPIC ;;
-    arm*-*-*)		PICFLAG=-fPIC ;;
-    hppa*-*-*)		PICFLAG=-fPIC ;;
-    i370-*-*)		PICFLAG=-fPIC ;;
-    ia64-*-*)		PICFLAG=-fpic ;;
-    i[[34567]]86-*-* | x86_64-*-*)
-			PICFLAG=-fpic ;;
-    m68k-*-*)		PICFLAG=-fpic ;;
-    mips*-*-linux*)	PICFLAG=-fPIC ;;
-    powerpc*-*-aix*)	;;
-    powerpc*-*-*)	PICFLAG=-fPIC ;;
-    sparc*-*-*)		case "${CFLAGS}" in
-			  *-fpic* ) PICFLAG=-fpic ;;
-			  * ) PICFLAG=-fPIC ;;
-			esac ;;
-    s390*-*-*)		PICFLAG=-fpic ;;
-    sh*-*-*)		PICFLAG=-fPIC ;;
-  esac
+if [[ "${shared}" != "yes" ]]; then
+  PICFLAG=
 fi
 AC_SUBST(PICFLAG)