Talin
2014-Jul-14 21:48 UTC
[LLVMdev] 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? -- -- Talin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140714/0dbde385/attachment.html>
Reid Kleckner
2014-Jul-14 22:17 UTC
[LLVMdev] Any equivalent of --allow-multiple-definitions in llvm-ld?
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>
Talin
2014-Jul-14 23:07 UTC
[LLVMdev] Any equivalent of --allow-multiple-definitions in llvm-ld?
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 <rnk at google.com> 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 <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 >> >> >-- -- Talin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140714/d3de4f9d/attachment.html>