As has been mentioned before, one impediment to complete the toplevel
libgcc move is libada's use of TARGET_LIBGCC2_CFLAGS.  AFAICS, it is
primarily used for gnatlib-*shared targets, so I assume that this was
done mostly (exclusively?) to get the flags necessary for PIC code
generation.  Since those flags aren't used for the static libgnat.a, it
were strange that the non-PIC flags were actually required, given that
all gnat.dg and ada/acats testing is only done with the static library.

If this is true, then we need two things:

* Change gcc-interface/Makefile.in and libada/Makefile.in to use PICFLAG
  instead of TARGET_LIBGCC2_CFLAGS.  This is what the patch below does.

* 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.

  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.

I've used the patch below as a proof-of-concept to complete the toplevel
libgcc move.  Together with companion patches to actually move all the
LIBGCC2* and LIB2* variables and corresponding files to toplevel libgcc,
I've sucessfully bootstrapped on i386-pc-solaris2.11.

Comments, suggestions?

        Rainer


2011-07-31  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

        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 (PICFLAG): Set.
        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.

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
@@ -117,6 +117,9 @@ case $enable_shared in
 esac
 ], [enable_shared=yes])
 AC_SUBST([enable_shared])
+# FIXME: Configure.
+PICFLAG=-fPIC
+AC_SUBST([PICFLAG])
 
 # These must be passed down, or are needed by gcc/libgcc.mvars
 AC_PROG_AWK
-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

Reply via email to