make the driver set the default for -mmacosx-version-min on Darwin

Geoffrey Keating gkeating@apple.com
Sat Feb 17 02:49:00 GMT 2007


This patch makes the GCC driver the one place that sets the default
for the -mmacosx-version-min flag on Darwin, and has it always inform the
linker, cc1, and through cc1 the header files of the value.

This should fix or avoid a bunch of bugs where one part or another of
the toolchain differed from the compiler in the minimum system version
to be targetted.  It does, however, mean that toolchain components can't
distinguish between the default case and an explicit user specification.

Bootstrapped and tested on powerpc-darwin9 and x86-darwin9.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-darwin-minversionalways.patch=========
2007-02-16  Geoffrey Keating  <geoffk@apple.com>

	* config/darwin.h (LINK_SPEC): Always pass -macosx_version_min
	to linker.
	(DARWIN_EXTRA_SPECS): Add %(darwin_minversion).
	* config/rs6000/darwin.h (SUBTARGET_OVERRIDE_OPTIONS): Just call
	darwin_rs6000_override_options.
	(C_COMMON_OVERRIDE_OPTIONS): Expect
	darwin_macosx_version_min to be non-NULL always.
	(TARGET_C99_FUNCTIONS): Likewise.
	(CC1_SPEC): Always pass -mmacosx-version-min to cc1*.
	(DARWIN_MINVERSION_SPEC): New.
	* config/rs6000/rs6000.c (darwin_rs6000_override_options): New.
	* config/i386/darwin.h (CC1_SPEC): Always pass -mmacosx-version-min
	to cc1*.  
	(DARWIN_MINVERSION_SPEC): New.
	* config/darwin.opt (mmacosx-version-min): Initialize to non-NULL
	value.
	* config/darwin-c.c (darwin_cpp_builtins): Expect
	darwin_macosx_version_min to be non-NULL always.

Index: gcc/config/darwin.opt
===================================================================
--- gcc/config/darwin.opt	(revision 122066)
+++ gcc/config/darwin.opt	(working copy)
@@ -23,8 +23,12 @@
 Target Report Var(darwin_fix_and_continue)
 Generate code suitable for fast turn around debugging
 
+; The Init here is for the convenience of GCC developers, so that
+; cc1 and cc1plus don't crash if no -mmacosx-version-min is passed.  The
+; driver will always pass a -mmacosx-version-min, so in normal use
+; the Init is never used.
 mmacosx-version-min=
-Target Joined Report Var(darwin_macosx_version_min)
+Target Joined Report Var(darwin_macosx_version_min) Init("10.1")
 The earliest MacOS X version on which this program will run
 
 mone-byte-bool
Index: gcc/config/darwin-c.c
===================================================================
--- gcc/config/darwin-c.c	(revision 122066)
+++ gcc/config/darwin-c.c	(working copy)
@@ -616,7 +616,6 @@
      to be defined and won't work if it isn't.  */
   builtin_define_with_value ("__APPLE_CC__", "1", false);
 
-  if (darwin_macosx_version_min)
-    builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
-			       version_as_macro(), false);
+  builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
+			     version_as_macro(), false);
 }
Index: gcc/config/i386/darwin.h
===================================================================
--- gcc/config/i386/darwin.h	(revision 122066)
+++ gcc/config/i386/darwin.h	(working copy)
@@ -74,6 +74,7 @@
 
 #undef CC1_SPEC
 #define CC1_SPEC "%{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \
+  -mmacosx-version-min=%(darwin_minversion) \
   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }}"
 
 #undef ASM_SPEC
@@ -82,6 +83,9 @@
 #define DARWIN_ARCH_SPEC "%{m64:x86_64;:i386}"
 #define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
 
+/* Determine a minimum version based on compiler options.  */
+#define DARWIN_MINVERSION_SPEC	"10.4"
+
 #undef SUBTARGET_EXTRA_SPECS
 #define SUBTARGET_EXTRA_SPECS                                   \
   DARWIN_EXTRA_SPECS                                            \
Index: gcc/config/rs6000/darwin.h
===================================================================
--- gcc/config/rs6000/darwin.h	(revision 122066)
+++ gcc/config/rs6000/darwin.h	(working copy)
@@ -55,74 +55,23 @@
 /* Translate config/rs6000/darwin.opt to config/darwin.h.  */
 #define TARGET_DYNAMIC_NO_PIC (TARGET_MACHO_DYNAMIC_NO_PIC)
 
