From: Gregor Jasny Date: Sun, 22 Aug 2021 10:47:04 +0000 (+0200) Subject: feat(cmake): Use the matching lld for clang X-Git-Tag: v4.4.1~9^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=117ad3fbcec014a0c106c5ce1b86040eaf5529fc;p=thirdparty%2Fccache.git feat(cmake): Use the matching lld for clang Otherwise one could end up on Ubuntu with clang-11 calling lld-10 which breaks IPO. --- diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 36f8a5116..e4fd3d70d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -104,7 +104,7 @@ jobs: echo "CC=clang-${{ matrix.config.version }}" >> $GITHUB_ENV echo "CXX=clang++-${{ matrix.config.version }}" >> $GITHUB_ENV - sudo apt install -y clang-${{ matrix.config.version }} g++-multilib + sudo apt install -y clang-${{ matrix.config.version }} g++-multilib lld-${{ matrix.config.version }} fi elif [ "${{ runner.os }}" = "macOS" ]; then HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 \ diff --git a/cmake/UseFastestLinker.cmake b/cmake/UseFastestLinker.cmake index 9b4fdd6ab..f7e079b4f 100644 --- a/cmake/UseFastestLinker.cmake +++ b/cmake/UseFastestLinker.cmake @@ -35,23 +35,31 @@ function(use_fastest_linker) return() endif() - set(use_default_linker 1) + # prefer an lld that matches the clang version + if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION MATCHES "^([0-9]*)\\.") + check_linker(lld-${CMAKE_MATCH_1}) + if(HAVE_LD_LLD-${CMAKE_MATCH_1}) + link_libraries("-fuse-ld=lld-${CMAKE_MATCH_1}") + message(STATUS "Using lld-${CMAKE_MATCH_1} linker") + return() + endif() + endif() + check_linker(lld) if(HAVE_LD_LLD) link_libraries("-fuse-ld=lld") - set(use_default_linker 0) message(STATUS "Using lld linker") - else() - check_linker(gold) - if(HAVE_LD_GOLD) - link_libraries("-fuse-ld=gold") - set(use_default_linker 0) - message(STATUS "Using gold linker") - endif() + return() endif() - if(use_default_linker) - message(STATUS "Using default linker") + + check_linker(gold) + if(HAVE_LD_GOLD) + link_libraries("-fuse-ld=gold") + message(STATUS "Using gold linker") + return() endif() + + message(STATUS "Using default linker") endfunction() option(USE_FASTER_LINKER "Use the lld or gold linker instead of the default for faster linking" TRUE)