This is an archive of the discontinued LLVM Phabricator instance.

[Clang][Driver] Added the support for setting GCC toolchain via environment variable
AbandonedPublic

Authored by tianshilei1992 on Nov 9 2020, 3:58 PM.

Details

Reviewers
jdoerfert
Summary

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.

Diff Detail

Event Timeline

tianshilei1992 created this revision.Nov 9 2020, 3:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 9 2020, 3:58 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
tianshilei1992 requested review of this revision.Nov 9 2020, 3:58 PM
tstellar added a subscriber: tstellar.

This code could be improved, but I don't think adding a specific environment variable for this a good solution. You can use the existing CCC_OVERRIDE_OPTIONS to get the same effect. e.g. CCC_OVERRIDE_OPTIONS=^--gcc-toolchain=/path/to/gcc

More documentation can be found here: https://github.com/llvm-mirror/clang/blob/master/tools/driver/driver.cpp#L75

tianshilei1992 abandoned this revision.Nov 9 2020, 6:42 PM

This code could be improved, but I don't think adding a specific environment variable for this a good solution. You can use the existing CCC_OVERRIDE_OPTIONS to get the same effect. e.g. CCC_OVERRIDE_OPTIONS=^--gcc-toolchain=/path/to/gcc

More documentation can be found here: https://github.com/llvm-mirror/clang/blob/master/tools/driver/driver.cpp#L75

Thanks for the tip, Tom! It really helps. This env is too obscure…