[PATCH] D28596: [compiler-rt] General definition for weak functions.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 19:49:00 PST 2017


The only way i can think to improve that is to make it so WEAK_ALIAS macro
comes first, and make WEAK_DEF comes second and static_assert if WEAK_ALIAS
has not been called (by using sizeof on the forward decl perhaps). This way
you will get a compiler error if you don't do both.

I don't even know if this would work (and i also don't think it should hold
up this change regardless since it's only a minor improvement).

That said, I'm fine with any approach that works, so I'll leave it up kuba@
and aizatsky@ to decide which they like better
On Wed, Jan 18, 2017 at 5:28 PM Marcos Pividori <mpividori at google.com>
wrote:

> Hi,
> Yes, what @zturner proposes works. @kubabrecka Would that make your
> editor work fine?
> I would prefer to use only one macro as I defined it before, because if we
> use 2 macros, we always need to remember to include both.
> But just let me know what you prefer and I will do that.
> Thanks,
> Marcos
>
> On Wed, Jan 18, 2017 at 4:43 PM, Zachary Turner via Phabricator <
> reviews at reviews.llvm.org> wrote:
>
> zturner added a comment.
>
> In https://reviews.llvm.org/D28596#649978, @mpividori wrote:
>
> > > 2. Having a macro only around the function name, i.e.: `WEAK_ATTRIBUTE
> void WEAK_NAME(OnPrint)(const char *str) { code }`.
> >
> > I can't do that because not only I need to change the name, I also need
> to add a linker pragma `WIN_WEAK_ALIAS(OnPrint, OnPrint__def)` and declare
> `OnPrint`.
> >  I mean, for non-windows `OnPrint` definition will be:
> >
> >   void OnPrint(const char *str) {
> >     // Default implementation
> >   }
> >
> >
> > And for Windows, it will be:
> >
> >   void OnPrint__def(const char *str) {
> >     // Default implementation
> >   }
> >   void OnPrint(const char *str);
> >   WIN_WEAK_ALIAS(OnPrint, OnPrint__def)
> >
> >
> > Thanks.
>
>
> What if instead of getting it all into one line, we settle for this:
>
>   void WEAK_FN_DEF(OnPrint)(const char *str) {
>   }
>   WEAK_FN_ALIAS(OnPrint)
>
> The macro `WEAK_FN_ALIAS` could look like this:
>
>   #define WEAK_FN_ALIAS(Fn) \
>     decltype(Fn##__def) Fn; \
>     WIN_WEAK_ALIAS(Fn, Fn##__def)
>
> On non-Windows platforms, it would just do nothing.  Apparently the crazy
> decltype magic works and should give you a definition named `OnPrint__def`
> and a forward declaration named `OnPrint`.
>
>
> https://reviews.llvm.org/D28596
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170119/93866c9c/attachment.html>


More information about the llvm-commits mailing list