From 8afde59054a6ceb214ec8b792f2e49f38ea3da52 Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Mon, 21 Apr 2025 10:56:36 +0200 Subject: [PATCH] macOS: Default to modern linker on x64 This patch changes the default macOS x64 linker from the slower legacy "classic" linker, to the much faster default modern macOS linker. A new CMake option `WITH_LEGACY_MACOS_X64_LINKER` was also introduced to use the old linker, set to OFF by default. As an example from testing on an Intel Macbook, this makes linking time go from 3min25s to 10s after this change. The reason why the legacy linker was enforced on x64 in the first place was to silence "platform load command not found" warnings during linking. Since this behavior is still desired on the BuildBot, the `WITH_LEGACY_MACOS_X64_LINKER` option is enforced in the BuildBot macOS configs. Pull Request: https://projects.blender.org/blender/blender/pulls/134639 --- CMakeLists.txt | 4 ++++ build_files/buildbot/config/blender_macos.cmake | 1 + build_files/cmake/platform/platform_apple.cmake | 4 +++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9169806f810..e6063ac431b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1259,6 +1259,10 @@ if(APPLE) include(platform_apple_xcode) endif() +if(APPLE) + option(WITH_LEGACY_MACOS_X64_LINKER "Use legacy macOS linker. Only on x64 platform. Minutes slower, but emits fewer warnings." OFF) + mark_as_advanced(WITH_LEGACY_MACOS_X64_LINKER) +endif() # ----------------------------------------------------------------------------- # Check for Conflicting/Unsupported Configurations diff --git a/build_files/buildbot/config/blender_macos.cmake b/build_files/buildbot/config/blender_macos.cmake index cb8d173151e..27a76ed82a5 100644 --- a/build_files/buildbot/config/blender_macos.cmake +++ b/build_files/buildbot/config/blender_macos.cmake @@ -5,3 +5,4 @@ include("${CMAKE_CURRENT_LIST_DIR}/../../cmake/config/blender_release.cmake") set(WITH_CYCLES_TEST_OSL ON CACHE BOOL "" FORCE) +set(WITH_LEGACY_MACOS_X64_LINKER ON CACHE BOOL "" FORCE) diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake index 8354d88a5c7..8c4fdc379d2 100644 --- a/build_files/cmake/platform/platform_apple.cmake +++ b/build_files/cmake/platform/platform_apple.cmake @@ -427,8 +427,10 @@ string(APPEND PLATFORM_LINKFLAGS ) if(${XCODE_VERSION} VERSION_GREATER_EQUAL 15.0) - if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64") + if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64" AND WITH_LEGACY_MACOS_X64_LINKER) # Silence "no platform load command found in , assuming: macOS". + # + # NOTE: Using ld_classic costs minutes of extra linking time. string(APPEND PLATFORM_LINKFLAGS " -Wl,-ld_classic") else() # Silence "ld: warning: ignoring duplicate libraries".