[LLVMdev] Any equivalent of --allow-multiple-definitions in llvm-ld?

Reid Kleckner rnk at google.com
Mon Jul 14 15:17:09 PDT 2014


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 <typename T> struct A {
  int foo() { return sizeof(T); }
};
template struct A<int>;

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

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

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

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

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


On Mon, Jul 14, 2014 at 2:48 PM, Talin <viridia at gmail.com> wrote:

> 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?
>
> --
> -- Talin
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140714/57f1b938/attachment.html>


More information about the llvm-dev mailing list