From nobody Tue Dec 2 02:04:32 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 C38D7346E66 for ; Fri, 21 Nov 2025 09:54:22 +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=1763718864; cv=none; b=TMxfxmu6ixfFjtcAC8WDAcLwZ5ONgz9TzIpkplSWkKROV20aBur3PYz0QiwqUbyozEW8P02DoX+aerfrSGXyc/nlD1tg6FSkeWESwUz+xLL8spu3GJpuQRzbtCzx7q/+nOFxFqqhabufGffvh3RfNPNI3mgf2PZkkCX/r4VsoCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718864; c=relaxed/simple; bh=3fxa9nb+Si9l1pzzCSpnKost1kEepSbXUXqxS3bIRf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mU86iUwH9evqFNt849dez67oiNGzHBvAW6G15NgVdIuYv67jH9Qbq7ffCZxRjYTUdak6bcTlfyAISMIJozpL5tPK2otqBSHFkOdN9xLckAkbmRgbv05Jk0ykgKvO9+VJBgRpTSb8UIQs9RohscAfJ8ygiNkgXqYZJKy0rv13N1U= 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=MFTtjy3P; 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="MFTtjy3P" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL1ujoC024731; Fri, 21 Nov 2025 09:54:16 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=0Nd/v 3d/dJX35jCEmtz1zI9yiLfwQZNJHrNILHcWOm8=; b=MFTtjy3P6jXLiVpMM2Fxp MOmZVo0DBQ8IE92QAnO2GaFv9bg0gHBNaqAG7g8YYJn+QL74Kg6X6qAc6/S3L+iG RzDW62yLbO+43heLa1ucIbr9KO+TAdyAtU3WIWWVFWDzBKQ0hWMbngs2deQxPqk8 dVzKr9VeYOEpenvmiKCi8wSc/55usx8e6UAqiCAt9fUN1NDyMdTCoZZ7n3H/B2oY wYGe5UWHXNvxRrxvKnYlORazJK9kHsUiZ0VsHmgwYZPf9CnxiN5ifwcITUwHgZVR XeoVRNSwoFia/OD8OzjNTmshrsIg9Ddol8j+luQREJaa/2TQ4ybTdcKixL38yClM A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbbk43y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:16 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL7uBOQ004315; Fri, 21 Nov 2025 09:54:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4ut3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:15 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5AL9rgUc021648; Fri, 21 Nov 2025 09:54:14 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-175-150.vpn.oracle.com [10.154.175.150]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4aefyd4ub2-18; Fri, 21 Nov 2025 09:54:14 +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 v6 17/30] objtool: Add the --disas= action Date: Fri, 21 Nov 2025 10:53:27 +0100 Message-ID: <20251121095340.464045-18-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251121095340.464045-1-alexandre.chartre@oracle.com> References: <20251121095340.464045-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-21_03,2025-11-20_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511210075 X-Authority-Analysis: v=2.4 cv=BoqQAIX5 c=1 sm=1 tr=0 ts=692036c8 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=Yos37rPc9-vhJleOp_oA:9 X-Proofpoint-ORIG-GUID: jpwcj0jBlo2Mrmp7CG0UMPrFhhxLe3b0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX05foun4BM4k5 h0g89KjuBlYBrpMFIGizHUX4ywyl0gqMfGzUVctWKie5Pf6f2tWh4jc40c2aD+eg12jL1Wj2HSa czXbjk1Pso1zGdp74m81puJb1+eummKf47bo/D7eaU2dRPRnoNAEmsKbvJ4q6vMM1MkaxcVqti4 oUYC7TjQOUNSPGxy3VHFQZ3AAVvkqKZfHYIZza4i41wEG1M/bDC9AlCQem/Jugj2hosBU6YYsto LTBkxEQG3l8Jetd7rTE5k0VADxs3/MxsQFNSL8thR4tQy8YPTNAQImrmzJiU+TCNiY0gAYRWacE Hdau8MFcBwlCDNndsOThlZHgVibCJym5oLtoUN054TwnLHwJXri1uVXmdWkVd+g9QgmHSn+zC3B RsRItDdyy36hlP65crc6Cbu2gfiL7g== X-Proofpoint-GUID: jpwcj0jBlo2Mrmp7CG0UMPrFhhxLe3b0 Content-Type: text/plain; charset="utf-8" Add the --disas=3D actions to disassemble the specified functions. The function pattern can be a single function name (e.g. --disas foo to disassemble the function with the name "foo"), or a shell wildcard pattern (e.g. --disas foo* to disassemble all functions with a name starting with "foo"). Signed-off-by: Alexandre Chartre --- tools/objtool/builtin-check.c | 2 ++ tools/objtool/check.c | 38 ++++++++++++++----------- tools/objtool/disas.c | 27 ++++++++++++++++++ tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/disas.h | 2 ++ 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 3329d370006b4..a0371312fe55a 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -75,6 +75,7 @@ static const struct option check_options[] =3D { OPT_GROUP("Actions:"), OPT_BOOLEAN(0, "checksum", &opts.checksum, "generate per-function check= sums"), OPT_BOOLEAN(0, "cfi", &opts.cfi, "annotate kernel control flow integrit= y (kCFI) function preambles"), + OPT_STRING_OPTARG('d', "disas", &opts.disas, "function-pattern", "disass= emble functions", "*"), OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake= ", "patch toolchain bugs/limitations", parse_hacks), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls f= or ftrace"), @@ -176,6 +177,7 @@ static bool opts_valid(void) } =20 if (opts.checksum || + opts.disas || opts.hack_jump_label || opts.hack_noinstr || opts.ibt || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 0da86834ab2ab..5bb932f211f6b 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2632,7 +2632,7 @@ static int decode_sections(struct objtool_file *file) * Must be before add_jump_destinations(), which depends on 'func' * being set for alternatives, to enable proper sibling call detection. */ - if (validate_branch_enabled() || opts.noinstr || opts.hack_jump_label) { + if (validate_branch_enabled() || opts.noinstr || opts.hack_jump_label || = opts.disas) { if (add_special_section_alts(file)) return -1; } @@ -4967,14 +4967,15 @@ int check(struct objtool_file *file) 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. + * Create a disassembly context if we might disassemble any + * instruction or function. */ - if (opts.verbose || opts.backtrace || opts.trace) { + if (opts.verbose || opts.backtrace || opts.trace || opts.disas) { disas_ctx =3D disas_context_create(file); - if (!disas_ctx) + if (!disas_ctx) { + opts.disas =3D false; opts.trace =3D false; + } objtool_disas_ctx =3D disas_ctx; } =20 @@ -5108,20 +5109,20 @@ int check(struct objtool_file *file) } =20 out: - if (!ret && !warnings) { - free_insns(file); - return 0; - } - - if (opts.werror && warnings) - ret =3D 1; - - if (opts.verbose) { + if (ret || warnings) { if (opts.werror && warnings) - WARN("%d warning(s) upgraded to errors", warnings); - disas_warned_funcs(disas_ctx); + ret =3D 1; + + if (opts.verbose) { + if (opts.werror && warnings) + WARN("%d warning(s) upgraded to errors", warnings); + disas_warned_funcs(disas_ctx); + } } =20 + if (opts.disas) + disas_funcs(disas_ctx); + if (disas_ctx) { disas_context_destroy(disas_ctx); objtool_disas_ctx =3D NULL; @@ -5129,6 +5130,9 @@ int check(struct objtool_file *file) =20 free_insns(file); =20 + if (!ret && !warnings) + return 0; + if (opts.backup && make_backup()) return 1; =20 diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index b53be240825da..9cc952e03c356 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -4,6 +4,7 @@ */ =20 #define _GNU_SOURCE +#include =20 #include #include @@ -556,3 +557,29 @@ void disas_warned_funcs(struct disas_context *dctx) disas_func(dctx, sym); } } + +void disas_funcs(struct disas_context *dctx) +{ + bool disas_all =3D !strcmp(opts.disas, "*"); + struct section *sec; + struct symbol *sym; + + for_each_sec(dctx->file->elf, sec) { + + if (!(sec->sh.sh_flags & SHF_EXECINSTR)) + continue; + + sec_for_each_sym(sec, sym) { + /* + * If the function had a warning and the verbose + * option is used then the function was already + * disassemble. + */ + if (opts.verbose && sym->warned) + continue; + + if (disas_all || fnmatch(opts.disas, sym->name, 0) =3D=3D 0) + disas_func(dctx, sym); + } + } +} diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 991365c10f0e9..e3af664864f30 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -28,6 +28,7 @@ struct opts { bool static_call; bool uaccess; int prefix; + const char *disas; =20 /* options: */ bool backtrace; diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 8959d4c455622..e8f395eff1598 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -15,6 +15,7 @@ struct disassemble_info; struct disas_context *disas_context_create(struct objtool_file *file); void disas_context_destroy(struct disas_context *dctx); void disas_warned_funcs(struct disas_context *dctx); +void disas_funcs(struct disas_context *dctx); int disas_info_init(struct disassemble_info *dinfo, int arch, int mach32, int mach64, const char *options); @@ -40,6 +41,7 @@ static inline struct disas_context *disas_context_create(= struct objtool_file *fi =20 static inline void disas_context_destroy(struct disas_context *dctx) {} static inline void disas_warned_funcs(struct disas_context *dctx) {} +static inline void disas_funcs(struct disas_context *dctx) {} =20 static inline int disas_info_init(struct disassemble_info *dinfo, int arch, int mach32, int mach64, --=20 2.43.5