From nobody Tue Dec 2 02:30:35 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 B6A863A8D57 for ; Wed, 19 Nov 2025 14:34:23 +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=1763562865; cv=none; b=Rx0DDdt6b454tGAUeWH2tvVTi4nodj34vvZxhOUWxm5DLKwqPFPD7c1x0Hj70ENrgflm0MsTN524ViXhkBmwpjgcaPWVgp+1PHAYiS5IgPEpTW023WNIb/wW97x9fTl9iRsAnPAu5+v9WYc1g4KnaNVzv19dFD6j6HbRLJwDDQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562865; c=relaxed/simple; bh=O6k4Mc72aWCclYkSA18TcNNn6U9QdlA0EHr9urjfwxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NH2l469btcCznwSQ+W+2BSrPfppSq1lqxUU0YO9liSwM9/ywuV5dT8Z7UJlxXueSuH3aT5Ov4q6MANMWu3lj5AUzx788R+50PzagW5oNOR140Ly7MuPvc+5xARfMNCTvOV6jrYp2weL9aT6+itsHwlpLJlFeF7kPmcxg3c1l8iA= 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=HR6VEGbW; 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="HR6VEGbW" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJEQx4k014116; Wed, 19 Nov 2025 14:33:48 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=tbtOn 6bQgkcXfkwF6kb5IBM1SH/bd9m0OokCDaude/A=; b=HR6VEGbWlJ4Y8m8QQNrIo JwsCdDr06bB+R/UoG7RrvHTAu/K2DIsZaVi0ubE0qNOZSV1AgmYcdnh1zqO6PzzU Y5KT6ETEFfENEnwc/MTxZyDXekqMNGGsMtXhsgNc9qyxmwHPeqYeMLdTTaDA35D5 TwyQaalNl7/ZL6nfHJyH1NEmLbWD3zWCzYfvGXGn1kkY5i+wbssjN1iKpSaSJLds UnyMrnx1pHx/7cdYLAQb20SySyWRoyeZGTBAR6TzJjt+ZCSdCOQIQXY+hnYHwXvU r0qG7dBWf84X4sEHHCfhVRRp87KLPKOPkthTv2H+PB5/a8egqQ3R4mUyWqfpH7lk A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej9077e3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:48 +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 5AJD6935002638; Wed, 19 Nov 2025 14:33:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyans8j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:47 +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 5AJEWno4022495; Wed, 19 Nov 2025 14:33:46 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-31; Wed, 19 Nov 2025 14:33:46 +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 30/30] objtool: Trim trailing NOPs in alternative Date: Wed, 19 Nov 2025 15:32:47 +0100 Message-ID: <20251119143247.3944213-31-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-Authority-Analysis: v=2.4 cv=OMAqHCaB c=1 sm=1 tr=0 ts=691dd54c b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=LzA7T5uYS_lx5g3k3C8A:9 X-Proofpoint-ORIG-GUID: G8Jlu-zN61iwIHxOBvsLjThQIA2FOJGS X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX2+sn6kUQ9hwJ 4sDkNmK1yUi55prGYNHDpypGX6FpAl2/topIw1vKmYGMlF5a8/uFaRSCwB/EsAi0+e22ZV2n642 bINOlrivJRbU8z+9VVosim0iKxREdUXMqW0bt/ygY/cy6zstNEEqnj+EI0vDzEoyGavnXs3YJvZ 4DfYP6+pMhKuY+lhfwV/zDDE4JZMaxQwntf9s7hbvwjR5Bfc4P9pYAvLCEYtr4McTDAgqwkz96z U8jnZ7Qz2WKonvBt9KFBk597fDWZ+/SxAEZxmaWvMgHwVbCz6YgbPrHMuqFPymSiWQ+8+zA0dQj Z4Is1Hf0iufhOGP5tSysWCu2totAOD67c/tmrO5nT9W08qoov+fMPZz3m4a5kMJENndAiQpiDS4 E7EzWp6a0+bgmcHFdTPb3xHAdGL3Hw== X-Proofpoint-GUID: G8Jlu-zN61iwIHxOBvsLjThQIA2FOJGS Content-Type: text/plain; charset="utf-8" When disassembling alternatives replace trailing NOPs with a single indication of the number of bytes covered with NOPs. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 78 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index f04bc14bef39e..441b9306eafcc 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -52,6 +52,7 @@ struct disas_alt { struct { char *str; /* instruction string */ int offset; /* instruction offset */ + int nops; /* number of nops */ } insn[DISAS_ALT_INSN_MAX]; /* alternative instructions */ int insn_idx; /* index of the next instruction to print */ }; @@ -727,7 +728,7 @@ static int disas_alt_init(struct disas_alt *dalt, } =20 static int disas_alt_add_insn(struct disas_alt *dalt, int index, char *ins= n_str, - int offset) + int offset, int nops) { int len; =20 @@ -740,6 +741,7 @@ static int disas_alt_add_insn(struct disas_alt *dalt, i= nt index, char *insn_str, len =3D strlen(insn_str); dalt->insn[index].str =3D insn_str; dalt->insn[index].offset =3D offset; + dalt->insn[index].nops =3D nops; if (len > dalt->width) dalt->width =3D len; =20 @@ -752,6 +754,7 @@ static int disas_alt_jump(struct disas_alt *dalt) struct instruction *dest_insn; char suffix[2] =3D { 0 }; char *str; + int nops; =20 orig_insn =3D dalt->orig_insn; dest_insn =3D dalt->alt->insn; @@ -762,14 +765,16 @@ static int disas_alt_jump(struct disas_alt *dalt) str =3D strfmt("jmp%-3s %lx <%s+0x%lx>", suffix, dest_insn->offset, dest_insn->sym->name, dest_insn->offset - dest_insn->sym->offset); + nops =3D 0; } else { str =3D strfmt("nop%d", orig_insn->len); + nops =3D orig_insn->len; } =20 if (!str) return -1; =20 - disas_alt_add_insn(dalt, 0, str, 0); + disas_alt_add_insn(dalt, 0, str, 0, nops); =20 return 1; } @@ -789,7 +794,7 @@ static int disas_alt_extable(struct disas_alt *dalt) if (!str) return -1; =20 - disas_alt_add_insn(dalt, 0, str, 0); + disas_alt_add_insn(dalt, 0, str, 0, 0); =20 return 1; } @@ -805,11 +810,13 @@ static int disas_alt_group(struct disas_context *dctx= , struct disas_alt *dalt) int offset; char *str; int count; + int nops; int err; =20 file =3D dctx->file; count =3D 0; offset =3D 0; + nops =3D 0; =20 alt_for_each_insn(file, DALT_GROUP(dalt), insn) { =20 @@ -818,7 +825,8 @@ static int disas_alt_group(struct disas_context *dctx, = struct disas_alt *dalt) if (!str) return -1; =20 - err =3D disas_alt_add_insn(dalt, count, str, offset); + nops =3D insn->type =3D=3D INSN_NOP ? insn->len : 0; + err =3D disas_alt_add_insn(dalt, count, str, offset, nops); if (err) break; offset +=3D insn->len; @@ -834,6 +842,7 @@ static int disas_alt_group(struct disas_context *dctx, = struct disas_alt *dalt) static int disas_alt_default(struct disas_context *dctx, struct disas_alt = *dalt) { char *str; + int nops; int err; =20 if (DALT_GROUP(dalt)) @@ -849,7 +858,8 @@ static int disas_alt_default(struct disas_context *dctx= , struct disas_alt *dalt) str =3D strdup(disas_result(dctx)); if (!str) return -1; - err =3D disas_alt_add_insn(dalt, 0, str, 0); + nops =3D dalt->orig_insn->type =3D=3D INSN_NOP ? dalt->orig_insn->len : 0; + err =3D disas_alt_add_insn(dalt, 0, str, 0, nops); if (err) return -1; =20 @@ -995,6 +1005,62 @@ static void disas_alt_print_compact(char *alt_name, s= truct disas_alt *dalts, } } =20 +/* + * Trim NOPs in alternatives. This replaces trailing NOPs in alternatives + * with a single indication of the number of bytes covered with NOPs. + * + * Return the maximum numbers of instructions in all alternatives after + * trailing NOPs have been trimmed. + */ +static int disas_alt_trim_nops(struct disas_alt *dalts, int alt_count, + int insn_count) +{ + struct disas_alt *dalt; + int nops_count; + const char *s; + int offset; + int count; + int nops; + int i, j; + + count =3D 0; + for (i =3D 0; i < alt_count; i++) { + offset =3D 0; + nops =3D 0; + nops_count =3D 0; + dalt =3D &dalts[i]; + for (j =3D insn_count - 1; j >=3D 0; j--) { + if (!dalt->insn[j].str || !dalt->insn[j].nops) + break; + offset =3D dalt->insn[j].offset; + free(dalt->insn[j].str); + dalt->insn[j].offset =3D 0; + dalt->insn[j].str =3D NULL; + nops +=3D dalt->insn[j].nops; + nops_count++; + } + + /* + * All trailing NOPs have been removed. If there was a single + * NOP instruction then re-add it. If there was a block of + * NOPs then indicate the number of bytes than the block + * covers (nop*). + */ + if (nops_count) { + s =3D nops_count =3D=3D 1 ? "" : "*"; + dalt->insn[j + 1].str =3D strfmt("nop%s%d", s, nops); + dalt->insn[j + 1].offset =3D offset; + dalt->insn[j + 1].nops =3D nops; + j++; + } + + if (j > count) + count =3D j; + } + + return count + 1; +} + /* * Disassemble an alternative. * @@ -1083,6 +1149,8 @@ static void *disas_alt(struct disas_context *dctx, * Print default and non-default alternatives. */ =20 + insn_count =3D disas_alt_trim_nops(dalts, alt_count, insn_count); + if (opts.wide) disas_alt_print_wide(alt_name, dalts, alt_count, insn_count); else --=20 2.43.5