public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Revised fix for PR65351
@ 2015-04-09 11:29 Iain Sandoe
  2015-04-09 11:30 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Iain Sandoe @ 2015-04-09 11:29 UTC (permalink / raw)
  To: Gcc Patch List; +Cc: Jakub Jelinek

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.

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Revised fix for PR65351
  2015-04-09 11:29 [PATCH] Revised fix for PR65351 Iain Sandoe
@ 2015-04-09 11:30 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2015-04-09 11:30 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: Gcc Patch List

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-09 11:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-09 11:29 [PATCH] Revised fix for PR65351 Iain Sandoe
2015-04-09 11:30 ` Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).