Thread (27 messages) 27 messages, 5 authors, 2d ago
WARM2d

[PATCH v3 10/12] objtool/klp: Convert local label references in special sections

From: George Guo <hidden>
Date: 2026-07-07 07:23:16
Also in: lkml, llvm, loongarch
Subsystem: objtool, the rest · Maintainers: Josh Poimboeuf, Peter Zijlstra, Linus Torvalds

From: George Guo <redacted>

GCC/GAS on LoongArch references special section entries (__ex_table,
__bug_table, __jump_table, .altinstructions) through local text labels
(.L*) instead of a section symbol plus offset.  The assembler keeps the
label because of linker relaxation: a "section + constant offset"
reference would go stale when the linker deletes or shrinks
instructions, while a symbol reference can be recomputed after
relaxation.

convert_reloc_secsym_to_sym() only handles the section symbol form and
returns early for such label references.  The label is never cloned
into the livepatch object, so should_keep_special_sym() cannot
correlate the entry with an included function and silently drops it: a
GCC-built livepatch module ends up missing the patched function's
__ex_table / __bug_table / __jump_table entries, with no error at
build or load time.

Redirect label references in text sections to the containing function
symbol, mirroring the section symbol case.  A label with no containing
function symbol (e.g. hand-written asm in a plain .text section) can't
be correlated; skip it rather than failing, since such entries belong
to unchanged code and are dropped anyway.

Reported-by: Joe Lawrence <joe.lawrence@redhat.com>
Suggested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: George Guo <redacted>
---
 tools/objtool/klp-diff.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/klp-diff.c b/tools/objtool/klp-diff.c
index b9624bd9439b..05fd70e24326 100644
--- a/tools/objtool/klp-diff.c
+++ b/tools/objtool/klp-diff.c
@@ -1423,8 +1423,41 @@ static int convert_reloc_secsym_to_sym(struct elf *elf, struct reloc *reloc)
 	if (!strcmp(reloc->sec->name, ".rela__patchable_function_entries"))
 		return convert_pfe_reloc(elf, reloc);
 
-	if (!is_sec_sym(sym))
+	if (!is_sec_sym(sym)) {
+		/*
+		 * Most toolchains reference special-section entries via the
+		 * section symbol plus an offset.  GCC/GAS on LoongArch instead
+		 * references a local text label (.L*): LoongArch linker
+		 * relaxation is the reason GAS keeps the label rather than
+		 * reducing it to a section symbol reference.  Such a label is
+		 * never cloned into the livepatch object, so the entry would be
+		 * silently dropped.  Redirect the relocation to the containing
+		 * function, mirroring the section-symbol case below.
+		 */
+		if (is_local_label(sym) && is_text_sec(sec)) {
+			unsigned long offset = sym->offset + reloc_addend(reloc);
+
+			sym = find_symbol_containing_inclusive(sec, offset);
+			if (!sym) {
+				/*
+				 * A local label with no containing function
+				 * symbol (e.g. hand-written asm in a plain .text
+				 * section).  It can't be correlated to a function,
+				 * so skip it rather than failing the build; such
+				 * entries belong to unchanged code and are dropped
+				 * anyway.
+				 */
+				return 1;
+			}
+
+			reloc->sym = sym;
+			set_reloc_sym(elf, reloc, sym->idx);
+			set_reloc_addend(elf, reloc, offset - sym->offset);
+			return 0;
+		}
+
 		return 0;
+	}
 
 	sym = find_symbol_containing_inclusive(sec, arch_adjusted_addend(reloc));
 	if (!sym) {
-- 
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help