Clang feature updates for v5.14-rc1
- Add CC_HAS_NO_PROFILE_FN_ATTR in preparation for PGO support in the face of the noinstr attribute, paving the way for PGO and fixing GCOV. (Nick Desaulniers) - x86_64 LTO coverage is expanded to 32-bit x86. (Nathan Chancellor) - Small fixes to CFI. (Mark Rutland, Nathan Chancellor) -----BEGIN PGP SIGNATURE----- iQJKBAABCgA0FiEEpcP2jyKd1g9yPm4TiXL039xtwCYFAmDbiFYWHGtlZXNjb29r QGNocm9taXVtLm9yZwAKCRCJcvTf3G3AJtd7D/9O7KE4M1O38TumCK9e6djPETb6 CHF5dpxnV5w1ZWgBysy8+nZ0ORWAm05rgF65K4ROBUhdrygEElIIkI88a/F9pDyE 99E0WTgQi4x4pFFJHF1Sj2G6YoCqrvFpZ45fMd8xk3y/sykhKO4k2A2ux1cHH1zh yYkzASDdukpr/xfcu1JCSFyjRU3Yk9aRzpg0PtrcMSDDuCYqg+oL91rxtkdXc6wS FbVSkUiFQq+RZk9h6DaiVDen/rPvo4rqgQYbdVM8s94gMaHA4MiMiQE6cKkClfdp zacqqh9Cjaeyievz6jkVSqFtmO7e231E6kAWg/ebqVjs6WIcS3NVEfGGjCEaCuMq qKy/m30YzpJ0jLbbQ9L/Cm3xu5ZqfSaQBQmBjNcBMkeMQN8o/P6qt6UASZfBXXCs ++MUpNQEJqxCyZdwu/6qlzfKUiGo5AJo7RRes5/shqTXQLLBni4j7vtkSYZsfPYr b1nHk6TnyY7PjcMekG/IWU89pMchEDswGxSGlrqoop1kT3zumzJeZdPAB8sdNjI8 aBb120qLIC8n9ybZZsNliNtK4IHerBOxDDJB40EEbtBCPowZDEUt/z/DQrKjbOv4 viOulu1D8f/MDXVBx2aTXGpMo/jQf7bKRITtpzt1eFWSTZzqCqWLfGRq2myjz0t5 f2x1rpJLC2oV4KNCYw== =IhVh -----END PGP SIGNATURE----- Merge tag 'clang-features-v5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux Pull clang feature updates from Kees Cook: - Add CC_HAS_NO_PROFILE_FN_ATTR in preparation for PGO support in the face of the noinstr attribute, paving the way for PGO and fixing GCOV. (Nick Desaulniers) - x86_64 LTO coverage is expanded to 32-bit x86. (Nathan Chancellor) - Small fixes to CFI. (Mark Rutland, Nathan Chancellor) * tag 'clang-features-v5.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: qemu_fw_cfg: Make fw_cfg_rev_attr a proper kobj_attribute Kconfig: Introduce ARCH_WANTS_NO_INSTR and CC_HAS_NO_PROFILE_FN_ATTR compiler_attributes.h: cleanups for GCC 4.9+ compiler_attributes.h: define __no_profile, add to noinstr x86, lto: Enable Clang LTO for 32-bit as well CFI: Move function_nocfi() into compiler.h MAINTAINERS: Add Clang CFI section
This commit is contained in:
commit
44b6ed4cfa
12
MAINTAINERS
12
MAINTAINERS
@ -4447,6 +4447,18 @@ F: include/linux/compiler-clang.h
|
||||
F: scripts/clang-tools/
|
||||
K: \b(?i:clang|llvm)\b
|
||||
|
||||
CLANG CONTROL FLOW INTEGRITY SUPPORT
|
||||
M: Sami Tolvanen <samitolvanen@google.com>
|
||||
M: Kees Cook <keescook@chromium.org>
|
||||
R: Nathan Chancellor <nathan@kernel.org>
|
||||
R: Nick Desaulniers <ndesaulniers@google.com>
|
||||
L: clang-built-linux@googlegroups.com
|
||||
S: Supported
|
||||
B: https://github.com/ClangBuiltLinux/linux/issues
|
||||
T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/clang/features
|
||||
F: include/linux/cfi.h
|
||||
F: kernel/cfi.c
|
||||
|
||||
CLEANCACHE API
|
||||
M: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
|
||||
L: linux-kernel@vger.kernel.org
|
||||
|
@ -285,6 +285,13 @@ config ARCH_THREAD_STACK_ALLOCATOR
|
||||
config ARCH_WANTS_DYNAMIC_TASK_STRUCT
|
||||
bool
|
||||
|
||||
config ARCH_WANTS_NO_INSTR
|
||||
bool
|
||||
help
|
||||
An architecture should select this if the noinstr macro is being used on
|
||||
functions to denote that the toolchain should avoid instrumenting such
|
||||
functions and is required for correctness.
|
||||
|
||||
config ARCH_32BIT_OFF_T
|
||||
bool
|
||||
depends on !64BIT
|
||||
|
@ -93,6 +93,7 @@ config ARM64
|
||||
select ARCH_WANT_FRAME_POINTERS
|
||||
select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36)
|
||||
select ARCH_WANT_LD_ORPHAN_WARN
|
||||
select ARCH_WANTS_NO_INSTR
|
||||
select ARCH_HAS_UBSAN_SANITIZE_ALL
|
||||
select ARM_AMBA
|
||||
select ARM_ARCH_TIMER
|
||||
|
@ -23,4 +23,20 @@
|
||||
#define __builtin_return_address(val) \
|
||||
(void *)(ptrauth_clear_pac((unsigned long)__builtin_return_address(val)))
|
||||
|
||||
#ifdef CONFIG_CFI_CLANG
|
||||
/*
|
||||
* With CONFIG_CFI_CLANG, the compiler replaces function address
|
||||
* references with the address of the function's CFI jump table
|
||||
* entry. The function_nocfi macro always returns the address of the
|
||||
* actual function instead.
|
||||
*/
|
||||
#define function_nocfi(x) ({ \
|
||||
void *addr; \
|
||||
asm("adrp %0, " __stringify(x) "\n\t" \
|
||||
"add %0, %0, :lo12:" __stringify(x) \
|
||||
: "=r" (addr)); \
|
||||
addr; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#endif /* __ASM_COMPILER_H */
|
||||
|
@ -321,22 +321,6 @@ static inline void *phys_to_virt(phys_addr_t x)
|
||||
#define virt_to_pfn(x) __phys_to_pfn(__virt_to_phys((unsigned long)(x)))
|
||||
#define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x))
|
||||
|
||||
#ifdef CONFIG_CFI_CLANG
|
||||
/*
|
||||
* With CONFIG_CFI_CLANG, the compiler replaces function address
|
||||
* references with the address of the function's CFI jump table
|
||||
* entry. The function_nocfi macro always returns the address of the
|
||||
* actual function instead.
|
||||
*/
|
||||
#define function_nocfi(x) ({ \
|
||||
void *addr; \
|
||||
asm("adrp %0, " __stringify(x) "\n\t" \
|
||||
"add %0, %0, :lo12:" __stringify(x) \
|
||||
: "=r" (addr)); \
|
||||
addr; \
|
||||
})
|
||||
#endif
|
||||
|
||||
/*
|
||||
* virt_to_page(x) convert a _valid_ virtual address to struct page *
|
||||
* virt_addr_valid(x) indicates whether a virtual address is valid
|
||||
|
@ -117,6 +117,7 @@ config S390
|
||||
select ARCH_USE_BUILTIN_BSWAP
|
||||
select ARCH_USE_CMPXCHG_LOCKREF
|
||||
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
|
||||
select ARCH_WANTS_NO_INSTR
|
||||
select ARCH_WANT_DEFAULT_BPF_JIT
|
||||
select ARCH_WANT_IPC_PARSE_VERSION
|
||||
select BUILDTIME_TABLE_SORT
|
||||
|
@ -103,8 +103,8 @@ config X86
|
||||
select ARCH_SUPPORTS_DEBUG_PAGEALLOC
|
||||
select ARCH_SUPPORTS_NUMA_BALANCING if X86_64
|
||||
select ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP if NR_CPUS <= 4096
|
||||
select ARCH_SUPPORTS_LTO_CLANG if X86_64
|
||||
select ARCH_SUPPORTS_LTO_CLANG_THIN if X86_64
|
||||
select ARCH_SUPPORTS_LTO_CLANG
|
||||
select ARCH_SUPPORTS_LTO_CLANG_THIN
|
||||
select ARCH_USE_BUILTIN_BSWAP
|
||||
select ARCH_USE_MEMTEST
|
||||
select ARCH_USE_QUEUED_RWLOCKS
|
||||
@ -113,6 +113,7 @@ config X86
|
||||
select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
|
||||
select ARCH_WANT_DEFAULT_BPF_JIT if X86_64
|
||||
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
|
||||
select ARCH_WANTS_NO_INSTR
|
||||
select ARCH_WANT_HUGE_PMD_SHARE
|
||||
select ARCH_WANT_LD_ORPHAN_WARN
|
||||
select ARCH_WANTS_THP_SWAP if X86_64
|
||||
|
@ -299,15 +299,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t fw_cfg_showrev(struct kobject *k, struct attribute *a, char *buf)
|
||||
static ssize_t fw_cfg_showrev(struct kobject *k, struct kobj_attribute *a,
|
||||
char *buf)
|
||||
{
|
||||
return sprintf(buf, "%u\n", fw_cfg_rev);
|
||||
}
|
||||
|
||||
static const struct {
|
||||
struct attribute attr;
|
||||
ssize_t (*show)(struct kobject *k, struct attribute *a, char *buf);
|
||||
} fw_cfg_rev_attr = {
|
||||
static const struct kobj_attribute fw_cfg_rev_attr = {
|
||||
.attr = { .name = "rev", .mode = S_IRUSR },
|
||||
.show = fw_cfg_showrev,
|
||||
};
|
||||
|
@ -219,6 +219,16 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
|
||||
__v; \
|
||||
})
|
||||
|
||||
/*
|
||||
* With CONFIG_CFI_CLANG, the compiler replaces function addresses in
|
||||
* instrumented C code with jump table addresses. Architectures that
|
||||
* support CFI can define this macro to return the actual function address
|
||||
* when needed.
|
||||
*/
|
||||
#ifndef function_nocfi
|
||||
#define function_nocfi(x) (x)
|
||||
#endif
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
/*
|
||||
|
@ -27,15 +27,16 @@
|
||||
*/
|
||||
#ifndef __has_attribute
|
||||
# define __has_attribute(x) __GCC4_has_attribute_##x
|
||||
# define __GCC4_has_attribute___assume_aligned__ (__GNUC_MINOR__ >= 9)
|
||||
# define __GCC4_has_attribute___assume_aligned__ 1
|
||||
# define __GCC4_has_attribute___copy__ 0
|
||||
# define __GCC4_has_attribute___designated_init__ 0
|
||||
# define __GCC4_has_attribute___externally_visible__ 1
|
||||
# define __GCC4_has_attribute___no_caller_saved_registers__ 0
|
||||
# define __GCC4_has_attribute___noclone__ 1
|
||||
# define __GCC4_has_attribute___no_profile_instrument_function__ 0
|
||||
# define __GCC4_has_attribute___nonstring__ 0
|
||||
# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8)
|
||||
# define __GCC4_has_attribute___no_sanitize_undefined__ (__GNUC_MINOR__ >= 9)
|
||||
# define __GCC4_has_attribute___no_sanitize_address__ 1
|
||||
# define __GCC4_has_attribute___no_sanitize_undefined__ 1
|
||||
# define __GCC4_has_attribute___fallthrough__ 0
|
||||
#endif
|
||||
|
||||
@ -238,6 +239,18 @@
|
||||
# define __nonstring
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Optional: only supported since GCC >= 7.1, clang >= 13.0.
|
||||
*
|
||||
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fprofile_005finstrument_005ffunction-function-attribute
|
||||
* clang: https://clang.llvm.org/docs/AttributeReference.html#no-profile-instrument-function
|
||||
*/
|
||||
#if __has_attribute(__no_profile_instrument_function__)
|
||||
# define __no_profile __attribute__((__no_profile_instrument_function__))
|
||||
#else
|
||||
# define __no_profile
|
||||
#endif
|
||||
|
||||
/*
|
||||
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute
|
||||
* clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn
|
||||
|
@ -210,7 +210,7 @@ struct ftrace_likely_data {
|
||||
/* Section for code which can't be instrumented at all */
|
||||
#define noinstr \
|
||||
noinline notrace __attribute((__section__(".noinstr.text"))) \
|
||||
__no_kcsan __no_sanitize_address
|
||||
__no_kcsan __no_sanitize_address __no_profile
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
|
@ -124,16 +124,6 @@ extern int mmap_rnd_compat_bits __read_mostly;
|
||||
#define lm_alias(x) __va(__pa_symbol(x))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* With CONFIG_CFI_CLANG, the compiler replaces function addresses in
|
||||
* instrumented C code with jump table addresses. Architectures that
|
||||
* support CFI can define this macro to return the actual function address
|
||||
* when needed.
|
||||
*/
|
||||
#ifndef function_nocfi
|
||||
#define function_nocfi(x) (x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* To prevent common memory management code establishing
|
||||
* a zero page mapping on a read fault.
|
||||
|
@ -83,6 +83,9 @@ config TOOLS_SUPPORT_RELR
|
||||
config CC_HAS_ASM_INLINE
|
||||
def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
|
||||
|
||||
config CC_HAS_NO_PROFILE_FN_ATTR
|
||||
def_bool $(success,echo '__attribute__((no_profile_instrument_function)) int x();' | $(CC) -x c - -c -o /dev/null -Werror)
|
||||
|
||||
config CONSTRUCTORS
|
||||
bool
|
||||
|
||||
|
@ -5,6 +5,7 @@ config GCOV_KERNEL
|
||||
bool "Enable gcov-based kernel profiling"
|
||||
depends on DEBUG_FS
|
||||
depends on !CC_IS_CLANG || CLANG_VERSION >= 110000
|
||||
depends on !ARCH_WANTS_NO_INSTR || CC_HAS_NO_PROFILE_FN_ATTR
|
||||
select CONSTRUCTORS
|
||||
default n
|
||||
help
|
||||
|
Loading…
Reference in New Issue
Block a user