From 4ec0a73aca88914770532995ef0c8faf01ba58ae Mon Sep 17 00:00:00 2001 From: Xiaozhou Liu Date: Fri, 14 Dec 2018 22:14:31 +0800 Subject: [PATCH] include/linux/compiler_types.h: don't pollute userspace with macro definitions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Macros 'inline' and '__gnu_inline' used to be defined in compiler-gcc.h, which was (and is) included entirely in (__KERNEL__ && !__ASSEMBLY__). Commit 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h mutually exclusive") had those macros exposed to userspace, unintentionally. Then commit a3f8a30f3f00 ("Compiler Attributes: use feature checks instead of version checks") moved '__gnu_inline' back into (__KERNEL__ && !__ASSEMBLY__) and 'inline' was left behind. Since 'inline' depends on '__gnu_inline', compiling error showing "unknown type name ‘__gnu_inline’" will pop up, if userspace somehow includes . Other macros like __must_check, notrace, etc. are in a similar situation. So just move all these macros back into (__KERNEL__ && !__ASSEMBLY__). Note: 1. This patch only affects what userspace sees. 2. __must_check (when !CONFIG_ENABLE_MUST_CHECK) and noinline_for_stack were once defined in __KERNEL__ only, but we believe that they can be put into !__ASSEMBLY__ too. Acked-by: Nick Desaulniers Signed-off-by: Xiaozhou Liu Signed-off-by: Miguel Ojeda --- include/linux/compiler_types.h | 152 ++++++++++++++++----------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index db192becfec4..c9699563c28b 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -110,82 +110,6 @@ struct ftrace_likely_data { #define __deprecated #define __deprecated_for_modules -#endif /* __KERNEL__ */ - -#endif /* __ASSEMBLY__ */ - -/* - * The below symbols may be defined for one or more, but not ALL, of the above - * compilers. We don't consider that to be an error, so set them to nothing. - * For example, some of them are for compiler specific plugins. - */ -#ifndef __designated_init -# define __designated_init -#endif - -#ifndef __latent_entropy -# define __latent_entropy -#endif - -#ifndef __randomize_layout -# define __randomize_layout __designated_init -#endif - -#ifndef __no_randomize_layout -# define __no_randomize_layout -#endif - -#ifndef randomized_struct_fields_start -# define randomized_struct_fields_start -# define randomized_struct_fields_end -#endif - -#ifndef __visible -#define __visible -#endif - -/* - * Assume alignment of return value. - */ -#ifndef __assume_aligned -#define __assume_aligned(a, ...) -#endif - -/* Are two types/vars the same type (ignoring qualifiers)? */ -#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) - -/* Is this type a native word size -- useful for atomic operations */ -#define __native_word(t) \ - (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ - sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) - -#ifndef __attribute_const__ -#define __attribute_const__ __attribute__((__const__)) -#endif - -#ifndef __noclone -#define __noclone -#endif - -/* Helpers for emitting diagnostics in pragmas. */ -#ifndef __diag -#define __diag(string) -#endif - -#ifndef __diag_GCC -#define __diag_GCC(version, severity, string) -#endif - -#define __diag_push() __diag(push) -#define __diag_pop() __diag(pop) - -#define __diag_ignore(compiler, version, option, comment) \ - __diag_ ## compiler(version, ignore, option) -#define __diag_warn(compiler, version, option, comment) \ - __diag_ ## compiler(version, warn, option) -#define __diag_error(compiler, version, option, comment) \ - __diag_ ## compiler(version, error, option) - /* * From the GCC manual: * @@ -282,4 +206,80 @@ struct ftrace_likely_data { */ #define noinline_for_stack noinline +#endif /* __KERNEL__ */ + +#endif /* __ASSEMBLY__ */ + +/* + * The below symbols may be defined for one or more, but not ALL, of the above + * compilers. We don't consider that to be an error, so set them to nothing. + * For example, some of them are for compiler specific plugins. + */ +#ifndef __designated_init +# define __designated_init +#endif + +#ifndef __latent_entropy +# define __latent_entropy +#endif + +#ifndef __randomize_layout +# define __randomize_layout __designated_init +#endif + +#ifndef __no_randomize_layout +# define __no_randomize_layout +#endif + +#ifndef randomized_struct_fields_start +# define randomized_struct_fields_start +# define randomized_struct_fields_end +#endif + +#ifndef __visible +#define __visible +#endif + +/* + * Assume alignment of return value. + */ +#ifndef __assume_aligned +#define __assume_aligned(a, ...) +#endif + +/* Are two types/vars the same type (ignoring qualifiers)? */ +#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) + +/* Is this type a native word size -- useful for atomic operations */ +#define __native_word(t) \ + (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ + sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) + +#ifndef __attribute_const__ +#define __attribute_const__ __attribute__((__const__)) +#endif + +#ifndef __noclone +#define __noclone +#endif + +/* Helpers for emitting diagnostics in pragmas. */ +#ifndef __diag +#define __diag(string) +#endif + +#ifndef __diag_GCC +#define __diag_GCC(version, severity, string) +#endif + +#define __diag_push() __diag(push) +#define __diag_pop() __diag(pop) + +#define __diag_ignore(compiler, version, option, comment) \ + __diag_ ## compiler(version, ignore, option) +#define __diag_warn(compiler, version, option, comment) \ + __diag_ ## compiler(version, warn, option) +#define __diag_error(compiler, version, option, comment) \ + __diag_ ## compiler(version, error, option) + #endif /* __LINUX_COMPILER_TYPES_H */ -- 2.17.1