From nobody Sat Jun 13 22:17:07 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C317F42315B; Tue, 5 May 2026 10:55:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777978563; cv=none; b=MxSL+qnO1chF3Y5SnfagrVP0Vg9wKc/+YpO61WveyWQ8hMq2r7fPpmJayfDfaMICFehm5KaavCyr1uTehnbnNEGN8gfsiwCQzt+KR4+x8Mf6Xz3u5Gikcn8dSMB1BDARUfQMCshAv+8lVWZZs927jpWC4u+TP7dTyTyoOK4JVoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777978563; c=relaxed/simple; bh=e4miB2ZovKQZjfR72QlvwCNACdSoKg1Blica6WfE1kw=; h=Date:From:To:Subject:Cc:MIME-Version:Message-ID:Content-Type; b=SrrdMSCmKigTzLh1CACH+MUXery5zASuMeQeHyHuzGlBlKQBa8BbTv/VKY19QHcVbHokBKhQN2/jtOyO+gV82tCm5PgBRN4329OkMle6esdXktcLCRrMX/KjWc9iHos1N2E8VB24n+Ef7ej5j9u1eJcSxqaxjf2Yd80KY2sGOBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WxOJM8Lo; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=dn2UEEFD; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WxOJM8Lo"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="dn2UEEFD" Date: Tue, 05 May 2026 10:55:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1777978558; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=38J4YBTdPhJmUzC4swG6FHvNghC5KLWCDYsJJddGPng=; b=WxOJM8Lojh6EgWrstlibqn/u56lp98bYgqrlNkp55BGY5eIpaG5eN8vxXNV7CTcmhMPv+N NSbeAoebbq4J9mA1MlceDWg5ivVnR2+CPkBIPyaY7CpACPJNSBD5ywzE97KrkSxTC4pWcv 5xyUYqCZd9pw+ycJNr/ihPYFza4mBMuFjEVZzvcFSFC5qDly6cfMO+MmSoaM/tfQbNFI4O 3EK0WXYD1Cwi5XCC3s5sApNXQtn6gRlk6TOmjKpNMqjlmjcLmKtEh0xnvNrMzbuUv+bpeV 1tW4NjlFrLWTy6AaHwTdOIhOjbzyby9/qUzgACl2J0LcZZPEKxR0WvbFe2qcXQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1777978558; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=38J4YBTdPhJmUzC4swG6FHvNghC5KLWCDYsJJddGPng=; b=dn2UEEFDDIlplCY4jbPpLJZ3WW7WxwM03T8AXr7l8f7ixzxY8zRXdbSEUThx/qV35RKWZU COiV4/mQJPVQvPAw== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] objtool: Add insn_sym() helper Cc: Song Liu , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177797855675.424702.10937352045438574110.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the objtool/core branch of tip: Commit-ID: 3ee67629b2b7fbe270f6c21d9a95219bbd214630 Gitweb: https://git.kernel.org/tip/3ee67629b2b7fbe270f6c21d9a95219bb= d214630 Author: Josh Poimboeuf AuthorDate: Sat, 04 Apr 2026 11:30:37 -07:00 Committer: Josh Poimboeuf CommitterDate: Mon, 04 May 2026 21:16:06 -07:00 objtool: Add insn_sym() helper Alternative replacement instructions awkwardly have insn->sym set to the function they get patched to rather than the symbol (or rather lack thereof) they belong to in the file. This makes it difficult to know where a given instruction actually lives. Add a new insn_sym() helper which preserves the existing semantic of insn->sym. Rename insn->sym to insn->_sym, which contains the actual ELF binary symbol (or NULL, for alternative replacements) an instruction lives in. The private insn->_sym value will be needed for a subsequent patch. Acked-by: Song Liu Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 31 +++++++++++--------------- tools/objtool/disas.c | 22 ++++++++---------- tools/objtool/include/objtool/check.h | 20 +++++++++++++++-- tools/objtool/include/objtool/warn.h | 6 ++--- tools/objtool/trace.c | 8 +++---- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index ae047be..4242582 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -495,7 +495,7 @@ static int decode_instructions(struct objtool_file *fil= e) } =20 sym_for_each_insn(file, func, insn) { - insn->sym =3D func; + insn->_sym =3D func; if (is_func_sym(func) && insn->type =3D=3D INSN_ENDBR && list_empty(&insn->call_node)) { @@ -859,15 +859,14 @@ static int create_ibt_endbr_seal_sections(struct objt= ool_file *file) list_for_each_entry(insn, &file->endbr_list, call_node) { =20 int *site =3D (int *)sec->data->d_buf + idx; - struct symbol *sym =3D insn->sym; + struct symbol *func =3D insn_func(insn); *site =3D 0; =20 - if (opts.module && sym && is_func_sym(sym) && - insn->offset =3D=3D sym->offset && - (!strcmp(sym->name, "init_module") || - !strcmp(sym->name, "cleanup_module"))) { + if (opts.module && func && insn->offset =3D=3D func->offset && + (!strcmp(func->name, "init_module") || + !strcmp(func->name, "cleanup_module"))) { ERROR("%s(): Magic init_module() function name is deprecated, use modul= e_init(fn) instead", - sym->name); + func->name); return -1; } =20 @@ -1581,7 +1580,7 @@ static int add_jump_destinations(struct objtool_file = *file) } =20 if (!dest_sym || is_sec_sym(dest_sym)) { - dest_sym =3D dest_insn->sym; + dest_sym =3D insn_sym(dest_insn); if (!dest_sym) goto set_jump_dest; } @@ -1597,7 +1596,7 @@ static int add_jump_destinations(struct objtool_file = *file) continue; } =20 - if (!insn->sym || insn->sym->pfunc =3D=3D dest_sym->pfunc) + if (!insn_sym(insn) || insn_sym(insn)->pfunc =3D=3D dest_sym->pfunc) goto set_jump_dest; =20 /* @@ -1770,7 +1769,6 @@ static int handle_group_alt(struct objtool_file *file, nop->offset =3D special_alt->new_off + special_alt->new_len; nop->len =3D special_alt->orig_len - special_alt->new_len; nop->type =3D INSN_NOP; - nop->sym =3D orig_insn->sym; nop->alt_group =3D new_alt_group; nop->fake =3D 1; } @@ -1789,7 +1787,6 @@ static int handle_group_alt(struct objtool_file *file, =20 last_new_insn =3D insn; =20 - insn->sym =3D orig_insn->sym; insn->alt_group =3D new_alt_group; =20 /* @@ -2432,12 +2429,12 @@ static int __annotate_late(struct objtool_file *fil= e, int type, struct instructi break; =20 case ANNOTYPE_NOCFI: - sym =3D insn->sym; + sym =3D insn_sym(insn); if (!sym) { ERROR_INSN(insn, "dodgy NOCFI annotation"); return -1; } - insn->sym->nocfi =3D 1; + sym->nocfi =3D 1; break; =20 default: @@ -2538,7 +2535,7 @@ static void mark_holes(struct objtool_file *file) * favour of a regular symbol, but leaves the code in place. */ for_each_insn(file, insn) { - if (insn->sym || !find_symbol_hole_containing(insn->sec, insn->offset)) { + if (insn_sym(insn) || !find_symbol_hole_containing(insn->sec, insn->offs= et)) { in_hole =3D false; continue; } @@ -2982,7 +2979,7 @@ static int update_cfi_state(struct instruction *insn, } =20 if (op->dest.reg =3D=3D CFI_BP && op->src.reg =3D=3D CFI_SP && - insn->sym->frame_pointer) { + insn_sym(insn)->frame_pointer) { /* addi.d fp,sp,imm on LoongArch */ if (cfa->base =3D=3D CFI_SP && cfa->offset =3D=3D op->src.offset) { cfa->base =3D CFI_BP; @@ -2994,7 +2991,7 @@ static int update_cfi_state(struct instruction *insn, if (op->dest.reg =3D=3D CFI_SP && op->src.reg =3D=3D CFI_BP) { /* addi.d sp,fp,imm on LoongArch */ if (cfa->base =3D=3D CFI_BP && cfa->offset =3D=3D 0) { - if (insn->sym->frame_pointer) { + if (insn_sym(insn)->frame_pointer) { cfa->base =3D CFI_SP; cfa->offset =3D -op->src.offset; } @@ -4171,7 +4168,7 @@ static int validate_retpoline(struct objtool_file *fi= le) * broken. */ list_for_each_entry(insn, &file->retpoline_call_list, call_node) { - struct symbol *sym =3D insn->sym; + struct symbol *sym =3D insn_sym(insn); =20 if (sym && (is_notype_sym(sym) || is_func_sym(sym)) && !sym->nocfi) { diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 5909023..e6a54a8 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -210,7 +210,7 @@ static bool disas_print_addr_alt(bfd_vma addr, struct d= isassemble_info *dinfo) offset =3D addr - alt_group->first_insn->offset; =20 addr =3D orig_first_insn->offset + offset; - sym =3D orig_first_insn->sym; + sym =3D insn_sym(orig_first_insn); =20 disas_print_addr_sym(orig_first_insn->sec, sym, addr, dinfo); =20 @@ -222,15 +222,13 @@ static void disas_print_addr_noreloc(bfd_vma addr, { struct disas_context *dctx =3D dinfo->application_data; struct instruction *insn =3D dctx->insn; - struct symbol *sym =3D NULL; + struct symbol *sym =3D insn_sym(insn); =20 if (disas_print_addr_alt(addr, dinfo)) return; =20 - if (insn->sym && addr >=3D insn->sym->offset && - addr < insn->sym->offset + insn->sym->len) { - sym =3D insn->sym; - } + if (sym && (addr < sym->offset || addr >=3D sym->offset + sym->len)) + sym =3D NULL; =20 disas_print_addr_sym(insn->sec, sym, addr, dinfo); } @@ -291,9 +289,9 @@ static void disas_print_address(bfd_vma addr, struct di= sassemble_info *dinfo) * up. So check it first. */ jump_dest =3D insn->jump_dest; - if (jump_dest && jump_dest->sym && jump_dest->offset =3D=3D addr) { + if (jump_dest && insn_sym(jump_dest) && jump_dest->offset =3D=3D addr) { if (!disas_print_addr_alt(addr, dinfo)) - disas_print_addr_sym(jump_dest->sec, jump_dest->sym, + disas_print_addr_sym(jump_dest->sec, insn_sym(jump_dest), addr, dinfo); return; } @@ -768,8 +766,8 @@ static int disas_alt_jump(struct disas_alt *dalt) if (orig_insn->len =3D=3D 5) suffix[0] =3D 'q'; str =3D strfmt("jmp%-3s %lx <%s+0x%lx>", suffix, - dest_insn->offset, dest_insn->sym->name, - dest_insn->offset - dest_insn->sym->offset); + dest_insn->offset, insn_sym(dest_insn)->name, + dest_insn->offset - insn_sym(dest_insn)->offset); nops =3D 0; } else { str =3D strfmt("nop%d", orig_insn->len); @@ -794,8 +792,8 @@ static int disas_alt_extable(struct disas_alt *dalt) =20 alt_insn =3D dalt->alt->insn; str =3D strfmt("resume at 0x%lx <%s+0x%lx>", - alt_insn->offset, alt_insn->sym->name, - alt_insn->offset - alt_insn->sym->offset); + alt_insn->offset, insn_sym(alt_insn)->name, + alt_insn->offset - insn_sym(alt_insn)->offset); if (!str) return -1; =20 diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index eea6472..fe08205 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -94,14 +94,30 @@ struct instruction { }; }; struct alternative *alts; - struct symbol *sym; + struct symbol *_sym; struct stack_op *stack_ops; struct cfi_state *cfi; }; =20 +/* + * Return the symbol associated with an instruction. For alternative + * replacements, return the symbol of the original code being replaced rat= her + * than NULL. insn->_sym reflects the actual location in the ELF file. + */ +static inline struct symbol *insn_sym(struct instruction *insn) +{ + struct symbol *sym =3D insn->_sym; + + if ((!sym || !is_func_sym(sym)) && + insn->alt_group && insn->alt_group->orig_group) + sym =3D insn->alt_group->orig_group->first_insn->_sym; + + return sym; +} + static inline struct symbol *insn_func(struct instruction *insn) { - struct symbol *sym =3D insn->sym; + struct symbol *sym =3D insn_sym(insn); =20 if (sym && sym->type !=3D STT_FUNC) sym =3D NULL; diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index a9936d6..870e147 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -77,13 +77,13 @@ static inline char *offstr(struct section *sec, unsigne= d long offset) #define WARN_INSN(insn, format, ...) \ ({ \ struct instruction *_insn =3D (insn); \ - if (!_insn->sym || !_insn->sym->warned) { \ + if (!insn_sym(_insn) || !insn_sym(_insn)->warned) { \ WARN_FUNC(_insn->sec, _insn->offset, format, \ ##__VA_ARGS__); \ BT_INSN(_insn, ""); \ } \ - if (_insn->sym) \ - _insn->sym->warned =3D 1; \ + if (insn_sym(_insn)) \ + insn_sym(_insn)->warned =3D 1; \ }) =20 #define BT_INSN(insn, format, ...) \ diff --git a/tools/objtool/trace.c b/tools/objtool/trace.c index 5dec44d..61c6aa3 100644 --- a/tools/objtool/trace.c +++ b/tools/objtool/trace.c @@ -169,8 +169,8 @@ void trace_alt_begin(struct instruction *orig_insn, str= uct alternative *alt, */ TRACE_ALT_INFO_NOADDR(orig_insn, "/ ", "%s for instruction at 0x%lx <%s+= 0x%lx>", alt_name, - orig_insn->offset, orig_insn->sym->name, - orig_insn->offset - orig_insn->sym->offset); + orig_insn->offset, insn_sym(orig_insn)->name, + orig_insn->offset - insn_sym(orig_insn)->offset); } else { TRACE_ALT_INFO_NOADDR(orig_insn, "/ ", "%s", alt_name); } @@ -185,8 +185,8 @@ void trace_alt_begin(struct instruction *orig_insn, str= uct alternative *alt, if (orig_insn->type =3D=3D INSN_NOP) { suffix[0] =3D (orig_insn->len =3D=3D 5) ? 'q' : '\0'; TRACE_ADDR(orig_insn, "jmp%-3s %lx <%s+0x%lx>", suffix, - alt_insn->offset, alt_insn->sym->name, - alt_insn->offset - alt_insn->sym->offset); + alt_insn->offset, insn_sym(alt_insn)->name, + alt_insn->offset - insn_sym(alt_insn)->offset); } else { TRACE_ADDR(orig_insn, "nop%d", orig_insn->len); trace_depth--;