Re: [PATCH v2] Compiler Attributes: don't pollute userspace with macro definitions

From: Miguel Ojeda
Date: Thu Dec 13 2018 - 16:59:25 EST


Hi Xiaozhou,

Couple of comments.

On Sun, Dec 9, 2018 at 4:27 AM Xiaozhou Liu <liuxiaozhou@xxxxxxxxxxxxx> wrote:
>
> v2: update commit message.

This line should go below the "---", since it shouldn't be part of the
commit message.

> +#ifdef __KERNEL__
> +
> #ifdef CONFIG_ENABLE_MUST_CHECK
> #define __must_check __attribute__((__warn_unused_result__))
> #else
> @@ -215,4 +217,6 @@ struct ftrace_likely_data {
> */
> #define noinline_for_stack noinline
>
> +#endif /* __KERNEL */

I wonder if we can/should simply move them into the __KERNEL__ &&
!__ASSEMBLY__ block that is above, instead. It would be simpler to
read, and there aren't apparently dependencies to those outside it
that go after the block.

I took a look at where the macros were at each "step", and, on one
hand, compiler-gcc.h was (and is) included entirely inside it, which
is from where most of the macros come originally from. On the other
hand, not all do: __must_check (the generic version, not the one in
-gcc.h) and noinline_for_stack were defined in __KERNEL__ (only)
before commit 815f0ddb346c ("include/linux/compiler*.h: make
compiler-*.h mutually exclusive"). But anyway using those two in
assembly does not make sense, right?

What do you think?

Greg/Linus, are you going to pick this (or a v3) directly? If not, I
can pick it up in compiler-attributes tree linux-next.

PS: In addition (related to this but not for this patch), we should
review whether other macros that are currently outside should be there
or simply pushed back into __KERNEL__ (and possibly __ASSEMBLY__). For
instance, __latent_entropy (the generic one) is outside, but it is
only defined in compiler-gcc.h, so the generic one should be inside
the __KERNEL__ && !__ASSEMBLY__ block, no?

Cheers,
Miguel