From nobody Tue Dec 2 01:49:04 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.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 5B52234D4DF for ; Fri, 21 Nov 2025 09:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718887; cv=none; b=ucNzecuKAezglDnL5m8Tn5xQzXcLVxaTti64sTHdoV7Cj8OPGoQIdA32GfjJHEEBvwBY0PDfY078yG9NRsuMDybBcn5unUbp3wrCFW1ofb7gpPLmIaHTzOmBAnPO6NnpmdsykvCgXLfWfVMoayT9wDt9bNyJsWyWqPeR+lcpH7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718887; c=relaxed/simple; bh=O6k4Mc72aWCclYkSA18TcNNn6U9QdlA0EHr9urjfwxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uFdQMEQZ/SUha2MMysmRu0pNJxxeRCLtr1ycZxhCSsQVqcqKy06z6yjHiwA4GEUUUee/d0IJwQESE/m7dnPlNPuhxwqy65BdHcg1SAwJ8Kfcfo8v53jARNjfMR9zdM1zuH+3/mduSRTHfmzT/jDI40JeqEOVo6njwakR7NhnawY= 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=WHhYBbTv; arc=none smtp.client-ip=205.220.165.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="WHhYBbTv" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL1xx5X021821; Fri, 21 Nov 2025 09:54:40 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=WHhYBbTvJzdDPJIlKCH6E UEKIRnMeS9+mBas+rAqevg0pkSiK/fnkHHIKYlkb8byauJcjSI/FIO3ixMsemZ8D t3pJSZsAicAaytsgG2FppXJ2rPJSks0X7hAZXabgxknfRoZC1Y0wzWmOBfcEz0SA h3uEI9aLV2MgEaDDZsnLR2l1pk8RwgcS3+c6f1HrGeGc/1PkRW7Rx7Y7cY75e7sK f6bdTmTZT2VkePypWT8oOnIjRpJj5GaEqKWTpjkh1KwkwynoyuHxYLU1g4EQnW5n cyp3hQLO0ZjSInU3Tsr01u+SkTdOLpwhEZOXiSPXRtKk89td7hgth/210Sn3wFUU w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejd1jtsn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:39 +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 5AL9sED6004512; Fri, 21 Nov 2025 09:54:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4v2d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:39 +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 5AL9rgV4021648; Fri, 21 Nov 2025 09:54:38 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-31; Fri, 21 Nov 2025 09:54:38 +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 30/30] objtool: Trim trailing NOPs in alternative Date: Fri, 21 Nov 2025 10:53:40 +0100 Message-ID: <20251121095340.464045-31-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-Proofpoint-GUID: A4Vwd41XK6x_riT1u5rryX8_NtvXYoBC X-Authority-Analysis: v=2.4 cv=Z/jh3XRA c=1 sm=1 tr=0 ts=692036e0 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=LzA7T5uYS_lx5g3k3C8A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX9iOYxQnSG0TD zAAc8L7yWBmJANKRjbh8oKtigvAb73Nhs3RPoPmpDkHomCm25D7uSWlZRC/EayjWnrnk1FDHigg +GxNWyIi8rmKv06pExTdi9+sH8lK9wOu/RQzBUqKrPrxouIqLFGu8uvvTcNejtuZgO4AmAT0vRV 9MNFfucx8o8pE9hC28nMt+6Nv2vdKl0cZvHHlErIQIYfTin9wJbMB3i7xzav/tHM7BVfphuKFUa OA4JE99A8chyGt2EopNgMu+j1fLYSje17QIfSTX5TtTVdxnzTqtAOWQbGGeAUKgnNmiRwvXuptl TpWVIz9u9YhYjm5j5TIDqh4KQu+j/w9uInHP8YTzGN4mTcCeFpw3Zq9LZim0PZSID8/SH1U9QU8 LklsCT1/x6HOAEKYPv/5EZ9LHN6myg== X-Proofpoint-ORIG-GUID: A4Vwd41XK6x_riT1u5rryX8_NtvXYoBC 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