-#define TARGET_OS_CPP_BUILTINS()                \
-  do                                            \
-    {                                           \
-      if (!TARGET_64BIT) builtin_define ("__ppc__");   \
-      if (TARGET_64BIT) builtin_define ("__ppc64__");  \
-      builtin_define ("__POWERPC__");           \
-      builtin_define ("__NATURAL_ALIGNMENT__"); \
-      darwin_cpp_builtins (pfile);		\
-    }                                           \
+#define TARGET_OS_CPP_BUILTINS()			\
+  do							\
+    {							\
+      if (!TARGET_64BIT) builtin_define ("__ppc__");	\
+      if (TARGET_64BIT) builtin_define ("__ppc64__");	\
+      builtin_define ("__POWERPC__");			\
+      builtin_define ("__NATURAL_ALIGNMENT__");		\
+      darwin_cpp_builtins (pfile);			\
+    }							\
   while (0)
 
+#define SUBTARGET_OVERRIDE_OPTIONS darwin_rs6000_override_options ()
 
-#define SUBTARGET_OVERRIDE_OPTIONS					\
-do {									\
-  /* The Darwin ABI always includes AltiVec, can't be (validly) turned	\
-     off.  */								\
-  rs6000_altivec_abi = 1;						\
-  TARGET_ALTIVEC_VRSAVE = 1;						\
-  if (DEFAULT_ABI == ABI_DARWIN)					\
-  {									\
-    if (MACHO_DYNAMIC_NO_PIC_P)						\
-      {									\
-        if (flag_pic)							\
-            warning (0, "-mdynamic-no-pic overrides -fpic or -fPIC");	\
-        flag_pic = 0;							\
-      }									\
-    else if (flag_pic == 1)						\
-      {									\
-        flag_pic = 2;							\
-      }									\
-  }									\
-  if (TARGET_64BIT && ! TARGET_POWERPC64)				\
-    {									\
-      target_flags |= MASK_POWERPC64;					\
-      warning (0, "-m64 requires PowerPC64 architecture, enabling");	\
-    }									\
-  if (flag_mkernel)							\
-    {									\
-      rs6000_default_long_calls = 1;					\
-      target_flags |= MASK_SOFT_FLOAT;					\
-    }									\
-									\
-  /* Make -m64 imply -maltivec.  Darwin's 64-bit ABI includes		\
-     Altivec.  */							\
-  if (!flag_mkernel && !flag_apple_kext					\
-      && TARGET_64BIT							\
-      && ! (target_flags_explicit & MASK_ALTIVEC))			\
-    target_flags |= MASK_ALTIVEC;					\
-									\
-  /* Unless the user (not the configurer) has explicitly overridden	\
-     it with -mcpu=G3 or -mno-altivec, then 10.5+ targets default to	\
-     G4 unless targetting the kernel.  */				\
-  if (!flag_mkernel							\
-      && !flag_apple_kext						\
-      && darwin_macosx_version_min					\
-      && strverscmp (darwin_macosx_version_min, "10.5") >= 0		\
-      && ! (target_flags_explicit & MASK_ALTIVEC)			\
-      && ! rs6000_select[1].string)					\
-    {									\
-      target_flags |= MASK_ALTIVEC;					\
-    }									\
-} while(0)
-
 #define C_COMMON_OVERRIDE_OPTIONS do {					\
   /* On powerpc, __cxa_get_exception_ptr is available starting in the	\
      10.4.6 libstdc++.dylib.  */					\
-  if ((! darwin_macosx_version_min					\
-       || strverscmp (darwin_macosx_version_min, "10.4.6") < 0)		\
+  if (strverscmp (darwin_macosx_version_min, "10.4.6") < 0		\
       && flag_use_cxa_get_exception_ptr == 2)				\
     flag_use_cxa_get_exception_ptr = 0;					\
   if (flag_mkernel)							\
@@ -144,6 +93,7 @@
 #define CC1_SPEC "\
   %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \
   %{static: %{Zdynamic: %e conflicting code gen style switches are used}}\
+  -mmacosx-version-min=%(darwin_minversion) \
   %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}}"
 
 #define DARWIN_ARCH_SPEC "%{m64:ppc64;:ppc}"
@@ -171,6 +121,13 @@
 #define DARWIN_CRT2_SPEC \
   "%{!m64:%:version-compare(!> 10.4 mmacosx-version-min= crt2.o%s)}"
 
