aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2019-10-29 19:52:20 +0000
committerIain Sandoe <iain@sandoe.co.uk>2019-10-29 19:52:20 +0000
commit5c5dba805f5e95c001240d8e0905bf85e7214f8d (patch)
tree3827a8955f6aba39d60186641726a9d60d16fa2a
parent0c2c2a03d3a4cb9334d9d716ad580badc8e2a4ee (diff)
[Darwin] Pick up SDKROOT as the sysroot fallback.
For compatibility with xcrun and the behaviour of the clang driver, make use of the setting of the SDKROOT environment variable when it is available. This applies to both finding headers and libraries (i.e. it is also passed to ld64). Priority: 1. User's command-line specified --sysroot= or -isysroot. 2. The SDKROOT variable when set, and validated. 3. Any sysroot provided by --with-sysroot= configuration parameter. SDKROOT is checked thus: 1. Presence. 2. That it starts with / (i.e. 'absolute'). 3. That it is not / only (since that's the default). 4. That it is readable by the process executing the driver. This is pretty much the same rule set as used by the clang driver. NOTE: (3) might turn out to be overly restrictive in the case that we have configured with --with-sysroot= and then we want to run on a system with an installation of the headers/libraries in /. We can revisit this if that turns out to be an important use-case. So one can do: xcrun --sdk macosx /path/to/gcc .... and that provides the SDK path as the sysroot to GCC as expected. CAVEAT: An unfortunate effect of the fact that gcc (and g++) are executables in the Xcode installation, which are found ahead of any such named in the $PATH PATH=/path/to/gcc/install:$PATH xcrun --sdk macosx gcc .... does *not* work, instead that executes the clang from the xcode/commmand line tools installation. PATH=/path/to/gcc/install:$PATH xcrun --sdk macosx x64_64-apple-darwinXX-gcc ... does work as expected, however. 2019-10-29 Iain Sandoe <iain@sandoe.co.uk> Backport from mainline 2019-10-03 Iain Sandoe <iain@sandoe.co.uk> PR target/87243 * config/darwin-driver.c (maybe_get_sysroot_from_sdkroot): New. (darwin_driver_init): Use the sysroot provided by SDKROOT when that is available and the user has not set one on the command line. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@277582 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/config/darwin-driver.c44
2 files changed, 54 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 40d9b16dc48..9d215fd636f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,16 @@
2019-10-29 Iain Sandoe <iain@sandoe.co.uk>
Backport from mainline
+ 2019-10-03 Iain Sandoe <iain@sandoe.co.uk>
+
+ PR target/87243
+ * config/darwin-driver.c (maybe_get_sysroot_from_sdkroot): New.
+ (darwin_driver_init): Use the sysroot provided by SDKROOT when that
+ is available and the user has not set one on the command line.
+
+2019-10-29 Iain Sandoe <iain@sandoe.co.uk>
+
+ Backport from mainline
2019-07-03 Iain Sandoe <iain@sandoe.co.uk>
* config/darwin.h (DRIVER_SELF_SPECS): Remove the linker cases.
diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index 206bf5f0ea9..3ecb83bd1ae 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -216,6 +216,28 @@ darwin_default_min_version (void)
return new_flag;
}
+/* See if we can find the sysroot from the SDKROOT environment variable. */
+
+static const char *
+maybe_get_sysroot_from_sdkroot ()
+{
+ const char *maybe_sysroot = getenv ("SDKROOT");
+
+ /* We'll use the same rules as the clang driver, for compatibility.
+ 1) The path must be absolute
+ 2) Ignore "/", that is the default anyway and we do not want the
+ sysroot semantics to be applied to it.
+ 3) It must exist (actually, we'll check it's readable too). */
+
+ if (maybe_sysroot == NULL
+ || *maybe_sysroot != '/'
+ || strlen (maybe_sysroot) == 1
+ || access (maybe_sysroot, R_OK) == -1)
+ return NULL;
+
+ return xstrndup (maybe_sysroot, strlen (maybe_sysroot));
+}
+
/* Translate -filelist and -framework options in *DECODED_OPTIONS
(size *DECODED_OPTIONS_COUNT) to use -Xlinker so that they are
considered to be linker inputs in the case that no other inputs are
@@ -240,6 +262,7 @@ darwin_driver_init (unsigned int *decoded_options_count,
bool appendM64 = false;
const char *vers_string = NULL;
bool seen_version_min = false;
+ bool seen_sysroot_p = false;
for (i = 1; i < *decoded_options_count; i++)
{
@@ -320,6 +343,11 @@ darwin_driver_init (unsigned int *decoded_options_count,
--*decoded_options_count;
break;
+ case OPT__sysroot_:
+ case OPT_isysroot:
+ seen_sysroot_p = true;
+ break;
+
default:
break;
}
@@ -381,6 +409,22 @@ darwin_driver_init (unsigned int *decoded_options_count,
&(*decoded_options)[*decoded_options_count - 1]);
}
+ if (! seen_sysroot_p)
+ {
+ /* We will pick up an SDKROOT if we didn't specify a sysroot and treat
+ it as overriding any configure-time --with-sysroot. */
+ const char *sdkroot = maybe_get_sysroot_from_sdkroot ();
+ if (sdkroot)
+ {
+ ++*decoded_options_count;
+ *decoded_options = XRESIZEVEC (struct cl_decoded_option,
+ *decoded_options,
+ *decoded_options_count);
+ generate_option (OPT__sysroot_, sdkroot, 1, CL_DRIVER,
+ &(*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. */