llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang-CL] __attribute__(( weak )) vs LTO

Open psiha opened this issue 4 years ago • 2 comments

a.cpp attribute(( weak )) void foo() {}

b.cpp void foo() {}

When a and b are linked w/ LTO you get duplicate symbol: void foo(). If LTO is not used then linking succeeds.

psiha avatar Jan 19 '22 09:01 psiha

Thin vs full LTO does not make a difference.

psiha avatar Jan 19 '22 10:01 psiha

FYI this seems specific to the COFF lld handling. It works fine as expected for ELF with clang++. I also confirmed that the bitcode generated by clang-cl -flto does give foo from a.cpp weak linkage: define weak dso_local void @"?foo@@YAXXZ"() #0 { ...

teresajohnson avatar Jan 20 '22 16:01 teresajohnson