diff mbox

Revised fix for PR65351

Message ID B2D37C20-0CE8-4D26-A108-5DBE557C29FF@codesourcery.com
State New
Headers show

Commit Message

Iain Sandoe April 9, 2015, 11:29 a.m. UTC
Hi,

It turns out that existing versions of clang (used as bootstrap on later Darwin editions) support -mdynamic-no-pic, but not the inverse.  The patch below revises mh-darwin so that it only adds -mdynamic-no-pic when the inverse is supported (for stage1 and boot cflags).  For later stages, built with GCC, it is known to be supported and can be added unconditionally.
When generating the PICFLAG, -mno-dynamic-no-pic is added only when -mdynamic-no-pic is present in CFLAGS.

OK for trunk?
Iain


2015-04-09  Jakub Jelinek  <jakub@redhat.com>
	    Iain Sandoe  <iain@codesourcery.com>

	PR target/65351
config/
	* mh-darwin: Only apply -mdynamic-no-pic for m32 Darwin when the compiler in
	use supports -mno-dynamic-no-pic.
	* picflag.m4: Only append -mno-dynamic-no-pic for Darwin when -mdynamic-no-pic
	is present in CFLAGS.

libiberty/
	* configure: Regenerate.
libada/
	* configure: Regenerate.
libgcc/
	* configure: Regenerate.
gcc/
	* configure: Regenerate.

Comments

Jakub Jelinek April 9, 2015, 11:30 a.m. UTC | #1
On Thu, Apr 09, 2015 at 12:29:06PM +0100, Iain Sandoe wrote:
> It turns out that existing versions of clang (used as bootstrap on later Darwin editions) support -mdynamic-no-pic, but not the inverse.  The patch below revises mh-darwin so that it only adds -mdynamic-no-pic when the inverse is supported (for stage1 and boot cflags).  For later stages, built with GCC, it is known to be supported and can be added unconditionally.
> When generating the PICFLAG, -mno-dynamic-no-pic is added only when -mdynamic-no-pic is present in CFLAGS.
> 
> OK for trunk?

Ok, thanks.

	Jakub
diff mbox

Patch

diff --git a/config/mh-darwin b/config/mh-darwin
index a039f20..148b730 100644
--- a/config/mh-darwin
+++ b/config/mh-darwin
@@ -1,18 +1,29 @@ 
 # The -mdynamic-no-pic ensures that the compiler executable is built without
 # position-independent-code -- the usual default on Darwin. This fix speeds
-# compiles by 3-5%.
-BOOT_CFLAGS += \
+# compiles by 3-5%.  Don't add it if the compiler doesn't also support
+# -mno-dynamic-no-pic to undo it.
+DARWIN_MDYNAMIC_NO_PIC := \
 `case ${host} in i?86-*-darwin* | powerpc-*-darwin*) \
-                 echo -mdynamic-no-pic ;; esac;`
+   $(CC) -S -xc /dev/null -o /dev/null -mno-dynamic-no-pic 2>/dev/null \
+   && echo -mdynamic-no-pic ;; esac`
+DARWIN_GCC_MDYNAMIC_NO_PIC := \
+`case ${host} in i?86-*-darwin* | powerpc-*-darwin*) \
+   $(CC) -S -xc /dev/null -o /dev/null -mno-dynamic-no-pic 2>/dev/null \
+   || echo -mdynamic-no-pic ;; esac`
 
 # ld on Darwin versions >= 10.7 defaults to PIE executables. Disable this for
 # gcc components, since it is incompatible with our pch implementation.
-BOOT_LDFLAGS += \
-`case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
+DARWIN_NO_PIE := `case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
+
+BOOT_CFLAGS += $(DARWIN_MDYNAMIC_NO_PIC)
+BOOT_LDFLAGS += $(DARWIN_NO_PIE)
 
 # Similarly, for cross-compilation.
-STAGE1_CFLAGS += \
-`case ${host} in i?86-*-darwin* | powerpc-*-darwin*)\
-                 echo -mdynamic-no-pic ;; esac;`
-STAGE1_LDFLAGS += \
-`case ${host} in *-*-darwin[1][1-9]*) echo -Wl,-no_pie ;; esac;`
+STAGE1_CFLAGS += $(DARWIN_MDYNAMIC_NO_PIC)
+STAGE1_LDFLAGS += $(DARWIN_NO_PIE)
+
+# Without -mno-dynamic-no-pic support, add -mdynamic-no-pic just to later
+# stages when we know it is built with gcc.
+STAGE2_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)
+STAGE3_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)
+STAGE4_CFLAGS += $(DARWIN_GCC_MDYNAMIC_NO_PIC)
diff --git a/config/picflag.m4 b/config/picflag.m4
index 836523d..2f5b972 100644
--- a/config/picflag.m4
+++ b/config/picflag.m4
@@ -7,11 +7,15 @@  AC_DEFUN([_GCC_PICFLAG], [
 case "${$2}" 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
-	# Cancel any earlier -mdynamic-no-pic, as that makes
-	# the code not suitable for shared libraries.
-	$1='-fno-common -mno-dynamic-no-pic'
+	# For darwin, common symbols are not allowed in MH_DYLIB files
+	case "${CFLAGS}" in
+	  # If we are using a compiler supporting mdynamic-no-pic
+	  # and the option has been tested as safe to add, then cancel
+	  # it here, since the code generated is incompatible with shared
+	  # libs.
+	  *-mdynamic-no-pic*) $1='-fno-common -mno-dynamic-no-pic' ;;
+	  *) $1=-fno-common ;;
+	esac
 	;;
     alpha*-dec-osf5*)
 	# PIC is the default.