From patchwork Sat Sep 12 14:33:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 517095 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 9B507140271 for ; Sun, 13 Sep 2015 00:34:15 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=LBrdhzD/; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :content-type:subject:date:message-id:cc:to:mime-version; q=dns; s=default; b=jByHh9fPH5WDQ8PdE8QC/lrSvBbi+8bS0I6fi52DQZU9e10Nts qL+hWptX/E6UHJS16Q9m99Usb8c0CYr065uQSiNnVpknumcH9QE5SzJRnNQ7yGoc ZuntHQ75VrRUbi4psZD8UyBj9S7Cd1y9TlWgjJJi4XUJ4duhlkApJrcB4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :content-type:subject:date:message-id:cc:to:mime-version; s= default; bh=FeGxOOP04LtUU40h1Wm/AMxfc3g=; b=LBrdhzD/IdR8zxtpOXE6 nmKgCxcvUSn1Sp5+RtFlPVxnKz164+62m/pAGsx119F+pT2vkpfSmiHNBrubERGS N+/Ebh2bIIjkENcatqNKeoP+npDRLbSV0Ul9s7Y9k6PJ3cNzwOLwho3eorrma7vs AvKDbyeK6CFR3DgCWRzY7Yg= Received: (qmail 44355 invoked by alias); 12 Sep 2015 14:34:06 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 44344 invoked by uid 89); 12 Sep 2015 14:34:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_40, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 12 Sep 2015 14:34:03 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1ZalsM-0000xV-Vc from Iain_Sandoe@mentor.com ; Sat, 12 Sep 2015 07:33:59 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Sat, 12 Sep 2015 15:33:56 +0100 From: Iain Sandoe Subject: [Darwin, Driver/specs] A bit more TLC, factor version-min code, lose some dead specs. Date: Sat, 12 Sep 2015 15:33:44 +0100 Message-ID: CC: Mike Stump To: gcc-patches List MIME-Version: 1.0 (Apple Message framework v1283) Hi, This is a clean-up and code re-factoring patch; NFC intended. a) The arcane version specs that attempted to figure out a version-min on the basis of inspecting other c/l flags have been dead for some time (since the driver started inserting a default); so let's lose those. b) We'll need access to the version-min at the outer level in the darwin-specific driver code in order to use that to figure out where to find sysroots, so let's factor the code to do that and shorten it at the same time. c) In the absence of any other information, the best choice we can make for version-min is 10.5, since that's the only version that (fully) supports all of our archs... d) ... however, we normally do have a version-min default, to let's make sure we provide that as the init. e) If a user elects to call a compiler (cc1*, f951, etc.) without a version-min, the init provided in (d) will kick in, and stop the compiler from segv-ing. However, we should warn the User that a default was used, because it's very likely not what was intended. OK for trunk? Iain gcc/ * config/darwin-driver.c (darwin_default_min_version): Refactor code. (darwin_driver_init): Note a version-min when provided on the c/l. * config/darwin.c (darwin_override_options): Warn the user if the compiler is invoked without a version-min. * config/darwin.h (%darwin_minversion): Remove. * config/i386/darwin.h: Likewise. * config/rs6000/darwin.h: Likewise. * config/darwin.opt (mmacosx-version-min=): Use the configured default, rather than an arbitrary constant. From 04cfd2ea513fdaa48826891dbc87615f97270950 Mon Sep 17 00:00:00 2001 From: Iain Sandoe Date: Mon, 7 Sep 2015 09:59:45 +0100 Subject: [PATCH] [Darwin, driver] Revise and clean up system version detection. This re-factors the system version detection and makes the version string available to the darwin_driver_init() routine, when it is available. We also delete all the "darwin_minversion" spec stuff which is unused and redundant. The default value for compilers is now set to match the configured default. If compilers are invoked directly without an explicit system version, a warning is given. --- gcc/config/darwin-driver.c | 109 +++++++++++++++++++-------------------------- gcc/config/darwin.c | 8 ++++ gcc/config/darwin.h | 10 ++--- gcc/config/darwin.opt | 5 +-- gcc/config/darwin12.h | 3 ++ gcc/config/i386/darwin.h | 10 ----- gcc/config/rs6000/darwin.h | 12 ----- 7 files changed, 65 insertions(+), 92 deletions(-) diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c index 727ea53..4042a68 100644 --- a/gcc/config/darwin-driver.c +++ b/gcc/config/darwin-driver.c @@ -96,73 +96,36 @@ darwin_find_version_from_kernel (void) included in tm.h). This may be overidden by setting the flag explicitly (or by the MACOSX_DEPLOYMENT_TARGET environment). */ -static void -darwin_default_min_version (unsigned int *decoded_options_count, - struct cl_decoded_option **decoded_options) +static const char * +darwin_default_min_version (void) { - const unsigned int argc = *decoded_options_count; - struct cl_decoded_option *const argv = *decoded_options; - unsigned int i; - const char *new_flag; - - /* If the command-line is empty, just return. */ - if (argc <= 1) - return; - - /* Don't do this if the user specified -mmacosx-version-min= or - -mno-macosx-version-min. */ - for (i = 1; i < argc; i++) - if (argv[i].opt_index == OPT_mmacosx_version_min_) - return; - - /* Retrieve the deployment target from the environment and insert - it as a flag. */ - { - const char * macosx_deployment_target; - macosx_deployment_target = getenv ("MACOSX_DEPLOYMENT_TARGET"); - if (macosx_deployment_target - /* Apparently, an empty string for MACOSX_DEPLOYMENT_TARGET means - "use the default". Or, possibly "use 10.1". We choose - to ignore the environment variable, as if it was never set. */ - && macosx_deployment_target[0]) - { - ++*decoded_options_count; - *decoded_options = XNEWVEC (struct cl_decoded_option, - *decoded_options_count); - (*decoded_options)[0] = argv[0]; - generate_option (OPT_mmacosx_version_min_, macosx_deployment_target, - 1, CL_DRIVER, &(*decoded_options)[1]); - memcpy (*decoded_options + 2, argv + 1, - (argc - 1) * sizeof (struct cl_decoded_option)); - return; - } - } + /* Try to retrieve the deployment target from the environment. */ + const char *new_flag = getenv ("MACOSX_DEPLOYMENT_TARGET"); + /* Apparently, an empty string for MACOSX_DEPLOYMENT_TARGET means + "use the default". Or, possibly "use 10.1". We choose + to ignore the environment variable, as if it was never set. */ + if (new_flag == NULL || new_flag[0] == 0) #ifndef CROSS_DIRECTORY_STRUCTURE - - /* Try to find the version from the kernel, if we fail - we print a message - and give up. */ - new_flag = darwin_find_version_from_kernel (); - if (!new_flag) - return; - + /* Try to find the version from the kernel, if we fail - we print a + message and give up. */ + new_flag = darwin_find_version_from_kernel (); #else - - /* For cross-compilers, default to the target OS version. */ - new_flag = DEF_MIN_OSX_VERSION; - + /* For cross-compilers, default to a minimum version determined by + the configuration. */ + new_flag = DEF_MIN_OSX_VERSION; #endif /* CROSS_DIRECTORY_STRUCTURE */ - /* Add the new flag. */ - ++*decoded_options_count; - *decoded_options = XNEWVEC (struct cl_decoded_option, - *decoded_options_count); - (*decoded_options)[0] = argv[0]; - generate_option (OPT_mmacosx_version_min_, new_flag, - 1, CL_DRIVER, &(*decoded_options)[1]); - memcpy (*decoded_options + 2, argv + 1, - (argc - 1) * sizeof (struct cl_decoded_option)); - return; + if (new_flag != NULL) + { + size_t len = strlen (new_flag); + if (len > 128) { /* Arbitrary limit, number should be like xx.yy.zz */ + warning (0, "couldn%'t understand version %s\n", new_flag); + return NULL; + } + new_flag = strndup (new_flag, len); + } + return new_flag; } /* Translate -filelist and -framework options in *DECODED_OPTIONS @@ -187,6 +150,8 @@ darwin_driver_init (unsigned int *decoded_options_count, bool seenM64 = false; bool appendM32 = false; bool appendM64 = false; + const char *vers_string = NULL; + bool seen_version_min = false; for (i = 1; i < *decoded_options_count; i++) { @@ -246,12 +211,15 @@ darwin_driver_init (unsigned int *decoded_options_count, CL_DRIVER, &(*decoded_options)[i]); break; + case OPT_mmacosx_version_min_: + seen_version_min = true; + vers_string = strndup ((*decoded_options)[i].arg, 32); + default: break; } } - darwin_default_min_version (decoded_options_count, decoded_options); /* Turn -arch xxxx into the appropriate -m32/-m64 flag. If the User tried to specify multiple arch flags (which is possible with some Darwin compilers) warn that this mode is not supported by this @@ -308,4 +276,21 @@ darwin_driver_init (unsigned int *decoded_options_count, &(*decoded_options)[*decoded_options_count - 1]); } + /* We will need to know the OS X version we're trying to build for here + so that we can figure out the mechanism and source for the sysroot to + be used. */ + if (! seen_version_min && *decoded_options_count > 1) + { + /* Not set by the User, try to figure it out. */ + vers_string = darwin_default_min_version (); + if (vers_string != NULL) + { + ++*decoded_options_count; + *decoded_options = XRESIZEVEC (struct cl_decoded_option, + *decoded_options, + *decoded_options_count); + generate_option (OPT_mmacosx_version_min_, vers_string, 1, CL_DRIVER, + &(*decoded_options)[*decoded_options_count - 1]); + } + } } diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index b6effec..7f3c915 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -3064,6 +3064,14 @@ darwin_kextabi_p (void) { void darwin_override_options (void) { + /* If a compiler is called directly, rather than via the driver, but + without a target system version specified, warn the user that a + default is in use. */ + if (!global_options_set.x_darwin_macosx_version_min) + warning_at (UNKNOWN_LOCATION, 0, + "%<-mmacosx-version-min%> is not set; using %<%s%>", + darwin_macosx_version_min); + /* Keep track of which (major) version we're generating code for. */ if (darwin_macosx_version_min) { diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index 9a31952..bb4451a 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -271,7 +271,6 @@ extern GTY(()) int darwin_ms_struct; %{headerpad_max_install_names} \ %{Zimage_base*:-image_base %*} \ %{Zinit*:-init %*} \ - %{!mmacosx-version-min=*:-macosx_version_min %(darwin_minversion)} \ %{mmacosx-version-min=*:-macosx_version_min %*} \ %{nomultidefs} \ %{Zmulti_module:-multi_module} %{Zsingle_module:-single_module} \ @@ -370,8 +369,7 @@ extern GTY(()) int darwin_ms_struct; #define DARWIN_EXTRA_SPECS \ { "darwin_crt1", DARWIN_CRT1_SPEC }, \ - { "darwin_dylib1", DARWIN_DYLIB1_SPEC }, \ - { "darwin_minversion", DARWIN_MINVERSION_SPEC }, + { "darwin_dylib1", DARWIN_DYLIB1_SPEC }, #define DARWIN_DYLIB1_SPEC \ "%:version-compare(!> 10.5 mmacosx-version-min= -ldylib1.o) \ @@ -916,7 +914,9 @@ extern void darwin_driver_init (unsigned int *,struct cl_decoded_option **); #define SUPPORTS_INIT_PRIORITY 0 /* When building cross-compilers (and native crosses) we shall default to - providing an osx-version-min of this unless overridden by the User. */ -#define DEF_MIN_OSX_VERSION "10.4" + providing an osx-version-min of this unless overridden by the User. + 10.5 is the only version that fully supports all our archs so that's the + fall-back default. */ +#define DEF_MIN_OSX_VERSION "10.5" #endif /* CONFIG_DARWIN_H */ diff --git a/gcc/config/darwin.opt b/gcc/config/darwin.opt index 5ab0e5c..eb1afe7 100644 --- a/gcc/config/darwin.opt +++ b/gcc/config/darwin.opt @@ -226,10 +226,9 @@ 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. Useful for setting the OS on which people -; usually debug. +; Init is never used. mmacosx-version-min= -Target Joined Report Var(darwin_macosx_version_min) Init("10.6") +Target Joined Report Var(darwin_macosx_version_min) Init(DEF_MIN_OSX_VERSION) The earliest MacOS X version on which this program will run mone-byte-bool diff --git a/gcc/config/darwin12.h b/gcc/config/darwin12.h index fdc1d0d..506364a 100644 --- a/gcc/config/darwin12.h +++ b/gcc/config/darwin12.h @@ -25,3 +25,6 @@ along with GCC; see the file COPYING3. If not see %:version-compare(>= 10.6 mmacosx-version-min= -lSystem) } } \ %{fno-pic|fno-PIC|fno-pie|fno-PIE|fapple-kext|mkernel|static|mdynamic-no-pic: \ %:version-compare(>= 10.7 mmacosx-version-min= -no_pie) } %G %L" + +#undef DEF_MIN_OSX_VERSION +#define DEF_MIN_OSX_VERSION "10.8" diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h index 6a2471a..2006a75 100644 --- a/gcc/config/i386/darwin.h +++ b/gcc/config/i386/darwin.h @@ -108,7 +108,6 @@ extern int darwin_emit_branch_islands; #undef CC1_SPEC #define CC1_SPEC "%(cc1_cpu) \ %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \ - %{!mmacosx-version-min=*:-mmacosx-version-min=%(darwin_minversion)} \ %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} " \ DARWIN_CC1_SPEC @@ -119,15 +118,6 @@ extern int darwin_emit_branch_islands; #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 \ - "%{!m64|fgnu-runtime:10.4; \ - ,objective-c|,objc-cpp-output:10.5; \ - ,objective-c-header:10.5; \ - ,objective-c++|,objective-c++-cpp-output:10.5; \ - ,objective-c++-header|,objc++-cpp-output:10.5; \ - :10.4}" - #undef ENDFILE_SPEC #define ENDFILE_SPEC \ "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h index 14d5477..82fcad2 100644 --- a/gcc/config/rs6000/darwin.h +++ b/gcc/config/rs6000/darwin.h @@ -93,7 +93,6 @@ extern int darwin_emit_branch_islands; %(cc1_cpu) \ %{g: %{!fno-eliminate-unused-debug-symbols: -feliminate-unused-debug-symbols }} \ %{static: %{Zdynamic: %e conflicting code gen style switches are used}}\ - %{!mmacosx-version-min=*:-mmacosx-version-min=%(darwin_minversion)} \ %{!mkernel:%{!static:%{!mdynamic-no-pic:-fPIC}}} \ %{faltivec:-maltivec -include altivec.h} %{fno-altivec:-mno-altivec} \ % 10.4 mmacosx-version-min= crt2.o%s)}" -/* Determine a minimum version based on compiler options. */ -#define DARWIN_MINVERSION_SPEC \ - "%{m64:%{fgnu-runtime:10.4; \ - ,objective-c|,objc-cpp-output:10.5; \ - ,objective-c-header:10.5; \ - ,objective-c++|,objective-c++-cpp-output:10.5; \ - ,objective-c++-header|,objc++-cpp-output:10.5; \ - :10.4}; \ - shared-libgcc:10.3; \ - :10.1}" - #undef SUBTARGET_EXTRA_SPECS #define SUBTARGET_EXTRA_SPECS \ DARWIN_EXTRA_SPECS \