Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_COMPILER_TYPES_H
0003 #error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
0004 #endif
0005 
0006 /*
0007  * Common definitions for all gcc versions go here.
0008  */
0009 #define GCC_VERSION (__GNUC__ * 10000       \
0010              + __GNUC_MINOR__ * 100 \
0011              + __GNUC_PATCHLEVEL__)
0012 
0013 /*
0014  * This macro obfuscates arithmetic on a variable address so that gcc
0015  * shouldn't recognize the original var, and make assumptions about it.
0016  *
0017  * This is needed because the C standard makes it undefined to do
0018  * pointer arithmetic on "objects" outside their boundaries and the
0019  * gcc optimizers assume this is the case. In particular they
0020  * assume such arithmetic does not wrap.
0021  *
0022  * A miscompilation has been observed because of this on PPC.
0023  * To work around it we hide the relationship of the pointer and the object
0024  * using this macro.
0025  *
0026  * Versions of the ppc64 compiler before 4.1 had a bug where use of
0027  * RELOC_HIDE could trash r30. The bug can be worked around by changing
0028  * the inline assembly constraint from =g to =r, in this particular
0029  * case either is valid.
0030  */
0031 #define RELOC_HIDE(ptr, off)                        \
0032 ({                                  \
0033     unsigned long __ptr;                        \
0034     __asm__ ("" : "=r"(__ptr) : "0"(ptr));              \
0035     (typeof(ptr)) (__ptr + (off));                  \
0036 })
0037 
0038 #ifdef CONFIG_RETPOLINE
0039 #define __noretpoline __attribute__((__indirect_branch__("keep")))
0040 #endif
0041 
0042 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
0043 
0044 #if defined(LATENT_ENTROPY_PLUGIN) && !defined(__CHECKER__)
0045 #define __latent_entropy __attribute__((latent_entropy))
0046 #endif
0047 
0048 /*
0049  * calling noreturn functions, __builtin_unreachable() and __builtin_trap()
0050  * confuse the stack allocation in gcc, leading to overly large stack
0051  * frames, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365
0052  *
0053  * Adding an empty inline assembly before it works around the problem
0054  */
0055 #define barrier_before_unreachable() asm volatile("")
0056 
0057 /*
0058  * Mark a position in code as unreachable.  This can be used to
0059  * suppress control flow warnings after asm blocks that transfer
0060  * control elsewhere.
0061  */
0062 #define unreachable() \
0063     do {                    \
0064         annotate_unreachable();     \
0065         barrier_before_unreachable();   \
0066         __builtin_unreachable();    \
0067     } while (0)
0068 
0069 #if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP)
0070 #define __HAVE_BUILTIN_BSWAP32__
0071 #define __HAVE_BUILTIN_BSWAP64__
0072 #define __HAVE_BUILTIN_BSWAP16__
0073 #endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
0074 
0075 #if GCC_VERSION >= 70000
0076 #define KASAN_ABI_VERSION 5
0077 #else
0078 #define KASAN_ABI_VERSION 4
0079 #endif
0080 
0081 #ifdef CONFIG_SHADOW_CALL_STACK
0082 #define __noscs __attribute__((__no_sanitize__("shadow-call-stack")))
0083 #endif
0084 
0085 #if __has_attribute(__no_sanitize_address__)
0086 #define __no_sanitize_address __attribute__((no_sanitize_address))
0087 #else
0088 #define __no_sanitize_address
0089 #endif
0090 
0091 #if defined(__SANITIZE_THREAD__) && __has_attribute(__no_sanitize_thread__)
0092 #define __no_sanitize_thread __attribute__((no_sanitize_thread))
0093 #else
0094 #define __no_sanitize_thread
0095 #endif
0096 
0097 #if __has_attribute(__no_sanitize_undefined__)
0098 #define __no_sanitize_undefined __attribute__((no_sanitize_undefined))
0099 #else
0100 #define __no_sanitize_undefined
0101 #endif
0102 
0103 #if defined(CONFIG_KCOV) && __has_attribute(__no_sanitize_coverage__)
0104 #define __no_sanitize_coverage __attribute__((no_sanitize_coverage))
0105 #else
0106 #define __no_sanitize_coverage
0107 #endif
0108 
0109 /*
0110  * Treat __SANITIZE_HWADDRESS__ the same as __SANITIZE_ADDRESS__ in the kernel,
0111  * matching the defines used by Clang.
0112  */
0113 #ifdef __SANITIZE_HWADDRESS__
0114 #define __SANITIZE_ADDRESS__
0115 #endif
0116 
0117 /*
0118  * Turn individual warnings and errors on and off locally, depending
0119  * on version.
0120  */
0121 #define __diag_GCC(version, severity, s) \
0122     __diag_GCC_ ## version(__diag_GCC_ ## severity s)
0123 
0124 /* Severity used in pragma directives */
0125 #define __diag_GCC_ignore   ignored
0126 #define __diag_GCC_warn     warning
0127 #define __diag_GCC_error    error
0128 
0129 #define __diag_str1(s)      #s
0130 #define __diag_str(s)       __diag_str1(s)
0131 #define __diag(s)       _Pragma(__diag_str(GCC diagnostic s))
0132 
0133 #if GCC_VERSION >= 80000
0134 #define __diag_GCC_8(s)     __diag(s)
0135 #else
0136 #define __diag_GCC_8(s)
0137 #endif
0138 
0139 #define __diag_ignore_all(option, comment) \
0140     __diag_GCC(8, ignore, option)
0141 
0142 /*
0143  * Prior to 9.1, -Wno-alloc-size-larger-than (and therefore the "alloc_size"
0144  * attribute) do not work, and must be disabled.
0145  */
0146 #if GCC_VERSION < 90100
0147 #undef __alloc_size__
0148 #endif