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.
)
I'm not entirely sure what D.PrefixDirs represents so maybe Android doesn't need this either.
The behavior the NDK depends on is being able to find tools co-located with the Clang driver location. Aside from as, these are all LLVM tools (lld and co).
The sysroot is expected to be in $CLANG/../sysroot. All our headers, libraries (aside from libgcc/libatomic), and CRT objects are located there.
The clang driver install location is expected to also be a GCC install directory, so libgcc/libatomic are expected at $CLANG/../lib/gcc/$TRIPLE/$GCC_VERSION.
Typical usage for the NDK does not involve -gcc-toolchain or -B at all.
If I've understood correctly, your change can be applied to Android as well without breaking any of those behaviors. @srhines will need to comment on whether the Android platform build needs this, but aiui anyone depending on this behavior just needs to fix their build to use -gcc-toolchain where they were previously using -B.
Of course, I can't speak to what our users with custom build systems that don't follow our docs might be doing.