[lld] [MachO LLD] Respect -all_load with --start-lib --end-lib style archives (PR #93993)

Nuri Amari via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 13:33:22 PDT 2024


NuriAmari wrote:

> For Mach-O, it might make sense for the non-positional -all_load to override --start-lib.
But I expect more reasoning behind this change.

I think the flag being global makes a difference.

Since it is global, a user can supply the flag to a build system and expect it to work without inspecting the rest of the linker invocation. The same is not true of --whole-archive. The user already needs to see the entire invocation to position the —whole-archive / —no-whole-archive flags correctly, at which point they can just remove —start-lib / —end-lib as required. —We use —start-lib / —end-lib for distributed thin-lto. Users should be able to safely switch between thin-lto and distributed thin-lto without having to audit the custom flags they’ve provided (within reason). 

To accomplish this without this change, the build system would need to inspect each linker invocation and remove —start-lib / —end-lib if -all_load is passed. That seems needlessly complex. It seems to me for a global flag, the behavior of a real archive, and —start-lib —end-lib should be the same.

> Btw, I'm curious how we handle the -force_load case (case OPT_force_load) for d-thinlto.

That is an attribute of the library being consumed (link_whole). Libraries with this attribute are passed to the linker without `--start-lib / --end-lib`. 

https://github.com/llvm/llvm-project/pull/93993


More information about the llvm-commits mailing list