[all-commits] [llvm/llvm-project] e90ec5: [CMake] Support per-target linker flags (#68393)

Vincent Lee via All-commits all-commits at lists.llvm.org
Tue Oct 17 14:05:17 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e90ec58b132a7244bdd8d45dd482fd78fe487f37
      https://github.com/llvm/llvm-project/commit/e90ec58b132a7244bdd8d45dd482fd78fe487f37
  Author: Vincent Lee <thevinster at users.noreply.github.com>
  Date:   2023-10-17 (Tue, 17 Oct 2023)

  Changed paths:
    M llvm/cmake/modules/AddLLVM.cmake
    M llvm/docs/CMake.rst

  Log Message:
  -----------
  [CMake] Support per-target linker flags (#68393)

`CMAKE_{C/CXX}_FLAGS` affects all targets in LLVM. This can
be undesirable in situations, like the case of enabling thinLTO,
where `-flto` is added to every source file. In reality, we only 
care about optimizing a select few of binaries, such as clang or lld,
that dominate the compilation pipeline. Auxiliary binaries in a 
distribution and not on the critical path can be kept non-optimized. 
This PR adds support of per-target linker flags, which can solve the
thinLTO problem by negating the effects of LTO via targeted linker 
flags on the targets. The example of negating thinLTO 
above can be done by doing the following:

```
set(LLVM_llvm-dwarfdump_LINKER_FLAGS "-Wl,--lto-O0" CACHE STRING "Custom linker flags to llvm-dwarfdump")
set(LLVM_lldb_LINKER_FLAGS "-Wl,--lto-O0" CACHE STRING "Custom linker flags to lldb")
```

There's other applications where this could be used (e.g. avoid
optimizing host tools for build speed improvement etc.). 
I've generalized this so that users can apply their desired flags to
targets that are generated by `llvm_add_library` or
`add_llvm_executable`.

Internally, our toolchain builds were on average 1.4x faster when
selectively choosing the binaries that we want optimized.




More information about the All-commits mailing list