Commit Graph

5 Commits

Author SHA1 Message Date
Marc Chevrier
0445190d2f LLD linker: avoid regression on archive libraries deduplication
Due to a bug on LLD linker for ELF binaries, deduplication should
occur only if CMP0156 and CMP0179 are NEW.

Fixes: #26447
2024-11-18 21:02:50 +01:00
Brad King
39fd396421 LINK_LIBRARIES_STRATEGY: Rename strategies to clarify expectations
Since commit 7abd3137b7 (Linking: Optionally reorder direct dependencies
from LINK_LIBRARIES, 2024-09-19, v3.31.0-rc1~53^2) the strategy name
`PRESERVE_ORDER` has led users to expect that it strictly preserves
order.  While the part of the link line generation logic controlled by
`LINK_LIBRARIES_STRATEGY` does preserve order, it is not the last step.
Toolchain-specific de-duplication can cause the order to change on the
actual link line generated in the build system.

Rename the strategies:

* `PRESERVE_ORDER` => `REORDER_MINIMALLY`
* `REORDER`        => `REORDER_FREELY`

The new names make it clear that reordering is always possible, just to
varying degrees.  Update the `LINK_LIBRARIES_STRATEGY` documentation to
clarify that the strategies do not directly control the final link line.

Fixes: #26400
Issue: #26271
2024-10-25 10:23:37 -04:00
Marc Chevrier
cd418d4bb6 Static libraries de-duplication: keep first occurrence
Fixes: #26335
2024-10-02 10:17:08 -04:00
Brad King
9b5c805bf6 Tests/RunCMake/LinkLibrariesStrategy: Check ordering results more strongly 2024-10-02 10:16:15 -04:00
Brad King
7abd3137b7 Linking: Optionally reorder direct dependencies from LINK_LIBRARIES
Traditionally CMake generates link lines by starting with the direct
link dependencies specified by `LINK_LIBRARIES` in their original order
and then appending indirect dependencies that the direct dependencies
do not express.  This gives projects control over ordering among
independent entries, which can be important when intermixing flags
and libraries, or when multiple libraries provide the same symbol.
However, it may also result in inefficient link lines.

Add support for an alternative strategy that can reorder direct link
dependencies to produce more efficient link lines.  This is useful
for projects that cannot easily specify their targets' direct
dependencies in an order that satisfies indirect dependencies.

Add a `CMAKE_LINK_LIBRARIES_STRATEGY` variable and corresponding
`LINK_LIBRARIES_STRATEGY` target property to select a strategy.

Fixes: #26271
2024-09-25 06:48:57 -04:00