+/* Determine a minimum version based on compiler options.  */
+#define DARWIN_MINVERSION_SPEC	\
+  "%{mmacosx-version-min=*:%*;	\
+     m64:10.4;			\
+     shared-libgcc:10.3;	\
+     :10.1}"
+
 #undef SUBTARGET_EXTRA_SPECS
 #define SUBTARGET_EXTRA_SPECS			\
   DARWIN_EXTRA_SPECS                            \
@@ -473,8 +430,7 @@
 #undef TARGET_C99_FUNCTIONS
 #define TARGET_C99_FUNCTIONS					\
   (TARGET_64BIT							\
-   || (darwin_macosx_version_min				\
-       && strverscmp (darwin_macosx_version_min, "10.3") >= 0))
+   || strverscmp (darwin_macosx_version_min, "10.3") >= 0)
 
 /* When generating kernel code or kexts, we don't use Altivec by
    default, as kernel code doesn't save/restore those registers.  */
Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c	(revision 122066)
+++ gcc/config/rs6000/rs6000.c	(working copy)
@@ -1169,6 +1169,61 @@
 	rs6000_hard_regno_mode_ok_p[m][r] = true;
 }
 
+#if TARGET_MACHO
+/* The Darwin version of SUBTARGET_OVERRIDE_OPTIONS.  */
+
+static void
+darwin_rs6000_override_options (void)
+{
+  /* The Darwin ABI always includes AltiVec, can't be (validly) turned
+     off.  */
+  rs6000_altivec_abi = 1;
+  TARGET_ALTIVEC_VRSAVE = 1;
+  if (DEFAULT_ABI == ABI_DARWIN)
+  {
+    if (MACHO_DYNAMIC_NO_PIC_P)
+      {
+        if (flag_pic)
+            warning (0, "-mdynamic-no-pic overrides -fpic or -fPIC");
+        flag_pic = 0;
+      }
+    else if (flag_pic == 1)
+      {
+        flag_pic = 2;
+      }
+  }
+  if (TARGET_64BIT && ! TARGET_POWERPC64)
+    {
+      target_flags |= MASK_POWERPC64;
+      warning (0, "-m64 requires PowerPC64 architecture, enabling");
+    }
+  if (flag_mkernel)
+    {
+      rs6000_default_long_calls = 1;
+      target_flags |= MASK_SOFT_FLOAT;
+    }
+
+  /* Make -m64 imply -maltivec.  Darwin's 64-bit ABI includes
+     Altivec.  */
+  if (!flag_mkernel && !flag_apple_kext
+      && TARGET_64BIT
+      && ! (target_flags_explicit & MASK_ALTIVEC))
+    target_flags |= MASK_ALTIVEC;
+
+  /* Unless the user (not the configurer) has explicitly overridden
+     it with -mcpu=G3 or -mno-altivec, then 10.5+ targets default to
+     G4 unless targetting the kernel.  */
+  if (!flag_mkernel
+      && !flag_apple_kext
+      && strverscmp (darwin_macosx_version_min, "10.5") >= 0
+      && ! (target_flags_explicit & MASK_ALTIVEC)
+      && ! rs6000_select[1].string)
+    {
+      target_flags |= MASK_ALTIVEC;
+    }
+}
+#endif
+
 /* If not otherwise specified by a target, make 'long double' equivalent to
    'double'.  */
 
Index: gcc/config/darwin.h
===================================================================
--- gcc/config/darwin.h	(revision 122066)
+++ gcc/config/darwin.h	(working copy)
@@ -297,8 +297,7 @@
    %{headerpad_max_install_names*} \
    %{Zimage_base*:-image_base %*} \
    %{Zinit*:-init %*} \
-   %{mmacosx-version-min=*:-macosx_version_min %*} \
-   %{!mmacosx-version-min=*:%{shared-libgcc:-macosx_version_min 10.3}} \
+   -macosx_version_min %(darwin_minversion) \
    %{nomultidefs} \
    %{Zmulti_module:-multi_module} %{Zsingle_module:-single_module} \
    %{Zmultiply_defined*:-multiply_defined %*} \
@@ -387,7 +386,8 @@
 
 #define DARWIN_EXTRA_SPECS     \
   { "darwin_crt1", DARWIN_CRT1_SPEC },                                 \
-  { "darwin_dylib1", DARWIN_DYLIB1_SPEC },
+  { "darwin_dylib1", DARWIN_DYLIB1_SPEC },			       \
+  { "darwin_minversion", DARWIN_MINVERSION_SPEC },
 
 #define DARWIN_DYLIB1_SPEC                                             \
   "%:version-compare(!> 10.5 mmacosx-version-min= -ldylib1.o)          \
============================================================



More information about the Gcc-patches mailing list