[PATCH] D113021: [cmake] Make LLVM_ENABLE_LLD=ON work better on macOS
Nico Weber via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 2 07:40:04 PDT 2021
thakis created this revision.
thakis added a reviewer: hans.
Herald added a subscriber: mgorny.
thakis requested review of this revision.
Herald added a project: LLVM.
LLVM_LINKER_IS_LLD is now set with LLVM_ENABLE_LLD=ON (or LLVM_USER_LINKER=lld)
even on APPLE, and we pass -Wl,-order_file when LLVM_LINKER_IS_LLD on APPLE
too.
To make this straightforward, change the linker detection logic to go through
the compiler driver on APPLE like on the other platforms.
No intended behavior change if LLVM_ENABLE_LLD isn't set.
https://reviews.llvm.org/D113021
Files:
clang/tools/driver/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
Index: llvm/cmake/modules/AddLLVM.cmake
===================================================================
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -166,33 +166,43 @@
set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
endfunction(add_llvm_symbol_exports)
-if (NOT DEFINED LLVM_LINKER_DETECTED)
+if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
+ # Detect what linker we have here
+ if(APPLE)
+ # Linkers with ld64-compatible flags.
+ set(version_flag "-Wl,-v")
+ else()
+ # Linkers with BFD ld-compatible flags.
+ set(version_flag "-Wl,--version")
+ endif()
+
+ if( LLVM_USE_LINKER )
+ set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} ${version_flag})
+ else()
+ separate_arguments(flags UNIX_COMMAND "${CMAKE_EXE_LINKER_FLAGS}")
+ set(command ${CMAKE_C_COMPILER} ${flags} ${version_flag})
+ endif()
+ execute_process(
+ COMMAND ${command}
+ OUTPUT_VARIABLE stdout
+ ERROR_VARIABLE stderr
+ )
+
if(APPLE)
- execute_process(
- COMMAND "${CMAKE_LINKER}" -v
- ERROR_VARIABLE stderr
- )
if("${stderr}" MATCHES "PROJECT:ld64")
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
set(LLVM_LINKER_IS_LD64 YES CACHE INTERNAL "")
message(STATUS "Linker detection: ld64")
+ elseif("${stderr}" MATCHES "^LLD" OR
+ "${stdout}" MATCHES "^LLD")
+ set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
+ set(LLVM_LINKER_IS_LLD YES CACHE INTERNAL "")
+ message(STATUS "Linker detection: lld")
else()
set(LLVM_LINKER_DETECTED NO CACHE INTERNAL "")
message(STATUS "Linker detection: unknown")
endif()
- elseif(NOT WIN32)
- # Detect what linker we have here
- if( LLVM_USE_LINKER )
- set(command ${CMAKE_C_COMPILER} -fuse-ld=${LLVM_USE_LINKER} -Wl,--version)
- else()
- separate_arguments(flags UNIX_COMMAND "${CMAKE_EXE_LINKER_FLAGS}")
- set(command ${CMAKE_C_COMPILER} ${flags} -Wl,--version)
- endif()
- execute_process(
- COMMAND ${command}
- OUTPUT_VARIABLE stdout
- ERROR_VARIABLE stderr
- )
+ else()
if("${stdout}" MATCHES "^mold")
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
message(STATUS "Linker detection: mold")
Index: clang/tools/driver/CMakeLists.txt
===================================================================
--- clang/tools/driver/CMakeLists.txt
+++ clang/tools/driver/CMakeLists.txt
@@ -95,7 +95,7 @@
(LLVM_LINKER_IS_LD64 OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
include(LLVMCheckLinkerFlag)
- if (LLVM_LINKER_IS_LD64)
+ if (LLVM_LINKER_IS_LD64 OR (LLVM_LINKER_IS_LLD and APPLE))
set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}")
elseif (LLVM_LINKER_IS_GOLD)
set(LINKER_ORDER_FILE_OPTION "-Wl,--section-ordering-file,${CLANG_ORDER_FILE}")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113021.384101.patch
Type: text/x-patch
Size: 2867 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211102/91d2e86c/attachment.bin>
More information about the llvm-commits
mailing list