[cfe-dev] Is there a way to get linkonce / selectany in C programs?

Reid Kleckner rnk at google.com
Wed Jul 2 14:13:41 PDT 2014


I can't think of any construct in standard C that will get linkonce_odr
linkage.

There is __attribute__((weak)) which gives 'weak' linkage.  There are two
differences:
1. It is not "odr", meaning it can be overridden by a different definition.
 Inlining or constant propagation is not allowed.
2. It is not discardable, meaning it cannot be dropped if unreferenced.


On Tue, Jul 1, 2014 at 11:16 PM, Talin <viridia at gmail.com> wrote:

> OK that makes sense. So forget selectany for a moment - what I really want
> to know is, is there any way, from C, to give a symbol linkonce linkage? Or
> is this capability only available via the IR?
>
>
> On Tue, Jul 1, 2014 at 11:13 PM, Nikola Smiljanic <popizdeh at gmail.com>
> wrote:
>
>> Grepping the source code tells me that selectany is only implemented as
>> microsoft extension. Test files use it in combination with __declspec and
>> they enable this functionality with -fsm-compatibility. Note that I have no
>> idea what this attribute actually does, I just did a search for you :)
>>
>>
>> On Wed, Jul 2, 2014 at 2:31 PM, Talin <viridia at gmail.com> wrote:
>>
>>> I'm working with a code generator that produces C code and I need
>>> linkonce to eliminate duplicate definitions - but the clang compiler
>>> complains that the 'selectany' attribute is not recognized (even though I
>>> see looking through the clang source code that there's code to handle it.)
>>> So I'm wondering why the attribute isn't recognized, I'm guessing it could
>>> be any number of things (platform [OS X], source language (.c), and so
>>> on...)
>>>
>>> --
>>> -- Talin
>>>
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>>
>>>
>>
>
>
> --
> -- Talin
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140702/172e6e17/attachment.html>


More information about the cfe-dev mailing list