[Driver] Suppress GCC detection under -B

Authored by MaskRay on Mar 19 2021, 3:42 PM.


[Driver] Suppress GCC detection under -B

In GCC, if -B $prefix is specified, $prefix is used to find executable files and startup files.
$prefix/include is added as an include search directory.

Clang overloads -B with GCC installation detection semantics which make the
behavior less predictable (due to the "largest GCC version wins" rule) and
interact poorly with --gcc-toolchain (--gcc-toolchain can be overridden by -B).

  • clang++ foo.cpp detects GCC installation under /usr.
  • clang++ --gcc-toolchain=Inputs foo.cpp detects GCC installation under Inputs.
  • clang++ -BA --gcc-toolchain=B foo.cpp detects GCC installation under A and B and the larger version wins. With this patch, only B is used for detection.
  • clang++ -BA foo.cpp detects GCC installation under A and /usr, and the larger GCC version wins. With this patch A is not used for detection.

This patch changes -B to drop the GCC detection semantics. Its executable
searching semantics are preserved. --gcc-toolchain is the recommended option to
specify the GCC installation detection directory.

Note: Clang detects GCC installation in various target dependent directories.
$sysroot/usr (sysroot defaults to "") is a common directory used by most targets.
Such a directory is expected to contain something like lib{,32,64}/gcc{,-cross}/$triple.
Clang will then construct library/include paths from the directory.

Differential Revision: https://reviews.llvm.org/D97993


MaskRayMar 19 2021, 3:42 PM
Differential Revision
D97993: [Driver] Suppress GCC detection under -B
rGd8d5ef2e9d84: Revert "[lldb/PlatformPOSIX] Change LoadImage default to RTLD_LAZY"