[<prev] [next>] [day] [month] [year] [list]
Message-ID: <22B977FCB8434D8A+8905ca92f19047804ba693f7cd3b2ef1e2721bad.1760463245.git.tanyuan@tinylab.org>
Date: Wed, 15 Oct 2025 14:22:39 +0800
From: Yuan Tan <tanyuan@...ylab.org>
To: arnd@...db.de,
masahiroy@...nel.org,
nathan@...nel.org,
palmer@...belt.com,
linux-kbuild@...r.kernel.org,
linux-riscv@...ts.infradead.org
Cc: linux-arch@...r.kernel.org,
linux-kernel@...r.kernel.org,
i@...kray.me,
tanyuan@...ylab.org,
falcon@...ylab.org,
ronbogo@...look.com,
z1652074432@...il.com,
lx24@....ynu.edu.cn
Subject: [PATCH v2 8/8] riscv: use PUSHSECTION in ex_table, jump_table, bug_table and alternatives
Replace 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.
Signed-off-by: Yuan Tan <tanyuan@...ylab.org>
Signed-off-by: Zhangjin Wu <falcon@...ylab.org>
Signed-off-by: Peihan Liu <ronbogo@...look.com>
---
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(-)
diff --git a/arch/riscv/include/asm/alternative-macros.h b/arch/riscv/include/asm/alternative-macros.h
index 9619bd5c8eba..dd24c3e1117b 100644
--- a/arch/riscv/include/asm/alternative-macros.h
+++ b/arch/riscv/include/asm/alternative-macros.h
@@ -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" \
diff --git a/arch/riscv/include/asm/asm-extable.h b/arch/riscv/include/asm/asm-extable.h
index 37d425d7a762..24eb29f2ef82 100644
--- a/arch/riscv/include/asm/asm-extable.h
+++ b/arch/riscv/include/asm/asm-extable.h
@@ -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" \
diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h
index 4c03e20ad11f..855860c34209 100644
--- a/arch/riscv/include/asm/bug.h
+++ b/arch/riscv/include/asm/bug.h
@@ -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" \
diff --git a/arch/riscv/include/asm/jump_label.h b/arch/riscv/include/asm/jump_label.h
index 3ab5f2e3212b..1134a9bc95a7 100644
--- a/arch/riscv/include/asm/jump_label.h
+++ b/arch/riscv/include/asm/jump_label.h
@@ -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" \
diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
index 61bd5ba6680a..e6d117047226 100644
--- a/arch/riscv/kernel/vmlinux.lds.S
+++ b/arch/riscv/kernel/vmlinux.lds.S
@@ -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 = .;
--
2.43.0
Powered by blists - more mailing lists