[PATCH] D113021: [cmake] Make LLVM_ENABLE_LLD=ON work better on macOS
Nico Weber via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 2 10:35:32 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2d3953499c8c: [cmake] Make LLVM_ENABLE_LLD=ON work better on macOS (authored by thakis).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Changed prior to commit:
https://reviews.llvm.org/D113021?vs=384101&id=384159#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113021/new/
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.384159.patch
Type: text/x-patch
Size: 2866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211102/47bb6b65/attachment.bin>
More information about the cfe-commits
mailing list