Any equivalent of --allow-multiple-definitions in llvm-ld?

I’m working with a C++ code generator that produces multiple instances of the same definition (specifically, it generates explicit instantiations of the same template in multiple output source files). With the GNU ld, I’m able to link successfully using the --allow-multiple-definitions flag; however this flag is not supported in llvm-ld.

Is there any way I can either convince llvm-ld to accept this without producing an error, or alternatively is there any way in C++ that I can trick the compiler into making these definitions linkonce?

Apparently lld accepts ‘-z muldefs’ for this purpose.

I’m curious if you can’t solve this easily at the C++ language level, though.

This explicit instantiation for example will be coalesced by the linker:

template struct A {
int foo() { return sizeof(T); }
};
template struct A;

This explicit specialization also defines inline functions which will be coalesced:

template struct A {
int foo() { return sizeof(T); }
};
template <> struct A {
int foo() { return 4; }
};

Only this out of line method definition for a fully specialized class template generates strong symbols:

template struct A {
int foo() { return sizeof(T); }
};
template <> struct A {
int foo();
};
int A::foo() { return 4; }

In which case, if I want them coalesced, I can probably just add the ‘inline’ keyword.

Thanks Reid. The specific symbols in this case are static data structures, not methods.