treewide: prefer __section from compiler_attributes.h
Subsystems (17)
v2 cover treewide: prefer __section from compiler_attributes.h
GCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
This fixes an Oops observed in distro's that use systemd and not net.core.bpf_jit_enable=1, when their kernels are compiled with Clang.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
https://bugs.llvm.org/show_bug.cgi?id=42950
https://marc.info/?l=linux-netdev&m=156412960619946&w=2
Changes V1 -> V2:
* drop arm64, arc, and sh patches as they were picked up by their maintainers.
* Split the previous V1 hunk from include/linux that touched include/linux/compiler.h off into its own patch for inclusion in stable, as it fixes a user visible issue.
* Collect Acks and Tested by tags.
Nick Desaulniers (14):
s390/boot: prefer __section from compiler_attributes.h include/linux/compiler.h: prefer __section from compiler_attributes.h
parisc: prefer __section from compiler_attributes.h
um: prefer __section from compiler_attributes.h
ia64: prefer __section from compiler_attributes.h
arm: prefer __section from compiler_attributes.h
mips: prefer __section from compiler_attributes.h
sparc: prefer __section from compiler_attributes.h
powerpc: prefer __section and __printf from compiler_attributes.h
x86: prefer __section from compiler_attributes.h include/asm-generic: prefer __section from compiler_attributes.h include/linux: prefer __section from compiler_attributes.h include/linux/compiler.h: remove unused KENTRY macro compiler_attributes.h: add note about __section
arch/arm/include/asm/cache.h | 2 +- arch/arm/include/asm/mach/arch.h | 4 ++-- arch/arm/include/asm/setup.h | 2 +- arch/ia64/include/asm/cache.h | 2 +- arch/mips/include/asm/cache.h | 2 +- arch/parisc/include/asm/cache.h | 2 +- arch/parisc/include/asm/ldcw.h | 2 +- arch/powerpc/boot/main.c | 3 +-- arch/powerpc/boot/ps3.c | 6 ++---- arch/powerpc/include/asm/cache.h | 2 +- arch/powerpc/kernel/btext.c | 2 +- arch/s390/boot/startup.c | 2 +- arch/sparc/include/asm/cache.h | 2 +- arch/sparc/kernel/btext.c | 2 +- arch/um/kernel/um_arch.c | 6 +++--- arch/x86/include/asm/cache.h | 2 +- arch/x86/include/asm/intel-mid.h | 2 +- arch/x86/include/asm/iommu_table.h | 5 ++--- arch/x86/include/asm/irqflags.h | 2 +- arch/x86/include/asm/mem_encrypt.h | 2 +- arch/x86/kernel/cpu/cpu.h | 3 +-- include/asm-generic/error-injection.h | 2 +- include/asm-generic/kprobes.h | 5 ++--- include/linux/cache.h | 6 +++--- include/linux/compiler.h | 31 ++++----------------------- include/linux/compiler_attributes.h | 10 +++++++++ include/linux/cpu.h | 2 +- include/linux/export.h | 2 +- include/linux/init_task.h | 4 ++-- include/linux/interrupt.h | 5 ++--- include/linux/sched/debug.h | 2 +- include/linux/srcutree.h | 2 +- 32 files changed, 54 insertions(+), 74 deletions(-)
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 1/14 s390/boot: perfer __section from compiler_attributes.h
GCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
--- arch/s390/boot/startup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/boot/startup.c +1 -1
@@ -46,7 +46,7 @@ struct diag_ops __bootdata_preserved(diag_dma_ops) = { .diag0c = _diag0c_dma, .diag308_reset = _diag308_reset_dma }; -static struct diag210 _diag210_tmp_dma __section(".dma.data"); +static struct diag210 _diag210_tmp_dma __section(.dma.data);struct diag210 *__bootdata_preserved (__diag210_tmp_dma ) = &_diag210_tmp_dma;void _swsusp_reset_dma (void );unsigned long __bootdata_preserved (__swsusp_reset_dma ) =__pa (_swsusp_reset_dma);
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 2/14 include/linux/compiler.h: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
This fixes an Oops observed in distro's that use systemd and not net.core.bpf_jit_enable=1, when their kernels are compiled with Clang.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- include/linux/compiler.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/compiler.h +4 -4
@@ -24,7 +24,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,long ______r; \static struct ftrace_likely_data \ __aligned(4) \ - __section("_ftrace_annotated_branch") \ +__section (_ftrace_annotated_branch) \ ______f = { \ .data.func = __func__, \ .data.file = __FILE__, \
@@ -60,7 +60,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,#define __trace_if_value (cond) ({ \ static struct ftrace_branch_data \ __aligned(4) \ - __section("_ftrace_branch") \ + __section(_ftrace_branch) \ __if_trace = { \ .func = __func__, \ .file = __FILE__, \
@@ -118,7 +118,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,".popsection\n\t" /* Annotate a C jump table to allow objtool to follow the code flow */ -#define __annotate_jump_table __section(".rodata..c_jump_table") +#define __annotate_jump_table __section(.rodata..c_jump_table)#else #define annotate_reachable ()
@@ -298,7 +298,7 @@ unsigned long read_word_at_a_time(const void *addr)* visible to the compiler. */ #define __ADDRESSABLE (sym) \ - static void * __section(".discard.addressable") __used \ + static void * __section(.discard.addressable) __used \ __PASTE(__addressable_##sym, __LINE__) = (void *)&sym;/**
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 3/14 parisc: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- arch/parisc/include/asm/cache.h | 2 +- arch/parisc/include/asm/ldcw.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/parisc/include/asm/cache.h +1 -1
@@ -22,7 +22,7 @@#define ARCH_DMA_MINALIGN L1_CACHE_BYTES -#define __read_mostly __attribute__((__section__(".data..read_mostly"))) +#define __read_mostly __section(.data..read_mostly)void parisc_cache_init (void );/* initializes cache-flushing */ void disable_sr_hashing_asm (int );/* low level support for above */
arch/parisc/include/asm/ldcw.h +1 -1
@@ -52,7 +52,7 @@ })#ifdef CONFIG_SMP -# define __lock_aligned __attribute__((__section__(".data..lock_aligned"))) +# define __lock_aligned __section(.data..lock_aligned)#endif #endif /* __PARISC_LDCW_H */
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 4/14 um: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- arch/um/kernel/um_arch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/um/kernel/um_arch.c +3 -3
@@ -52,9 +52,9 @@ struct cpuinfo_um boot_cpu_data = { .ipi_pipe = { -1, -1 } }; -union thread_union cpu0_irqstack - __attribute__((__section__(".data..init_irqstack"))) = - { .thread_info = INIT_THREAD_INFO(init_task) }; +union thread_union cpu0_irqstack __section(.data..init_irqstack) = { + .thread_info =INIT_THREAD_INFO (init_task) +};/* Changed in setup_arch, which is called in early boot */ static char host_info[(__NEW_UTS_LEN +1 ) *5 ];
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 5/14 ia64: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- arch/ia64/include/asm/cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/include/asm/cache.h +1 -1
@@ -25,6 +25,6 @@# define SMP_CACHE_BYTES (1 << 3)#endif -#define __read_mostly __attribute__((__section__(".data..read_mostly"))) +#define __read_mostly __section(.data..read_mostly)#endif /* _ASM_IA64_CACHE_H */
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 6/14 arm: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- arch/arm/include/asm/cache.h | 2 +- arch/arm/include/asm/mach/arch.h | 4 ++-- arch/arm/include/asm/setup.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
arch/arm/include/asm/cache.h +1 -1
@@ -24,6 +24,6 @@#define ARCH_SLAB_MINALIGN 8#endif -#define __read_mostly __attribute__((__section__(".data..read_mostly"))) +#define __read_mostly __section(.data..read_mostly)#endif
arch/arm/include/asm/mach/arch.h +2 -2
@@ -81,7 +81,7 @@ extern const struct machine_desc __arch_info_begin[], __arch_info_end[];#define MACHINE_START (_type,_name) \ static const struct machine_desc __mach_desc_##_type \ __used \ - __attribute__((__section__(".arch.info.init"))) = { \ + __section(.arch.info.init) = { \ .nr = MACH_TYPE_##_type, \ .name = _name,
@@ -91,7 +91,7 @@ static const struct machine_desc __mach_desc_##_type \#define DT_MACHINE_START (_name, _namestr) \ static const struct machine_desc __mach_desc_##_name \ __used \ - __attribute__((__section__(".arch.info.init"))) = { \ + __section(.arch.info.init) = { \ .nr = ~0, \ .name = _namestr,
arch/arm/include/asm/setup.h +1 -1
@@ -14,7 +14,7 @@#include <uapi/asm/setup.h> -#define __tag __used __attribute__((__section__(".taglist.init"))) +#define __tag __used __section(.taglist.init)#define __tagtable (tag, fn) \ static const struct tagtable __tagtable_##fn __tag = { tag, fn }
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 7/14 mips: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- arch/mips/include/asm/cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/cache.h +1 -1
@@ -14,6 +14,6 @@#define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) -#define __read_mostly __attribute__((__section__(".data..read_mostly"))) +#define __read_mostly __section(.data..read_mostly)#endif /* _ASM_CACHE_H */
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 8/14 sparc: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- arch/sparc/include/asm/cache.h | 2 +- arch/sparc/kernel/btext.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/sparc/include/asm/cache.h +1 -1
@@ -21,6 +21,6 @@#define SMP_CACHE_BYTES (1 << SMP_CACHE_BYTES_SHIFT) -#define __read_mostly __attribute__((__section__(".data..read_mostly"))) +#define __read_mostly __section(.data..read_mostly)#endif /* !(_SPARC_CACHE_H) */
arch/sparc/kernel/btext.c +1 -1
@@ -24,7 +24,7 @@ static void draw_byte_32(unsigned char *bits, unsigned int *base, int rb);static void draw_byte_16 (unsigned char *bits,unsigned int *base,int rb);static void draw_byte_8 (unsigned char *bits,unsigned int *base,int rb); -#define __force_data __attribute__((__section__(".data"))) +#define __force_data __section(.data) static int g_loc_X __force_data; static int g_loc_Y __force_data;
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 9/14 powerpc: prefer __section and __printf from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- arch/powerpc/boot/main.c | 3 +-- arch/powerpc/boot/ps3.c | 6 ++---- arch/powerpc/include/asm/cache.h | 2 +- arch/powerpc/kernel/btext.c | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-)
arch/powerpc/boot/main.c +1 -2
@@ -150,8 +150,7 @@ static struct addr_range prep_initrd(struct addr_range vmlinux, void *chosen,* edit the command line passed to vmlinux (by setting /chosen/bootargs). * The buffer is put in it's own section so that tools may locate it easier. */ -static char cmdline[BOOT_COMMAND_LINE_SIZE] - __attribute__((__section__("__builtin_cmdline"))); +static char cmdline[BOOT_COMMAND_LINE_SIZE] __section(__builtin_cmdline);static void prep_cmdline (void *chosen) {
arch/powerpc/boot/ps3.c +2 -4
@@ -24,8 +24,7 @@ extern int lv1_get_repository_node_value(u64 in_1, u64 in_2, u64 in_3,#ifdef DEBUG #define DBG(fmt...) printf(fmt)#else -static inline int __attribute__ ((format (printf,1 ,2 )))DBG ( -const char *fmt, ...) {return 0 ;} +static inline int __printf(1, 2) DBG(const char *fmt, ...) { return 0; } #endif BSS_STACK(4096);
@@ -35,8 +34,7 @@ BSS_STACK(4096);* The buffer is put in it's own section so that tools may locate it easier. */ -static char cmdline[BOOT_COMMAND_LINE_SIZE] - __attribute__((__section__("__builtin_cmdline"))); +static char cmdline[BOOT_COMMAND_LINE_SIZE] __section(__builtin_cmdline);static void prep_cmdline (void *chosen) {
arch/powerpc/include/asm/cache.h +1 -1
@@ -91,7 +91,7 @@ static inline u32 l1_cache_bytes(void) isync#else -#define __read_mostly __attribute__((__section__(".data..read_mostly"))) +#define __read_mostly __section(.data..read_mostly)#ifdef CONFIG_PPC_BOOK3S_32 extern long _get_L2CR (void );
arch/powerpc/kernel/btext.c +1 -1
@@ -26,7 +26,7 @@static void scrollscreen (void );#endif -#define __force_data __attribute__((__section__(".data"))) +#define __force_data __section(.data) static int g_loc_X __force_data; static int g_loc_Y __force_data;
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 10/14 x86: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- arch/x86/include/asm/cache.h | 2 +- arch/x86/include/asm/intel-mid.h | 2 +- arch/x86/include/asm/iommu_table.h | 5 ++--- arch/x86/include/asm/irqflags.h | 2 +- arch/x86/include/asm/mem_encrypt.h | 2 +- arch/x86/kernel/cpu/cpu.h | 3 +-- 6 files changed, 7 insertions(+), 9 deletions(-)
arch/x86/include/asm/cache.h +1 -1
@@ -8,7 +8,7 @@#define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) -#define __read_mostly __attribute__((__section__(".data..read_mostly"))) +#define __read_mostly __section(.data..read_mostly)#define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
arch/x86/include/asm/intel-mid.h +1 -1
@@ -43,7 +43,7 @@ struct devs_id {#define sfi_device (i) \ static const struct devs_id *const __intel_mid_sfi_##i##_dev __used \ - __attribute__((__section__(".x86_intel_mid_dev.init"))) = &i + __section(.x86_intel_mid_dev.init) = &i/** * struct mid_sd_board_info - template for SD device creation
arch/x86/include/asm/iommu_table.h +2 -3
@@ -50,9 +50,8 @@ struct iommu_table_entry {#define __IOMMU_INIT (_detect, _depend, _early_init, _late_init, _finish)\ static const struct iommu_table_entry \ - __iommu_entry_##_detect __used \ - __attribute__ ((unused, __section__(".iommu_table"), \ - aligned((sizeof(void *))))) \ + __iommu_entry_##_detect __used __section(.iommu_table) \ + __aligned((sizeof(void *))) \ = {_detect, _depend, _early_init, _late_init, \ _finish ? IOMMU_FINISH_IF_DETECTED : 0}/*
arch/x86/include/asm/irqflags.h +1 -1
@@ -9,7 +9,7 @@#include <asm/nospec-branch.h> /* Provide __cpuidle; we can't safely include <linux/cpu.h> */ -#define __cpuidle __attribute__((__section__(".cpuidle.text"))) +#define __cpuidle __section(.cpuidle.text)/* * Interrupt control:
arch/x86/include/asm/mem_encrypt.h +1 -1
@@ -50,7 +50,7 @@ void __init mem_encrypt_free_decrypted_mem(void);bool sme_active (void );bool sev_active (void ); -#define __bss_decrypted __attribute__((__section__(".bss..decrypted"))) +#define __bss_decrypted __section(.bss..decrypted)#else /* !CONFIG_AMD_MEM_ENCRYPT */
arch/x86/kernel/cpu/cpu.h +1 -2
@@ -38,8 +38,7 @@ struct _tlb_table {#define cpu_dev_register (cpu_devX) \ static const struct cpu_dev *const __cpu_dev_##cpu_devX __used \ - __attribute__((__section__(".x86_cpu_dev.init"))) = \ - &cpu_devX; + __section(.x86_cpu_dev.init) = &cpu_devX;extern const struct cpu_dev *const __x86_cpu_dev_start[], *const __x86_cpu_dev_end[];
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 11/14 include/asm-generic: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- include/asm-generic/error-injection.h | 2 +- include/asm-generic/kprobes.h | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-)
include/asm-generic/error-injection.h +1 -1
@@ -23,7 +23,7 @@ struct error_injection_entry {*/ #define ALLOW_ERROR_INJECTION (fname, _etype) \ static struct error_injection_entry __used \ - __attribute__((__section__("_error_injection_whitelist"))) \ + __section(_error_injection_whitelist) \ _eil_addr_##fname = { \ .addr = (unsigned long)fname, \ .etype = EI_ETYPE_##_etype, \
include/asm-generic/kprobes.h +2 -3
@@ -9,12 +9,11 @@* by using this macro. */ # define __NOKPROBE_SYMBOL (fname) \ -static unsigned long __used \ - __attribute__((__section__("_kprobe_blacklist"))) \ +static unsigned long __used __section(_kprobe_blacklist) \ _kbl_addr_##fname = (unsigned long)fname;# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname)/* Use this to forbid a kprobes attach on very low level functions */ -# define __kprobes __attribute__((__section__(".kprobes.text"))) +# define __kprobes __section(.kprobes.text)# define nokprobe_inline __always_inline#else # define NOKPROBE_SYMBOL (fname)
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 12/14 include/linux: prefer __section from compiler_attributes.h
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- include/linux/cache.h | 6 +++--- include/linux/cpu.h | 2 +- include/linux/export.h | 2 +- include/linux/init_task.h | 4 ++-- include/linux/interrupt.h | 5 ++--- include/linux/sched/debug.h | 2 +- include/linux/srcutree.h | 2 +- 7 files changed, 11 insertions(+), 12 deletions(-)
include/linux/cache.h +3 -3
@@ -28,7 +28,7 @@* but may get written to during init, so can't live in .rodata (via "const"). */ #ifndef __ro_after_init -#define __ro_after_init __attribute__((__section__(".data..ro_after_init"))) +#define __ro_after_init __section(.data..ro_after_init)#endif #ifndef ____cacheline_aligned
@@ -45,8 +45,8 @@#ifndef __cacheline_aligned#define __cacheline_aligned \ - __attribute__((__aligned__(SMP_CACHE_BYTES), \ - __section__(".data..cacheline_aligned"))) + __aligned(SMP_CACHE_BYTES) \ + __section(.data..cacheline_aligned)#endif /* __cacheline_aligned */ #ifndef __cacheline_aligned_in_smp
include/linux/cpu.h +1 -1
@@ -166,7 +166,7 @@ void cpu_startup_entry(enum cpuhp_state state);void cpu_idle_poll_ctrl (bool enable);/* Attach to any functions which should be considered cpuidle. */ -#define __cpuidle __attribute__((__section__(".cpuidle.text"))) +#define __cpuidle __section(.cpuidle.text)bool cpu_in_idle (unsigned long pc);
include/linux/export.h +1 -1
@@ -104,7 +104,7 @@ struct kernel_symbol {* discarded in the final link stage. */ #define __ksym_marker (sym) \ - static int __ksym_marker_##sym[0] __section(".discard.ksym") __used + static int __ksym_marker_##sym[0] __section(.discard.ksym) __used#define __EXPORT_SYMBOL (sym, sec) \ __ksym_marker(sym); \
include/linux/init_task.h +2 -2
@@ -51,12 +51,12 @@ extern struct cred init_cred;/* Attach to the init_task data structure for proper alignment */ #ifdef CONFIG_ARCH_TASK_STRUCT_ON_STACK -#define __init_task_data __attribute__((__section__(".data..init_task"))) +#define __init_task_data __section(.data..init_task)#else #define __init_task_data/**/ #endif /* Attach to the thread_info data structure for proper alignment */ -#define __init_thread_info __attribute__((__section__(".data..init_thread_info"))) +#define __init_thread_info __section(.data..init_thread_info)#endif
include/linux/interrupt.h +2 -3
@@ -741,8 +741,7 @@ extern int arch_early_irq_init(void);/* * We want to know which function is an entrypoint of a hardirq or a softirq. */ -#define __irq_entry __attribute__((__section__(".irqentry.text"))) -#define __softirq_entry \ - __attribute__((__section__(".softirqentry.text"))) +#define __irq_entry __section(.irqentry.text) +#define __softirq_entry __section(.softirqentry.text)#endif
include/linux/sched/debug.h +1 -1
@@ -42,7 +42,7 @@ extern void proc_sched_set_task(struct task_struct *p);#endif /* Attach to any functions which should be ignored in wchan output. */ -#define __sched __attribute__((__section__(".sched.text"))) +#define __sched __section(.sched.text)/* Linker adds these: start and end of __sched functions */ extern char __sched_text_start[], __sched_text_end[];
include/linux/srcutree.h +1 -1
@@ -124,7 +124,7 @@ struct srcu_struct {# define __DEFINE_SRCU (name, is_static) \ is_static struct srcu_struct name; \ struct srcu_struct * const __srcu_struct_##name \ - __section("___srcu_struct_ptrs") = &name + __section(___srcu_struct_ptrs) = &name#else # define __DEFINE_SRCU (name, is_static) \ static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data); \
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 13/14 include/linux/compiler.h: remove unused KENTRY macro
In reply to Nick DesaulniersThis macro is not used throughout the kernel. Delete it rather than update the __section to be a fully spelled out __attribute__((__section__())) to avoid
https://bugs.llvm.org/show_bug.cgi?id=42950.
--- include/linux/compiler.h | 23 ----------------------- 1 file changed, 23 deletions(-)
include/linux/compiler.h +0 -23
@@ -136,29 +136,6 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, } while (0)#endif -/* -* KENTRY - kernel entry point -* This can be used to annotate symbols (functions or data) that are used -* without their linker symbol being referenced explicitly. For example, -* interrupt vector handlers, or functions in the kernel image that are found -* programatically. -* -* Not required for symbols exported with EXPORT_SYMBOL, or initcalls. Those -* are handled in their own way (with KEEP() in linker scripts). -* -* KENTRY can be avoided if the symbols in question are marked as KEEP() in the -* linker script. For example an architecture could KEEP() its entire -* boot/exception vector code rather than annotate each function and data. -*/ -#ifndef KENTRY -# define KENTRY (sym) \ - extern typeof(sym) sym; \ - static const unsigned long __kentry_##sym \ - __used \ - __section("___kentry" "+" #sym ) \ - = (unsigned long)&sym; -#endif -#ifndef RELOC_HIDE # define RELOC_HIDE (ptr, off) \ ({ unsigned long __ptr; \
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
PATCH v2 14/14 compiler_attributes.h: add note about __section
In reply to Nick DesaulniersGCC unescapes escaped string section names while Clang does not. Because __section uses the # stringification operator for the section name, it doesn't need to be escaped.
Instead, we should:
1. Prefer __section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
See the discussions in:
--- include/linux/compiler_attributes.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/linux/compiler_attributes.h +10 -0
@@ -225,6 +225,16 @@#define __pure __attribute__((__pure__))/* +* Note: Since this macro makes use of the "stringification operator" `#`, a +* quoted string literal should not be passed to it. eg. +* prefer: +* __section(.foo) +* to: +* __section(".foo") +* unless the section name is dynamically built up, in which case the +* verbose __attribute__((__section__(".foo" x))) should be preferred. +* See also: https://bugs.llvm.org/show_bug.cgi?id=42950 +* * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-section-function-attribute * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-section-variable-attribute * clang: https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate
Signature · 1 line
2.23.0.187.g17f5b7556c-goog
Quoted 10 lines · Nick Desaulniers
GCC unescapes escaped string section names while Clang does not. Because
__sectionuses the#stringification operator for the section name, it doesn't need to be escaped.This fixes an Oops observed in distro's that use systemd and not net.core.bpf_jit_enable=1, when their kernels are compiled with Clang.
Instead, we should:
1. Prefer__section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the
Please use __ before and after section
i.e. __attribute__((__section__("<section_name>")))
Quoted 9 lines · Joe Perches
Quoted 7 lines · Nick Desaulniers
GCC unescapes escaped string section names while Clang does not. Because
__sectionuses the#stringification operator for the section name, it doesn't need to be escaped.This fixes an Oops observed in distro's that use systemd and not net.core.bpf_jit_enable=1, when their kernels are compiled with Clang.
Quoted 9 lines
Quoted 3 lines
Instead, we should:
1. Prefer__section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating thePlease use __ before and after section
i.e. __attribute__((__section__("<section_name>")))
*explitive*!!!
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 8 lines · Nick Desaulniers
GCC unescapes escaped string section names while Clang does not. Because
__sectionuses the#stringification operator for the section name, it doesn't need to be escaped.This fixes an Oops observed in distro's that use systemd and not net.core.bpf_jit_enable=1, when their kernels are compiled with Clang.
Quoted 9 lines
Instead, we should:
1. Prefer__section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of__define_initcallinarch/um/include/shared/init.h).This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -r
Hi Nick,
thanks for the v2 of your patch-series.
I just checked v2 on top of Linux v5.3-rc6...
sdi@iniza:~/src/linux-kernel/linux$ grep -e __section\(\" -e __section__\(\" -r
include/linux/compiler_attributes.h: * __section(".foo")
include/linux/compiler_attributes.h: * verbose
__attribute__((__section__(".foo" x))) should be preferred.OK: Description of the problem ^^
arch/sh/include/asm/cache.h:#define __read_mostly __attribute__((__section__(".data..read_mostly")))
PATCH next-20190827 ^^
sh: prefer __section from compiler_attributes.h
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?h=next-20190827&id=baf58858e8b6d853a7a8308901fcdd438e92a522
arch/arm64/kernel/smp_spin_table.c:volatile unsigned long __section(".mmuoff.data.read") arch/arm64/include/asm/cache.h:#define __read_mostly __attribute__((__section__(".data..read_mostly")))
PATCH next-20190827 ^^
arm64: prefer __section from compiler_attributes.h
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?h=next-20190827&id=80d838122643a09a9f99824adea4b4261e4451e6
arch/um/include/shared/init.h: __attribute__((__section__(".initcall" level ".init"))) = fn
??? ^^
Quoted 4 lines
See the discussions in:
https://bugs.llvm.org/show_bug.cgi?id=42950
https://marc.info/?l=linux-netdev&m=156412960619946&w=2
List CBL issue tracker to discussions:
https://github.com/ClangBuiltLinux/linux/issues/619
- Sedat -
Quoted 61 lines
Changes V1 -> V2:
* drop arm64, arc, and sh patches as they were picked up by their maintainers.
* Split the previous V1 hunk frominclude/linuxthat touchedinclude/linux/compiler.hoff into its own patch for inclusion in stable, as it fixes a user visible issue.
* Collect Acks and Tested by tags.Nick Desaulniers (14):
s390/boot: prefer__sectionfromcompiler_attributes.hinclude/linux/compiler.h: prefer__sectionfromcompiler_attributes.h
parisc: prefer__sectionfromcompiler_attributes.h
um: prefer__sectionfromcompiler_attributes.h
ia64: prefer__sectionfromcompiler_attributes.h
arm: prefer__sectionfromcompiler_attributes.h
mips: prefer__sectionfromcompiler_attributes.h
sparc: prefer__sectionfromcompiler_attributes.h
powerpc: prefer__sectionand__printffromcompiler_attributes.h
x86: prefer__sectionfromcompiler_attributes.hinclude/asm-generic: prefer__sectionfromcompiler_attributes.hinclude/linux: prefer__sectionfromcompiler_attributes.hinclude/linux/compiler.h: remove unused KENTRY macrocompiler_attributes.h: add note about__sectionarch/arm/include/asm/cache.h | 2 +- arch/arm/include/asm/mach/arch.h | 4 ++-- arch/arm/include/asm/setup.h | 2 +- arch/ia64/include/asm/cache.h | 2 +- arch/mips/include/asm/cache.h | 2 +- arch/parisc/include/asm/cache.h | 2 +- arch/parisc/include/asm/ldcw.h | 2 +- arch/powerpc/boot/main.c | 3 +-- arch/powerpc/boot/ps3.c | 6 ++---- arch/powerpc/include/asm/cache.h | 2 +- arch/powerpc/kernel/btext.c | 2 +- arch/s390/boot/startup.c | 2 +- arch/sparc/include/asm/cache.h | 2 +- arch/sparc/kernel/btext.c | 2 +- arch/um/kernel/um_arch.c | 6 +++--- arch/x86/include/asm/cache.h | 2 +- arch/x86/include/asm/intel-mid.h | 2 +- arch/x86/include/asm/iommu_table.h | 5 ++--- arch/x86/include/asm/irqflags.h | 2 +- arch/x86/include/asm/mem_encrypt.h | 2 +- arch/x86/kernel/cpu/cpu.h | 3 +-- include/asm-generic/error-injection.h | 2 +- include/asm-generic/kprobes.h | 5 ++--- include/linux/cache.h | 6 +++--- include/linux/compiler.h | 31 ++++----------------------- include/linux/compiler_attributes.h | 10 +++++++++ include/linux/cpu.h | 2 +- include/linux/export.h | 2 +- include/linux/init_task.h | 4 ++-- include/linux/interrupt.h | 5 ++--- include/linux/sched/debug.h | 2 +- include/linux/srcutree.h | 2 +- 32 files changed, 54 insertions(+), 74 deletions(-)--
2.23.0.187.g17f5b7556c-goog
Quoted 8 lines · Sedat Dilek
Quoted 5 lines · Nick Desaulniers
GCC unescapes escaped string section names while Clang does not. Because
__sectionuses the#stringification operator for the section name, it doesn't need to be escaped.
Quoted 8 lines
Quoted 8 lines
This fixes an Oops observed in distro's that use systemd and not net.core.bpf_jit_enable=1, when their kernels are compiled with Clang.
Instead, we should:
1. Prefer__section(.section_name_no_quotes).
2. Only use __attribute__((__section(".section"))) when creating the section name via C preprocessor (see the definition of__define_initcallinarch/um/include/shared/init.h).
Case 2 referenced below.
Quoted 7 lines
Quoted 4 lines
This antipattern was found with:
$ grep -e __section\(\" -e __section__\(\" -rHi Nick,
Quoted 7 lines
thanks for the v2 of your patch-series.
I just checked v2 on top of Linux v5.3-rc6...
arch/um/include/shared/init.h:__attribute__((__section__(".initcall" level ".init")))= fn??? ^^
Right, thanks for checking. That case is a section dynamically built via preprocessor, so that's the case I'm referring to in case 2.
Quoted 8 lines
Quoted 5 lines
See the discussions in:
https://bugs.llvm.org/show_bug.cgi?id=42950
https://marc.info/?l=linux-netdev&m=156412960619946&w=2List CBL issue tracker to discussions:
https://github.com/ClangBuiltLinux/linux/issues/619
Will do in v3!
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 5 lines
$ grep -e __section\(\" -e __section__\(\" -r
arch/um/include/shared/init.h:__attribute__((__section__(".initcall" level ".init")))= fn
2. Only use __attribute__((__section__(".section"))) when creating the section name via C preprocessor (see the definition of __define_initcall in arch/um/include/shared/init.h).
Who reads commit messages?
/me hides
- Sedat -