Skip to content

Commit

Permalink
Move LLD configuration into configuretools.cmake
Browse files Browse the repository at this point in the history
Also update PGO stuff to not to use gold linker when
lld is present.
  • Loading branch information
janvorli committed Jul 15, 2021
1 parent 1ea2887 commit 9bfa3a0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
4 changes: 0 additions & 4 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ elseif (CLR_CMAKE_HOST_UNIX)
# Use uppercase CMAKE_BUILD_TYPE for the string comparisons below
string(TOUPPER ${CMAKE_BUILD_TYPE} UPPERCASE_CMAKE_BUILD_TYPE)

if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CLR_CMAKE_HOST_ARCH_S390X AND NOT CLR_CMAKE_HOST_OSX AND NOT CLR_CMAKE_HOST_FREEBSD)
add_linker_flag(-fuse-ld=lld)
endif ()

set(CLR_SANITIZE_CXX_OPTIONS "")
set(CLR_SANITIZE_LINK_OPTIONS "")

Expand Down
28 changes: 17 additions & 11 deletions eng/native/configuretools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,23 @@ if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER)
endif()

if (NOT CLR_CMAKE_HOST_WIN32)
# detect linker
set(ldVersion ${CMAKE_C_COMPILER};-Wl,--version)
execute_process(COMMAND ${ldVersion}
ERROR_QUIET
OUTPUT_VARIABLE ldVersionOutput)

if("${ldVersionOutput}" MATCHES "GNU ld" OR "${ldVersionOutput}" MATCHES "GNU gold" OR "${ldVersionOutput}" MATCHES "GNU linkers")
set(LD_GNU 1)
elseif("${ldVersionOutput}" MATCHES "Solaris Link")
set(LD_SOLARIS 1)
else(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_MACCATALYST)
set(LD_OSX 1)
if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CLR_CMAKE_HOST_ARCH_S390X AND NOT CLR_CMAKE_HOST_OSX AND NOT CLR_CMAKE_HOST_FREEBSD)
add_linker_flag(-fuse-ld=lld)
set(LD_LLVM 1)
else()
# detect linker
set(ldVersion ${CMAKE_C_COMPILER};-Wl,--version)
execute_process(COMMAND ${ldVersion}
ERROR_QUIET
OUTPUT_VARIABLE ldVersionOutput)

if("${ldVersionOutput}" MATCHES "GNU ld" OR "${ldVersionOutput}" MATCHES "GNU gold" OR "${ldVersionOutput}" MATCHES "GNU linkers")
set(LD_GNU 1)
elseif("${ldVersionOutput}" MATCHES "Solaris Link")
set(LD_SOLARIS 1)
else(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_MACCATALYST)
set(LD_OSX 1)
endif()
endif()
endif()
2 changes: 1 addition & 1 deletion eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function(preprocess_files PreprocessedFilesList)
endfunction()

function(set_exports_linker_option exports_filename)
if(LD_GNU OR LD_SOLARIS)
if(LD_GNU OR LD_SOLARIS OR LD_LLVM)
# Add linker exports file option
if(LD_SOLARIS)
set(EXPORTS_LINKER_OPTION -Wl,-M,${exports_filename} PARENT_SCOPE)
Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/pgosupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ function(add_pgo TargetName)
else(CLR_CMAKE_HOST_WIN32)
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-generate)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-ld=gold -fprofile-instr-generate")
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fprofile-instr-generate")
if(NOT LD_LLVM)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -fuse-ld=gold")
endif()
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
endif(CLR_CMAKE_HOST_WIN32)
elseif(CLR_CMAKE_PGO_OPTIMIZE)
Expand Down Expand Up @@ -54,7 +57,10 @@ function(add_pgo TargetName)
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6))
if(HAVE_LTO)
target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-use=${ProfilePath} -Wno-profile-instr-out-of-date -Wno-profile-instr-unprofiled)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-ld=gold -fprofile-instr-use=${ProfilePath}")
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fprofile-instr-use=${ProfilePath}")
if(NOT LD_LLVM)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -fuse-ld=gold")
endif()
else(HAVE_LTO)
message(WARNING "LTO is not supported, skipping profile guided optimizations")
endif(HAVE_LTO)
Expand Down

0 comments on commit 9bfa3a0

Please sign in to comment.