[clang] [Driver] More flexible rules for loading default configs
authorMichał Górny <mgorny@gentoo.org>
Thu, 29 Sep 2022 18:58:35 +0000 (20:58 +0200)
committerMichał Górny <mgorny@gentoo.org>
Thu, 29 Sep 2022 18:58:59 +0000 (20:58 +0200)
commit063e17d8b04b41cd8bd174aebb6603eb1a76d34a
tree1d36713e90bfe0fd64d67a2af49c83bebd215234
parent062e515b701930a17e3d6b75b3a27cb4d9a6f984
[clang] [Driver] More flexible rules for loading default configs

Change the default config file loading logic to be more flexible
and more readable at the same time.  The new algorithm focuses on four
locations, in order:

1. <triple>-<mode>.cfg using real driver mode
2. <triple>-<mode>.cfg using executable suffix
3. <triple>.cfg + <mode>.cfg using real driver mode
4. <triple>.cfg + <mode>.cfg using executable suffix

This is meant to preserve reasonable level of compatibility with
the existing use, while introducing more flexibility and making the code
simpler.  Notably:

1. In this layout, the actual target triple is normally respected,
   and e.g. in `-m32` build the `x86_64-*` configs will never be used.

2. Both real driver mode (preferable) and executable suffix are
   supported.  This permits correctly handling calls with explicit
   `--driver-mode=` while at the same time preserving compatibility
   with the existing code.

3. The first two locations provide users with the ability to override
   configuration per specific target+mode combinaton, while the next two
   make it possible to independently specify per-target and per-mode
   configuration.

4. All config file locations are applicable independently of whether
   clang is started via a prefixed executable, or bare `clang`.

5. If the target is not explicitly specified and the executable prefix
   does not name a valid triple, it is used instead of the actual target
   triple for backwards compatibility.

This is particularly meant to address Gentoo's use case for
configuration files: to configure the default runtimes (i.e. `-rtlib=`,
`-stdlib=`) and `--gcc-install-dir=` for all the relevant drivers,
as well as to make it more convenient for users to override `-W` flags
to test compatibility with future versions of Clang easier.

Differential Revision: https://reviews.llvm.org/D134337
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst
clang/include/clang/Driver/Driver.h
clang/lib/Driver/Driver.cpp
clang/test/Driver/config-file3.c