Live Patching
 help / color / mirror / Atom feed
From: George Guo <dongtai.guo@linux.dev>
To: chenhuacai@kernel.org, jpoimboe@kernel.org, peterz@infradead.org,
	jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com
Cc: kernel@xen0n.name, joe.lawrence@redhat.com, rostedt@goodmis.org,
	ardb@kernel.org, nathan@kernel.org,
	nick.desaulniers+lkml@gmail.com, yangtiezhu@loongson.cn,
	jiaxun.yang@flygoat.com, wangrui@loongson.cn,
	liukexin@kylinos.cn, guodongtai@kylinos.cn, xry111@xry111.site,
	wangyuli@aosc.io, loongarch@lists.linux.dev,
	live-patching@vger.kernel.org, llvm@lists.linux.dev,
	linux-kernel@vger.kernel.org
Subject: [PATCH v4 13/14] objtool/klp: Keep LoongArch tablejump annotation table entries
Date: Fri, 24 Jul 2026 19:41:26 +0800	[thread overview]
Message-ID: <20260724114128.31451-14-dongtai.guo@linux.dev> (raw)
In-Reply-To: <20260724114128.31451-1-dongtai.guo@linux.dev>

From: George Guo <guodongtai@kylinos.cn>

With -mannotate-tablejump, LoongArch compilers emit a
.discard.tablejump_annotate section.  Each entry is a pair of 8-byte
words: the address of a jump instruction and the address of its jump
table.  objtool reads these pairs to find switch jump tables when
decoding.

klp-diff creates one fake symbol per 8-byte word and clones a word only
if should_keep_special_sym() accepts it.  The default rule keeps a word
only if it references a function that was cloned into the output
module.  The instruction-side word references the function and is
kept.  The table-side word references the jump table via its .rodata
section symbol, which is not a function symbol, so it is dropped.

The cloned annotate section then holds only instruction-side words,
compacted together.  The pairing is destroyed.  Parsing the malformed
section crashes objtool on the patch module and no .ko is produced:

  Building patch module: livepatch-shadow-newpid.ko
  livepatch-shadow-newpid.o: error: SIGSEGV: objtool crash!

Keep all .discard.tablejump_annotate words whose referenced symbol has
been cloned.

Reproduced with the shadow-newpid test, which patches
proc_pid_status().  That function contains two switch jump tables.

Before, klp-diff clones only the instruction-side words:

  DEBUG: vmlinux.o: _discard_tablejump_annotate_57441 [+DATA]
  DEBUG: vmlinux.o:         .discard.tablejump_annotate+0x0: proc_pid_status+0xc70 [FUNC GLOBAL]
  DEBUG: vmlinux.o: _discard_tablejump_annotate_57443 [+DATA]
  DEBUG: vmlinux.o:         .discard.tablejump_annotate+0x8: proc_pid_status+0xd2c [FUNC GLOBAL]

After, the full pairs are kept, including the .rodata table words:

  DEBUG: vmlinux.o: _discard_tablejump_annotate_57441 [+DATA]
  DEBUG: vmlinux.o:         .discard.tablejump_annotate+0x0: proc_pid_status+0xc70 [FUNC GLOBAL]
  DEBUG: vmlinux.o: _discard_tablejump_annotate_57442 [+DATA]
  DEBUG: vmlinux.o:         .discard.tablejump_annotate+0x8: .rodata.proc_pid_status+0x0 [SECTION]
  DEBUG: vmlinux.o: _discard_tablejump_annotate_57443 [+DATA]
  DEBUG: vmlinux.o:         .discard.tablejump_annotate+0x10: proc_pid_status+0xd2c [FUNC GLOBAL]
  DEBUG: vmlinux.o: _discard_tablejump_annotate_57444 [+DATA]
  DEBUG: vmlinux.o:         .discard.tablejump_annotate+0x18: .rodata.proc_pid_status+0x80 [SECTION]

