Skip to content

Commit

Permalink
Fix fast linker selection for old GCC versions (ccache#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderLanin authored Jan 25, 2021
1 parent bcd08a3 commit 6b552a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ jobs:
if [ "${{ runner.os }}" = "Linux" ]; then
sudo apt-get update
# Install ld.gold (binutils) and ld.lld on different runs.
# Binding to Ubuntu 20 has no special meaning.
if [ "${{ matrix.config.os }}" = "ubuntu-20.04" ]; then
sudo apt-get install -y ninja-build elfutils libzstd-dev
sudo apt-get install -y ninja-build elfutils libzstd-dev lld
else
sudo apt-get install -y ninja-build elfutils libzstd1-dev
sudo apt-get install -y ninja-build elfutils libzstd1-dev binutils
fi
if [ "${{ matrix.config.compiler }}" = "gcc" ]; then
Expand Down
25 changes: 13 additions & 12 deletions cmake/UseFastestLinker.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ function(use_fastest_linker)
message(WARNING "use_fastest_linker() disabled, as it is not called at the project top level")
return()
endif()

find_program(HAS_LD_LLD ld.lld)
if(HAS_LD_LLD)
link_libraries(-fuse-ld=lld)
message_verbose("Using lld linker for faster linking")

find_program(FASTER_LINKER ld.lld)
if(NOT FASTER_LINKER)
find_program(FASTER_LINKER ld.gold)
endif()

if(FASTER_LINKER)
# Note: Compiler flag -fuse-ld requires gcc 9 or clang 3.8.
# Instead override CMAKE_CXX_LINK_EXECUTABLE directly.
# By default CMake uses the compiler executable for linking.
set(CMAKE_CXX_LINK_EXECUTABLE "${FASTER_LINKER} <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
message_verbose("Using ${FASTER_LINKER} linker for faster linking")
else()
find_program(HAS_LD_GOLD ld.gold)
if(HAS_LD_GOLD)
link_libraries(-fuse-ld=gold)
message_verbose("Using gold linker for faster linking")
else()
message_verbose("Using default linker")
endif()
message_verbose("Using default linker")
endif()
endfunction()

Expand Down

0 comments on commit 6b552a3

Please sign in to comment.