From nobody Tue Dec 2 02:30:07 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 9579A36826E for ; Wed, 19 Nov 2025 14:33:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562820; cv=none; b=DIF5UwEF8ECQJD7LL82iNr2xZV3EVm9+9zbxX0yaIAL9Pt3mhsAjFOU3mtSp02QrVrqpb69+LBCVGD8DbXkM1RhYJ6cB13TNe8DHU4rkGfUZJIaPh9wSQ3dBrf3Jh3N/gm5R0uhxuDZXeCgoOP3TDCm2I/ObJp+J5RTUTweOZLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562820; c=relaxed/simple; bh=YkVE8o/kT/Bg7Y9+jPbxOgbhf2/XriYuj31lOMc2CpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WhZM6x78OJ/bYobFo2QGABjK6RjEpghe6h/m4EobcUUS3Bn3PcY2ivU2YOqxZwMeDNNSpjb8ObYUKV5/fnWelTEWGgOJy5jZe/TG+0IQL3eGHb/nCDacpihiIBZKCxGRVeG9krwHKNXiJ8sNBr1MlTCsb/Hbol5d/DL3WOLkfl8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=EuS/e12X; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="EuS/e12X" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJER20v020438; Wed, 19 Nov 2025 14:33:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=emSJ5 LXhXFwAjBgGHZXvoQmG2QIEZhSBueUDoizevIk=; b=EuS/e12XWgInNRV16JevD dC18gSbLxPtbiCr2K29iIphAT7eys50R0VRNO3yvmvsUkTE5jNG9JiVRp2/MyGLF /aFHDjvAK/0PjcLxkI6aC0XW8vEu9wodrKCFCOhqGYqrOdHCfELxpRnUmfTL3Qr6 wzDo1/kN5QtyLvj5cht5xQJ4AoYG/zyS6LX+SvzWXBz/FJvTBGtyBHXRvAarbO56 gPha0YHn9aN1j6To+LZwk0MwKLylAGUGx9WeYtPTooUUzZTuy/VuQH04LhsZiyd0 +XEOGRYINgJe0w4OE+aEmZh/Z1MNppL0cHPx6prN1M1Bufy+iSu/KGCu3RzZck0J Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbby1sr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:04 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJEPuVH002532; Wed, 19 Nov 2025 14:33:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyanreg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:03 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5AJEWnnI022495; Wed, 19 Nov 2025 14:33:03 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-160-110.vpn.oracle.com [10.154.160.110]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4aefyanr5p-8; Wed, 19 Nov 2025 14:33:03 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, david.laight.linux@gmail.com Cc: alexandre.chartre@oracle.com Subject: [PATCH v5 07/30] objtool: Disassemble instruction on warning or backtrace Date: Wed, 19 Nov 2025 15:32:24 +0100 Message-ID: <20251119143247.3944213-8-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251119143247.3944213-1-alexandre.chartre@oracle.com> References: <20251119143247.3944213-1-alexandre.chartre@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-19_04,2025-11-18_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511190116 X-Proofpoint-GUID: SuREY7mRKCtXR99b_xeCfSLBeiO1hNgR X-Authority-Analysis: v=2.4 cv=JZyxbEKV c=1 sm=1 tr=0 ts=691dd520 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=49cdYLv4DVxkACFpF8YA:9 X-Proofpoint-ORIG-GUID: SuREY7mRKCtXR99b_xeCfSLBeiO1hNgR X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX2RIYB0CH32dq j/BYZ5O6R5DoSQJCIAU8vlUF7VMobWgsIHiAgvPYzEqbQEz62avKgfrLPYbp78+NA38nSu/a03E RUEoem+JARuth/WrcPhFxXakToJm3RGgrNQMv3uB7WdYvLP0C+iOwyyMneSN3rQVcWPRzGFq1wa 0L9ybbJBxdOmzPWIxEOOJgTwWhzu7BWlKp6V+3UNaS7ZsROdcRob95gVfYU1CJZOvZ8v8ddOLFZ k0VbkRK6+VKB+ZQNrykjM7p35hcHQn2Kkb1XyT4sCtm8IfT3LmxL8GxxN9+ghg/uCjPDGk45mee sOwGeWFAojNvf0n1/8MlSxuI7GBeDUZ4kfcuuuYQDR8uoLoY5SAjgsYWhKOqnAS0ViIezsKYB4Z W8iZVBJKLNYNvcB5OXaRH8fbOLcAJg== Content-Type: text/plain; charset="utf-8" When an instruction warning (WARN_INSN) or backtrace (BT_INSN) is issued, disassemble the instruction to provide more context. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 36 ++++++++++++++++++++++----- tools/objtool/disas.c | 5 ++-- tools/objtool/include/objtool/check.h | 2 ++ tools/objtool/include/objtool/disas.h | 13 ++++++++++ tools/objtool/include/objtool/warn.h | 16 ++++++++---- 5 files changed, 58 insertions(+), 14 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 8937667f075df..dd61c3242def5 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4844,11 +4844,34 @@ static void free_insns(struct objtool_file *file) free(chunk->addr); } =20 +static struct disas_context *objtool_disas_ctx; + +const char *objtool_disas_insn(struct instruction *insn) +{ + struct disas_context *dctx =3D objtool_disas_ctx; + + if (!dctx) + return ""; + + disas_insn(dctx, insn); + return disas_result(dctx); +} + int check(struct objtool_file *file) { - struct disas_context *disas_ctx; + struct disas_context *disas_ctx =3D NULL; int ret =3D 0, warnings =3D 0; =20 + /* + * If the verbose or backtrace option is used then we need a + * disassembly context to disassemble instruction or function + * on warning or backtrace. + */ + if (opts.verbose || opts.backtrace) { + disas_ctx =3D disas_context_create(file); + objtool_disas_ctx =3D disas_ctx; + } + arch_initial_func_cfi_state(&initial_func_cfi); init_cfi_state(&init_cfi); init_cfi_state(&func_cfi); @@ -4990,11 +5013,12 @@ int check(struct objtool_file *file) if (opts.verbose) { if (opts.werror && warnings) WARN("%d warning(s) upgraded to errors", warnings); - disas_ctx =3D disas_context_create(file); - if (disas_ctx) { - disas_warned_funcs(disas_ctx); - disas_context_destroy(disas_ctx); - } + disas_warned_funcs(disas_ctx); + } + + if (disas_ctx) { + disas_context_destroy(disas_ctx); + objtool_disas_ctx =3D NULL; } =20 free_insns(file); diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 89daa121b40b0..a030b06c121d2 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -303,7 +303,7 @@ void disas_context_destroy(struct disas_context *dctx) free(dctx); } =20 -static char *disas_result(struct disas_context *dctx) +char *disas_result(struct disas_context *dctx) { return dctx->result; } @@ -311,8 +311,7 @@ static char *disas_result(struct disas_context *dctx) /* * Disassemble a single instruction. Return the size of the instruction. */ -static size_t disas_insn(struct disas_context *dctx, - struct instruction *insn) +size_t disas_insn(struct disas_context *dctx, struct instruction *insn) { disassembler_ftype disasm =3D dctx->disassembler; struct disassemble_info *dinfo =3D &dctx->info; diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index ad9c73504b120..f96aabd7d54dc 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -141,4 +141,6 @@ struct instruction *next_insn_same_sec(struct objtool_f= ile *file, struct instruc insn && insn->offset < sym->offset + sym->len; \ insn =3D next_insn_same_sec(file, insn)) =20 +const char *objtool_disas_insn(struct instruction *insn); + #endif /* _CHECK_H */ diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 3ec3ce2e4e6f0..1aee1fbe0bb97 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -17,6 +17,8 @@ void disas_warned_funcs(struct disas_context *dctx); int disas_info_init(struct disassemble_info *dinfo, int arch, int mach32, int mach64, const char *options); +size_t disas_insn(struct disas_context *dctx, struct instruction *insn); +char *disas_result(struct disas_context *dctx); =20 #else /* DISAS */ =20 @@ -38,6 +40,17 @@ static inline int disas_info_init(struct disassemble_inf= o *dinfo, return -1; } =20 +static inline size_t disas_insn(struct disas_context *dctx, + struct instruction *insn) +{ + return -1; +} + +static inline char *disas_result(struct disas_context *dctx) +{ + return NULL; +} + #endif /* DISAS */ =20 #endif /* _DISAS_H */ diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index a1e3927d8e7ce..f32abc7b1be14 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -77,9 +77,11 @@ static inline char *offstr(struct section *sec, unsigned= long offset) #define WARN_INSN(insn, format, ...) \ ({ \ struct instruction *_insn =3D (insn); \ - if (!_insn->sym || !_insn->sym->warned) \ + if (!_insn->sym || !_insn->sym->warned) { \ WARN_FUNC(_insn->sec, _insn->offset, format, \ ##__VA_ARGS__); \ + BT_INSN(_insn, ""); \ + } \ if (_insn->sym) \ _insn->sym->warned =3D 1; \ }) @@ -87,10 +89,14 @@ static inline char *offstr(struct section *sec, unsigne= d long offset) #define BT_INSN(insn, format, ...) \ ({ \ if (opts.verbose || opts.backtrace) { \ - struct instruction *_insn =3D (insn); \ - char *_str =3D offstr(_insn->sec, _insn->offset); \ - WARN(" %s: " format, _str, ##__VA_ARGS__); \ - free(_str); \ + struct instruction *__insn =3D (insn); \ + char *_str =3D offstr(__insn->sec, __insn->offset); \ + const char *_istr =3D objtool_disas_insn(__insn); \ + int _len; \ + _len =3D snprintf(NULL, 0, " %s: " format, _str, ##__VA_ARGS__); \ + _len =3D (_len < 50) ? 50 - _len : 0; \ + WARN(" %s: " format " %*s%s", _str, ##__VA_ARGS__, _len, "", _istr); \ + free(_str); \ } \ }) =20 --=20 2.43.5