[llvm-dev] LinkOnceODRLinkage behavior on Windows

Reid Kleckner via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 16 14:22:34 PST 2018


Yes, apply comdats to get the old behavior. This was recently discussed in
the swift tracker: https://github.com/apple/swift/pull/20059
It happened back in 2015, but I don't have any better reference material,
unfortunately.

On Fri, Nov 16, 2018 at 11:54 AM Daniele Vettorel via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
>
> I'm compiling two files with clang 6.0: testA.c and testB.c.
>
> On both files I am running a custom compiler IR-level pass that inserts a
> zero-initialized global variable called globalVarTest. I set the linkage of
> such global variable to be LinkOnceODRLinkage.
>
> Now, when I link testA.c and testB.c together (that is, the object files
> obtained by compiling them separately), the linker complains that there are
> multiple definitions of globalVarTest.
>
> Isn't LinkOnceODRLinkage supposed to tell the linker that if both
> definitions match, the symbols is the same and it can therefore pick any of
> the two definitions when building the final executable?
>
> The same procedure works on Linux. Is this a limitation of the Windows
> linker? I have been able to achieve the same effect using COMDAT sections
> but I wonder if that's an appropriate thing to do or if there's a better
> mechanism to achieve what I want.
>
> Thanks,
> Daniele
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181116/c90fe950/attachment.html>


More information about the llvm-dev mailing list