We faced an issue in one of testcases of D41987 patch (ELF/lto/defsym.ll).
There we have 2 symbols declarations:
define hidden void @bar2() { call void @this_is_bar2() ret void } define hidden void @bar3() { call void @this_is_bar3() ret void }
and want to redefine one of them with -defsym=bar2=bar3 linker option.
We define bar2 on linker side before calling LTO code. With that resolution for bar2 we pass to
ThinLTO is Prevealing=0, VisibleToRegularObj=1,LinkerRedefined=1.
ThinLTO returns us strong bar2 symbol and we fail with multiple symbol definition of 'bar2'.
Patch sets WeakAnyLinkage for all LinkerRedefined symbols and not only those that are Prevealing.
Such change stops bar2 from being exported:
https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/IPO/FunctionImport.cpp#L181
and then LTO sets bar2 linkage to internal here:
https://github.com/llvm-mirror/llvm/blob/master/lib/LTO/LTO.cpp#L329
Symbol never shows up in the output anymore and that fixes the issue for us.
Though as was mentioned by Rafael in D38239 thread, "This seems to be a bit of a hack.
With it llvm sets the linkage to weak to prevent inlining and that ends up avoiding the symbol for being used,
but that seems to happen in a profitability logic, not correctness."
Posting it to discuss how this can be fixed in a better way.