Re: [PATCH v4 14/18] static_call: Add static_cond_call()

From: Peter Zijlstra
Date: Tue May 05 2020 - 05:39:24 EST


On Tue, May 05, 2020 at 09:50:26AM +0200, Rasmus Villemoes wrote:
> On 04/05/2020 22.14, Peter Zijlstra wrote:

> Anyway, it's hard to judge what version of the !HAVE_STATIC_CALL
> implementation is best when there's no !HAVE_STATIC_CALL use cases to
> look at. I just want to ensure that whatever limitations or gotchas
> (e.g., "arguments are evaluated regardless of NULLness of func", or
> alternatively "arguments must not have side effects") it ends up with
> get documented.

I can certainly try and write a better comment for it.

> > #define __static_cond_call(name) \
> > ({ \
> > void *func = READ_ONCE(name.func); \
> > if (!func) \
> > func = &__static_call_nop; \
> > (typeof(__SCT__##name)*)func; \
> > })
>
> I think you can just make it
>
> #define __static_cond_call(name) \
> ( \
> (typeof(__SCT__##name)*) ((void *)name.func ? : (void *)__static_call_nop) \
> )

I _think_ the compiler sees the two as exactly the same, but then, I've
not seen the inside of a modern compiler.

> but that simplification is not enough to make gcc change its mind about
> how to compile it :( But I'm guessing that various sanitizers or static
> checkers might complain about the UB.

Yeah, we'll see.