[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72nYfCucffu4y9UMgZ357iXeeObZrhYoLb5e7cJgr170RA@mail.gmail.com>
Date: Sun, 26 Aug 2018 20:30:24 +0200
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Eli Friedman <efriedma@...eaurora.org>,
Christopher Li <sparse@...isli.org>,
Kees Cook <keescook@...omium.org>,
Ingo Molnar <mingo@...nel.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Masahiro Yamada <yamada.masahiro@...ionext.com>,
Joe Perches <joe@...ches.com>,
Dominique Martinet <asmadeus@...ewreck.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] include/linux/compiler*.h: Use feature checking instead
of version checks for attributes
Hi,
A couple of extra notes on my patch.
On Sun, Aug 26, 2018 at 7:57 PM, Miguel Ojeda
<miguel.ojeda.sandonis@...il.com> wrote:
> +/*
> + * Optional attributes: your compiler may or may not support them.
> + *
> + * To check for them, we use __has_attribute, which is supported on gcc >= 5,
> + * clang >= 2.9 and icc >= 17. In the meantime, to support 4.6 <= gcc < 5,
> + * we implement it by hand.
> + */
> +#ifndef __has_attribute
> +#define __has_attribute(x) __GCC46_has_attribute_##x
> +#define __GCC46_has_attribute_assume_aligned 0
> +#define __GCC46_has_attribute_designated_init 0
> +#define __GCC46_has_attribute_externally_visible 1
> +#define __GCC46_has_attribute_noclone 1
> +#define __GCC46_has_attribute_optimize 1
> +#define __GCC46_has_attribute_no_sanitize_address 0
Note that:
- assume_aligned came with gcc 4.9
- no_sanitize_address came with gcc 4.8
So if we feel it is important to have them there (before gcc 5), we
would need here a quick version check here.
> +#endif
> +
> +/*
> + * __assume_aligned(n, k): Tell the optimizer that the returned
> + * pointer can be assumed to be k modulo n. The second argument is
> + * optional (default 0), so we use a variadic macro to make the
> + * shorthand.
> + *
> + * Beware: Do not apply this to functions which may return
> + * ERR_PTRs. Also, it is probably unwise to apply it to functions
> + * returning extra information in the low bits (but in that case the
> + * compiler should see some alignment anyway, when the return value is
> + * massaged by 'flags = ptr & 3; ptr &= ~3;').
> + */
> +#if __has_attribute(assume_aligned)
> +#define __assume_aligned(a, ...) __attribute__((assume_aligned(a, ## __VA_ARGS__)))
> +#else
> +#define __assume_aligned(a, ...)
> +#endif
Beforehand, these were !defined(__CHECKER__). I am not sure if sparse
complains too much about it. Maybe sparse could learn __has_attribute.
Cheers,
Miguel
Powered by blists - more mailing lists