Author: Fangrui Song Date: 2022-05-18T12:40:27-07:00 New Revision: d8166e1900c05429abc726d379bc33281c4c98e4
URL: https://github.com/llvm/llvm-project/commit/d8166e1900c05429abc726d379bc33281c4c98e4 DIFF: https://github.com/llvm/llvm-project/commit/d8166e1900c05429abc726d379bc33281c4c98e4.diff LOG: [Driver] Refactor /opt/rh detection Check /opt/rh first to avoid `/opt/rh/*` newfstatat/etc calls on other distributions. Added: Modified: clang/lib/Driver/ToolChains/Gnu.cpp Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 003a97e2c3ebb..b73634bad631a 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -2147,9 +2147,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( return; } - // Non-Solaris is much simpler - most systems just go with "/usr". - if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux) { - // Yet, still look for RHEL/CentOS devtoolsets and gcc-toolsets. + // For Linux, if --sysroot is not specified, look for RHEL/CentOS devtoolsets + // and gcc-toolsets. + if (SysRoot.empty() && TargetTriple.getOS() == llvm::Triple::Linux && + D.getVFS().exists("/opt/rh")) { Prefixes.push_back("/opt/rh/gcc-toolset-11/root/usr"); Prefixes.push_back("/opt/rh/gcc-toolset-10/root/usr"); Prefixes.push_back("/opt/rh/devtoolset-11/root/usr"); @@ -2162,6 +2163,8 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( Prefixes.push_back("/opt/rh/devtoolset-3/root/usr"); Prefixes.push_back("/opt/rh/devtoolset-2/root/usr"); } + + // Fall back to /usr which is used by most non-Solaris systems. Prefixes.push_back(SysRoot.str() + "/usr"); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits