Commit 079b8e29 authored by Zsolt Parragi's avatar Zsolt Parragi

Clang: prefer lld-link over link.exe

Objects compiled with -flto can only be linked with the llvm linker.
Before this change, clang-cl only supperted IPO with manual linker
selection.
parent 6e3655db
......@@ -69,7 +69,12 @@ if(("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_SIMULATE_ID}" STREQUAL "xMSVC" AND
OR (CMAKE_GENERATOR MATCHES "Visual Studio"
AND NOT CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android"))
find_program(CMAKE_LINKER NAMES link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
if("x${CMAKE_${_CMAKE_PROCESSING_LANGUAGE}_COMPILER_ID}" STREQUAL "xClang")
find_program(CMAKE_NM NAMES ${_CMAKE_TOOLCHAIN_PREFIX}nm llvm-nm HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
set(_CMAKE_ADDITIONAL_LINKER_NAMES "lld-link")
endif()
find_program(CMAKE_LINKER NAMES ${_CMAKE_ADDITIONAL_LINKER_NAMES} link HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
find_program(CMAKE_MT NAMES mt HINTS ${_CMAKE_TOOLCHAIN_LOCATION})
list(APPEND _CMAKE_TOOL_VARS LINKER MT)
......@@ -115,6 +120,17 @@ else()
list(APPEND _CMAKE_TOOL_VARS AR RANLIB STRIP LINKER NM OBJDUMP OBJCOPY READELF DLLTOOL ADDR2LINE)
unset(_CMAKE_ADDITIONAL_AR_NAMES)
unset(_CMAKE_ADDITIONAL_RANLIB_NAMES)
unset(_CMAKE_ADDITIONAL_STRIP_NAMES)
unset(_CMAKE_ADDITIONAL_LINKER_NAMES)
unset(_CMAKE_ADDITIONAL_NM_NAMES)
unset(_CMAKE_ADDITIONAL_OBJDUMP_NAMES)
unset(_CMAKE_ADDITIONAL_OBJCOPY_NAMES)
unset(_CMAKE_ADDITIONAL_READELF_NAMES)
unset(_CMAKE_ADDITIONAL_DLLTOOL_NAMES)
unset(_CMAKE_ADDITIONAL_ADDR2LINE_NAMES)
endif()
  • are the unset necessary? The variables get unset later in a loop

    foreach(var IN LISTS _CMAKE_TOOL_VARS)
      get_property(_CMAKE_TOOL_CACHED CACHE CMAKE_${var} PROPERTY TYPE)
      if(_CMAKE_TOOL_CACHED)
        mark_as_advanced(CMAKE_${var})
      endif()
      unset(_CMAKE_ADDITIONAL_${var}_NAMES)
    endforeach()
  • Fixed in !3920 (merged), thanks.

Please register or sign in to reply
if(CMAKE_PLATFORM_HAS_INSTALLNAME)
......
  • mentioned in commit 4684e64c

    Toggle commit list
  • @dutow Is there a description somewhere of what exactly does cmake to build executables with clang.exe? I try to add support for clang.exe in https://github.com/microsoft/vscode-cmake-tools The 32-bit clang.exe builds use ll.lld.exe to link. clang-cl.exe uses lld-link.exe I think. In one of your comments you said that debugging with clang.exe works but if I use the MSVC debugger in VSCode, the breakpoints get hit and the call stack is displayed but there is no info about any variables. Does clang.exe produce MSVC compatible output when building with CMake?

  • @Zingam since this MR, linking uses clang++ -fuse-ld=lld-link - and I'm quite sure I've used link.exe before that, as ld.lld doesn't expose a few MSVC specific features.

    The issue is most likely that I don't see /Zi in the debug flags, which should be there... looks like I accidentally removed that during some of the initial refactorings, and I've never really used the debugger with it after that. I'll check and fix this later today.

  • @Zingam sorry for the late reply, I tried a few configurations, and I see the variables in my project. (using the CMake 3.16 release, latest VS2017 & VSCode & CMake plugin, tested both 32 and 64 bit builds)

    The only issue I had is that the cmake plugin wants to launch gdb (which it can't of course), but I was able to use the VS debugger by manually adding a launch target.

    Could you help me with reproducing?

Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment