This is needed when config.guess is removed (D109837) and
-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on is enabled.
LLVM_DEFAULT_TARGET_TRIPLE is recommended to be the Debian multiarch style
"x86_64-linux-gnu" (gcc -dumpmachine output). CMake will install runtime
libraries to lib/clang/14.0.0/x86_64-linux-gnu/, but clang --print-runtime-dir
detects lib/clang/14.0.0/x86_64-unknown-linux-gnu/ where
"x86_64-unknown-linux-gnu" is a normalized triple and fails to find the library.
To fix this, respect --target= (which defaults to LLVM_DEFAULT_TARGET_TRIPLE)
and a small set of GCC multilib style triple transformation (currently probably
just -m32 and -m64, otherwise *do no normalization*. I don't think we
support -mx32 or MIPS/RISC-V's fancy multilib combinations) to construct
the multiarch search path.
To this end, add UnnormalizedTriple to computeTargetTriple and add arch
transformation code. Then update getRuntimePath/getStdlibPath/addLibCxxIncludePaths
to use the unnormalized triple.
It would probably be nice to pass the unnormalized triple to getToolChain, but
currently it would result in numerous issues, because a unnormalized triple has
wrong OS/environment and can confuse driver code in many places.
Tested the following commands succeed.
-DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu /tmp/out/custom0/bin/clang++ --stdlib=libc++ -fsanitize=address a.cc /tmp/out/custom0/bin/clang++ --target=x86_64-linux-gnu --stdlib=libc++ -fsanitize=address a.cc # this is a hack /tmp/out/custom0/bin/clang++ --target=x86_64-unknown-linux-gnu --stdlib=libc++ -fsanitize=address a.cc -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-linux-gnu /tmp/out/custom1/bin/clang++ --stdlib=libc++ -fsanitize=address a.cc /tmp/out/custom1/bin/clang++ --target=x86_64-linux-gnu --stdlib=libc++ -fsanitize=address a.cc
For Debian, using --target=x86_linux-gnu with -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu is a hack.
The preferred fix is to default LLVM_DEFAULT_TARGET_TRIPLE to x86_64-linux-gnu:
see https://discourse.llvm.org/t/rfc-fix-loose-behaviors-of-clang-target/60272
I find the name UnnormalizedTriple a bit confusing as it may imply that there's some "un-normalization" process involved. I'd prefer using a TargetTriple to refer to "triple given by the user (via the --target= option)" and NormalizedTriple as "normalized triple".