Skip to content

Commit 0016216

Browse files
authored
CompilerRT: Normalize COMPILER_RT_DEFAULT_TARGET_TRIPLE (#88407)
If LLVM is configured with -DLLVM_DEFAULT_TARGET_TRIPLE, and the argument is not normalized, such as Debian-style vendor-less triple, clang will try to find libclang_rt in lib/<normalized_triple>, while libclang_rt is placed into lib/<triple_arg>. Let's also place libclang_rt into lib/<normalized_triple>.
1 parent d5c654b commit 0016216

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

compiler-rt/cmake/Modules/CompilerRTUtils.cmake

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,22 @@ macro(construct_compiler_rt_default_triple)
362362
message(FATAL_ERROR "CMAKE_C_COMPILER_TARGET must also be set when COMPILER_RT_DEFAULT_TARGET_ONLY is ON")
363363
endif()
364364
message(STATUS "cmake c compiler target: ${CMAKE_C_COMPILER_TARGET}")
365-
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${CMAKE_C_COMPILER_TARGET})
365+
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
366+
execute_process(COMMAND ${CMAKE_C_COMPILER} --target=${CMAKE_C_COMPILER_TARGET} -print-effective-triple
367+
OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE
368+
OUTPUT_STRIP_TRAILING_WHITESPACE)
369+
else()
370+
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${CMAKE_C_COMPILER_TARGET})
371+
endif()
366372
else()
367-
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${LLVM_TARGET_TRIPLE} CACHE STRING
368-
"Default triple for which compiler-rt runtimes will be built.")
373+
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
374+
execute_process(COMMAND ${CMAKE_C_COMPILER} --target=${LLVM_TARGET_TRIPLE} -print-effective-triple
375+
OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE
376+
OUTPUT_STRIP_TRAILING_WHITESPACE)
377+
else()
378+
set(COMPILER_RT_DEFAULT_TARGET_TRIPLE ${LLVM_TARGET_TRIPLE} CACHE STRING
379+
"Default triple for which compiler-rt runtimes will be built.")
380+
endif()
369381
endif()
370382

371383
string(REPLACE "-" ";" LLVM_TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE})

0 commit comments

Comments
 (0)