init/Kconfig: add CONFIG_TRIM_UNUSED_SYSCALLS and related options
Subsystems (5)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/8 init/Kconfig: add CONFIG_TRIM_UNUSED_SYSCALLS and related options
From: Yuhang Zheng <[email protected]>
Introduce configuration options to enable dead code/data elimination for unused system calls.
This change adds the following Kconfig symbols:
- TRIM_UNUSED_SYSCALLS: user option to enable trimming of unused system calls
- HAVE_TRIM_UNUSED_SYSCALLS: architecture capability symbol
- USED_SYSCALLS: string list of system calls to keep(separated by spaces)
These options integrate with scripts/Makefile.asm-headers and syscalltbl.sh to generate syscall tables only for selected entries. The feature depends on LD_DEAD_CODE_DATA_ELIMINATION and on architectures that use syscalltbl.sh to generate their syscall tables.
--- init/Kconfig | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
init/Kconfig +33 -0
@@ -1628,6 +1628,9 @@ config SYSFS_SYSCALL config HAVE_PCSPKR_PLATFORM bool +config HAVE_TRIM_UNUSED_SYSCALLS + bool + menuconfig EXPERT bool "Configure standard kernel features (expert users)" # Unhide debug options, to make the on-by-default options visible
@@ -1932,6 +1935,36 @@ config CACHESTAT_SYSCALL If unsure say Y here. +config TRIM_UNUSED_SYSCALLS + bool "Trim unused syscalls" if EXPERT + default n + depends on HAVE_TRIM_UNUSED_SYSCALLS + depends on LD_DEAD_CODE_DATA_ELIMINATION + help + Enable this option to trim unused system calls from the final kernel + image. Only the syscalls explicitly listed in CONFIG_USED_SYSCALLS + will be kept. + + Note that some unused syscalls may still be retained if their sections + are forcibly kept by other sections created with .pushsection and + preserved via KEEP() in the linker script. + + If unsure, say N. + +config USED_SYSCALLS + string "Configure used syscalls" if EXPERT + depends on TRIM_UNUSED_SYSCALLS + default "" + help + Specify a list of system calls that should be kept when + TRIM_UNUSED_SYSCALLS is enabled. + + The system calls should be listed one by one, separated by spaces. + For example, set CONFIG_USED_SYSCALLS="write exit reboot". If left + empty, all syscalls will be trimmed. + + If unsure, please disable TRIM_UNUSED_SYSCALLS. + config KALLSYMS bool "Load all symbols for debugging/ksymoops" if EXPERT default y
Signature · 1 line
2.43.0
PATCH v2 2/8 scripts/syscalltbl.sh: add optional --used-syscalls argument for syscall trimming
In reply to a message not in the archiveFrom: Yuhang Zheng <[email protected]>
Add support for an optional --used-syscalls argument to scripts/syscalltbl.sh. When provided, the argument takes a comma-separated list of syscall names that should remain enabled in the generated syscall table. Any syscall not present in the list will be replaced with a __SYSCALL(nr, sys_ni_syscall) entry.
This enables selective system call table generation when CONFIG_TRIM_UNUSED_SYSCALLS is set.
--- scripts/syscalltbl.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
scripts/syscalltbl.sh +18 -1
@@ -22,12 +22,14 @@ usage() { echo >&2 " OUTFILE output header file" echo >&2 echo >&2 "options:" - echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)" + echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)" + echo >&2 " --used-syscalls SYSCALLS Keep only the specified syscall; trim others" exit 1 } # default unless specified by options abis= +used_syscalls= while [ $# -gt 0 ] do
@@ -35,6 +37,14 @@ do --abis) abis=$(echo "($2)" | tr ',' '|') shift 2;; + --used-syscalls=*) + used_syscalls_raw=${1#--used-syscalls=} + if [ -z "$used_syscalls_raw" ]; then + used_syscalls='^$' + else + used_syscalls=$(echo "$used_syscalls_raw" | tr ',' '|') + fi + shift;; -*) echo "$1: unknown option" >&2 usage;;
@@ -52,6 +62,7 @@ outfile="$2" nxt=0 + grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | { while read nr abi name native compat noreturn; do
@@ -66,6 +77,12 @@ grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | { nxt=$((nxt + 1)) done + if [ -n "$used_syscalls" ] && ! echo "$name" | grep -qwE "$used_syscalls"; then + echo "__SYSCALL($nr, sys_ni_syscall)" + nxt=$((nr + 1)) + continue + fi + if [ "$compat" = "-" ]; then unset compat fi
Signature · 1 line
2.43.0
PATCH v2 3/8 scripts/Makefile.asm-headers: pass USED_SYSCALLS to syscalltbl.sh
In reply to a message not in the archiveFrom: Yuhang Zheng <[email protected]>
Include auto.conf in asm-headers and pass CONFIG_USED_SYSCALLS to syscalltbl.sh when CONFIG_TRIM_UNUSED_SYSCALLS is enabled.
--- scripts/Makefile.asm-headers | 4 ++++ 1 file changed, 4 insertions(+)
scripts/Makefile.asm-headers +4 -0
@@ -13,6 +13,8 @@ PHONY := all all: +include $(objtree)/include/config/auto.conf + src := $(srctree)/$(subst /generated,,$(obj)) syscall_abis_32 += common,32
@@ -68,6 +70,8 @@ quiet_cmd_systbl = SYSTBL $@ cmd_systbl = $(CONFIG_SHELL) $(systbl) \ $(if $(systbl-args-$*),$(systbl-args-$*),$(systbl-args)) \ --abis $(subst $(space),$(comma),$(strip $(syscall_abis_$*))) \ + $(if $(CONFIG_TRIM_UNUSED_SYSCALLS), \ + --used-syscalls=$(subst $(space),$(comma),$(strip $(CONFIG_USED_SYSCALLS)))) \ $< $@ all: $(generic-y) $(syscall-y)
Signature · 1 line
2.43.0
PATCH v2 4/8 riscv: enable HAVE_TRIM_UNUSED_SYSCALLS when toolchain supports DCE
In reply to a message not in the archiveFrom: Yuhang Zheng <[email protected]>
Enable HAVE_TRIM_UNUSED_SYSCALLS on RISC-V when the toolchain supports dead code and data elimination.
This allows the unused syscalls and related code to be trimmed at link time based on the list of actually used syscalls.
While this enables per-syscall elimination, some syscall entries still cannot be fully discarded due to sections that are force-kept by the linker, such as ex_table, bug_table, jump_table, and .alternative.
--- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+)
arch/riscv/Kconfig +1 -0
@@ -198,6 +198,7 @@ config RISCV select HAVE_SAMPLE_FTRACE_DIRECT_MULTI select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS + select HAVE_TRIM_UNUSED_SYSCALLS select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU select IRQ_DOMAIN select IRQ_FORCED_THREADING
Signature · 1 line
2.43.0
PATCH v2 5/8 kconfig: add CONFIG_PUSHSECTION_WITH_RELOC for relocation support
In reply to a message not in the archiveIf the assembler supports the '.reloc' directive with 'BFD_RELOC_NONE', we can establish a reference between a section created by '.pushsection' and its caller function by emitting a relocation in the caller.
Known toolchain minimums:
- GNU binutils (gas) >= 2.26
- LLVM integrated assembler (IAS) >= 13.0.0
All assemblers meeting the kernel's minimum toolchain requirements already support it.
--- init/Kconfig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
init/Kconfig +16 -0
@@ -1631,6 +1631,10 @@ config HAVE_PCSPKR_PLATFORM config HAVE_TRIM_UNUSED_SYSCALLS bool +config AS_HAS_BFD_RELOC_NONE + bool + def_bool $(as-instr,.reloc .$(comma) BFD_RELOC_NONE$(comma)) + menuconfig EXPERT bool "Configure standard kernel features (expert users)" # Unhide debug options, to make the on-by-default options visible
@@ -1965,6 +1969,18 @@ config USED_SYSCALLS If unsure, please disable TRIM_UNUSED_SYSCALLS. +config PUSHSECTION_WITH_RELOC + bool "Trim more syscalls" + depends on TRIM_UNUSED_SYSCALLS && AS_HAS_BFD_RELOC_NONE + default y + help + Enable building relocation-based references between sections created + by '.pushsection' and their caller functions when the assembler + supports the '.reloc' directive. + + This allows the linker to establish proper dependencies, remove the + need for KEEP(). + config KALLSYMS bool "Load all symbols for debugging/ksymoops" if EXPERT default y
Signature · 1 line
2.43.0
PATCH v2 6/8 compiler.h: introduce PUSHSECTION macro to establish proper references
In reply to a message not in the archiveWhen a section is created by .pushsection in assembly, there is no reference between the caller function and the newly created section. As a result, --gc-sections may incorrectly discard the newly created section.
To prevent such incorrect garbage collection, kernel code often wraps these sections with KEEP() in linker scripts. While this guarantees that the sections are retained, it introduces a dependency inversion: unused sections are kept unnecessarily, and any sections they reference are also forcibly retained. This prevents the linker from eliminating truly unused code or data.
Introduce a new PUSHSECTION macro in include/linux/compiler.h to create a proper reference between the .pushsection caller and the generated section. The macro is fully compatible with all existing .pushsection parameters and has no side effects, making it safe to replace all current .pushsection usages with this version.
PUSHSECTION works by emitting a unique label inside the new section, and adding a relocation from the caller function to that label. This ensures the linker recognizes the dependency and keeps both sections alive together. So we don't need to wrap the section with KEEP() in linker anymore.
To guarantee uniqueness of the section and label names, both __COUNTER__ and %= are used:
Either alone is insufficient:
- __COUNTER__ alone fails when the function containing PUSHSECTION is inlined multiple times, causing duplicate labels.
- %= alone fails when multiple PUSHSECTION directives appear within a single inline assembly block.
In assembly code, a separate definition is provided because the C macro cannot ensure unique section/label names when expanded inside an assembler macro (.macro).
--- include/linux/compiler.h | 43 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)
include/linux/compiler.h +42 -1
@@ -3,6 +3,7 @@#define __LINUX_COMPILER_H#include <linux/compiler_types.h> +#include <linux/stringify.h> #ifndef __ASSEMBLY__
@@ -267,7 +268,47 @@ static inline void *offset_to_ptr(const int *off)return (void *)((unsigned long )off + *off); } -#endif /* __ASSEMBLY__ */ +#ifdef CONFIG_PUSHSECTION_WITH_RELOC +#define __PUSHSECTION_RELOC (lbl) ".reloc ., BFD_RELOC_NONE, " lbl "\n\t" +#define __PUSHSECTION_HELPER (prefix) __stringify(prefix.%=) "_" __stringify(__COUNTER__) +#define __PUSHSECTION_LABEL (lbl) lbl ":\n\t" +#else +#define __PUSHSECTION_RELOC (lbl) +#define __PUSHSECTION_HELPER (prefix) __stringify(prefix) +#define __PUSHSECTION_LABEL (lbl) +#endif + +#define _PUSHSECTION (lbl, sec, ...) \ + __PUSHSECTION_RELOC(lbl) \ + ".pushsection " sec ", " #__VA_ARGS__ "\n\t" __PUSHSECTION_LABEL(lbl) + +#define PUSHSECTION (sec, ...) \ + _PUSHSECTION(__PUSHSECTION_HELPER(.Lsec), __PUSHSECTION_HELPER(sec), __VA_ARGS__) + +#else /* __ASSEMBLY__ */ + +#ifdef CONFIG_PUSHSECTION_WITH_RELOC +#define __PUSHSECTION_RELOC .reloc ., BFD_RELOC_NONE, \label +#define __PUSHSECTION_HELPER (prefix) prefix\().\@ +#define __PUSHSECTION_LABEL \label: +#else +#define __PUSHSECTION_RELOC +#define __PUSHSECTION_HELPER (prefix) prefix +#define __PUSHSECTION_LABEL +#endif + +.macro _PUSHSECTION label:req, section:req, args:vararg + __PUSHSECTION_RELOC + .pushsection __PUSHSECTION_HELPER(\section), \args + __PUSHSECTION_LABEL +.endm + +.macro PUSHSECTION section:req, args:vararg + _PUSHSECTION .Lsec\@, \section, \args +.endm + +#endif /* !__ASSEMBLY__ */ +#ifdef CONFIG_64BIT #define ARCH_SEL (a,b) a
Signature · 1 line
2.43.0
kernel test robot
build botRe: [PATCH v2 6/8] compiler.h: introduce PUSHSECTION macro to establish proper references
kernel test robot noticed the following build errors:
Hi Yuan,
kernel test robot noticed the following build errors:
[auto build test ERROR on soc/for-next]
[also build test ERROR on arnd-asm-generic/master linus/master v6.18-rc1 next-20251015] [cannot apply to masahiroy-kbuild/for-next masahiroy-kbuild/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yuan-Tan/scripts-syscalltbl-sh-add-optional-used-syscalls-argument-for-syscall-trimming/20251015-181934 base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next patch link: https://lore.kernel.org/r/40854460DE090346%2Bc30007da67d26ae0e8651732f32a8ede4926db14.1760463245.git.tanyuan%40tinylab.org patch subject: [PATCH v2 6/8] compiler.h: introduce PUSHSECTION macro to establish proper references config: arm-randconfig-001-20251016 (https://download.01.org/0day-ci/archive/20251016/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 39f292ffa13d7ca0d1edff27ac8fd55024bb4d19) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251016/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> ld.lld: error: ./arch/arm/kernel/vmlinux.lds:1: unknown directive: .macro >>> .macro _PUSHSECTION label:req, section:req, args:vararg >>> ^
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v2 6/8] compiler.h: introduce PUSHSECTION macro to establish proper references
In reply to Yuan Tankernel test robot noticed the following build errors:
Hi Yuan,
kernel test robot noticed the following build errors:
[auto build test ERROR on soc/for-next]
[also build test ERROR on arnd-asm-generic/master linus/master v6.18-rc1 next-20251015] [cannot apply to masahiroy-kbuild/for-next masahiroy-kbuild/fixes]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yuan-Tan/scripts-syscalltbl-sh-add-optional-used-syscalls-argument-for-syscall-trimming/20251015-181934 base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next patch link: https://lore.kernel.org/r/40854460DE090346%2Bc30007da67d26ae0e8651732f32a8ede4926db14.1760463245.git.tanyuan%40tinylab.org patch subject: [PATCH v2 6/8] compiler.h: introduce PUSHSECTION macro to establish proper references config: sh-randconfig-002-20251016 (https://download.01.org/0day-ci/archive/20251016/[email protected]/config) compiler: sh4-linux-gcc (GCC) 14.3.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251016/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> sh4-linux-ld:./arch/sh/kernel/vmlinux.lds:2: syntax error
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 7/8 vmlinux.lds.h: support conditional KEEP() in linker script
In reply to a message not in the archiveIntroduce a conditional KEEP() helper, COND_KEEP(), that allows a section to be kept only if a corresponding NOKEEP_<sec> macro is not defined. This provides a finer-grained mechanism to control which sections are protected from garbage collection.
Traditionally, many sections — for example, the exception table and jump table — are created by .pushsection and wrapped with KEEP() in vmlinux.lds.h to prevent them from being discarded by the linker, even when they are not actually referenced. This can block dead code and data elimination (DCE) when the section is known to be safe to drop.
With COND_KEEP(), architectures or subsystems can safely remove the KEEP() in cases where the section can be safely garbage-collected.
The implementation adds:
- __KEEP_ACT_0() / __KEEP_ACT_1() helpers for macro expansion
- BSEC_MAIN() to handle possible sub-section patterns, such as
__ex_table.18
- COND_KEEP() macro, which wraps KEEP() conditionally based on
__is_defined(NOKEEP_<sec>)Example usage:
COND_KEEP(alternative, *(.alternative*))
Additionally, move the ___PASTE()/__PASTE() definitions in include/linux/compiler_types.h out from under the '#ifndef __ASSEMBLY__' guard so that they are visible to assembly.
No functional change unless NOKEEP_<sec> is defined.
--- include/asm-generic/vmlinux.lds.h | 12 ++++++++++-- include/linux/compiler_types.h | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-)
include/asm-generic/vmlinux.lds.h +10 -2
@@ -51,6 +51,7 @@*/ #include <asm-generic/codetag.lds.h> +#include <linux/compiler_types.h> #ifndef LOAD_OFFSET #define LOAD_OFFSET 0
@@ -113,14 +114,21 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..L* .bss..compoundliteral*#define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]* +#define BSEC_MAIN (sec) sec sec##.[0-9a-zA-Z_]*#else #define DATA_MAIN .data .data.rel .data.rel.local#define SDATA_MAIN .sdata#define RODATA_MAIN .rodata#define BSS_MAIN .bss#define SBSS_MAIN .sbss +#define BSEC_MAIN (sec) sec#endif +#define __KEEP_ACT_0 (sec) KEEP(sec) +#define __KEEP_ACT_1 (sec) sec + +#define COND_KEEP (sec, list) __PASTE(__KEEP_ACT_, __is_defined(NOKEEP_##sec))(list) +/* * GCC 4.5 and later have a 32 bytes section alignment for structures. * Except GCC 4.9, that feels the need to align on 64 bytes.
@@ -196,12 +204,12 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)#define BOUNDED_SECTION_PRE_LABEL (_sec_, _label_, _BEGIN_, _END_) \ _BEGIN_##_label_ = .; \ - KEEP(*(_sec_)) \ + COND_KEEP(_sec_, *(BSEC_MAIN(_sec_))) \ _END_##_label_ = .;#define BOUNDED_SECTION_POST_LABEL (_sec_, _label_, _BEGIN_, _END_) \ _label_##_BEGIN_ = .; \ - KEEP(*(_sec_)) \ + COND_KEEP(_sec_, *(BSEC_MAIN(_sec_))) \ _label_##_END_ = .;#define BOUNDED_SECTION_BY (_sec_, _label_) \
include/linux/compiler_types.h +4 -4
@@ -79,10 +79,6 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } # define __builtin_warning(x, y...) (1)#endif /* __CHECKER__ */ -/* Indirect macros required for expanded argument pasting, eg. __LINE__. */ -#define ___PASTE (a,b) a##b -#define __PASTE (a,b) ___PASTE(a,b) -#ifdef __KERNEL__/* Attributes */
@@ -425,6 +421,10 @@ struct ftrace_likely_data {#endif /* __ASSEMBLY__ */ +/* Indirect macros required for expanded argument pasting, eg. __LINE__. */ +#define ___PASTE (a, b) a##b +#define __PASTE (a, b) ___PASTE(a, b) +/* * 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.
Signature · 1 line
2.43.0
PATCH v2 8/8 riscv: use PUSHSECTION in ex_table, jump_table, bug_table and alternatives
In reply to a message not in the archiveReplace plain .pushsection with the new PUSHSECTION macro for __ex_table, __bug_table, __jump_table, and .alternative on RISC-V.
PUSHSECTION establishes proper references between the caller and the generated sections, allowing --gc-sections to recognize their dependencies correctly. This avoids the need for KEEP() and prevents dependency inversion where unused sections keep others alive.
With this change, CONFIG_TRIM_UNUSED_SYSCALLS can correctly discard unused syscalls together with their exception tables.
This update takes effect only when built with an assembler that supports BFD_RELOC_NONE, and falls back to the existing behavior otherwise.
--- arch/riscv/include/asm/alternative-macros.h | 8 +++++--- arch/riscv/include/asm/asm-extable.h | 10 ++++++---- arch/riscv/include/asm/bug.h | 2 +- arch/riscv/include/asm/jump_label.h | 3 ++- arch/riscv/kernel/vmlinux.lds.S | 9 ++++++++- 5 files changed, 22 insertions(+), 10 deletions(-)
arch/riscv/include/asm/alternative-macros.h +5 -3
@@ -2,9 +2,11 @@#ifndef __ASM_ALTERNATIVE_MACROS_H#define __ASM_ALTERNATIVE_MACROS_H +#include <linux/compiler.h> +#ifdef CONFIG_RISCV_ALTERNATIVE -#ifdef __ASSEMBLER__ +#ifdef __ASSEMBLY__ .macro ALT_ENTRY oldptr newptr vendor_id patch_id new_len .4byte \oldptr - .
@@ -16,7 +18,7 @@ .macro ALT_NEW_CONTENT vendor_id, patch_id, enable = 1, new_c .if \enable - .pushsection .alternative,"a" +PUSHSECTION .alternative,"a" ALT_ENTRY 886b, 888f, \vendor_id, \patch_id, 889f - 888f .popsection .subsection 1
@@ -67,7 +69,7 @@#define ALT_NEW_CONTENT (vendor_id, patch_id, enable, new_c) \ ".if " __stringify(enable) " == 1\n" \ - ".pushsection .alternative, \"a\"\n" \ + PUSHSECTION(.alternative, "a") \ ALT_ENTRY("886b", "888f", __stringify(vendor_id), __stringify(patch_id), "889f - 888f") \ ".popsection\n" \ ".subsection 1\n" \
arch/riscv/include/asm/asm-extable.h +6 -4
@@ -2,6 +2,8 @@#ifndef __ASM_ASM_EXTABLE_H#define __ASM_ASM_EXTABLE_H +#include <linux/compiler.h> +#define EX_TYPE_NONE 0#define EX_TYPE_FIXUP 1#define EX_TYPE_BPF 2
@@ -10,10 +12,10 @@#ifdef CONFIG_MMU -#ifdef __ASSEMBLER__ +#ifdef __ASSEMBLY__#define __ASM_EXTABLE_RAW (insn, fixup, type, data) \ - .pushsection __ex_table, "a"; \ + PUSHSECTION __ex_table, "a"; \ .balign 4; \ .long ((insn) - .); \ .long ((fixup) - .); \
@@ -31,8 +33,8 @@#include <linux/stringify.h> #include <asm/gpr-num.h> -#define __ASM_EXTABLE_RAW (insn, fixup, type, data) \ - ".pushsection __ex_table, \"a\"\n" \ +#define __ASM_EXTABLE_RAW (insn, fixup, type, data) \ + PUSHSECTION(__ex_table, "a") \ ".balign 4\n" \ ".long ((" insn ") - .)\n" \ ".long ((" fixup ") - .)\n" \
arch/riscv/include/asm/bug.h +1 -1
@@ -54,7 +54,7 @@ typedef u32 bug_insn_t;#define ARCH_WARN_ASM (file, line, flags, size) \ "1:\n\t" \ "ebreak\n" \ - ".pushsection __bug_table,\"aw\"\n\t" \ + PUSHSECTION(__bug_table, "aw") \ "2:\n\t" \ __BUG_ENTRY(file, line, flags) "\n\t" \ ".org 2b + " size "\n\t" \
arch/riscv/include/asm/jump_label.h +2 -1
@@ -11,13 +11,14 @@#include <linux/types.h> #include <asm/asm.h> +#include <linux/compiler.h> #define HAVE_JUMP_LABEL_BATCH #define JUMP_LABEL_NOP_SIZE 4#define JUMP_TABLE_ENTRY (key, label) \ - ".pushsection __jump_table, \"aw\" \n\t" \ + PUSHSECTION(__jump_table, "aw") \ ".align " RISCV_LGPTR " \n\t" \ ".long 1b - ., " label " - . \n\t" \ "" RISCV_PTR " " key " - . \n\t" \
arch/riscv/kernel/vmlinux.lds.S +8 -1
@@ -7,6 +7,13 @@ #define RO_EXCEPTION_TABLE_ALIGN 4 #define RUNTIME_DISCARD_EXIT +#ifdef CONFIG_PUSHSECTION_WITH_RELOC +#define NOKEEP___jump_table 1 +#define NOKEEP___ex_table 1 +#define NOKEEP___bug_table 1 +#define NOKEEP_alternative 1 +#endif + #ifdef CONFIG_XIP_KERNEL #include "vmlinux-xip.lds.S" #else
@@ -117,7 +124,7 @@ SECTIONS . = ALIGN(8); .alternative : { __alt_start = .; - KEEP(*(.alternative)) + COND_KEEP(alternative, *(.alternative*)) __alt_end = .; } __init_end = .;
Signature · 1 line
2.43.0