[cmake] Fix LLD detection when compiler ABI detection fails (#248417)
#246222 and #247156 replaced `CMAKE_LINKER` matching in
HandleLLVMOptions.cmake with checks on
`CMAKE_C_COMPILER_LINKER_{ID,FRONTEND_VARIANT}`.
Those CMake variables are only populated when compiler ABI detection
succeeds. During cross-compilation of Windows runtimes (e.g. aarch64 or
i386 on an x86_64 host with `LLVM_WINSYSROOT`), ABI detection fails
because `/winsysroot:` is only added later in HandleLLVMOptions.cmake,
leaving `CMAKE_C_COMPILER_LINKER_*` empty. As a result,
`clang_rt.profile` was silently built without hardware atomics:
- `LINKER_IS_LLD_LINK` evaluated to FALSE even though
`LLVMExternalProjectUtils.cmake` passed `-DCMAKE_LINKER=.../lld-link`.
- `/winsysroot:` was omitted from linker flags.
- Subsequent `compiler-rt` `try_compile` checks failed (including
`COMPILER_RT_TARGET_HAS_ATOMICS`), falling back to non-atomic
`lprofBoolCmpXchg` / `lprofPtrFetchAdd`.
Fall back to checking the basename of `CMAKE_LINKER` when
`CMAKE_C_COMPILER_LINKER_ID` is empty. The fallback is intentionally
restored for both `LINKER_IS_LLD` and `LINKER_IS_LLD_LINK` (matching
pre-#246222 behavior, including `CLANG_CL AND LINKER_IS_LLD`), while
keeping `CMAKE_C_COMPILER_LINKER_*` authoritative whenever ABI detection
succeeds.
Note: `AddLLVM.cmake` has a similar regression on non-Windows
cross-builds (printing "Linker detection: unknown"), left for a
follow-up.
Tested: cross-compiled `compiler-rt` `clang_rt.profile-{aarch64,i386}`
for `aarch64-pc-windows-msvc` and `i386-pc-windows-msvc` with
`LLVM_WINSYSROOT` before and after this patch. Both targets went from
`COMPILER_RT_TARGET_HAS_ATOMICS - Failed` (with `lprofBoolCmpXchg` /
`lprofPtrFetchAdd` in the built `.lib`) to `Success` (no non-atomic
fallbacks).
Co-authored-by: Victor Hugo Vianna Silva <victorvianna@google.com>