[PATCH] D91107: [Clang][Driver] Added the support for setting GCC toolchain via environment variable

Shilei Tian via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 15:58:45 PST 2020


tianshilei1992 created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Currently, GCC toolchain can only be set via the option `--gcc-toolchain`. On
many HPC clusters, like Summit, because of its old system, the default GCC is
4.8.5. Users usually use `module load gcc/$(version)` to load another GCC.
However, the module package manager can only set some environment variables like
`PATH`, it cannot control Clang's GCC toolchain. As a result, no matter which
GCC users are using, it always ends up with the system version. What's more,
sometimes it's not easy to pass the option to the build system.

I did talk to some LLVM users about this problem. Some of them thought LLVM
works purely w/o GCC, and many thought Clang can select the right GCC they are
setting. I also saw an "issue" on GitHub about failing to compile OpenMP source
code using LLVM after a patch that set default C++ version to C++14, and it is
actually because the user compiled LLVM with GCC 6.4.0, and then set `clang` and
`clang++` as the default compiler to compile OpenMP. Since the user was using a
cluster with CentOS 7 whose default GCC is 4.8.5, and GCC 4.8.5 does not fully
support C++14, the problem occurred.

This patch added the support for setting GCC toolchain via an environment
variable `GCC_TOOLCHAIN`. It will be read if `--gcc-toolchain` is not set. In
this way, as long as those package managers set the environment variable when
loading different versions of GCC, Clang can also pick up the right version.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91107

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1856,6 +1856,12 @@
   if (A)
     return A->getValue();
 
+  // If --gcc-toochain is not set, we then check the environment variable
+  // GCC_TOOLCHAIN because sometimes it is not easy to pass the option to the
+  // driver.
+  if (const char *GCCToolchainEnv = ::getenv("GCC_TOOLCHAIN"))
+    return GCCToolchainEnv;
+
   // If we have a SysRoot, ignore GCC_INSTALL_PREFIX.
   // GCC_INSTALL_PREFIX specifies the gcc installation for the default
   // sysroot and is likely not valid with a different sysroot.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91107.304006.patch
Type: text/x-patch
Size: 707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201109/5118608e/attachment.bin>


More information about the cfe-commits mailing list