From nobody Tue Dec 2 02:30:04 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 ED9933730EC for ; Wed, 19 Nov 2025 14:34:07 +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=1763562849; cv=none; b=qhM710kfKJa3ryvIRRedzFeWS+zTGGvGEVt/Yvm4KiDSbNxxuoDAsFUHdYPaGtLKZeKneuVj9WMVUNQkWgfOxAjQRJ9mts1+ZzQJFfKvpFx7MyqkHufH1KEmhcIo7lXapm6gGZUHjKqJEQs5R/0wP2owM5XIbDnWcHV9+xlgEyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562849; c=relaxed/simple; bh=3fxa9nb+Si9l1pzzCSpnKost1kEepSbXUXqxS3bIRf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hn7JUyBJQdu6Qmx884o+93quzI5S/ABiguNIJCUIBaKtjuhVENFjYgHZyDJZhe9ZEESbDil0ZppjtGpMC5DC3VGgJTrRQVGXd/LuDLYQQ6rMtZfcqdPZp/ikG+oQSB74NsZ9lRzBKvWeIuwY5rcR9alXQZpcdQ+nfdWOpFwMXzI= 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=o8wX6/7Z; 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="o8wX6/7Z" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJEQxBS009381; Wed, 19 Nov 2025 14:33:23 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=o8wX6/7ZRCKm3+Dai1MO9 gtagVkninKKZ8THaxmbSXgz8p2lmT1YSQuar6lPjICWwA7ErIEQfb0Y3ZL2t0ti+ p1cmGR6P0UDYJZPRO6PUVhLmbbVEBvbMSqC1/OGqBRqvFkCLwOgJOrrJzvOQWRU+ 7eoRPv5X0jguKg8mXLZdTBv1GGn7H8ZRKpFzhPqKqh19db+4L/mnliG5sOtiixPm kLaZLEHCNnMa5IlmhJWcnSveArTbD7QNoGuenZsf6IwoV0WR8GTiyKP01JSA+bGp nBplcSt7iNJrMz+JpNOu2+kRFZwkm2OyO7CmIeyVcPSKFbtc4CmfV9N2R59ZMGCR g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej8j75jd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:23 +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 5AJCplqQ002424; Wed, 19 Nov 2025 14:33:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyanrs0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:22 +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 5AJEWnnc022495; Wed, 19 Nov 2025 14:33:22 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-18; Wed, 19 Nov 2025 14:33:21 +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 17/30] objtool: Add the --disas= action Date: Wed, 19 Nov 2025 15:32:34 +0100 Message-ID: <20251119143247.3944213-18-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-ORIG-GUID: Uf2d50KfI7ub2qD0i8yg8v06xzuHUYtV X-Proofpoint-GUID: Uf2d50KfI7ub2qD0i8yg8v06xzuHUYtV X-Authority-Analysis: v=2.4 cv=I7xohdgg c=1 sm=1 tr=0 ts=691dd533 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=Yos37rPc9-vhJleOp_oA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX0rs+M63ol4+t J2COXfQfT1EnEvh2zfveE9jNSWHPSGy6fW9Zf5f5cWdU53pL29NLOj5jLDt7E7PwYWmoBg3W22a mcl0CN3MJeMwrG3CXYOaDW96K8RAqhyqzJ1rBYEby4r/bkOMcz00p7kGZWYbF76/e/LkEPA1wTv sI7PCdlwsTBwoFp70lssFVbdzzJNP1X203JZxTVbxjN1lh0SqaG+9PbpJyC7u1DpdHcBcAMkTlR yIZ87kOcACdsBlj9cQUYvZ/oDI1x3BVoAALGi6gjpik22yO8jTD682p557ZQ/HDt1z6B5V2ceb3 prwkvOnJUBPXPrce7Md+16Le1QDVK7DN7AgOZKACwmfyLbvQPn+Xhpvl8FJi1fYW8x+C/D9BzI0 TCP6WK5jyj+N/uwR1YnH575fLUQlUQ== 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