Skip to content

Commit

Permalink
GH-40400: [C++] Add support for LLD (#40927)
Browse files Browse the repository at this point in the history
### Rationale for this change

Add support for the LLD LLVM linker, it is faster than the default linker.

### What changes are included in this PR?

Added `ARROW_USE_LLD` as a CMake option, test if GCC supports the flags and then set the linker flags if so when the option is enabled.

### Are these changes tested?

When this is enabled then the libraries and tests will use the linker flag.

### Are there any user-facing changes?

No
* GitHub Issue: #40400

Authored-by: Marcus D. Hanwell <marcus@voltrondata.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
cryos authored Apr 5, 2024
1 parent df7da77 commit 6f6b3b4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ci/docker/ubuntu-20.04-cpp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ RUN apt-get update -y -q && \
libutf8proc-dev \
libxml2-dev \
libzstd-dev \
lld \
make \
ninja-build \
nlohmann-json3-dev \
Expand Down Expand Up @@ -164,6 +165,7 @@ ENV absl_SOURCE=BUNDLED \
ARROW_SUBSTRAIT=ON \
ARROW_USE_ASAN=OFF \
ARROW_USE_CCACHE=ON \
ARROW_USE_LLD=ON \
ARROW_USE_UBSAN=OFF \
ARROW_WITH_BROTLI=ON \
ARROW_WITH_BZ2=ON \
Expand Down
1 change: 1 addition & 0 deletions ci/scripts/cpp_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ else
-DARROW_USE_CCACHE=${ARROW_USE_CCACHE:-ON} \
-DARROW_USE_GLOG=${ARROW_USE_GLOG:-OFF} \
-DARROW_USE_LD_GOLD=${ARROW_USE_LD_GOLD:-OFF} \
-DARROW_USE_LLD=${ARROW_USE_LLD:-OFF} \
-DARROW_USE_MOLD=${ARROW_USE_MOLD:-OFF} \
-DARROW_USE_PRECOMPILED_HEADERS=${ARROW_USE_PRECOMPILED_HEADERS:-OFF} \
-DARROW_USE_STATIC_CRT=${ARROW_USE_STATIC_CRT:-OFF} \
Expand Down
2 changes: 2 additions & 0 deletions cpp/cmake_modules/DefineOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ takes precedence over ccache if a storage backend is configured" ON)

define_option(ARROW_USE_LD_GOLD "Use ld.gold for linking on Linux (if available)" OFF)

define_option(ARROW_USE_LLD "Use the LLVM lld for linking (if available)" OFF)

define_option(ARROW_USE_MOLD "Use mold for linking on Linux (if available)" OFF)

define_option(ARROW_USE_PRECOMPILED_HEADERS "Use precompiled headers when compiling"
Expand Down
28 changes: 28 additions & 0 deletions cpp/cmake_modules/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,34 @@ if(NOT WIN32 AND NOT APPLE)
endif()
endif()

if(ARROW_USE_LLD)
find_program(LD_LLD ld.lld)
if(LD_LLD)
unset(LLD_LINKER_FLAGS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "9.1.0")
set(LLD_LINKER_FLAGS "-fuse-ld=lld")
else()
message(STATUS "Need GCC 9.1.0 or later to use LLD linker: ${CMAKE_CXX_COMPILER_VERSION}"
)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(LLD_LINKER_FLAGS "--ld-path=${LD_LLD}")
else()
message(STATUS "Using the default linker because compiler doesn't support LLD: ${CMAKE_CXX_COMPILER_ID}"
)
endif()
if(LLD_LINKER_FLAGS)
message(STATUS "Using optional LLVM LLD linker")
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${LLD_LINKER_FLAGS}")
string(APPEND CMAKE_MODULE_LINKER_FLAGS " ${LLD_LINKER_FLAGS}")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " ${LLD_LINKER_FLAGS}")
else()
message(STATUS "Using the default linker because the LLD isn't supported")
endif()
endif()
endif()

# compiler flags for different build types (run 'cmake -DCMAKE_BUILD_TYPE=<type> .')
# For all builds:
# For CMAKE_BUILD_TYPE=Debug
Expand Down

0 comments on commit 6f6b3b4

Please sign in to comment.