and the patch module builds.

Co-developed-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: Kexin Liu <liukexin@kylinos.cn>
Signed-off-by: George Guo <guodongtai@kylinos.cn>
---
 tools/objtool/klp-diff.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index 92cf0fc3ff2f..f151ffc71184 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1956,6 +1956,7 @@ static int create_fake_symbols(struct elf *elf)
 static bool should_keep_special_sym(struct elf *elf, struct symbol *sym)
 {
 	bool annotate_insn = !strcmp(sym->sec->name, ".discard.annotate_insn");
+	bool tablejump_annotate = !strcmp(sym->sec->name, ".discard.tablejump_annotate");
 	struct reloc *reloc;
 
 	if (is_sec_sym(sym) || !sym->sec->rsec)
@@ -1968,6 +1969,16 @@ static bool should_keep_special_sym(struct elf *elf, struct symbol *sym)
 		if (!reloc->sym->clone || is_undef_sym(reloc->sym->clone))
 			continue;
 
+		/*
+		 * .discard.tablejump_annotate (LoongArch -mannotate-tablejump)
+		 * holds pairs of words: a jump instruction and its jump table.
+		 * The table word references the table via its .rodata section
+		 * symbol, which the is_func_sym() rule below would drop,
+		 * breaking the pairing.  Keep both words of each entry.
+		 */
+		if (tablejump_annotate)
+			return true;
+
 		/*
 		 * Keep special section references to cloned functions.
 		 * In some cases annotate_insn can also reference cloned alt
-- 
2.53.0


  parent reply	other threads:[~2026-07-24 11:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 11:41 [PATCH v4 00/14] LoongArch: Add livepatch build (KLP) support George Guo
2026-07-24 11:41 ` [PATCH v4 01/14] objtool/LoongArch: Add arch_adjusted_addend() for KLP support George Guo
2026-07-24 11:41 ` [PATCH v4 02/14] LoongArch: Mark special sections " George Guo
2026-07-24 11:41 ` [PATCH v4 03/14] livepatch/klp-build: use -fPIC and drop direct-extern-access on LoongArch George Guo
2026-07-24 11:41 ` [PATCH v4 04/14] LoongArch: Fix EFI linking with -fdata-sections George Guo
2026-07-24 11:41 ` [PATCH v4 05/14] objtool/klp: Add LoongArch jump opcode bytes support George Guo
2026-07-24 11:41 ` [PATCH v4 06/14] klp-build: Add LoongArch syscall patching macro George Guo
2026-07-24 11:41 ` [PATCH v4 07/14] LoongArch: Add livepatch build (KLP) support George Guo
2026-07-24 11:41 ` [PATCH v4 08/14] LoongArch: Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY George Guo
2026-07-24 11:41 ` [PATCH v4 09/14] objtool/klp: Convert local label references George Guo
2026-07-24 11:41 ` [PATCH v4 10/14] objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for " George Guo
2026-07-24 11:41 ` [PATCH v4 11/14] objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCREL George Guo
2026-07-24 11:41 ` [PATCH v4 12/14] objtool/LoongArch: Enable inline alternative cloning for KLP George Guo
2026-07-24 11:41 ` George Guo [this message]
2026-07-24 11:41 ` [PATCH v4 14/14] objtool/klp: Rewrite PC-relative data references to GOT on LoongArch George Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724114128.31451-14-dongtai.guo@linux.dev \
    --to=dongtai.guo@linux.dev \
    --cc=ardb@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=guodongtai@kylinos.cn \
    --cc=jiaxun.yang@flygoat.com \
    --cc=jikos@kernel.org \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liukexin@kylinos.cn \
    --cc=live-patching@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=loongarch@lists.linux.dev \
    --cc=mbenes@suse.cz \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=wangrui@loongson.cn \
    --cc=wangyuli@aosc.io \
    --cc=xry111@xry111.site \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox