This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Fix LTO option on Windows
ClosedPublic

Authored by aganea on Sep 7 2018, 11:02 AM.

Details

Summary

Previously, the option LLVM_ENABLE_LLD was not adequatly taken into account when using LLVM_ENABLE_LTO on Windows.

The picture below shows the problem before the patch. CMAKE_LINKER says lld-link.exe, however when running configure, CMAKE_LINKER is back to link.exe (the message was printed in HandleLLVMOptions.cmake. This is probably caused by CMakeCXXCompiler.cmake which indeed overrides CMAKE_LINKER (I'm using CMake 3.12.0).

This causes LINKER_IS_LLD_LINK not being set, which in turns prevents using LTO.

Diff Detail

Repository
rL LLVM

Event Timeline

aganea created this revision.Sep 7 2018, 11:02 AM
rnk accepted this revision.Sep 7 2018, 12:54 PM

Wow, three different ways to set the linker. I'm impressed with how many cooks there are in our kitchen.

This revision is now accepted and ready to land.Sep 7 2018, 12:54 PM
This revision was automatically updated to reflect the committed changes.

Is this a bug in CMake? Maybe you should report it on their bug tracker.

aganea added a comment.Sep 7 2018, 1:40 PM

Is this a bug in CMake? Maybe you should report it on their bug tracker.

I will, but I need to investigate the issue more in-depth. This happens when passing -T"LLVM-vs201X" to cmake.
I'll upgrade CMake and switch to using -Tllvm instead see if the issue is still there.

Is this a bug in CMake? Maybe you should report it on their bug tracker.

The issue have been fixed in CMake 3.12.2

CMAKE_LINKER MATCHES "lld-link\.exe"

@aganea, can you please elaborate on the need for the backslash that you added?

aganea added a comment.Oct 5 2018, 8:22 PM

CMAKE_LINKER MATCHES "lld-link\.exe"

@aganea, can you please elaborate on the need for the backslash that you added?

It is not needed per se. But given than MATCHES takes a regular expression on the right side, I machinally replaced the . (maching any character) by \. (escaped dot) while looking for a bug. Is that an issue?