Stop the build if the linker produces an error code. Otherwise, the numbers in
the linker's error message can be misinterpreted as a linker version number, the
build completes successfully, and the resulting compiler doesn't work because
the supposed linker version number is invalid.

https://github.com/llvm/llvm-project/issues/186194
--- a/tools/clang/CMakeLists.txt
+++ b/tools/clang/CMakeLists.txt
@@ -386,9 +386,9 @@
 if (APPLE)
   set(LD_V_OUTPUT)
   execute_process(
-    COMMAND sh -c "${CMAKE_LINKER} -v 2>&1 | head -1"
+    COMMAND "${CMAKE_LINKER}" -v
     RESULT_VARIABLE HAD_ERROR
-    OUTPUT_VARIABLE LD_V_OUTPUT
+    ERROR_VARIABLE LD_V_OUTPUT
   )
   if (NOT HAD_ERROR)
     if ("${LD_V_OUTPUT}" MATCHES ".*ld64-([0-9.]+).*")
