https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87243
--- Comment #12 from Iain Sandoe <iains at gcc dot gnu.org> --- Author: iains Date: Sun Oct 20 16:43:57 2019 New Revision: 277213 URL: https://gcc.gnu.org/viewcvs?rev=277213&root=gcc&view=rev Log: [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. gcc/ 2019-10-20 Iain Sandoe <i...@sandoe.co.uk> Backport from mainline 2019-10-03 Iain Sandoe <i...@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. Modified: branches/gcc-8-branch/gcc/ChangeLog branches/gcc-8-branch/gcc/config/darwin-driver.c