[llvm] [LTO] Drop the weak function if there is a non-weak global symbol (PR #76287)

Steven Wu via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 28 09:47:28 PST 2023


cachemeifyoucan wrote:

@teresajohnson This is `ModuleLinker` that mostly affects FullLTO, rather than thinLTO. I don't remember how `lld` implements fullLTO, is it not using `ModuleLinker` at all?

In the context of fullLTO, `ld64` doesn't really care about weak symbols that has a non-weak def in asm or other definitions. Because every symbol gets pulled into one module, in worst case, LTO codegen is going to produce both weak and non-weak definition and ld64 is going to pick one and dead-strip the other (if codegen can write both into the single output object file, I am not sure what is going to happen there).

In a more general context, apple linker is good at dead-stripping, and it also picks non-weak symbols over weak symbols, so adding such new function in LTO should not affect ld64.

> If I understand correctly, the new LTO gives control of symbol resolution to the caller? This way rustc can choose which symbols to use, just like llvm-lto2 or lld. I tried it at https://github.com/rust-lang/rust/pull/119348.

If rust compiler has idea of which symbol to use, using IRMover is probably better since it gives you much better control of the behavior, rather than rely on a single builtin behavior in ModuleLinker.

> So will we continue to maintain the legacy LTO?

While it is not required to implement new features that are available in new LTO interface in legacy LTO interface, please don't break legacy LTO since we still have users of them. 

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


More information about the llvm-commits mailing list