This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Add LLVM_UNITTEST_LINK_FLAGS option
ClosedPublic

Authored by nikic on Jun 30 2023, 6:07 AM.

Details

Summary

Add an option to specify additional linker flags for unit tests only. For example, this allows doing something like -DLLVM_UNITTEST_LINK_FLAGS="-Wl,-plugin-opt=O0" if you're doing LTO builds, or -DLLVM_UNITTEST_LINK_FLAGS="-fno-lto" if you're using fat LTO objects.

The build system already does this itself if the LLVM_ENABLE_LTO flag is used, but this does not cover all possible LTO configurations. (E.g. we're using ld.bfd with LLVMgold.so, which isn't one of the supported configurations.)

Diff Detail

Event Timeline

nikic created this revision.Jun 30 2023, 6:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 6:07 AM
nikic requested review of this revision.Jun 30 2023, 6:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 30 2023, 6:07 AM
phosek added inline comments.Jun 30 2023, 9:37 AM
llvm/cmake/modules/AddLLVM.cmake
1613–1614

For variables that are intended to be used by users, I'd prefer to keep them in the top-level CMakeLists.txt file for easier discoverability.

1615–1616

LINK_FLAGS property is deprecated and superseded by LINK_OPTIONS, see https://cmake.org/cmake/help/latest/prop_tgt/LINK_FLAGS.html. Can you use target_link_options instead?

nikic added inline comments.Jun 30 2023, 2:21 PM
llvm/cmake/modules/AddLLVM.cmake
1613–1614

The reason I put it here is that the option is shared across all subprojects using unit tests, so just putting it in llvm/CMakeLists.txt wouldn't work. Maybe HandleLLVMOptions would be the right place to define such a shared option?

nikic updated this revision to Diff 536711.Jul 3 2023, 3:39 AM

Move option to HandleLLVMOptions, use target_link_options.

phosek accepted this revision.Jul 4 2023, 7:32 PM

LGTM

This revision is now accepted and ready to land.Jul 4 2023, 7:32 PM
This revision was automatically updated to reflect the committed changes.