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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Talin-3
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
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

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

Reid Kleckner-2
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 <[hidden email]> 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
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

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

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


On Mon, Jul 14, 2014 at 3:17 PM, Reid Kleckner <[hidden email]> wrote:
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 <[hidden email]> 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
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





--
-- Talin

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev