linux/compiler-clang.h: define HAVE_BUILTIN_BSWAP*
PATCH 1/1 linux/compiler-clang.h: define HAVE_BUILTIN_BSWAP*
From: Arnd Bergmann <[email protected]>
Separating compiler-clang.h from compiler-gcc.h inadventently dropped the definitions of the three HAVE_BUILTIN_BSWAP macros, which requires falling back to the open-coded version and hoping that the compiler detects it.
Since all versions of clang support the __builtin_bswap interfaces, add back the flags and have the headers pick these up automatically.
This results in a 4% improvement of compilation speed for arm defconfig.
--- include/linux/compiler-clang.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/compiler-clang.h +10 -0
@@ -33,6 +33,16 @@#define __no_sanitize_thread#endif +/* +* sparse (__CHECKER__) pretends to be gcc, but can't do constant +* folding in __builtin_bswap*() (yet), so don't set these for it. +*/ +#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP ) && !defined(__CHECKER__) +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ +#define __HAVE_BUILTIN_BSWAP16__ +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP && !__CHECKER__ */ +#if __has_feature (undefined_behavior_sanitizer)/* GCC does not have __SANITIZE_UNDEFINED__ */ #define __no_sanitize_undefined \
Signature · 1 line
2.29.2
Quoted 6 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Separating
compiler-clang.hfromcompiler-gcc.hinadventently dropped the definitions of the threeHAVE_BUILTIN_BSWAPmacros, which requires falling back to the open-coded version and hoping that the compiler detects it.
Quoted 7 lines
Since all versions of clang support the
__builtin_bswapinterfaces, add back the flags and have the headers pick these up automatically.This results in a 4% improvement of compilation speed for arm defconfig.
Fixes 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")Signed-off-by Arnd Bergmann <[email protected]>
Quoted 28 lines
--- include/linux/compiler-clang.h | 10 ++++++++++ 1 file changed, 10 insertions(+)include/linux/compiler-clang.h +10
-0@@ -33,6 +33,16 @@#define __no_sanitize_thread#endif +/* +* sparse (__CHECKER__) pretends to be gcc, but can't do constant +* folding in __builtin_bswap*() (yet), so don't set these for it. +*/ +#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP ) && !defined(__CHECKER__) +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ +#define __HAVE_BUILTIN_BSWAP16__ +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP && !__CHECKER__ */ +#if __has_feature (undefined_behavior_sanitizer)/* GCC does not have __SANITIZE_UNDEFINED__ */ #define __no_sanitize_undefined \Signature · 1 line
2.29.2
Quoted 6 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Separating
compiler-clang.hfromcompiler-gcc.hinadventently dropped the definitions of the threeHAVE_BUILTIN_BSWAPmacros, which requires falling back to the open-coded version and hoping that the compiler detects it.
Quoted 7 lines
Since all versions of clang support the
__builtin_bswapinterfaces, add back the flags and have the headers pick these up automatically.This results in a 4% improvement of compilation speed for arm defconfig.
Fixes 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")Signed-off-by Arnd Bergmann <[email protected]>
Signature · 1 line
Kees Cook
Quoted 10 lines · On Thu, 25 Feb 2021 12:03:48 -0800 Kees Cook <[email protected]> wrote:
Quoted 9 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Separating
compiler-clang.hfromcompiler-gcc.hinadventently dropped the definitions of the threeHAVE_BUILTIN_BSWAPmacros, which requires falling back to the open-coded version and hoping that the compiler detects it.Since all versions of clang support the
__builtin_bswapinterfaces, add back the flags and have the headers pick these up automatically.
Quoted 6 lines
Quoted 4 lines
This results in a 4% improvement of compilation speed for arm defconfig.
Fixes 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")Signed-off-by Arnd Bergmann <[email protected]>
I figured 4% better compile time isn't significant enough to justify a backport. Thoughts?
Quoted 1 line
Reviewed-by Kees Cook <[email protected]>
Quoted 14 lines · Andrew Morton
Quoted 12 lines · On Thu, 25 Feb 2021 12:03:48 -0800 Kees Cook <[email protected]> wrote:
Quoted 11 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Separating
compiler-clang.hfromcompiler-gcc.hinadventently dropped the definitions of the threeHAVE_BUILTIN_BSWAPmacros, which requires falling back to the open-coded version and hoping that the compiler detects it.Since all versions of clang support the
__builtin_bswapinterfaces, add back the flags and have the headers pick these up automatically.This results in a 4% improvement of compilation speed for arm defconfig.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Fixes 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")Signed-off-by Arnd Bergmann <[email protected]>I figured 4% better compile time isn't significant enough to justify a backport. Thoughts?
It's a trivial change, so I think it's worth it?
Quoted 3 lines
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>
Signature · 1 line
Kees Cook
Nathan Chancellor
maintainerQuoted 18 lines · Kees Cook
Quoted 17 lines · Andrew Morton
Quoted 15 lines · On Thu, 25 Feb 2021 12:03:48 -0800 Kees Cook <[email protected]> wrote:
Quoted 13 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Separating
compiler-clang.hfromcompiler-gcc.hinadventently dropped the definitions of the threeHAVE_BUILTIN_BSWAPmacros, which requires falling back to the open-coded version and hoping that the compiler detects it.Since all versions of clang support the
__builtin_bswapinterfaces, add back the flags and have the headers pick these up automatically.This results in a 4% improvement of compilation speed for arm defconfig.
Fixes 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")Signed-off-by Arnd Bergmann <[email protected]>
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
I figured 4% better compile time isn't significant enough to justify a backport. Thoughts?
It's a trivial change, so I think it's worth it?
Indeed. Any wins that we can get with compile time, we should take. Clang is being widely used in production systems now so I feel like with a trivial change plus user visible impact, it should be backported.
Not to mention that the generated code in theory should be better because it is the compiler's builtin, rather than a hand rolled one, AND this is technically a regression, given that it worked before compiler.h was split.
Cheers,
Nathan
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>Signature · 1 line
Kees Cook
Quoted 9 lines · Nathan Chancellor
Indeed. Any wins that we can get with compile time, we should take. Clang is being widely used in production systems now so I feel like with a trivial change plus user visible impact, it should be backported.
Not to mention that the generated code in theory should be better because it is the compiler's builtin, rather than a hand rolled one, AND this is technically a regression, given that it worked before
compiler.hwas split.
Compilation speed shouldn't be an argument for a stable change unless it is something egregious like a 50% that may affect users or tightly timed CIs.
Fixing an important runtime regression is a stronger argument, but the patch doesn't show what the effects are, so it isn't justified (yet).
Please note that this kind of change touches a lot of code all over the place, which could always trigger other runtime regressions or even bad codegen (yes, very unlikely, but it happens).
Cheers,
Miguel
Miguel Ojeda
Acked-byQuoted 2 lines · Kees Cook
It's a trivial change, so I think it's worth it?
It is simple, but it is not trivial since it may change codegen.
Cheers,
Miguel
Quoted 15 lines · Andrew Morton
Quoted 12 lines · On Thu, 25 Feb 2021 12:03:48 -0800 Kees Cook <[email protected]> wrote:
Quoted 11 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Separating
compiler-clang.hfromcompiler-gcc.hinadventently dropped the definitions of the threeHAVE_BUILTIN_BSWAPmacros, which requires falling back to the open-coded version and hoping that the compiler detects it.Since all versions of clang support the
__builtin_bswapinterfaces, add back the flags and have the headers pick these up automatically.This results in a 4% improvement of compilation speed for arm defconfig.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Fixes 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")Signed-off-by Arnd Bergmann <[email protected]>I figured 4% better compile time isn't significant enough to justify a backport. Thoughts?
If I made a mistake in 815f0ddb346c, then it would be important to correct it since 815f0ddb346c has existed for a few stable branches (first landed in v4.19-rc1).
Quoted 3 lines
Quoted 2 lines
Reviewed-by Kees Cook <[email protected]>
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 13 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
Fixes 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive")Signed-off-by Arnd Bergmann <[email protected]>--- include/linux/compiler-clang.h | 10 ++++++++++ 1 file changed, 10 insertions(+)include/linux/compiler-clang.h +0
-0
include/linux/compiler-clang.h line 39
Quoted 7 lines
include/linux/compiler-clang.h +4
-0@@ -33,6 +33,16 @@#define __no_sanitize_thread#endif +/* +* sparse (__CHECKER__) pretends to be gcc, but can't do constant +* folding in __builtin_bswap*() (yet), so don't set these for it. +*/
This is not true anymore since 2017. Also, a much recent version of Sparse is needed for _Generic(), for example).
Can you remove the comment and the test for __CHECKER__?
Best regards,
-- Luc