From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:59871) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZLzP-0006fq-UL for guix-patches@gnu.org; Mon, 25 Nov 2019 16:33:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iZLzN-0003c0-0r for guix-patches@gnu.org; Mon, 25 Nov 2019 16:33:47 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:43817) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iZLzM-0003bg-Q4 for guix-patches@gnu.org; Mon, 25 Nov 2019 16:33:44 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iZLzM-0002Xy-NO for guix-patches@gnu.org; Mon, 25 Nov 2019 16:33:44 -0500 Subject: [bug#38376] [PATCH] gnu: clang: Fix search path detection with --sysroot. Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:34960) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZImA-0001A0-9o for guix-patches@gnu.org; Mon, 25 Nov 2019 13:07:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iZIm7-0006HO-Bc for guix-patches@gnu.org; Mon, 25 Nov 2019 13:07:53 -0500 Received: from mail-40132.protonmail.ch ([185.70.40.132]:35321) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iZIlw-0006BC-KI for guix-patches@gnu.org; Mon, 25 Nov 2019 13:07:50 -0500 Date: Mon, 25 Nov 2019 18:01:48 +0000 From: Carl Dong Message-ID: <20191125180144.1060289-1-contact@carldong.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Carl Dong Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 38376@debbugs.gnu.org Cc: Carl Dong Prior to this commit, we had 1. Patched out a lot of search path detection in clang's codebase which didn't make sense in Guix 2. Used -DC_INCLUDE_DIRS=3D to point clang to our libc, which, as a side effect, causes the search path detection code in clang to return early, and skip some search path detection This was fine when running clang normally, but when a user supplies clang with --sysroot, clang _should_ do the search path detection. This commit fixes runing clang with --sysroot. More details included as comments in the gnu/packages/patches/clang-*-libc-search-path.patch files. * gnu/packages/patches/clang-3.5-libc-search-path.patch: Restore search path detection code relative to $SYSROOT. Add @C_EXTRA_INCLUDE_DIRS@, a C_INCLUDE_DIRS replacement which does not return early. * gnu/packages/patches/clang-3.8-libc-search-path.patch: Same as above. * gnu/packages/patches/clang-6.0-libc-search-path.patch: Same as above. * gnu/packages/patches/clang-7.0-libc-search-path.patch: Same as above. * gnu/packages/llvm.scm: Substitute @C_EXTRA_INCLUDE_DIRS@ instead of using -DC_INCLUDE_DIRS=3D. --- gnu/packages/llvm.scm | 13 ++- .../patches/clang-3.5-libc-search-path.patch | 74 ++++++++------- .../patches/clang-3.8-libc-search-path.patch | 70 ++++++++------- .../patches/clang-6.0-libc-search-path.patch | 77 ++++++++-------- .../patches/clang-7.0-libc-search-path.patch | 89 +++++++++---------- 5 files changed, 169 insertions(+), 154 deletions(-) diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm index 082e6e96ca..383180e140 100644 --- a/gnu/packages/llvm.scm +++ b/gnu/packages/llvm.scm @@ -190,12 +190,7 @@ compiler. In LLVM this library is called \"compiler-r= t\".") =20 ;; Find libgcc_s, crtbegin.o, and crtend.o. (string-append "-DGCC_INSTALL_PREFIX=3D" - (assoc-ref %build-inputs "gcc-lib")) - - ;; Use a sane default include directory. - (string-append "-DC_INCLUDE_DIRS=3D" - (assoc-ref %build-inputs "libc") - "/include")) + (assoc-ref %build-inputs "gcc-lib"))) =20 ;; Don't use '-g' during the build to save space. #:build-type "Release" @@ -207,6 +202,7 @@ compiler. In LLVM this library is called \"compiler-rt= \".") (let ((libc (assoc-ref inputs "libc")) (compiler-rt (assoc-ref inputs "clang-runtime")= ) (gcc (assoc-ref inputs "gcc")) + (kernel-headers (assoc-ref inputs "kernel-heade= rs")) (version (string->number ,(version-major (package-version clang-runtim= e))))) @@ -232,7 +228,10 @@ compiler. In LLVM this library is called \"compiler-r= t\".") ;; Make sure libc's libdir is on the search pa= th, to ;; allow crt1.o & co. to be found. (("@GLIBC_LIBDIR@") - (string-append libc "/lib")))) + (string-append libc "/lib")) + (("@C_EXTRA_INCLUDE_DIRS@") + (string-append libc "/include" ":" + kernel-headers "/include")))) (else (substitute* "lib/Driver/Tools.cpp" ;; Patch the 'getLinuxDynamicLinker' function = so that diff --git a/gnu/packages/patches/clang-3.5-libc-search-path.patch b/gnu/pa= ckages/patches/clang-3.5-libc-search-path.patch index 50e4480239..54fb9be7d8 100644 --- a/gnu/packages/patches/clang-3.5-libc-search-path.patch +++ b/gnu/packages/patches/clang-3.5-libc-search-path.patch @@ -8,7 +8,7 @@ to make sure Clang also works on non-GuixSD systems. =20 --- cfe-3.6.0.src/lib/Driver/ToolChains.cpp=092015-02-18 22:03:07.00000000= 0 +0100 +++ cfe-3.6.0.src/lib/Driver/ToolChains.cpp=092015-06-19 16:37:20.45970104= 4 +0200 -@@ -2931,6 +2931,9 @@ Linux::Linux(const Driver &D, const llvm +@@ -3040,6 +3040,9 @@ =20 Linker =3D GetLinkerPath(); =20 @@ -18,7 +18,7 @@ to make sure Clang also works on non-GuixSD systems. Distro Distro =3D DetectDistro(Arch); =20 if (IsOpenSUSE(Distro) || IsUbuntu(Distro)) { -@@ -2973,6 +2976,7 @@ Linux::Linux(const Driver &D, const llvm +@@ -3082,6 +3085,7 @@ =20 if (IsOpenSUSE(Distro)) ExtraOpts.push_back("--enable-new-dtags"); @@ -26,41 +26,49 @@ to make sure Clang also works on non-GuixSD systems. =20 // The selection of paths to try here is designed to match the patterns= which // the GCC driver itself uses, as this is part of the GCC-compatible dr= iver. -@@ -3043,14 +3047,12 @@ Linux::Linux(const Driver &D, const llvm - addPathIfExists(D.Dir + "/../" + OSLibDir, Paths); - } +@@ -3194,6 +3198,10 @@ =20 -- addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths); -- addPathIfExists(SysRoot + "/lib/../" + OSLibDir, Paths); -- addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths); -- addPathIfExists(SysRoot + "/usr/lib/../" + OSLibDir, Paths); -- - // Try walking via the GCC triple path in case of biarch or multiarch G= CC - // installations with strange symlinks. - if (GCCInstallation.isValid()) { -+ // The following code would end up adding things like -+ // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path= . -+#if 0 - addPathIfExists(SysRoot + "/usr/lib/" + GCCInstallation.getTriple().s= tr() + - "/../../" + OSLibDir, Paths); -=20 -@@ -3060,6 +3062,7 @@ Linux::Linux(const Driver &D, const llvm - addPathIfExists(GCCInstallation.getInstallPath() + - BiarchSibling.gccSuffix(), Paths); - } -+#endif -=20 - // See comments above on the multilib variant for details of why this= is - // included even from outside the sysroot. -@@ -3083,8 +3086,9 @@ Linux::Linux(const Driver &D, const llvm - if (StringRef(D.Dir).startswith(SysRoot)) - addPathIfExists(D.Dir + "/../lib", Paths); -=20 -- addPathIfExists(SysRoot + "/lib", Paths); -- addPathIfExists(SysRoot + "/usr/lib", Paths); + addPathIfExists(SysRoot + "/lib", Paths); + addPathIfExists(SysRoot + "/usr/lib", Paths); ++ + // Add libc's lib/ directory to the search path, so that crt1.o, crti.o= , + // and friends can be found. + addPathIfExists("@GLIBC_LIBDIR@", Paths); } =20 bool Linux::HasNativeLLVMSupport() const { +@@ -3384,6 +3392,34 @@ + addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); +=20 + addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); ++ ++ // Check for configure-time "extra" C include directories. When constru= cting a ++ // toolchain, @C_EXTRA_INCLUDE_DIRS@ should be replaced with something = like a ++ // colon-separated string of the include dirs of libc and kernel header= s. ++ // ++ // The reason why we use this mechanism instead of C_INCLUDE_DIRS above= is ++ // because when a user supplies clang with --sysroot, the normal expect= ation ++ // is that clang will detect and add the proper $SYSROOT/$MULTIARCHINCL= , ++ // $SYSROOT/include, and $SYSROOT/usr/include to its list of search pat= hs. ++ // However, if C_INCLUDE_DIRS is not empty, this function will return e= arly ++ // and not attempt to add the aforementioned search paths, which is not ++ // desirable. ++ // ++ // By adding our configure-time "extra" C include directories here, aft= er ++ // we've added $SYSROOT/include and $SYSROOT/usr/include, we make sure = that IF ++ // --sysroot is supplied on the command line, we pick up the expected s= earch ++ // paths in the $SYSROOT, and that they come before our configure-time = "extra" ++ // C include directories. ++ StringRef CExtraIncludeDirs("@C_EXTRA_INCLUDE_DIRS@"); ++ if (CExtraIncludeDirs !=3D "") { ++ SmallVector dirs; ++ CExtraIncludeDirs.split(dirs, ":"); ++ for (StringRef dir : dirs) { ++ StringRef Prefix =3D ++ llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""= ; ++ addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); ++ } ++ } + } +=20 + /// \brief Helper to add the variant paths of a libstdc++ installation. diff --git a/gnu/packages/patches/clang-3.8-libc-search-path.patch b/gnu/pa= ckages/patches/clang-3.8-libc-search-path.patch index 0f7d0a4add..243d167755 100644 --- a/gnu/packages/patches/clang-3.8-libc-search-path.patch +++ b/gnu/packages/patches/clang-3.8-libc-search-path.patch @@ -29,41 +29,49 @@ changes in clang 3.8. =20 // The selection of paths to try here is designed to match the patterns= which // the GCC driver itself uses, as this is part of the GCC-compatible dr= iver. -@@ -3771,14 +3775,12 @@ - addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); - } +@@ -3817,6 +3821,10 @@ =20 -- addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); -- addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); -- addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); -- addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); -- - // Try walking via the GCC triple path in case of biarch or multiarch G= CC - // installations with strange symlinks. - if (GCCInstallation.isValid()) { -+ // The following code would end up adding things like -+ // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path= . -+#if 0 - addPathIfExists(D, - SysRoot + "/usr/lib/" + GCCInstallation.getTriple().s= tr() + - "/../../" + OSLibDir, -@@ -3791,6 +3793,7 @@ - BiarchSibling.gccSuffix(), - Paths); - } -+#endif -=20 - // See comments above on the multilib variant for details of why this= is - // included even from outside the sysroot. -@@ -3815,8 +3818,9 @@ - if (StringRef(D.Dir).startswith(SysRoot)) - addPathIfExists(D, D.Dir + "/../lib", Paths); -=20 -- addPathIfExists(D, SysRoot + "/lib", Paths); -- addPathIfExists(D, SysRoot + "/usr/lib", Paths); + addPathIfExists(D, SysRoot + "/lib", Paths); + addPathIfExists(D, SysRoot + "/usr/lib", Paths); ++ + // Add libc's lib/ directory to the search path, so that crt1.o, crti.o= , + // and friends can be found. + addPathIfExists(D, "@GLIBC_LIBDIR@", Paths); } =20 bool Linux::HasNativeLLVMSupport() const { return true; } +@@ -4026,6 +4034,34 @@ + addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); +=20 + addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); ++ ++ // Check for configure-time "extra" C include directories. When constru= cting a ++ // toolchain, @C_EXTRA_INCLUDE_DIRS@ should be replaced with something = like a ++ // colon-separated string of the include dirs of libc and kernel header= s. ++ // ++ // The reason why we use this mechanism instead of C_INCLUDE_DIRS above= is ++ // because when a user supplies clang with --sysroot, the normal expect= ation ++ // is that clang will detect and add the proper $SYSROOT/$MULTIARCHINCL= , ++ // $SYSROOT/include, and $SYSROOT/usr/include to its list of search pat= hs. ++ // However, if C_INCLUDE_DIRS is not empty, this function will return e= arly ++ // and not attempt to add the aforementioned search paths, which is not ++ // desirable. ++ // ++ // By adding our configure-time "extra" C include directories here, aft= er ++ // we've added $SYSROOT/include and $SYSROOT/usr/include, we make sure = that IF ++ // --sysroot is supplied on the command line, we pick up the expected s= earch ++ // paths in the $SYSROOT, and that they come before our configure-time = "extra" ++ // C include directories. ++ StringRef CExtraIncludeDirs("@C_EXTRA_INCLUDE_DIRS@"); ++ if (CExtraIncludeDirs !=3D "") { ++ SmallVector dirs; ++ CExtraIncludeDirs.split(dirs, ":"); ++ for (StringRef dir : dirs) { ++ StringRef Prefix =3D ++ llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""= ; ++ addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); ++ } ++ } + } +=20 +=20 diff --git a/gnu/packages/patches/clang-6.0-libc-search-path.patch b/gnu/pa= ckages/patches/clang-6.0-libc-search-path.patch index a62e8063c2..d80c798467 100644 --- a/gnu/packages/patches/clang-6.0-libc-search-path.patch +++ b/gnu/packages/patches/clang-6.0-libc-search-path.patch @@ -8,18 +8,17 @@ to make sure Clang also works on non-GuixSD systems. =20 --- cfe-6.0.0.src/lib/Driver/ToolChains/Linux.cpp +++ cfe-6.0.0.src/lib/Driver/ToolChains/Linux.cpp -@@ -207,7 +207,9 @@ - PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + +@@ -208,6 +208,9 @@ GCCInstallation.getTriple().str() + "/bin") .str()); -- +=20 + // Comment out the distro-specific tweaks so that they don't bite when + // using Guix on a foreign distro. +#if 0 Distro Distro(D.getVFS()); =20 if (Distro.IsAlpineLinux()) { -@@ -255,6 +257,7 @@ +@@ -255,6 +258,7 @@ =20 if (IsAndroid || Distro.IsOpenSUSE()) ExtraOpts.push_back("--enable-new-dtags"); @@ -27,41 +26,49 @@ to make sure Clang also works on non-GuixSD systems. =20 // The selection of paths to try here is designed to match the patterns= which // the GCC driver itself uses, as this is part of the GCC-compatible dr= iver. -@@ -329,14 +332,12 @@ - addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths); - } -=20 -- addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); -- addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); -- addPathIfExists(D, SysRoot + "/usr/lib/" + MultiarchTriple, Paths); -- addPathIfExists(D, SysRoot + "/usr/lib/../" + OSLibDir, Paths); -- - // Try walking via the GCC triple path in case of biarch or multiarch G= CC - // installations with strange symlinks. - if (GCCInstallation.isValid()) { -+ // The following code would end up adding things like -+ // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path= . -+#if 0 - addPathIfExists(D, - SysRoot + "/usr/lib/" + GCCInstallation.getTriple().s= tr() + - "/../../" + OSLibDir, -@@ -349,6 +350,7 @@ - BiarchSibling.gccSuffix(), - Paths); - } -+#endif +@@ -375,6 +379,10 @@ =20 - // See comments above on the multilib variant for details of why this= is - // included even from outside the sysroot. -@@ -373,8 +375,9 @@ - if (StringRef(D.Dir).startswith(SysRoot)) - addPathIfExists(D, D.Dir + "/../lib", Paths); -=20 -- addPathIfExists(D, SysRoot + "/lib", Paths); -- addPathIfExists(D, SysRoot + "/usr/lib", Paths); + addPathIfExists(D, SysRoot + "/lib", Paths); + addPathIfExists(D, SysRoot + "/usr/lib", Paths); ++ + // Add libc's lib/ directory to the search path, so that crt1.o, crti.o= , + // and friends can be found. + addPathIfExists(D, "@GLIBC_LIBDIR@", Paths); } =20 bool Linux::HasNativeLLVMSupport() const { return true; } +@@ -710,6 +718,34 @@ + addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); +=20 + addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); ++ ++ // Check for configure-time "extra" C include directories. When constru= cting a ++ // toolchain, @C_EXTRA_INCLUDE_DIRS@ should be replaced with something = like a ++ // colon-separated string of the include dirs of libc and kernel header= s. ++ // ++ // The reason why we use this mechanism instead of C_INCLUDE_DIRS above= is ++ // because when a user supplies clang with --sysroot, the normal expect= ation ++ // is that clang will detect and add the proper $SYSROOT/$MULTIARCHINCL= , ++ // $SYSROOT/include, and $SYSROOT/usr/include to its list of search pat= hs. ++ // However, if C_INCLUDE_DIRS is not empty, this function will return e= arly ++ // and not attempt to add the aforementioned search paths, which is not ++ // desirable. ++ // ++ // By adding our configure-time "extra" C include directories here, aft= er ++ // we've added $SYSROOT/include and $SYSROOT/usr/include, we make sure = that IF ++ // --sysroot is supplied on the command line, we pick up the expected s= earch ++ // paths in the $SYSROOT, and that they come before our configure-time = "extra" ++ // C include directories. ++ StringRef CExtraIncludeDirs("@C_EXTRA_INCLUDE_DIRS@"); ++ if (CExtraIncludeDirs !=3D "") { ++ SmallVector dirs; ++ CExtraIncludeDirs.split(dirs, ":"); ++ for (StringRef dir : dirs) { ++ StringRef Prefix =3D ++ llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""= ; ++ addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); ++ } ++ } + } +=20 + static std::string DetectLibcxxIncludePath(StringRef base) { diff --git a/gnu/packages/patches/clang-7.0-libc-search-path.patch b/gnu/pa= ckages/patches/clang-7.0-libc-search-path.patch index 07ff8c90bd..445b5d17ac 100644 --- a/gnu/packages/patches/clang-7.0-libc-search-path.patch +++ b/gnu/packages/patches/clang-7.0-libc-search-path.patch @@ -8,7 +8,7 @@ to make sure Clang also works on non-GuixSD systems. =20 --- a/lib/Driver/ToolChains/Linux.cpp +++ b/lib/Driver/ToolChains/Linux.cpp -@@ -225,7 +225,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Trip= le, const ArgList &Args) +@@ -225,7 +225,9 @@ PPaths.push_back(Twine(GCCInstallation.getParentLibPath() + "/../" + GCCInstallation.getTriple().str() + "/bin") .str()); @@ -19,7 +19,7 @@ to make sure Clang also works on non-GuixSD systems. Distro Distro(D.getVFS()); =20 if (Distro.IsAlpineLinux()) { -@@ -284,6 +286,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Trip= le, const ArgList &Args) +@@ -284,6 +286,7 @@ =20 if (IsAndroid || Distro.IsOpenSUSE()) ExtraOpts.push_back("--enable-new-dtags"); @@ -27,56 +27,49 @@ to make sure Clang also works on non-GuixSD systems. =20 // The selection of paths to try here is designed to match the patterns= which // the GCC driver itself uses, as this is part of the GCC-compatible dr= iver. -@@ -342,7 +345,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Trip= le, const ArgList &Args) - // the cross. Note that GCC does include some of these directories in= some - // configurations but this seems somewhere between questionable and s= imply - // a bug. -- if (StringRef(LibPath).startswith(SysRoot)) { -+ if (0) { - addPathIfExists(D, LibPath + "/" + MultiarchTriple, Paths); - addPathIfExists(D, LibPath + "/../" + OSLibDir, Paths); - } -@@ -361,6 +364,8 @@ Linux::Linux(const Driver &D, const llvm::Triple &Trip= le, const ArgList &Args) - addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths); - addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths); +@@ -431,6 +434,10 @@ =20 -+ // This requires the commented distro tweaks above. -+#if 0 - if (IsAndroid) { - // Android sysroots contain a library directory for each supported OS - // version as well as some unversioned libraries in the usual multiar= ch -@@ -389,10 +394,14 @@ Linux::Linux(const Driver &D, const llvm::Triple &Tr= iple, const ArgList &Args) - addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths); - addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Path= s); - } -+#endif -=20 - // Try walking via the GCC triple path in case of biarch or multiarch G= CC - // installations with strange symlinks. - if (GCCInstallation.isValid()) { -+ // The following code would end up adding things like -+ // "/usr/lib/x86_64-unknown-linux-gnu/../../lib64" to the search path= . -+#if 0 - addPathIfExists(D, - SysRoot + "/usr/lib/" + GCCInstallation.getTriple().s= tr() + - "/../../" + OSLibDir, -@@ -405,6 +414,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Trip= le, const ArgList &Args) - BiarchSibling.gccSuffix(), - Paths); - } -+#endif -=20 - // See comments above on the multilib variant for details of why this= is - // included even from outside the sysroot. -@@ -429,8 +439,9 @@ Linux::Linux(const Driver &D, const llvm::Triple &Trip= le, const ArgList &Args) - if (StringRef(D.Dir).startswith(SysRoot)) - addPathIfExists(D, D.Dir + "/../lib", Paths); -=20 -- addPathIfExists(D, SysRoot + "/lib", Paths); -- addPathIfExists(D, SysRoot + "/usr/lib", Paths); + addPathIfExists(D, SysRoot + "/lib", Paths); + addPathIfExists(D, SysRoot + "/usr/lib", Paths); ++ + // Add libc's lib/ directory to the search path, so that crt1.o, crti.o= , + // and friends can be found. + addPathIfExists(D, "@GLIBC_LIBDIR@", Paths); } =20 bool Linux::HasNativeLLVMSupport() const { return true; } +@@ -794,6 +801,34 @@ + addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/include"); +=20 + addExternCSystemInclude(DriverArgs, CC1Args, SysRoot + "/usr/include"); ++ ++ // Check for configure-time "extra" C include directories. When constru= cting a ++ // toolchain, @C_EXTRA_INCLUDE_DIRS@ should be replaced with something = like a ++ // colon-separated string of the include dirs of libc and kernel header= s. ++ // ++ // The reason why we use this mechanism instead of C_INCLUDE_DIRS above= is ++ // because when a user supplies clang with --sysroot, the normal expect= ation ++ // is that clang will detect and add the proper $SYSROOT/$MULTIARCHINCL= , ++ // $SYSROOT/include, and $SYSROOT/usr/include to its list of search pat= hs. ++ // However, if C_INCLUDE_DIRS is not empty, this function will return e= arly ++ // and not attempt to add the aforementioned search paths, which is not ++ // desirable. ++ // ++ // By adding our configure-time "extra" C include directories here, aft= er ++ // we've added $SYSROOT/include and $SYSROOT/usr/include, we make sure = that IF ++ // --sysroot is supplied on the command line, we pick up the expected s= earch ++ // paths in the $SYSROOT, and that they come before our configure-time = "extra" ++ // C include directories. ++ StringRef CExtraIncludeDirs("@C_EXTRA_INCLUDE_DIRS@"); ++ if (CExtraIncludeDirs !=3D "") { ++ SmallVector dirs; ++ CExtraIncludeDirs.split(dirs, ":"); ++ for (StringRef dir : dirs) { ++ StringRef Prefix =3D ++ llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : ""= ; ++ addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir); ++ } ++ } + } +=20 + static std::string DetectLibcxxIncludePath(StringRef base) { --=20 2.24.0