From 1677b76b6c8ee655dc2f2ef48f95cd42bb3ea52f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 28 Jul 2020 20:56:32 -0400 Subject: [PATCH 1/5] try using faster alternatives to GNU ld when building (many) test executables --- cmake/Modules/Testing.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmake/Modules/Testing.cmake b/cmake/Modules/Testing.cmake index a36067938f..35b16f89e2 100644 --- a/cmake/Modules/Testing.cmake +++ b/cmake/Modules/Testing.cmake @@ -16,6 +16,18 @@ if(ENABLE_TESTING) set(MEMORYCHECK_COMMAND "${VALGRIND_BINARY}" CACHE FILEPATH "Memory Check Command") set(MEMORYCHECK_COMMAND_OPTIONS "${VALGRIND_DEFAULT_OPTIONS}" CACHE STRING "Memory Check Command Options") + # check if a faster linker is available + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER) + check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + if(HAVE_LLD_LINKER) + target_link_options(lammps PUBLIC -fuse-ld=lld) + elseif(HAVE_OLD_LINKER) + target_link_options(lammps PUBLIC -fuse-ld=gold) + endif() + endif() + include(CTest) enable_testing() From 4d9781f9b69929b3d4a20d8fe7f7727677027f14 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 11:10:14 -0400 Subject: [PATCH 2/5] fix typo an reorder --- cmake/Modules/Testing.cmake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/Testing.cmake b/cmake/Modules/Testing.cmake index 35b16f89e2..3207bc4b3b 100644 --- a/cmake/Modules/Testing.cmake +++ b/cmake/Modules/Testing.cmake @@ -17,13 +17,13 @@ if(ENABLE_TESTING) set(MEMORYCHECK_COMMAND_OPTIONS "${VALGRIND_DEFAULT_OPTIONS}" CACHE STRING "Memory Check Command Options") # check if a faster linker is available - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER) - check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER) if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER) + check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER) if(HAVE_LLD_LINKER) target_link_options(lammps PUBLIC -fuse-ld=lld) - elseif(HAVE_OLD_LINKER) + elseif(HAVE_GOLD_LINKER) target_link_options(lammps PUBLIC -fuse-ld=gold) endif() endif() From 1f1767f5afbbb963d9a3de14c977ea5b5b0adc5d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 17:36:34 -0400 Subject: [PATCH 3/5] convert linker choice to (advanced) choice. only for Clang and GNU at the moment --- cmake/Modules/Testing.cmake | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmake/Modules/Testing.cmake b/cmake/Modules/Testing.cmake index 3207bc4b3b..29f8b61802 100644 --- a/cmake/Modules/Testing.cmake +++ b/cmake/Modules/Testing.cmake @@ -16,15 +16,30 @@ if(ENABLE_TESTING) set(MEMORYCHECK_COMMAND "${VALGRIND_BINARY}" CACHE FILEPATH "Memory Check Command") set(MEMORYCHECK_COMMAND_OPTIONS "${VALGRIND_DEFAULT_OPTIONS}" CACHE STRING "Memory Check Command Options") - # check if a faster linker is available + # check if a faster linker is available. + # only verified with GNU and Clang compilers and new CMake if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) - include(CheckCXXCompilerFlag) - check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER) - check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER) - if(HAVE_LLD_LINKER) - target_link_options(lammps PUBLIC -fuse-ld=lld) - elseif(HAVE_GOLD_LINKER) - target_link_options(lammps PUBLIC -fuse-ld=gold) + if((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") + OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) + include(CheckCXXCompilerFlag) + set(CMAKE_CUSTOM_LINKER_DEFAULT default) + check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER) + check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER) + check_cxx_compiler_flag(-fuse-ld=bfd HAVE_BFD_LINKER) + if(HAVE_LLD_LINKER) + set(CMAKE_CUSTOM_LINKER_DEFAULT lld) + elseif(HAVE_GOLD_LINKER) + set(CMAKE_CUSTOM_LINKER_DEFAULT gold) + elseif(HAVE_BFD_LINKER) + set(CMAKE_CUSTOM_LINKER_DEFAULT bfd) + endif() + set(CMAKE_CUSTOM_LINKER_VALUES lld gold bfd default) + set(CMAKE_CUSTOM_LINKER ${CMAKE_CUSTOM_LINKER_DEFAULT} CACHE STRING "Choose a custom linker for faster linking (lld, gold, bfd, default)") + validate_option(CMAKE_CUSTOM_LINKER CMAKE_CUSTOM_LINKER_VALUES) + mark_as_advanced(CMAKE_CUSTOM_LINKER) + if(NOT "${CMAKE_CUSTOM_LINKER}" STREQUAL "default") + target_link_options(lammps PUBLIC -fuse-ld=${CMAKE_CUSTOM_LINKER}) + endif() endif() endif() From d0b6ce82848d285216407af9f07bb4bb8ec8b599 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 17:46:24 -0400 Subject: [PATCH 4/5] displace target link options (if supported by CMake version) --- cmake/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index f505057b6c..cc4c1cc905 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -747,6 +747,12 @@ if (${_index} GREATER -1) endif() message(STATUS "<<< Linker flags: >>>") message(STATUS "Executable name: ${LAMMPS_BINARY}") +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13) + get_target_property(OPTIONS lammps LINK_OPTIONS) + if(OPTIONS) + message(STATUS "Linker options: ${OPTIONS}") + endif() +endif() if(CMAKE_EXE_LINKER_FLAGS) message(STATUS "Executable linker flags: ${CMAKE_EXE_LINKER_FLAGS}") endif() From 2fa642d95e6c57340e0afbf1efe9490e56577028 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 18:01:17 -0400 Subject: [PATCH 5/5] document custom linker choice --- doc/src/Build_development.rst | 17 +++++++++++++++++ doc/utils/sphinx-config/false_positives.txt | 1 + 2 files changed, 18 insertions(+) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index 6b72a73cd0..1569723357 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -259,6 +259,23 @@ and working. of mis-compiled code (or an undesired large loss of precision due to significant reordering of operations and thus less error cancellation). +Use custom linker for faster link times when ENABLE_TESTING is active +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +When compiling LAMMPS with enabled tests, most test executables will +need to be linked against the LAMMPS library. Since this can be a +large with many C++ objects when many packages are enabled, link times +can become very long on machines that use the GNU BFD linker (e.g. +Linux systems). Alternatives like the ``lld`` linker of the LLVM project +or the ``gold`` linker available with GNU binutils can speed up this step +substantially. CMake will by default test if any of the two can be +enabled and use it when ``ENABLE_TESTING`` is active. It can also be +selected manually through the ``CMAKE_CUSTOM_LINKER`` CMake variable. +Allowed values are ``lld``, ``gold``, ``bfd``, or ``default``. The +``default`` option will use the system default linker otherwise, the +linker is chosen explicitly. This option is only available for the +GNU or Clang C++ compiler. + Tests for other components and utility functions ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 9aa5954986..2bf3e917cf 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -236,6 +236,7 @@ bilayer bilayers binsize binstyle +binutils biomolecular biomolecule Biomolecules