From nobody Tue Dec 2 01:28:38 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 834A8293B75 for ; Fri, 21 Nov 2025 09:53:53 +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=1763718835; cv=none; b=HL2k9hANoX+b6SW+srurahh07yA2198d6kelQ0/WdLIqdR00GSweJRkPCTFzVSB67VIVYCrj2h6FVbYbzRHUXzTy1wJbLJ8d+Co2HhyLB0G/s+BPHIhBcJUodvN0Boryhx6QBv+QzGzX1CdjJoIGLJ512ysEDZAJKwGnsn/VrCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718835; c=relaxed/simple; bh=yQaMg0aHKsiExmKDcJg+AwtHJoQYgyNqzxsPL3STdig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LN+fWYkQRxSci2Gnm+S5KpS462398UOaCY8bytwtIi2mMa94Vwud/oxg5oyfr2+xdVNp4xjtGi7HaZ7qW9K41UDcuW68ohbUdEpW61mN3NvLZLOKI2w0SjMuQKv96aKNr02ftoMn/+LxchtfpsqidXofB5eKzuHozq6HxI820Jw= 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=l/V2w423; 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="l/V2w423" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL1v0pH031466; Fri, 21 Nov 2025 09:53:46 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=INJU7 HeynSiJPcn6nyrTqeyB5TQxx+QjVJFXWaQTfoo=; b=l/V2w423bmcpFlUKjPtSz /XBjWUMhodmc3ylRqghNyU2nd6je83S5taQN8LnZetvOe0o8nnGgcJlSyXvV3dXV fTfklGtZAb77DEBSP04JKmK+XmVH42Yhzmsc3o1YYPLz2yYzxLHgrXCQ8TsnJUAJ 5LXpK6z8F3JLGU/MA7KGd6IpPmyThJEEC1SN2XmFt066f9oR0NOeUMG3OIlx5bOK P6YWNIQ4EF9EL4qwLy9w33EPY6j6bbLqvN2Ka+qvlAqfMtvrRh6CGSBIuMn96q3b 0PecVsLAbE3R6XsaPZkoS2cjtcEOHxPpqheOpP5eSiuWSUZAZz1hMQtHRMEP/p+P Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbutn69-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:45 +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 5AL7t9bB004348; Fri, 21 Nov 2025 09:53:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uc0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:45 +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 5AL9rgU6021648; Fri, 21 Nov 2025 09:53:44 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-2; Fri, 21 Nov 2025 09:53:44 +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 01/30] objtool: Move disassembly functions to a separated file Date: Fri, 21 Nov 2025 10:53:11 +0100 Message-ID: <20251121095340.464045-2-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-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfXwlcGxUqKZVNt oVUBpu1SGft21buMb+YlzB9mVuIJjPpm+eH2jGoO5EVq0Ta8Rk6zNO9xS48W+mgqYM8gAHEaF89 +XYE+hKzWFoPs78glTkVd4WXWdvU2i7vqNXSWRM/G96hbUMMhuXcJ9uu8mDBjmyVioLsU0lno0z Gif6QI0hwCDDhXHsVH6ueNTJAjl3QAdrxH0a3Fy4z4dz9NfOevBZhiDtVD4NL+gUFeXLmkmoptM ubkZ3kbmc0WGeQ+8r+tbUWP0xGtnJB6r4FlqvHuSnZWi/p9BCy9RPXRMSxt++SroUpqqk865ZeP oI2PwKAPPjiEaLV/US6MOvcggJNVoFIX7dVF8Uxj8uH5hftM9oyiMVy+8wacuCbgoILBtvEtKyV v73HoViJTqs24oE1dsTthIblOHwdLg== X-Proofpoint-GUID: nNWv80sHESybAjdnLDb1joUKbaWXGDGF X-Proofpoint-ORIG-GUID: nNWv80sHESybAjdnLDb1joUKbaWXGDGF X-Authority-Analysis: v=2.4 cv=Rdydyltv c=1 sm=1 tr=0 ts=692036a9 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=dBVU6wt392Vc8wzyTJAA:9 Content-Type: text/plain; charset="utf-8" objtool disassembles functions which have warnings. Move the code to do that to a dedicated file. The code is just moved, it is not changed. Signed-off-by: Alexandre Chartre --- tools/objtool/Build | 1 + tools/objtool/check.c | 81 ---------------------- tools/objtool/disas.c | 90 +++++++++++++++++++++++++ tools/objtool/include/objtool/objtool.h | 2 + 4 files changed, 93 insertions(+), 81 deletions(-) create mode 100644 tools/objtool/disas.c diff --git a/tools/objtool/Build b/tools/objtool/Build index 8cd71b9a5eef1..17e50a1766d0e 100644 --- a/tools/objtool/Build +++ b/tools/objtool/Build @@ -7,6 +7,7 @@ objtool-y +=3D special.o objtool-y +=3D builtin-check.o objtool-y +=3D elf.o objtool-y +=3D objtool.o +objtool-y +=3D disas.o =20 objtool-$(BUILD_ORC) +=3D orc_gen.o orc_dump.o objtool-$(BUILD_KLP) +=3D builtin-klp.o klp-diff.o klp-post-link.o diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 72c7f6f03350b..6a5b06052dd22 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4783,87 +4783,6 @@ static int validate_reachable_instructions(struct ob= jtool_file *file) return warnings; } =20 -/* 'funcs' is a space-separated list of function names */ -static void disas_funcs(const char *funcs) -{ - const char *objdump_str, *cross_compile; - int size, ret; - char *cmd; - - cross_compile =3D getenv("CROSS_COMPILE"); - if (!cross_compile) - cross_compile =3D ""; - - objdump_str =3D "%sobjdump -wdr %s | gawk -M -v _funcs=3D'%s' '" - "BEGIN { split(_funcs, funcs); }" - "/^$/ { func_match =3D 0; }" - "/<.*>:/ { " - "f =3D gensub(/.*<(.*)>:/, \"\\\\1\", 1);" - "for (i in funcs) {" - "if (funcs[i] =3D=3D f) {" - "func_match =3D 1;" - "base =3D strtonum(\"0x\" $1);" - "break;" - "}" - "}" - "}" - "{" - "if (func_match) {" - "addr =3D strtonum(\"0x\" $1);" - "printf(\"%%04x \", addr - base);" - "print;" - "}" - "}' 1>&2"; - - /* fake snprintf() to calculate the size */ - size =3D snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + = 1; - if (size <=3D 0) { - WARN("objdump string size calculation failed"); - return; - } - - cmd =3D malloc(size); - - /* real snprintf() */ - snprintf(cmd, size, objdump_str, cross_compile, objname, funcs); - ret =3D system(cmd); - if (ret) { - WARN("disassembly failed: %d", ret); - return; - } -} - -static void disas_warned_funcs(struct objtool_file *file) -{ - struct symbol *sym; - char *funcs =3D NULL, *tmp; - - for_each_sym(file->elf, sym) { - if (sym->warned) { - if (!funcs) { - funcs =3D malloc(strlen(sym->name) + 1); - if (!funcs) { - ERROR_GLIBC("malloc"); - return; - } - strcpy(funcs, sym->name); - } else { - tmp =3D malloc(strlen(funcs) + strlen(sym->name) + 2); - if (!tmp) { - ERROR_GLIBC("malloc"); - return; - } - sprintf(tmp, "%s %s", funcs, sym->name); - free(funcs); - funcs =3D tmp; - } - } - } - - if (funcs) - disas_funcs(funcs); -} - __weak bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc) { unsigned int type =3D reloc_type(reloc); diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c new file mode 100644 index 0000000000000..3a7cb1b8002ec --- /dev/null +++ b/tools/objtool/disas.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2015-2017 Josh Poimboeuf + */ + +#include +#include + +#include + +/* 'funcs' is a space-separated list of function names */ +static void disas_funcs(const char *funcs) +{ + const char *objdump_str, *cross_compile; + int size, ret; + char *cmd; + + cross_compile =3D getenv("CROSS_COMPILE"); + if (!cross_compile) + cross_compile =3D ""; + + objdump_str =3D "%sobjdump -wdr %s | gawk -M -v _funcs=3D'%s' '" + "BEGIN { split(_funcs, funcs); }" + "/^$/ { func_match =3D 0; }" + "/<.*>:/ { " + "f =3D gensub(/.*<(.*)>:/, \"\\\\1\", 1);" + "for (i in funcs) {" + "if (funcs[i] =3D=3D f) {" + "func_match =3D 1;" + "base =3D strtonum(\"0x\" $1);" + "break;" + "}" + "}" + "}" + "{" + "if (func_match) {" + "addr =3D strtonum(\"0x\" $1);" + "printf(\"%%04x \", addr - base);" + "print;" + "}" + "}' 1>&2"; + + /* fake snprintf() to calculate the size */ + size =3D snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + = 1; + if (size <=3D 0) { + WARN("objdump string size calculation failed"); + return; + } + + cmd =3D malloc(size); + + /* real snprintf() */ + snprintf(cmd, size, objdump_str, cross_compile, objname, funcs); + ret =3D system(cmd); + if (ret) { + WARN("disassembly failed: %d", ret); + return; + } +} + +void disas_warned_funcs(struct objtool_file *file) +{ + struct symbol *sym; + char *funcs =3D NULL, *tmp; + + for_each_sym(file->elf, sym) { + if (sym->warned) { + if (!funcs) { + funcs =3D malloc(strlen(sym->name) + 1); + if (!funcs) { + ERROR_GLIBC("malloc"); + return; + } + strcpy(funcs, sym->name); + } else { + tmp =3D malloc(strlen(funcs) + strlen(sym->name) + 2); + if (!tmp) { + ERROR_GLIBC("malloc"); + return; + } + sprintf(tmp, "%s %s", funcs, sym->name); + free(funcs); + funcs =3D tmp; + } + } + } + + if (funcs) + disas_funcs(funcs); +} diff --git a/tools/objtool/include/objtool/objtool.h b/tools/objtool/includ= e/objtool/objtool.h index f7051bbe0bcb2..35f926cf9c254 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -49,4 +49,6 @@ int check(struct objtool_file *file); int orc_dump(const char *objname); int orc_create(struct objtool_file *file); =20 +void disas_warned_funcs(struct objtool_file *file); + #endif /* _OBJTOOL_H */ --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 DF3802D8DC4 for ; Fri, 21 Nov 2025 09:53:54 +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=1763718836; cv=none; b=tdvnVirI58Tj4x5VIggI0AKTeLYoIvDzw7YeuYdqDNENlzVM5C5mSBEfn1Zf5au1dbQCWgpcg8i5Pby0Og3+BXobCuk4pssi0Yi5VeCmfGyi2yZ/hK4H7yUeQGnoi8oR2kPJTiCeAtoHCuzuC2eTY+jcc/yLPx0X1VeEUJyfNxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718836; c=relaxed/simple; bh=95K/Q5zxLPGKMSA3WOKaRU2vl5mgeraLLgVVWwwfURk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XLppLhxi1Zj13UhqXB9stKgFDKDRhI1kb5PE64i49wt1VnRxiRfl5+nkcxAg+lKlPy8D0ckel0HOha7x9TZQRY0txorgA60JOWr9mUM+yhLE8qIIFD84mRC6+ABYNUBf6EdrPwZESr82LI0gLKVbuIG+H6FgZtATgYgUXgnICFA= 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=YQTrd6DD; 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="YQTrd6DD" 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 5AL1xx5U021821; Fri, 21 Nov 2025 09:53:47 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=/j0Bb GUY91yblx/1ZicbT4wGKsgAXWlYfC2RMzCuA3w=; b=YQTrd6DD11tnk2EZh7ndU 2ETVFQteZN9RTG9g4ulE0qc2MuYpkTll3qis8s17RKa5qHskHYV55t7W/dDM95+5 aP6fy1/Vh86iC7pglzsvKPIH9ZqVYTGf2Wq6JQtQjUMNa0NBm4nB1JMnnLdz0N+K SyhuZg7Mnh1G6Nm8e+Z5LrfF8ZrgpbWvvv2255Sh4xyXmtCvEut45j0gN4m0Gqyy blV7xcQOuALMVKpALuQCoV6Fp+w9x3zF8gQjGNcXGBKTakSb6OCinWeAXjMWBlcl z5zP7ZlaI/141RbL8yGWSIxw8Y7bnnlxJXP+ElqwpKuYR3Kb8wR0ENRXPnSkP7tQ Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejd1jtqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:47 +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 5AL8E1qF005173; Fri, 21 Nov 2025 09:53:47 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:46 +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 5AL9rgU8021648; Fri, 21 Nov 2025 09:53:46 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-3; Fri, 21 Nov 2025 09:53: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 v6 02/30] objtool: Create disassembly context Date: Fri, 21 Nov 2025 10:53:12 +0100 Message-ID: <20251121095340.464045-3-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: 3MywW0cABc4bvchTWeW6FQE3nXYjQKS3 X-Authority-Analysis: v=2.4 cv=Z/jh3XRA c=1 sm=1 tr=0 ts=692036ab cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=-R_vEHidSSj7PnaEDHgA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX7u/RodOvI7fR Q+XvgVQlWiihiNIH/gcOJdsOSAn2k7t5914GIc/OuZJ2bV6TXVUgUxf9wQDGW41OBrirs2MsHMR 2KRBhgpnWr2Wmsv16hAIXuq5PYF5f6P/7ok44lsT0w1RfOPx+wmW1rQPxj0aE/w/dmh9fQ9Jb/3 4nbMmCcwPeFBGGZzPBHDhanGtRLciwCYYi/oUWiIxYOdOrVgFJVsLFm3OHsv/lZ+DCI7jmX3iTI +MqoLzGvWhViSMR8RIoIPZKv5zK7XVRzmlEHA8irL2F5gn0SmK0aNYTuOF4Y0f2Z3IwTx+PXoOG lXhT1O7PqcBOwCW8o/2N65dXLrCWEz7z7VZ13e+5WZpB7Q9IXWdhOVRJBb3rKIzkM/ybg6lV61h w/rJYdn8NLq3po6pdVk6vuhUWdhBjw== X-Proofpoint-ORIG-GUID: 3MywW0cABc4bvchTWeW6FQE3nXYjQKS3 Content-Type: text/plain; charset="utf-8" Create a structure to store information for disassembling functions. For now, it is just a wrapper around an objtool file. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 6 ++++- tools/objtool/disas.c | 32 +++++++++++++++++++++++-- tools/objtool/include/objtool/disas.h | 14 +++++++++++ tools/objtool/include/objtool/objtool.h | 2 -- 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 tools/objtool/include/objtool/disas.h diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 6a5b06052dd22..5083e47eef08d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -4854,6 +4855,7 @@ static void free_insns(struct objtool_file *file) =20 int check(struct objtool_file *file) { + struct disas_context *disas_ctx; int ret =3D 0, warnings =3D 0; =20 arch_initial_func_cfi_state(&initial_func_cfi); @@ -4997,7 +4999,9 @@ int check(struct objtool_file *file) if (opts.verbose) { if (opts.werror && warnings) WARN("%d warning(s) upgraded to errors", warnings); - disas_warned_funcs(file); + disas_ctx =3D disas_context_create(file); + disas_warned_funcs(disas_ctx); + disas_context_destroy(disas_ctx); } =20 if (opts.backup && make_backup()) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 3a7cb1b8002ec..7a18e51d43e62 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -4,10 +4,35 @@ */ =20 #include +#include #include =20 #include =20 +struct disas_context { + struct objtool_file *file; +}; + +struct disas_context *disas_context_create(struct objtool_file *file) +{ + struct disas_context *dctx; + + dctx =3D malloc(sizeof(*dctx)); + if (!dctx) { + WARN("failed to allocate disassembly context"); + return NULL; + } + + dctx->file =3D file; + + return dctx; +} + +void disas_context_destroy(struct disas_context *dctx) +{ + free(dctx); +} + /* 'funcs' is a space-separated list of function names */ static void disas_funcs(const char *funcs) { @@ -58,12 +83,15 @@ static void disas_funcs(const char *funcs) } } =20 -void disas_warned_funcs(struct objtool_file *file) +void disas_warned_funcs(struct disas_context *dctx) { struct symbol *sym; char *funcs =3D NULL, *tmp; =20 - for_each_sym(file->elf, sym) { + if (!dctx) + return; + + for_each_sym(dctx->file->elf, sym) { if (sym->warned) { if (!funcs) { funcs =3D malloc(strlen(sym->name) + 1); diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h new file mode 100644 index 0000000000000..5c543b69fc612 --- /dev/null +++ b/tools/objtool/include/objtool/disas.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. + */ + +#ifndef _DISAS_H +#define _DISAS_H + +struct disas_context; +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); + +#endif /* _DISAS_H */ diff --git a/tools/objtool/include/objtool/objtool.h b/tools/objtool/includ= e/objtool/objtool.h index 35f926cf9c254..f7051bbe0bcb2 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -49,6 +49,4 @@ int check(struct objtool_file *file); int orc_dump(const char *objname); int orc_create(struct objtool_file *file); =20 -void disas_warned_funcs(struct objtool_file *file); - #endif /* _OBJTOOL_H */ --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 D03FD3431F8 for ; Fri, 21 Nov 2025 09:54:04 +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=1763718848; cv=none; b=vFX00xshKEKhu2czsmVuOoZSlAS3rrjK5VP+df0Ax2pFJijcjDzpBlXbbDrjYD3prfKh/HKlkNZXmFMIgXX9y5pv3DJDd96CUEdqeDvXW5kxEwC0VUFaZRR/V/0bdsnoP7O8y7ci1I2AujfyET2j5qHsh1gkSIqnhg5RzvR56RA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718848; c=relaxed/simple; bh=ie9+agxrIdnjIahV5tXO1h0ze2OxXBzi+rLP3EXXtJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E6SvLGa2uswVTFwio8+FLIAqv/UZf5DkswwRtR904/xKqHlpL3dliVCfWL5hoY7fgrqyKbai5Vca/0hpkpuY2Yi84KLMOiTdEv5aVvY9GMmWqRj7goNX5o7FYRlQc3pQll6YRL63uqdiyfQsQTr1x+If3yibHNHsA4NQ93Lidx4= 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=UkEjPy3t; 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="UkEjPy3t" 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 5AL1uOpb020661; Fri, 21 Nov 2025 09:53:50 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=lZ2du SgvIZCqddO2WbDjPfMVUUfeOjLsstMx9XhdgmI=; b=UkEjPy3t5TOpwX3jTxxgw NVGVx96EJaFBcC/os5jZ7RnRFZiaxo+rLCCKrcSuFh4B2VE0rctmV4Qi3MG/UwK3 OwWXUQ/SXWLybS6LCClxNcHWE0/Ku8VLEqftkpOraCy3JBKd38Sufl7qIPfLsD01 jXgEOCUPAHWtPVZmevY++IpactT8d0nzXRvcVZYGtGnGuymAk6U3Q7x5/CapyH6m 68t+G2wj9jaK6p3Nn2EgyVblLxbbVMDDc8IpAeeGrF6k3v5xItQMF0piudLDZWh1 hTIq57tBwJ8WxBEfLpyqhJqfZprsJ3o6V7B1YLRmFM58j67Lc6kAk0lewmjLzZBz g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aj5dtsjew-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:49 +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 5AL8q8sF004524; Fri, 21 Nov 2025 09:53:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4ud2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:48 +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 5AL9rgUA021648; Fri, 21 Nov 2025 09:53:48 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-4; Fri, 21 Nov 2025 09:53:48 +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 03/30] objtool: Disassemble code with libopcodes instead of running objdump Date: Fri, 21 Nov 2025 10:53:13 +0100 Message-ID: <20251121095340.464045-4-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-Spam-Details-Enc: AW1haW4tMjUxMTIwMDA5OSBTYWx0ZWRfX1GdbJ4uw9biK P3YSUj1HVBoVae3TCBgfsWBjrvCISyM9U2uvNpESOB1uVRo8hjpFgIw9wawIR9xdO/b3haF7MsV +0dmPiF/Nyyo2XFmwPNV2leBFPbIPfIXpM60a1Us8CT3zhnltZObWUpWWP95N3js7YRQuYTHplH IAtl2OeuSyif++JZTAy2URWVKq8S3CfaW5g6zj0zxtdT+mJ1bv2y4S2h6/qEl7QRrDjK+c5eKRA k6NwoiB9zggUtMNhjFYkP1hJItGn1ztAQ7nj0ZJhAbhWsCyBIeN1X5cjgp6pL+a/R4xBarI9slf Vcbtw5gcahq9rD+X+dp3kYEaff67KGeYAufs5klC1JXRTaCasvbfxwsSXPaTtNNpn7grkzMBCFG he4sZD3AtuKkSFBsbpx9EcVCCbvZwA== X-Authority-Analysis: v=2.4 cv=Dckaa/tW c=1 sm=1 tr=0 ts=692036ad cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=-fz06vnXIPU7J7R3txoA:9 X-Proofpoint-GUID: XhcKNZvVy_edOkXUmESp_OwontZ_OeRh X-Proofpoint-ORIG-GUID: XhcKNZvVy_edOkXUmESp_OwontZ_OeRh Content-Type: text/plain; charset="utf-8" objtool executes the objdump command to disassemble code. Use libopcodes instead to have more control about the disassembly scope and output. If libopcodes is not present then objtool is built without disassembly support. Signed-off-by: Alexandre Chartre --- tools/objtool/.gitignore | 2 + tools/objtool/Build | 3 +- tools/objtool/Makefile | 25 ++++ tools/objtool/arch/loongarch/decode.c | 12 ++ tools/objtool/arch/powerpc/decode.c | 12 ++ tools/objtool/arch/x86/decode.c | 12 ++ tools/objtool/check.c | 14 +- tools/objtool/disas.c | 187 +++++++++++++++++--------- tools/objtool/include/objtool/arch.h | 9 ++ tools/objtool/include/objtool/check.h | 5 + tools/objtool/include/objtool/disas.h | 29 ++++ 11 files changed, 238 insertions(+), 72 deletions(-) diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore index 4faa4dd72f350..759303657bd7c 100644 --- a/tools/objtool/.gitignore +++ b/tools/objtool/.gitignore @@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only arch/x86/lib/inat-tables.c /objtool +feature +FEATURE-DUMP.objtool fixdep libsubcmd/ diff --git a/tools/objtool/Build b/tools/objtool/Build index 17e50a1766d0e..9d1e8f28ef953 100644 --- a/tools/objtool/Build +++ b/tools/objtool/Build @@ -7,7 +7,8 @@ objtool-y +=3D special.o objtool-y +=3D builtin-check.o objtool-y +=3D elf.o objtool-y +=3D objtool.o -objtool-y +=3D disas.o + +objtool-$(BUILD_DISAS) +=3D disas.o =20 objtool-$(BUILD_ORC) +=3D orc_gen.o orc_dump.o objtool-$(BUILD_KLP) +=3D builtin-klp.o klp-diff.o klp-post-link.o diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 021f55b7bd872..df793ca6fc1a1 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -70,6 +70,29 @@ OBJTOOL_CFLAGS +=3D $(if $(elfshdr),,-DLIBELF_USE_DEPREC= ATED) # Always want host compilation. HOST_OVERRIDES :=3D CC=3D"$(HOSTCC)" LD=3D"$(HOSTLD)" AR=3D"$(HOSTAR)" =20 +# +# To support disassembly, objtool needs libopcodes which is provided +# with libbdf (binutils-dev or binutils-devel package). +# +FEATURE_USER =3D .objtool +FEATURE_TESTS =3D libbfd disassembler-init-styled +FEATURE_DISPLAY =3D +include $(srctree)/tools/build/Makefile.feature + +ifeq ($(feature-disassembler-init-styled), 1) + OBJTOOL_CFLAGS +=3D -DDISASM_INIT_STYLED +endif + +BUILD_DISAS :=3D n + +ifeq ($(feature-libbfd),1) + BUILD_DISAS :=3D y + OBJTOOL_CFLAGS +=3D -DDISAS + OBJTOOL_LDFLAGS +=3D -lopcodes +endif + +export BUILD_DISAS + AWK =3D awk MKDIR =3D mkdir =20 @@ -103,6 +126,8 @@ clean: $(LIBSUBCMD)-clean $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -nam= e '\.*.d' -delete $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep + $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool + $(Q)$(RM) -r -- $(OUTPUT)feature =20 FORCE: =20 diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 0115b97c526b8..1de86ebb637d5 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include #include +#include #include #include #include @@ -414,3 +415,14 @@ unsigned long arch_jump_table_sym_offset(struct reloc = *reloc, struct reloc *tabl return reloc->sym->offset + reloc_addend(reloc); } } + +#ifdef DISAS + +int arch_disas_info_init(struct disassemble_info *dinfo) +{ + return disas_info_init(dinfo, bfd_arch_loongarch, + bfd_mach_loongarch32, bfd_mach_loongarch64, + NULL); +} + +#endif /* DISAS */ diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index 3a9b748216edc..4f68b402e7855 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -127,3 +128,14 @@ unsigned int arch_reloc_size(struct reloc *reloc) return 8; } } + +#ifdef DISAS + +int arch_disas_info_init(struct disassemble_info *dinfo) +{ + return disas_info_init(dinfo, bfd_arch_powerpc, + bfd_mach_ppc, bfd_mach_ppc64, + NULL); +} + +#endif /* DISAS */ diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index cc85db7b65a41..83e9c604ce105 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -16,6 +16,7 @@ =20 #include #include +#include #include #include #include @@ -949,3 +950,14 @@ bool arch_absolute_reloc(struct elf *elf, struct reloc= *reloc) return false; } } + +#ifdef DISAS + +int arch_disas_info_init(struct disassemble_info *dinfo) +{ + return disas_info_init(dinfo, bfd_arch_i386, + bfd_mach_i386_i386, bfd_mach_x86_64, + "att"); +} + +#endif /* DISAS */ diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5083e47eef08d..de156e91ee8b7 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4980,8 +4980,6 @@ int check(struct objtool_file *file) goto out; } =20 - free_insns(file); - if (opts.stats) { printf("nr_insns_visited: %ld\n", nr_insns_visited); printf("nr_cfi: %ld\n", nr_cfi); @@ -4990,8 +4988,10 @@ int check(struct objtool_file *file) } =20 out: - if (!ret && !warnings) + if (!ret && !warnings) { + free_insns(file); return 0; + } =20 if (opts.werror && warnings) ret =3D 1; @@ -5000,10 +5000,14 @@ int check(struct objtool_file *file) if (opts.werror && warnings) WARN("%d warning(s) upgraded to errors", warnings); disas_ctx =3D disas_context_create(file); - disas_warned_funcs(disas_ctx); - disas_context_destroy(disas_ctx); + if (disas_ctx) { + disas_warned_funcs(disas_ctx); + disas_context_destroy(disas_ctx); + } } =20 + free_insns(file); + if (opts.backup && make_backup()) return 1; =20 diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 7a18e51d43e62..11ac2ec04afc1 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -4,18 +4,56 @@ */ =20 #include +#include #include #include =20 +#include #include +#include =20 struct disas_context { struct objtool_file *file; + disassembler_ftype disassembler; + struct disassemble_info info; }; =20 +#define DINFO_FPRINTF(dinfo, ...) \ + ((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__)) + +/* + * Initialize disassemble info arch, mach (32 or 64-bit) and options. + */ +int disas_info_init(struct disassemble_info *dinfo, + int arch, int mach32, int mach64, + const char *options) +{ + struct disas_context *dctx =3D dinfo->application_data; + struct objtool_file *file =3D dctx->file; + + dinfo->arch =3D arch; + + switch (file->elf->ehdr.e_ident[EI_CLASS]) { + case ELFCLASS32: + dinfo->mach =3D mach32; + break; + case ELFCLASS64: + dinfo->mach =3D mach64; + break; + default: + return -1; + } + + dinfo->disassembler_options =3D options; + + return 0; +} + struct disas_context *disas_context_create(struct objtool_file *file) { struct disas_context *dctx; + struct disassemble_info *dinfo; + int err; =20 dctx =3D malloc(sizeof(*dctx)); if (!dctx) { @@ -24,8 +62,49 @@ struct disas_context *disas_context_create(struct objtoo= l_file *file) } =20 dctx->file =3D file; + dinfo =3D &dctx->info; + + init_disassemble_info_compat(dinfo, stdout, + (fprintf_ftype)fprintf, + fprintf_styled); + + dinfo->read_memory_func =3D buffer_read_memory; + dinfo->application_data =3D dctx; + + /* + * bfd_openr() is not used to avoid doing ELF data processing + * and caching that has already being done. Here, we just need + * to identify the target file so we call an arch specific + * function to fill some disassemble info (arch, mach). + */ + + dinfo->arch =3D bfd_arch_unknown; + dinfo->mach =3D 0; + + err =3D arch_disas_info_init(dinfo); + if (err || dinfo->arch =3D=3D bfd_arch_unknown || dinfo->mach =3D=3D 0) { + WARN("failed to init disassembly arch"); + goto error; + } + + dinfo->endian =3D (file->elf->ehdr.e_ident[EI_DATA] =3D=3D ELFDATA2MSB) ? + BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; + + disassemble_init_for_target(dinfo); + + dctx->disassembler =3D disassembler(dinfo->arch, + dinfo->endian =3D=3D BFD_ENDIAN_BIG, + dinfo->mach, NULL); + if (!dctx->disassembler) { + WARN("failed to create disassembler function"); + goto error; + } =20 return dctx; + +error: + free(dctx); + return NULL; } =20 void disas_context_destroy(struct disas_context *dctx) @@ -33,86 +112,62 @@ void disas_context_destroy(struct disas_context *dctx) free(dctx); } =20 -/* 'funcs' is a space-separated list of function names */ -static void disas_funcs(const char *funcs) +/* + * Disassemble a single instruction. Return the size of the instruction. + */ +static size_t disas_insn(struct disas_context *dctx, + struct instruction *insn) { - const char *objdump_str, *cross_compile; - int size, ret; - char *cmd; - - cross_compile =3D getenv("CROSS_COMPILE"); - if (!cross_compile) - cross_compile =3D ""; - - objdump_str =3D "%sobjdump -wdr %s | gawk -M -v _funcs=3D'%s' '" - "BEGIN { split(_funcs, funcs); }" - "/^$/ { func_match =3D 0; }" - "/<.*>:/ { " - "f =3D gensub(/.*<(.*)>:/, \"\\\\1\", 1);" - "for (i in funcs) {" - "if (funcs[i] =3D=3D f) {" - "func_match =3D 1;" - "base =3D strtonum(\"0x\" $1);" - "break;" - "}" - "}" - "}" - "{" - "if (func_match) {" - "addr =3D strtonum(\"0x\" $1);" - "printf(\"%%04x \", addr - base);" - "print;" - "}" - "}' 1>&2"; - - /* fake snprintf() to calculate the size */ - size =3D snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + = 1; - if (size <=3D 0) { - WARN("objdump string size calculation failed"); - return; + disassembler_ftype disasm =3D dctx->disassembler; + struct disassemble_info *dinfo =3D &dctx->info; + + if (insn->type =3D=3D INSN_NOP) { + DINFO_FPRINTF(dinfo, "nop%d", insn->len); + return insn->len; } =20 - cmd =3D malloc(size); + /* + * Set the disassembler buffer to read data from the section + * containing the instruction to disassemble. + */ + dinfo->buffer =3D insn->sec->data->d_buf; + dinfo->buffer_vma =3D 0; + dinfo->buffer_length =3D insn->sec->sh.sh_size; =20 - /* real snprintf() */ - snprintf(cmd, size, objdump_str, cross_compile, objname, funcs); - ret =3D system(cmd); - if (ret) { - WARN("disassembly failed: %d", ret); - return; + return disasm(insn->offset, &dctx->info); +} + +/* + * Disassemble a function. + */ +static void disas_func(struct disas_context *dctx, struct symbol *func) +{ + struct instruction *insn; + size_t addr; + + printf("%s:\n", func->name); + sym_for_each_insn(dctx->file, func, insn) { + addr =3D insn->offset; + printf(" %6lx: %s+0x%-6lx ", + addr, func->name, addr - func->offset); + disas_insn(dctx, insn); + printf("\n"); } + printf("\n"); } =20 +/* + * Disassemble all warned functions. + */ void disas_warned_funcs(struct disas_context *dctx) { struct symbol *sym; - char *funcs =3D NULL, *tmp; =20 if (!dctx) return; =20 for_each_sym(dctx->file->elf, sym) { - if (sym->warned) { - if (!funcs) { - funcs =3D malloc(strlen(sym->name) + 1); - if (!funcs) { - ERROR_GLIBC("malloc"); - return; - } - strcpy(funcs, sym->name); - } else { - tmp =3D malloc(strlen(funcs) + strlen(sym->name) + 2); - if (!tmp) { - ERROR_GLIBC("malloc"); - return; - } - sprintf(tmp, "%s %s", funcs, sym->name); - free(funcs); - funcs =3D tmp; - } - } + if (sym->warned) + disas_func(dctx, sym); } - - if (funcs) - disas_funcs(funcs); } diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index d89f8b5ec14e3..18c0e69ee6170 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -103,4 +103,13 @@ bool arch_absolute_reloc(struct elf *elf, struct reloc= *reloc); unsigned int arch_reloc_size(struct reloc *reloc); unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc= *table); =20 +#ifdef DISAS + +#include +#include + +int arch_disas_info_init(struct disassemble_info *dinfo); + +#endif /* DISAS */ + #endif /* _ARCH_H */ diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index d73b0c3ae1ee3..674f57466d125 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -127,4 +127,9 @@ struct instruction *next_insn_same_sec(struct objtool_f= ile *file, struct instruc insn && insn->sec =3D=3D _sec; \ insn =3D next_insn_same_sec(file, insn)) =20 +#define sym_for_each_insn(file, sym, insn) \ + for (insn =3D find_insn(file, sym->sec, sym->offset); \ + insn && insn->offset < sym->offset + sym->len; \ + insn =3D next_insn_same_sec(file, insn)) + #endif /* _CHECK_H */ diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 5c543b69fc612..3ec3ce2e4e6f0 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -7,8 +7,37 @@ #define _DISAS_H =20 struct disas_context; +struct disassemble_info; + +#ifdef DISAS + 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); +int disas_info_init(struct disassemble_info *dinfo, + int arch, int mach32, int mach64, + const char *options); + +#else /* DISAS */ + +#include + +static inline struct disas_context *disas_context_create(struct objtool_fi= le *file) +{ + WARN("Rebuild with libopcodes for disassembly support"); + return NULL; +} + +static inline void disas_context_destroy(struct disas_context *dctx) {} +static inline void disas_warned_funcs(struct disas_context *dctx) {} + +static inline int disas_info_init(struct disassemble_info *dinfo, + int arch, int mach32, int mach64, + const char *options) +{ + return -1; +} + +#endif /* DISAS */ =20 #endif /* _DISAS_H */ --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 564E334253B for ; Fri, 21 Nov 2025 09:54:00 +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=1763718841; cv=none; b=E1vibRXgipYFVXBIL57pGc9c55SrIO/BT5IUChJg0XqF5B8SFbPqd4X+EUW5/5GzOHVcVyTUNL5BVo0LbMLM9w3ZTjK9JpynZCV233SUI69wyJXMCN9YIMrqTLOFpM2SqR0KzyDYtXnDGvF+KdR9fThLPvDlDeU0toRfs8Kd5Vc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718841; c=relaxed/simple; bh=y+f42A7JvxwlCYs9lZRBZaYEuUvBOM/jlbSPz3pra4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CvMea++nv5XIcA3oks/qChuMSPlXI5Q/45MhZw8f4nNlhaeMaETCZwJWqFggVBSjKCP/RCquQmnWfzIh+pnYIidFleVy0uv6StUV5eWMkB6aHRZ/CS5zyvfMeFN5N2nZU2sUs2291Ml99e9pa/v/GNcAVH4bLmvMjEVJXgP2SBQ= 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=pjYihzyq; 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="pjYihzyq" 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 5AL1vkvZ019646; Fri, 21 Nov 2025 09:53:51 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=4P/PW B6DyanXCLPNsd1extPQtV24iAUr4mJbjPckT0M=; b=pjYihzyqZNZZ6TyK2JRPy 22YM20WWUl7QllpjRNyy385LHaw381GxZpg4vbmMG9kNiVMv4/KOpj3zcP21C+r2 GNiNym2jc24vh/8MvTl26acs/UcUKi7vd95k/nbfeN8spBWp+1rdHSwBGwRZrFjV zz1RsDXMtsjkHwRn5BGyb2RQCw6UqINz0dMPp5TTBTlVADo5yBblYXlrPDtw84Gb s0uMKakbGEp5hXH/jWM6wUMqnO0FbeYpyZt2hW6LrlMUD4Y6OSMs93cyQ/QlXAdc Ad+VSEi0g9UFmxTeLs0kgN2djYfhaii04EJtXag18v7dN3X8Dd3FEAKhmbeBCTeQ g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejd1jtqx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:51 +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 5AL7toiC004334; Fri, 21 Nov 2025 09:53:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4udu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:50 +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:53:50 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-5; Fri, 21 Nov 2025 09:53:50 +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 04/30] tool build: Remove annoying newline in build output Date: Fri, 21 Nov 2025 10:53:14 +0100 Message-ID: <20251121095340.464045-5-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: ccPqo7hQvMhLrslAcaB060N2ZKclhTbA X-Authority-Analysis: v=2.4 cv=Z/jh3XRA c=1 sm=1 tr=0 ts=692036af cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=gaUgYgG710qbGCIvUrAA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX9izlszkoraHQ ELNBsNp/PLUA6xJmGkXNbiWVbvqRe15SiLV5HM2Fwpf+GAFyOtxzedcp7N4NAN7v4MUt/q935C8 Bm6egnI1qj1hNzAcv2GhcaXPqNmC2lX3Tx/i5zxdldX0OHeTbwy/1pVOmjXsLBGzab+OuFAqrdL Dh21sIGvfNlevQ9tUhmbMYSMxwL0iyDyB5HMAO1FFED85AhCOyXLiznz/Y2NMwdPpkGF0IoLkWz jJIxvRWKwqzcJ/+g3r4i9dVMGnDXbhYX84VAWihL+EHJgyoBLh4AXogfJiz/PdQTPIfA8jtBmEz A9XBK/A4RhW/ocJU5uOZ2t1i1zXDFNifqBptLh979BPz2vqSth5hV1+uSkdYIDdz5GgZGOSdDR/ fBttBy3jsnvpUJ00G7KlpHX5nC+5Lw== X-Proofpoint-ORIG-GUID: ccPqo7hQvMhLrslAcaB060N2ZKclhTbA Content-Type: text/plain; charset="utf-8" Remove the newline which is printed during feature discovery when nothing else is printed. Signed-off-by: Alexandre Chartre --- tools/build/Makefile.feature | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 32bbe29fe5f6c..300a329bc581d 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -315,5 +315,7 @@ endef =20 ifeq ($(FEATURE_DISPLAY_DEFERRED),) $(call feature_display_entries) - $(info ) + ifeq ($(feature_display),1) + $(info ) + endif endif --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 D0C5A343200 for ; Fri, 21 Nov 2025 09:54: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=1763718849; cv=none; b=bvHXEC13wZcsNSJLzSaWXv1mWf6vyFvRKRP5FOZQ2uyLsnAh7XR0LL88PPHhggDEQOtP6ziNK5vO3/8F5EGOzRmTzLZ1aSYzVaJhcuj2DW3MW3EM2n/uZo5f/czWp+P7cZ+7nTr5zdJgvxFguSwdFKp/hSb/GORGzL5cPcGlglA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718849; c=relaxed/simple; bh=a/tZqH6yoCp0oI+4zMdzIYRX9dEOb7LapX8eE/EOS5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mGhouyX/fO4/SAc/5rVdjEjZ7F1tBUt+KpOOxKjOX3oONM7inQ/CUPEeA6el3gqq+1dEJicRj0tOodgdRmQFSa7DKUUuIjJHYiFYbP2ykSmRkx5HBrqYGHakrbzkzfHicI6JUj3SwoqoyevFun6fL00+aPbkuZFSwHDe9vQATsA= 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=AgPmCcTy; 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="AgPmCcTy" 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 5AL1uhhb024577; Fri, 21 Nov 2025 09:53:53 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=acGRP E+Gaanopu1vPCh+NsD0MvL71AXjorO3QXC/qQ0=; b=AgPmCcTyBDAXwqAL9VkiW 0a3iTYuFLp1ufA8kDkmObRF7KfJxgHGCHXdWeumxdQGSRnG4d4yOyJadX1l871iW 31LBsZWgLwcLZK2rWVRErmGwjAQ45oqtLKDbLPbUGpOUvM545LYHQ2QjF/LGT4It GDXFroGDAbUyp3mkIYaNwyOwx/fYc3Jjwgf90LvuY4jv86b/AQ7dNrxmKn5oRZs2 ujp6tRo6XerWKoBQlt+cPSvSmTU+KX+Kl3chu4YTWuA04CliuMPJ8glXU69xEISL dt6LPwEkJ7n7vZoN+UWFNTkI/XlMiCYgLwnmvr2H9rwn3v9rfZK5vNnuODmki37g g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbbk41s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:53 +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 5AL8T30Y004363; Fri, 21 Nov 2025 09:53:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:52 +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 5AL9rgUE021648; Fri, 21 Nov 2025 09:53:52 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-6; Fri, 21 Nov 2025 09:53:51 +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 05/30] objtool: Print symbol during disassembly Date: Fri, 21 Nov 2025 10:53:15 +0100 Message-ID: <20251121095340.464045-6-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=692036b1 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=kcBrYugwK0_vbWm54lEA:9 X-Proofpoint-ORIG-GUID: sf3PG8QQA2hnpGDQ6JN8jWG7jQY4Roov X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX81dDPrERHkaT 44Vx2UCyM3730ajBWqLXvUUrW3NcTOdyjD1s2ah1bzAP3/cWr11ILcn/2talzpW/Lz94egdiNfX ldrdsdyFN6T5C2My202jogSuh+0ymENt33si4uSIZrUvtnZn4TmIquNeSW23z5jSzR3shAzMRyC SsdUGOF8sHhZPZ47W/0MJu+/1G39USnctc3PyA0W3vvL09a7AT1rwEj4wtpfQNm9KC2hIKbL4F/ KKMyT9mz9wzA3KHa58DA4tt66C3rKa3npLToHwsfZpBzMO1wyOGsBKY9Zx27lO5yujBmvS1W6ML /DL2q0RDzUczxYCdWh3bPqJZWgSCRlZNBPiMG+wnAXMI5OFt5Rh6XYw4X3axNMVutbkntwpNMYI SFb8s/myHggz6rEQmBPMbdYxyl4xpw== X-Proofpoint-GUID: sf3PG8QQA2hnpGDQ6JN8jWG7jQY4Roov Content-Type: text/plain; charset="utf-8" Print symbols referenced during disassembly instead of just printing raw addresses. Also handle address relocation. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 9 -- tools/objtool/disas.c | 134 ++++++++++++++++++++++++++ tools/objtool/include/objtool/check.h | 9 ++ 3 files changed, 143 insertions(+), 9 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index de156e91ee8b7..8937667f075df 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -134,15 +134,6 @@ static struct instruction *prev_insn_same_sym(struct o= bjtool_file *file, for (insn =3D next_insn_same_sec(file, insn); insn; \ insn =3D next_insn_same_sec(file, insn)) =20 -static inline struct symbol *insn_call_dest(struct instruction *insn) -{ - if (insn->type =3D=3D INSN_JUMP_DYNAMIC || - insn->type =3D=3D INSN_CALL_DYNAMIC) - return NULL; - - return insn->_call_dest; -} - static inline struct reloc *insn_jump_table(struct instruction *insn) { if (insn->type =3D=3D INSN_JUMP_DYNAMIC || diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 11ac2ec04afc1..dee10ab86fa29 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -14,13 +14,144 @@ =20 struct disas_context { struct objtool_file *file; + struct instruction *insn; disassembler_ftype disassembler; struct disassemble_info info; }; =20 +static int sprint_name(char *str, const char *name, unsigned long offset) +{ + int len; + + if (offset) + len =3D sprintf(str, "%s+0x%lx", name, offset); + else + len =3D sprintf(str, "%s", name); + + return len; +} + #define DINFO_FPRINTF(dinfo, ...) \ ((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__)) =20 +static void disas_print_addr_sym(struct section *sec, struct symbol *sym, + bfd_vma addr, struct disassemble_info *dinfo) +{ + char symstr[1024]; + char *str; + + if (sym) { + sprint_name(symstr, sym->name, addr - sym->offset); + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr); + } else { + str =3D offstr(sec, addr); + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str); + free(str); + } +} + +static void disas_print_addr_noreloc(bfd_vma addr, + struct disassemble_info *dinfo) +{ + struct disas_context *dctx =3D dinfo->application_data; + struct instruction *insn =3D dctx->insn; + struct symbol *sym =3D NULL; + + if (insn->sym && addr >=3D insn->sym->offset && + addr < insn->sym->offset + insn->sym->len) { + sym =3D insn->sym; + } + + disas_print_addr_sym(insn->sec, sym, addr, dinfo); +} + +static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *= dinfo) +{ + struct disas_context *dctx =3D dinfo->application_data; + struct instruction *insn =3D dctx->insn; + unsigned long offset; + struct reloc *reloc; + char symstr[1024]; + char *str; + + reloc =3D find_reloc_by_dest_range(dctx->file->elf, insn->sec, + insn->offset, insn->len); + if (!reloc) { + /* + * There is no relocation for this instruction although + * the address to resolve points to the next instruction. + * So this is an effective reference to the next IP, for + * example: "lea 0x0(%rip),%rdi". The kernel can reference + * the next IP with _THIS_IP_ macro. + */ + DINFO_FPRINTF(dinfo, "0x%lx <_THIS_IP_>", addr); + return; + } + + offset =3D arch_insn_adjusted_addend(insn, reloc); + + /* + * If the relocation symbol is a section name (for example ".bss") + * then we try to further resolve the name. + */ + if (reloc->sym->type =3D=3D STT_SECTION) { + str =3D offstr(reloc->sym->sec, reloc->sym->offset + offset); + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str); + free(str); + } else { + sprint_name(symstr, reloc->sym->name, offset); + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr); + } +} + +/* + * Resolve an address into a "+" string. + */ +static void disas_print_address(bfd_vma addr, struct disassemble_info *din= fo) +{ + struct disas_context *dctx =3D dinfo->application_data; + struct instruction *insn =3D dctx->insn; + struct instruction *jump_dest; + struct symbol *sym; + bool is_reloc; + + /* + * If the instruction is a call/jump and it references a + * destination then this is likely the address we are looking + * up. So check it first. + */ + jump_dest =3D insn->jump_dest; + if (jump_dest && jump_dest->sym && jump_dest->offset =3D=3D addr) { + disas_print_addr_sym(jump_dest->sec, jump_dest->sym, + addr, dinfo); + return; + } + + /* + * If the address points to the next instruction then there is + * probably a relocation. It can be a false positive when the + * current instruction is referencing the address of the next + * instruction. This particular case will be handled in + * disas_print_addr_reloc(). + */ + is_reloc =3D (addr =3D=3D insn->offset + insn->len); + + /* + * The call destination offset can be the address we are looking + * up, or 0 if there is a relocation. + */ + sym =3D insn_call_dest(insn); + if (sym && (sym->offset =3D=3D addr || (sym->offset =3D=3D 0 && is_reloc)= )) { + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, sym->name); + return; + } + + if (!is_reloc) + disas_print_addr_noreloc(addr, dinfo); + else + disas_print_addr_reloc(addr, dinfo); +} + /* * Initialize disassemble info arch, mach (32 or 64-bit) and options. */ @@ -69,6 +200,7 @@ struct disas_context *disas_context_create(struct objtoo= l_file *file) fprintf_styled); =20 dinfo->read_memory_func =3D buffer_read_memory; + dinfo->print_address_func =3D disas_print_address; dinfo->application_data =3D dctx; =20 /* @@ -121,6 +253,8 @@ static size_t disas_insn(struct disas_context *dctx, disassembler_ftype disasm =3D dctx->disassembler; struct disassemble_info *dinfo =3D &dctx->info; =20 + dctx->insn =3D insn; + if (insn->type =3D=3D INSN_NOP) { DINFO_FPRINTF(dinfo, "nop%d", insn->len); return insn->len; diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 674f57466d125..ad9c73504b120 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -117,6 +117,15 @@ static inline bool is_jump(struct instruction *insn) return is_static_jump(insn) || is_dynamic_jump(insn); } =20 +static inline struct symbol *insn_call_dest(struct instruction *insn) +{ + if (insn->type =3D=3D INSN_JUMP_DYNAMIC || + insn->type =3D=3D INSN_CALL_DYNAMIC) + return NULL; + + return insn->_call_dest; +} + struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset); =20 --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 BC0633431FC for ; Fri, 21 Nov 2025 09:54: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=1763718849; cv=none; b=I0yMYY5HNv+w5YmGmxRhDbSI/i/Xk/b81WufDXyG/1/G02xh270PphXBbb7L4rcJpi03NgMyZDyFRo5fYBjK/2Vi9B7eFb4RnfqFr73FP4mHGaBZ82yrUbT/nhD0RFBUZznLUBXlK68oiWi4cIfMKjcCWQpLOBgtu1Dp255zJFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718849; c=relaxed/simple; bh=i3WA1QZmJqbW2yAAB6OrBZDMl1dOFJZ3Ewd690cDo4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mlz7ORHQdxmaE9qxUFKuosQxEF2+mS2QZdgTzMbntwYyAXLw6EMiZc8NA0pMjoanhm6iYsDyOPKdmzzWF+7tOMKc26vFU0jm+HzfpokMYD2KJxt5N4ihyoz1xC5J3m9OL3k257M22JyvLgJy0I03QrfRYqYJZynOKqan5BXYzEU= 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=K25xsMTk; 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="K25xsMTk" 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 5AL1uON8024366; Fri, 21 Nov 2025 09:53:55 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=DAOmw fvpy7JkJWn5tQTT+kXs1v6gly525QPLmSGGH+o=; b=K25xsMTkJzFSRD8GKoqXw s+fZwqmcfUebxyb25JSbaBf3SvXf6S7HHy2wjxzWfgKKD+UaOXBcbqX+gGPJ5bb7 QgnHWIw3+CU3FU42zYmf23WRCwTQdhETVn/obJEekWc+PFH/FxN0IsFX9pQc7NDx 2xGvfLEvNp9zU6Cvd5AUxup9gItC0QJJ2sQMA9RyDKWOag/MeXT43rMY9paWLdYG qfR9vpYQGBLr/xUFwX8D9QuSq9a6O9xqjM72wIJi4yP3+e+FnwAHlOBZkh+EkNBV uQnxd9LFIia33ilxKFvjGF3l+gGm394mRPL65VKOZ7ykvwzvL5ti52NCgcUY3QjY g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbbk41y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:55 +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 5AL70wCo004512; Fri, 21 Nov 2025 09:53:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:54 +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 5AL9rgUG021648; Fri, 21 Nov 2025 09:53:53 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-7; Fri, 21 Nov 2025 09:53:53 +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 06/30] objtool: Store instruction disassembly result Date: Fri, 21 Nov 2025 10:53:16 +0100 Message-ID: <20251121095340.464045-7-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=692036b3 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=jcmHYjYDc9FjrwFKAggA:9 X-Proofpoint-ORIG-GUID: h1Momk_VjGZgVBvc1jCl0cTcCxSlJFc_ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX+9k05ZZ1SWVz Tp7hOEI1fWMY+M8c6UZjh87RwlDxEa6qTBbkInaMYyvlQhbM/9cduhN5zT53zMAkTX03e22m8iT 7Iv9yXcYqpg1IXqmPGW1ujCAQ6pNK4kGtSNsmA5jBPltKVYq/gU8+mvT1wZDxdIUTob1Z4MaVTM 5aEtC2ZXBsXz2ifzZHHjV6/KSt/kOzwOXZ7j7U32jQSiAVAts9xgnzxyyi8hUu/kIpo8bdJZe5H Wb/Hr5ETYPIZnlc7nGPQjr9KVFNgil96zjNOFlcm/0F5VTHoD7sV9vipoMigPsyyLPQ0MFJA7fk EGYk29F3vfCPlaP40q9txp2TEW9I6RVkgvAzEDbfO5ei2TM5gcFIn+4jf8KhaukHyTZ92dBuFlK NOPHX9JIRCFshKNKz2YaYu+1JRviKg== X-Proofpoint-GUID: h1Momk_VjGZgVBvc1jCl0cTcCxSlJFc_ Content-Type: text/plain; charset="utf-8" When disassembling an instruction store the result instead of directly printing it. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 77 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index dee10ab86fa29..89daa121b40b0 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -12,9 +12,16 @@ #include #include =20 +/* + * Size of the buffer for storing the result of disassembling + * a single instruction. + */ +#define DISAS_RESULT_SIZE 1024 + struct disas_context { struct objtool_file *file; struct instruction *insn; + char result[DISAS_RESULT_SIZE]; disassembler_ftype disassembler; struct disassemble_info info; }; @@ -34,6 +41,59 @@ static int sprint_name(char *str, const char *name, unsi= gned long offset) #define DINFO_FPRINTF(dinfo, ...) \ ((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__)) =20 +static int disas_result_fprintf(struct disas_context *dctx, + const char *fmt, va_list ap) +{ + char *buf =3D dctx->result; + int avail, len; + + len =3D strlen(buf); + if (len >=3D DISAS_RESULT_SIZE - 1) { + WARN_FUNC(dctx->insn->sec, dctx->insn->offset, + "disassembly buffer is full"); + return -1; + } + avail =3D DISAS_RESULT_SIZE - len; + + len =3D vsnprintf(buf + len, avail, fmt, ap); + if (len < 0 || len >=3D avail) { + WARN_FUNC(dctx->insn->sec, dctx->insn->offset, + "disassembly buffer is truncated"); + return -1; + } + + return 0; +} + +static int disas_fprintf(void *stream, const char *fmt, ...) +{ + va_list arg; + int rv; + + va_start(arg, fmt); + rv =3D disas_result_fprintf(stream, fmt, arg); + va_end(arg); + + return rv; +} + +/* + * For init_disassemble_info_compat(). + */ +static int disas_fprintf_styled(void *stream, + enum disassembler_style style, + const char *fmt, ...) +{ + va_list arg; + int rv; + + va_start(arg, fmt); + rv =3D disas_result_fprintf(stream, fmt, arg); + va_end(arg); + + return rv; +} + static void disas_print_addr_sym(struct section *sec, struct symbol *sym, bfd_vma addr, struct disassemble_info *dinfo) { @@ -195,9 +255,8 @@ struct disas_context *disas_context_create(struct objto= ol_file *file) dctx->file =3D file; dinfo =3D &dctx->info; =20 - init_disassemble_info_compat(dinfo, stdout, - (fprintf_ftype)fprintf, - fprintf_styled); + init_disassemble_info_compat(dinfo, dctx, + disas_fprintf, disas_fprintf_styled); =20 dinfo->read_memory_func =3D buffer_read_memory; dinfo->print_address_func =3D disas_print_address; @@ -244,6 +303,11 @@ void disas_context_destroy(struct disas_context *dctx) free(dctx); } =20 +static char *disas_result(struct disas_context *dctx) +{ + return dctx->result; +} + /* * Disassemble a single instruction. Return the size of the instruction. */ @@ -254,6 +318,7 @@ static size_t disas_insn(struct disas_context *dctx, struct disassemble_info *dinfo =3D &dctx->info; =20 dctx->insn =3D insn; + dctx->result[0] =3D '\0'; =20 if (insn->type =3D=3D INSN_NOP) { DINFO_FPRINTF(dinfo, "nop%d", insn->len); @@ -282,10 +347,10 @@ static void disas_func(struct disas_context *dctx, st= ruct symbol *func) printf("%s:\n", func->name); sym_for_each_insn(dctx->file, func, insn) { addr =3D insn->offset; - printf(" %6lx: %s+0x%-6lx ", - addr, func->name, addr - func->offset); disas_insn(dctx, insn); - printf("\n"); + printf(" %6lx: %s+0x%-6lx %s\n", + addr, func->name, addr - func->offset, + disas_result(dctx)); } printf("\n"); } --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 D51E534321C for ; Fri, 21 Nov 2025 09:54:09 +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=1763718851; cv=none; b=UCNQwhmIxK3NwANYpwDmo7PzNg0/S0PhA5dHZ5RTdQ0ZkLAIlfFQe7tuu3l4yQd1dx1kWV4ERorSUfNp4kFIE5jbt7a1QIk5M+RVCUGYCevu65iXr757Q0Wh+/iK/sLeCIBlGz4nCsdqBwpAvcimDCek9ntFGNt841iMq3/61hM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718851; c=relaxed/simple; bh=YkVE8o/kT/Bg7Y9+jPbxOgbhf2/XriYuj31lOMc2CpQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qZEc5DdyAys6qex5zV3077Ass60cX8jdvn7Pf0HmC/M4Wp1fVIA0NqIv2jXa0p75P/BzPfdw6TPApMAa30SKLCjjB7MRoVt9PvMZ5v9GGJTobc2W2tBnLH7ubZhZ+YHvyYNVoLfU4Q5cH/tnzsx7tum1oRG6+J1nRr2PXC5TMWQ= 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=drQLTOae; 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="drQLTOae" 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 5AL3siSo003416; Fri, 21 Nov 2025 09:53:57 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=drQLTOae7dEQV1a/ejOCq UsJzle10K+r4FpYl8qltd8jFslLJiBxSPjqZkbITjea6RKmXVd7HStsVwcScthqc rYsmfGE8EwLyY/mtLOS/r5TUWcODmDj8GbvpctUzrPdGXTGMD/vVj5Knexnt2g4K mj4t3iu6dOPRNDByq8pqPWjGAoqLzjqCd9TQpEoyv8L9SJBh7gd/MYQw22DLoisy vJsnm4pFdQ41BfOE04ryghZTENeFviqII4inxn4EeZ69nWFbpn2V+5nj08ixMUP/ iEjuKYs2DIvZk2SEsPir6dOgaAxquveZLegYNMpqyv8JgX4YHOWFcq35SA6zgnj2 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 4aejbc2ncy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:57 +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 5AL83bqL004518; Fri, 21 Nov 2025 09:53:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uft-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:56 +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 5AL9rgUI021648; Fri, 21 Nov 2025 09:53:55 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-8; Fri, 21 Nov 2025 09:53:55 +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 07/30] objtool: Disassemble instruction on warning or backtrace Date: Fri, 21 Nov 2025 10:53:17 +0100 Message-ID: <20251121095340.464045-8-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: IqnZGhvkqE_CQeNCQTwpXNhfD-iVfd5F X-Authority-Analysis: v=2.4 cv=JZyxbEKV c=1 sm=1 tr=0 ts=692036b5 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=49cdYLv4DVxkACFpF8YA:9 X-Proofpoint-ORIG-GUID: IqnZGhvkqE_CQeNCQTwpXNhfD-iVfd5F X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX9FBigrtcreDI 1nhriSTajcpldLuMzPvDEcSMq+CRmP61NixW8x/LZb0fWxbZJyID9IdAwueMIUKKtKtU6+C4wU1 GmSsWPmpTyoAqYDRE65cAK25B7ZedJF14VDFZLuSrRp/4xZLtMqEwbkWEgPNNZpHoLxzO+mas9k 76T4c02QLeXj13kCvBjlu1oKaizeImn8Maog9bYOnooRZurzlP7hW6B7mFR2JIBPtg/mEN712ip syypSTRMmRg2fe5btjsJXZ1m38GdAte59iXxQagMF8BR5h/3By8S3vw9esxLxEqF/UaLwLaYlE9 x5OX5GU2xPLNWO6PWHebmWGfXf+lTu8I39Z2qzM6bKJHFwlvI7deTfzMd155dN9/InggBLQL8Z+ x5fw7tM/R361z1eNd5DjImFJwDf7Ww== 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 From nobody Tue Dec 2 01:28:38 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 D0377340DA1 for ; Fri, 21 Nov 2025 09:54:05 +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=1763718848; cv=none; b=R2Famb1k9WwRk10wnOm7aqmQHNWkN0u+KodjR9NtnZJlFIkGO4tGVhEBLNMZCjb/NcVGOE2ig042BR6Krq/4p71BCxF1A0AWYpQXtlXk+hujOUGAcyvsgQ4JrqNTEBFxpX3T74UNSqXvqvGk0RDd7Th26pOwKU4wxKIy2vGgFyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718848; c=relaxed/simple; bh=Bkw5njLypzARFwZCnNosvIVfb346eHdmoGekhIaJMOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OKDIJ03pYrdCeOI8+9LFwcrgWffAeUNX9GykDgSGcGvQHGvSjoxGdoJRPeAaIsgD7h1Ww+L/jXagd4gLA+rpT79HdHdB4H/qegDZ4RWby97zR9t9wDpWYLsHoMbFwNLL6sjoeZi+nXIVi/43DMUzXR92JwualSWiWV9ImdOpqLY= 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=T5E8JjsU; 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="T5E8JjsU" 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 5AL1uGjl001171; Fri, 21 Nov 2025 09:53:59 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=r6DHo XToyeMrK0vIiucnvHJDqi+ZsZ7Jo4qUgVmjP9c=; b=T5E8JjsUUFc+1FFRBOg1z A3+fVisEZuHzU3J8IPEWumsSl2BRERcMLVxT5LEjZl1esQb+5Vz816Kt0T087hAw CXItlqZRGyYB1+GUKji0RdmzPqfyIHVWxqGZP90dbM3WqBPhxaKHbr3oxFpDrHEr oYiLZ6GRbPG0jDVx+n3yaNBJe4uco8TPdaKMRXEq1mLK9he69o/jDqV+DRqN+tdw ZTWm1T3jE5w77AgwaaENjRWXp7FICs/8ITfO40eoSE4pmki/MBI8cMM1wnvUsVv8 0w//6xHcOWeWAi/I9BgpuHH3B+Nb2LGckyDqRUaNFbaDA46qGuC0/mR3MD+MOEvl 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 4aej90awxp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:59 +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 5AL7Z2Sg004320; Fri, 21 Nov 2025 09:53:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4ugf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:53:58 +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 5AL9rgUK021648; Fri, 21 Nov 2025 09:53:57 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-9; Fri, 21 Nov 2025 09:53:57 +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 08/30] objtool: Extract code to validate instruction from the validate branch loop Date: Fri, 21 Nov 2025 10:53:18 +0100 Message-ID: <20251121095340.464045-9-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=OMAqHCaB c=1 sm=1 tr=0 ts=692036b7 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=45N9rFkX92oTsxCXvtEA:9 X-Proofpoint-ORIG-GUID: IPDDoBjgi9sQZpqyfl35wyEjjobcK8np X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfXw5odEeaKK0ZG otTM12fTJQL5bpIIz81ZZjA1D9MGuBTZ9/ApWQLgT0UOq+vSD6gTzu1cEn9JNOc99Q6fwb6y3WT kkmhnYLR36Zpgd8W6T3n+hJ5ciy3zMdfrv0W8TDqt69ureXif9M6/bcYGVyQRI7a7fCPp0Jb91I lMYEKn5zxh4hhDuDQf73+n1gM2NbLKjj19vvyyFgLAHsscrwnrcr+nQgrusdJNQAhCg3tBoNJJj dqaKFSMYHNL/vKb2z/VfXWj0MwCLZ6MlrN87OB/32QgxbaBbh4HdAhxBUZPXlr5NA1n9fpWnLA5 949l9z19ntcUYmnKUsAUhHc/ThdnawbRGR0Saaio4ov15xatXZi8v4zmw3UBVdQCLnKrqVpCWpP cgJJJfqgAtXiv2E7PlD5i3Otk7iLCw== X-Proofpoint-GUID: IPDDoBjgi9sQZpqyfl35wyEjjobcK8np Content-Type: text/plain; charset="utf-8" The code to validate a branch loops through all instructions of the branch and validate each instruction. Move the code to validate an instruction to a separated function. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 386 ++++++++++++++++++++++-------------------- 1 file changed, 205 insertions(+), 181 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index dd61c3242def5..9c1888e21c1d8 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3706,253 +3706,277 @@ static void checksum_update_insn(struct objtool_f= ile *file, struct symbol *func, checksum_update(func, insn, &offset, sizeof(offset)); } =20 -/* - * Follow the branch starting at the given instruction, and recursively fo= llow - * any other branches (jumps). Meanwhile, track the frame pointer state at - * each instruction and validate all the rules described in - * tools/objtool/Documentation/objtool.txt. - */ static int validate_branch(struct objtool_file *file, struct symbol *func, - struct instruction *insn, struct insn_state state) + struct instruction *insn, struct insn_state state); + +static int validate_insn(struct objtool_file *file, struct symbol *func, + struct instruction *insn, struct insn_state *statep, + struct instruction *prev_insn, struct instruction *next_insn, + bool *dead_end) { struct alternative *alt; - struct instruction *next_insn, *prev_insn =3D NULL; u8 visited; int ret; =20 - if (func && func->ignore) - return 0; + /* + * Any returns before the end of this function are effectively dead + * ends, i.e. validate_branch() has reached the end of the branch. + */ + *dead_end =3D true; =20 - while (1) { - next_insn =3D next_insn_to_validate(file, insn); + visited =3D VISITED_BRANCH << statep->uaccess; + if (insn->visited & VISITED_BRANCH_MASK) { + if (!insn->hint && !insn_cfi_match(insn, &statep->cfi)) + return 1; =20 - if (opts.checksum && func && insn->sec) - checksum_update_insn(file, func, insn); + if (insn->visited & visited) + return 0; + } else { + nr_insns_visited++; + } =20 - if (func && insn_func(insn) && func !=3D insn_func(insn)->pfunc) { - /* Ignore KCFI type preambles, which always fall through */ - if (is_prefix_func(func)) - return 0; + if (statep->noinstr) + statep->instr +=3D insn->instr; =20 - if (file->ignore_unreachables) - return 0; + if (insn->hint) { + if (insn->restore) { + struct instruction *save_insn, *i; =20 - WARN("%s() falls through to next function %s()", - func->name, insn_func(insn)->name); - func->warned =3D 1; + i =3D insn; + save_insn =3D NULL; =20 - return 1; - } + sym_for_each_insn_continue_reverse(file, func, i) { + if (i->save) { + save_insn =3D i; + break; + } + } =20 - visited =3D VISITED_BRANCH << state.uaccess; - if (insn->visited & VISITED_BRANCH_MASK) { - if (!insn->hint && !insn_cfi_match(insn, &state.cfi)) + if (!save_insn) { + WARN_INSN(insn, "no corresponding CFI save for CFI restore"); return 1; + } =20 - if (insn->visited & visited) - return 0; - } else { - nr_insns_visited++; + if (!save_insn->visited) { + /* + * If the restore hint insn is at the + * beginning of a basic block and was + * branched to from elsewhere, and the + * save insn hasn't been visited yet, + * defer following this branch for now. + * It will be seen later via the + * straight-line path. + */ + if (!prev_insn) + return 0; + + WARN_INSN(insn, "objtool isn't smart enough to handle this CFI save/re= store combo"); + return 1; + } + + insn->cfi =3D save_insn->cfi; + nr_cfi_reused++; } =20 - if (state.noinstr) - state.instr +=3D insn->instr; + statep->cfi =3D *insn->cfi; + } else { + /* XXX track if we actually changed statep->cfi */ =20 - if (insn->hint) { - if (insn->restore) { - struct instruction *save_insn, *i; + if (prev_insn && !cficmp(prev_insn->cfi, &statep->cfi)) { + insn->cfi =3D prev_insn->cfi; + nr_cfi_reused++; + } else { + insn->cfi =3D cfi_hash_find_or_add(&statep->cfi); + } + } =20 - i =3D insn; - save_insn =3D NULL; + insn->visited |=3D visited; =20 - sym_for_each_insn_continue_reverse(file, func, i) { - if (i->save) { - save_insn =3D i; - break; - } - } + if (propagate_alt_cfi(file, insn)) + return 1; =20 - if (!save_insn) { - WARN_INSN(insn, "no corresponding CFI save for CFI restore"); - return 1; - } + if (insn->alts) { + for (alt =3D insn->alts; alt; alt =3D alt->next) { + ret =3D validate_branch(file, func, alt->insn, *statep); + if (ret) { + BT_INSN(insn, "(alt)"); + return ret; + } + } + } =20 - if (!save_insn->visited) { - /* - * If the restore hint insn is at the - * beginning of a basic block and was - * branched to from elsewhere, and the - * save insn hasn't been visited yet, - * defer following this branch for now. - * It will be seen later via the - * straight-line path. - */ - if (!prev_insn) - return 0; + if (skip_alt_group(insn)) + return 0; =20 - WARN_INSN(insn, "objtool isn't smart enough to handle this CFI save/r= estore combo"); - return 1; - } + if (handle_insn_ops(insn, next_insn, statep)) + return 1; =20 - insn->cfi =3D save_insn->cfi; - nr_cfi_reused++; - } + switch (insn->type) { =20 - state.cfi =3D *insn->cfi; - } else { - /* XXX track if we actually changed state.cfi */ + case INSN_RETURN: + return validate_return(func, insn, statep); =20 - if (prev_insn && !cficmp(prev_insn->cfi, &state.cfi)) { - insn->cfi =3D prev_insn->cfi; - nr_cfi_reused++; - } else { - insn->cfi =3D cfi_hash_find_or_add(&state.cfi); - } + case INSN_CALL: + case INSN_CALL_DYNAMIC: + ret =3D validate_call(file, insn, statep); + if (ret) + return ret; + + if (opts.stackval && func && !is_special_call(insn) && + !has_valid_stack_frame(statep)) { + WARN_INSN(insn, "call without frame pointer save/setup"); + return 1; } =20 - insn->visited |=3D visited; + break; =20 - if (propagate_alt_cfi(file, insn)) - return 1; + case INSN_JUMP_CONDITIONAL: + case INSN_JUMP_UNCONDITIONAL: + if (is_sibling_call(insn)) { + ret =3D validate_sibling_call(file, insn, statep); + if (ret) + return ret; =20 - if (insn->alts) { - for (alt =3D insn->alts; alt; alt =3D alt->next) { - ret =3D validate_branch(file, func, alt->insn, state); - if (ret) { - BT_INSN(insn, "(alt)"); - return ret; - } + } else if (insn->jump_dest) { + ret =3D validate_branch(file, func, + insn->jump_dest, *statep); + if (ret) { + BT_INSN(insn, "(branch)"); + return ret; } } =20 - if (skip_alt_group(insn)) + if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL) return 0; =20 - if (handle_insn_ops(insn, next_insn, &state)) - return 1; - - switch (insn->type) { - - case INSN_RETURN: - return validate_return(func, insn, &state); + break; =20 - case INSN_CALL: - case INSN_CALL_DYNAMIC: - ret =3D validate_call(file, insn, &state); + case INSN_JUMP_DYNAMIC: + case INSN_JUMP_DYNAMIC_CONDITIONAL: + if (is_sibling_call(insn)) { + ret =3D validate_sibling_call(file, insn, statep); if (ret) return ret; + } =20 - if (opts.stackval && func && !is_special_call(insn) && - !has_valid_stack_frame(&state)) { - WARN_INSN(insn, "call without frame pointer save/setup"); - return 1; - } + if (insn->type =3D=3D INSN_JUMP_DYNAMIC) + return 0; =20 - break; + break; =20 - case INSN_JUMP_CONDITIONAL: - case INSN_JUMP_UNCONDITIONAL: - if (is_sibling_call(insn)) { - ret =3D validate_sibling_call(file, insn, &state); - if (ret) - return ret; + case INSN_SYSCALL: + if (func && (!next_insn || !next_insn->hint)) { + WARN_INSN(insn, "unsupported instruction in callable function"); + return 1; + } =20 - } else if (insn->jump_dest) { - ret =3D validate_branch(file, func, - insn->jump_dest, state); - if (ret) { - BT_INSN(insn, "(branch)"); - return ret; - } - } + break; =20 - if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL) - return 0; + case INSN_SYSRET: + if (func && (!next_insn || !next_insn->hint)) { + WARN_INSN(insn, "unsupported instruction in callable function"); + return 1; + } + + return 0; =20 + case INSN_STAC: + if (!opts.uaccess) break; =20 - case INSN_JUMP_DYNAMIC: - case INSN_JUMP_DYNAMIC_CONDITIONAL: - if (is_sibling_call(insn)) { - ret =3D validate_sibling_call(file, insn, &state); - if (ret) - return ret; - } + if (statep->uaccess) { + WARN_INSN(insn, "recursive UACCESS enable"); + return 1; + } =20 - if (insn->type =3D=3D INSN_JUMP_DYNAMIC) - return 0; + statep->uaccess =3D true; + break; =20 + case INSN_CLAC: + if (!opts.uaccess) break; =20 - case INSN_SYSCALL: - if (func && (!next_insn || !next_insn->hint)) { - WARN_INSN(insn, "unsupported instruction in callable function"); - return 1; - } + if (!statep->uaccess && func) { + WARN_INSN(insn, "redundant UACCESS disable"); + return 1; + } =20 - break; + if (func_uaccess_safe(func) && !statep->uaccess_stack) { + WARN_INSN(insn, "UACCESS-safe disables UACCESS"); + return 1; + } =20 - case INSN_SYSRET: - if (func && (!next_insn || !next_insn->hint)) { - WARN_INSN(insn, "unsupported instruction in callable function"); - return 1; - } + statep->uaccess =3D false; + break; =20 - return 0; + case INSN_STD: + if (statep->df) { + WARN_INSN(insn, "recursive STD"); + return 1; + } =20 - case INSN_STAC: - if (!opts.uaccess) - break; + statep->df =3D true; + break; =20 - if (state.uaccess) { - WARN_INSN(insn, "recursive UACCESS enable"); - return 1; - } + case INSN_CLD: + if (!statep->df && func) { + WARN_INSN(insn, "redundant CLD"); + return 1; + } =20 - state.uaccess =3D true; - break; + statep->df =3D false; + break; =20 - case INSN_CLAC: - if (!opts.uaccess) - break; + default: + break; + } =20 - if (!state.uaccess && func) { - WARN_INSN(insn, "redundant UACCESS disable"); - return 1; - } + *dead_end =3D insn->dead_end; =20 - if (func_uaccess_safe(func) && !state.uaccess_stack) { - WARN_INSN(insn, "UACCESS-safe disables UACCESS"); - return 1; - } + return 0; +} =20 - state.uaccess =3D false; - break; +/* + * Follow the branch starting at the given instruction, and recursively fo= llow + * any other branches (jumps). Meanwhile, track the frame pointer state at + * each instruction and validate all the rules described in + * tools/objtool/Documentation/objtool.txt. + */ +static int validate_branch(struct objtool_file *file, struct symbol *func, + struct instruction *insn, struct insn_state state) +{ + struct instruction *next_insn, *prev_insn =3D NULL; + bool dead_end; + int ret; =20 - case INSN_STD: - if (state.df) { - WARN_INSN(insn, "recursive STD"); - return 1; - } + if (func && func->ignore) + return 0; =20 - state.df =3D true; - break; + while (1) { + next_insn =3D next_insn_to_validate(file, insn); =20 - case INSN_CLD: - if (!state.df && func) { - WARN_INSN(insn, "redundant CLD"); - return 1; - } + if (opts.checksum && func && insn->sec) + checksum_update_insn(file, func, insn); =20 - state.df =3D false; - break; + if (func && insn_func(insn) && func !=3D insn_func(insn)->pfunc) { + /* Ignore KCFI type preambles, which always fall through */ + if (is_prefix_func(func)) + return 0; =20 - default: - break; + if (file->ignore_unreachables) + return 0; + + WARN("%s() falls through to next function %s()", + func->name, insn_func(insn)->name); + func->warned =3D 1; + + return 1; } =20 - if (insn->dead_end) - return 0; + ret =3D validate_insn(file, func, insn, &state, prev_insn, next_insn, + &dead_end); + if (dead_end) + break; =20 if (!next_insn) { if (state.cfi.cfa.base =3D=3D CFI_UNDEFINED) @@ -3970,7 +3994,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, insn =3D next_insn; } =20 - return 0; + return ret; } =20 static int validate_unwind_hint(struct objtool_file *file, --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 D66EC343203 for ; Fri, 21 Nov 2025 09:54:06 +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=1763718850; cv=none; b=uRmFq4lNGyN7y5/uioOPzhxTmDsQ7FXW8+P7BnlQeOOS0Ttf+Fs+MbOXKuUXbspNHon9X9HAQ2d09eVRhxtnTxKsb45f+09U2hLmM7NIjJZFOokfYXb/ZPxFTKzwATD13k+XbhXiGCN8IIRX0n0INn/ir8lxSdZQMRt2yagMun8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718850; c=relaxed/simple; bh=EgXDDBXOnrKhdE9lJK2jPMp3X0L5wN7RjejezeP/Grg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A3ejW/Q8eAvgiMJCbRHG1r5cLx3Fu5LcoDdAZtPpMx/+2gCE/+Xh7+tZJF1lVjNrvO6v6pTRGvo/hLPpmp5gVVB6r11jVoZwMgdUCPCv/3Adk7FLsa/xbUmSGHHJH4o9UFw+yJZu/5ExUI9GNPLSIfTe0uc+ylBjwDEbl8Npm/Y= 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=pcLtvFp7; 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="pcLtvFp7" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL1wUIE007472; Fri, 21 Nov 2025 09:54:00 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=VGRwi c8vTmtFuqAPaehco0TodJY4hrxVG3MvM/5nUbg=; b=pcLtvFp7z24wcfccpGz57 2vvgYndqFRQ3ZklGOML6a6XSMAKGmMnbBsYMDHMWt2BNiZoZXnLN8lhsLHMewp+1 KorgW+rloKUQ81asksR+JK7GIjXXJdvxAsRrWwBzZlQfRCV+0LmYbwUqy3GIMbJ0 goISI5s5u2fPftdKBjXUnggTQBJRT2CcnR7d/0PSEz+R5pP9sFq5fEPGQJJYyMd1 0tBWURdKFxkWxo9uR7OSF5VX2H1Nj21u5v3r9WdnKzxiKng1Xy1CTH/Ul+vnmxXl tDYVWQzfbNROzvFfnrdq9AqncbIeTh0A6zmRljaNqL6LwvXspNKkTAPQWnayRgkF g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbq2w3k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:00 +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 5AL98xOi004483; Fri, 21 Nov 2025 09:54:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uhb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:00 +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 5AL9rgUM021648; Fri, 21 Nov 2025 09:53:59 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-10; Fri, 21 Nov 2025 09:53:59 +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 09/30] objtool: Record symbol name max length Date: Fri, 21 Nov 2025 10:53:19 +0100 Message-ID: <20251121095340.464045-10-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-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfXwrfP0k6Bzkly dh1lDcTmzYahX0y7/Nss1IUjQkb4/vAS4xrBh0ATCOS0P+C/amJs8c+obL/DeQ83gfnN2wUx/vj Tn36OxSMZmyXi2LVqp+bVP1FSDX2A3/ODVrFEHVEnKlTfAmE+TC4BuEoMAxir+zQZN//QAngZ7D Z0lLeT//5mwF9jLBZ8Ydk8mrSvKGEgiEsQXNfWqP+I+HZa9Ce66UrPONPPHGgjiwVO1o624165G 8yfq1T9IfshgZLIQw3hudNTuPDpbUmPyu87Wri+HcQ5kj7LRPH6RXsXIbtYpCOn10/B3ppnG1u2 dAh6WMAeB0dIRpyz5lsCTk6ymUYh7PGKRvESJluuoNQTUMii454HnkFER8hLmtCu330t5J7qTdl cLLrb1xa9cWQyZSSmkLuTgSkAB6xAg== X-Proofpoint-ORIG-GUID: jRVQvRG656daRC62Ynsh-9D4qv2kUFeX X-Proofpoint-GUID: jRVQvRG656daRC62Ynsh-9D4qv2kUFeX X-Authority-Analysis: v=2.4 cv=a+o9NESF c=1 sm=1 tr=0 ts=692036b8 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=xKpiAcmDGk3KfUQPlkUA:9 Content-Type: text/plain; charset="utf-8" Keep track of the maximum length of symbol names. This will help formatting the code flow between different functions. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 9c1888e21c1d8..42a33898b695d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -37,6 +37,8 @@ static struct cfi_state init_cfi; static struct cfi_state func_cfi; static struct cfi_state force_undefined_cfi; =20 +static size_t sym_name_max_len; + struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset) { @@ -2484,6 +2486,7 @@ static bool is_profiling_func(const char *name) static int classify_symbols(struct objtool_file *file) { struct symbol *func; + size_t len; =20 for_each_sym(file->elf, func) { if (is_notype_sym(func) && strstarts(func->name, ".L")) @@ -2510,6 +2513,10 @@ static int classify_symbols(struct objtool_file *fil= e) =20 if (is_profiling_func(func->name)) func->profiling_func =3D true; + + len =3D strlen(func->name); + if (len > sym_name_max_len) + sym_name_max_len =3D len; } =20 return 0; --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 84AAB34405D for ; Fri, 21 Nov 2025 09:54:12 +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=1763718854; cv=none; b=lDOOPgvteU7q/Y5Dzkdja9BWm46gMn//3Z1GBitFTkCupUz9t95DYjyxEXChzqYnVhd3/kn0oLslOtNDLH1O8c41UO+RDt01wse8bxsfyndjEDeIn+o4wUyxmNFvxv7PDACnfSncJMOhXfvz1CxXNvRQe3gj2NOFTB5eEJl0a4I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718854; c=relaxed/simple; bh=d+TXQOsWa6Oo+r+yx297uCy4zdrfdHh7zUXuCcAkEsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hYvCuyLgvJV9kJnJ34LZlk+ud9GCG8EKJt8KTKqDdpbVYisy4vO2V3C+zu/G+BpT8D62SapoQc20+aUrj8IPLsSKFvD95iCdtuFrePC1OcoylTHsVvtYcTRW2Na1Wg5GjV3yDij7gl54xlDylpsX0HFa1bFg1S+wH3vyqCqAABQ= 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=dUDce9Px; 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="dUDce9Px" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL1v0pN031466; Fri, 21 Nov 2025 09:54:03 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=KKFQ3 Alq1mZVpvNjBa9NBh2zD8OC98EocXiOkfmjuzQ=; b=dUDce9PxkaymW7HafyY5j aNMP4dE2jGgvyUaejaAEYI8m6fKLaWLTLVzqfPCHkWU0fRYtUdpeCP16W5Q8SVEL CQ8fuAFZQCffrAA6to7/wfxOudLbghtuBOWCuY7dMOYCVPaFYU7A5B282tswyuP6 jHQoHkxgvSwnIK9XiopBm9dkBOtXxg+139ifDzRWsqBuv8mgaWEXDBvVJrywYerw QPalEjeg798rGZLM+WwMxKMfB8Qio4OozQwhzzRbbk0EBtPWvn0zGvzxdLceB010 NYqsBU/weeojWhRFAoi3+mDs+mjQHsZD9PmJpetFBa+is+j0AY7akoA/VEa+I+yW 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 4aejbutn7c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:02 +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 5AL87Rpq004350; Fri, 21 Nov 2025 09:54:02 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4ujb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:01 +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 5AL9rgUO021648; Fri, 21 Nov 2025 09:54:01 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-11; Fri, 21 Nov 2025 09:54:01 +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 10/30] objtool: Add option to trace function validation Date: Fri, 21 Nov 2025 10:53:20 +0100 Message-ID: <20251121095340.464045-11-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-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX8FiQ+x3dbUSt zM/3SGXy6GZmKv57ZaAVs4MjwafuWPXZE5fzepD4wEI9oOfVMUOTwWk4zBN2lUcRrxZc5QyirSG AXAyS9wF65/hcktGlrzu9vOh/pUCjYLlVgOjlnQb1ioYpzRuEsfCsC0OidML6EEH2lgtjr9asPR EkpRAnEh94RYrdsIt54yLnAIFk/vA2wPMO0RZ+WQ+XIelwo+y0AqhrKiQ01EYySiadJQCVtmAJ7 oJSOAZI+MPVCFwo5EsruwqQ2Qt3GS7Ogr1jk3oH8OR+ZKAbUxFSOobapk6L1nNDoRTWE/+mUrHW KVuNBA+RLeYji3TyCfXKNTLhl0DPLNpN9t/fAjd3arpv61PGfNM2EVhNgF68iGh/hWop3RBU47h a/fHX/BVaURCechPmvAlPoY+zQ960g== X-Proofpoint-GUID: iKvR6ZaiLN3X7tafvYsV380-6Qhe1uM9 X-Proofpoint-ORIG-GUID: iKvR6ZaiLN3X7tafvYsV380-6Qhe1uM9 X-Authority-Analysis: v=2.4 cv=Rdydyltv c=1 sm=1 tr=0 ts=692036ba cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=V8xLiWHIaeRBKmcjQykA:9 Content-Type: text/plain; charset="utf-8" Add an option to trace and have information during the validation of specified functions. Functions are specified with the --trace option which can be a single function name (e.g. --trace foo to trace the function with the name "foo"), or a shell wildcard pattern (e.g. --trace foo* to trace all functions with a name starting with "foo"). Signed-off-by: Alexandre Chartre --- tools/objtool/Build | 1 + tools/objtool/builtin-check.c | 1 + tools/objtool/check.c | 104 +++++++++++++++++---- tools/objtool/disas.c | 115 ++++++++++++++++++++++++ tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/check.h | 6 +- tools/objtool/include/objtool/disas.h | 11 +++ tools/objtool/include/objtool/trace.h | 68 ++++++++++++++ tools/objtool/include/objtool/warn.h | 1 + tools/objtool/trace.c | 9 ++ 10 files changed, 299 insertions(+), 18 deletions(-) create mode 100644 tools/objtool/include/objtool/trace.h create mode 100644 tools/objtool/trace.c diff --git a/tools/objtool/Build b/tools/objtool/Build index 9d1e8f28ef953..9982e665d58da 100644 --- a/tools/objtool/Build +++ b/tools/objtool/Build @@ -9,6 +9,7 @@ objtool-y +=3D elf.o objtool-y +=3D objtool.o =20 objtool-$(BUILD_DISAS) +=3D disas.o +objtool-$(BUILD_DISAS) +=3D trace.o =20 objtool-$(BUILD_ORC) +=3D orc_gen.o orc_dump.o objtool-$(BUILD_KLP) +=3D builtin-klp.o klp-diff.o klp-post-link.o diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index aab7fa9c7e00a..3329d370006b4 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -103,6 +103,7 @@ static const struct option check_options[] =3D { OPT_STRING('o', "output", &opts.output, "file", "output file name"), OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section address= es in warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), + OPT_STRING(0, "trace", &opts.trace, "func", "trace function validation"= ), OPT_BOOLEAN('v', "verbose", &opts.verbose, "verbose warnings"), OPT_BOOLEAN(0, "werror", &opts.werror, "return error on warnings"), =20 diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 42a33898b695d..2352b9668b126 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4,6 +4,7 @@ */ =20 #define _GNU_SOURCE /* memmem() */ +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +39,9 @@ static struct cfi_state init_cfi; static struct cfi_state func_cfi; static struct cfi_state force_undefined_cfi; =20 -static size_t sym_name_max_len; +struct disas_context *objtool_disas_ctx; + +size_t sym_name_max_len; =20 struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset) @@ -3608,8 +3612,10 @@ static bool skip_alt_group(struct instruction *insn) return false; =20 /* ANNOTATE_IGNORE_ALTERNATIVE */ - if (insn->alt_group->ignore) + if (insn->alt_group->ignore) { + TRACE_INSN(insn, "alt group ignored"); return true; + } =20 /* * For NOP patched with CLAC/STAC, only follow the latter to avoid @@ -3715,6 +3721,8 @@ static void checksum_update_insn(struct objtool_file = *file, struct symbol *func, =20 static int validate_branch(struct objtool_file *file, struct symbol *func, struct instruction *insn, struct insn_state state); +static int do_validate_branch(struct objtool_file *file, struct symbol *fu= nc, + struct instruction *insn, struct insn_state state); =20 static int validate_insn(struct objtool_file *file, struct symbol *func, struct instruction *insn, struct insn_state *statep, @@ -3736,8 +3744,10 @@ static int validate_insn(struct objtool_file *file, = struct symbol *func, if (!insn->hint && !insn_cfi_match(insn, &statep->cfi)) return 1; =20 - if (insn->visited & visited) + if (insn->visited & visited) { + TRACE_INSN(insn, "already visited"); return 0; + } } else { nr_insns_visited++; } @@ -3774,8 +3784,10 @@ static int validate_insn(struct objtool_file *file, = struct symbol *func, * It will be seen later via the * straight-line path. */ - if (!prev_insn) + if (!prev_insn) { + TRACE_INSN(insn, "defer restore"); return 0; + } =20 WARN_INSN(insn, "objtool isn't smart enough to handle this CFI save/re= store combo"); return 1; @@ -3803,13 +3815,23 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, return 1; =20 if (insn->alts) { + int i, num_alts; + + num_alts =3D 0; + for (alt =3D insn->alts; alt; alt =3D alt->next) + num_alts++; + + i =3D 1; for (alt =3D insn->alts; alt; alt =3D alt->next) { + TRACE_INSN(insn, "alternative %d/%d", i, num_alts); ret =3D validate_branch(file, func, alt->insn, *statep); if (ret) { BT_INSN(insn, "(alt)"); return ret; } + i++; } + TRACE_INSN(insn, "alternative DEFAULT"); } =20 if (skip_alt_group(insn)) @@ -3821,10 +3843,16 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, switch (insn->type) { =20 case INSN_RETURN: + TRACE_INSN(insn, "return"); return validate_return(func, insn, statep); =20 case INSN_CALL: case INSN_CALL_DYNAMIC: + if (insn->type =3D=3D INSN_CALL) + TRACE_INSN(insn, "call"); + else + TRACE_INSN(insn, "indirect call"); + ret =3D validate_call(file, insn, statep); if (ret) return ret; @@ -3840,13 +3868,18 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, case INSN_JUMP_CONDITIONAL: case INSN_JUMP_UNCONDITIONAL: if (is_sibling_call(insn)) { + TRACE_INSN(insn, "sibling call"); ret =3D validate_sibling_call(file, insn, statep); if (ret) return ret; =20 } else if (insn->jump_dest) { - ret =3D validate_branch(file, func, - insn->jump_dest, *statep); + if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL) + TRACE_INSN(insn, "unconditional jump"); + else + TRACE_INSN(insn, "jump taken"); + + ret =3D validate_branch(file, func, insn->jump_dest, *statep); if (ret) { BT_INSN(insn, "(branch)"); return ret; @@ -3856,10 +3889,12 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL) return 0; =20 + TRACE_INSN(insn, "jump not taken"); break; =20 case INSN_JUMP_DYNAMIC: case INSN_JUMP_DYNAMIC_CONDITIONAL: + TRACE_INSN(insn, "indirect jump"); if (is_sibling_call(insn)) { ret =3D validate_sibling_call(file, insn, statep); if (ret) @@ -3872,6 +3907,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_SYSCALL: + TRACE_INSN(insn, "syscall"); if (func && (!next_insn || !next_insn->hint)) { WARN_INSN(insn, "unsupported instruction in callable function"); return 1; @@ -3880,6 +3916,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_SYSRET: + TRACE_INSN(insn, "sysret"); if (func && (!next_insn || !next_insn->hint)) { WARN_INSN(insn, "unsupported instruction in callable function"); return 1; @@ -3888,6 +3925,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, return 0; =20 case INSN_STAC: + TRACE_INSN(insn, "stac"); if (!opts.uaccess) break; =20 @@ -3900,6 +3938,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_CLAC: + TRACE_INSN(insn, "clac"); if (!opts.uaccess) break; =20 @@ -3917,6 +3956,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_STD: + TRACE_INSN(insn, "std"); if (statep->df) { WARN_INSN(insn, "recursive STD"); return 1; @@ -3926,6 +3966,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_CLD: + TRACE_INSN(insn, "cld"); if (!statep->df && func) { WARN_INSN(insn, "redundant CLD"); return 1; @@ -3938,8 +3979,10 @@ static int validate_insn(struct objtool_file *file, = struct symbol *func, break; } =20 - *dead_end =3D insn->dead_end; + if (insn->dead_end) + TRACE_INSN(insn, "dead end"); =20 + *dead_end =3D insn->dead_end; return 0; } =20 @@ -3949,8 +3992,8 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, * each instruction and validate all the rules described in * tools/objtool/Documentation/objtool.txt. */ -static int validate_branch(struct objtool_file *file, struct symbol *func, - struct instruction *insn, struct insn_state state) +static int do_validate_branch(struct objtool_file *file, struct symbol *fu= nc, + struct instruction *insn, struct insn_state state) { struct instruction *next_insn, *prev_insn =3D NULL; bool dead_end; @@ -3959,7 +4002,8 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (func && func->ignore) return 0; =20 - while (1) { + do { + insn->trace =3D 0; next_insn =3D next_insn_to_validate(file, insn); =20 if (opts.checksum && func && insn->sec) @@ -3982,10 +4026,15 @@ static int validate_branch(struct objtool_file *fil= e, struct symbol *func, =20 ret =3D validate_insn(file, func, insn, &state, prev_insn, next_insn, &dead_end); - if (dead_end) - break; =20 - if (!next_insn) { + if (!insn->trace) { + if (ret) + TRACE_INSN(insn, "warning (%d)", ret); + else + TRACE_INSN(insn, NULL); + } + + if (!dead_end && !next_insn) { if (state.cfi.cfa.base =3D=3D CFI_UNDEFINED) return 0; if (file->ignore_unreachables) @@ -3999,7 +4048,20 @@ static int validate_branch(struct objtool_file *file= , struct symbol *func, =20 prev_insn =3D insn; insn =3D next_insn; - } + + } while (!dead_end); + + return ret; +} + +static int validate_branch(struct objtool_file *file, struct symbol *func, + struct instruction *insn, struct insn_state state) +{ + int ret; + + trace_depth_inc(); + ret =3D do_validate_branch(file, func, insn, state); + trace_depth_dec(); =20 return ret; } @@ -4460,10 +4522,18 @@ static int validate_symbol(struct objtool_file *fil= e, struct section *sec, if (opts.checksum) checksum_init(func); =20 + if (opts.trace && !fnmatch(opts.trace, sym->name, 0)) { + trace_enable(); + TRACE("%s: validation begin\n", sym->name); + } + ret =3D validate_branch(file, func, insn, *state); if (ret) BT_INSN(insn, "<=3D=3D=3D (sym)"); =20 + TRACE("%s: validation %s\n\n", sym->name, ret ? "failed" : "end"); + trace_disable(); + if (opts.checksum) checksum_finish(func); =20 @@ -4875,8 +4945,6 @@ 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; @@ -4898,8 +4966,10 @@ int check(struct objtool_file *file) * disassembly context to disassemble instruction or function * on warning or backtrace. */ - if (opts.verbose || opts.backtrace) { + if (opts.verbose || opts.backtrace || opts.trace) { disas_ctx =3D disas_context_create(file); + if (!disas_ctx) + opts.trace =3D false; objtool_disas_ctx =3D disas_ctx; } =20 diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index a030b06c121d2..0ca6e6c8559fd 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -308,6 +308,121 @@ char *disas_result(struct disas_context *dctx) return dctx->result; } =20 +#define DISAS_INSN_OFFSET_SPACE 10 +#define DISAS_INSN_SPACE 60 + +/* + * Print a message in the instruction flow. If insn is not NULL then + * the instruction address is printed in addition of the message, + * otherwise only the message is printed. In all cases, the instruction + * itself is not printed. + */ +static int disas_vprint(FILE *stream, struct section *sec, unsigned long o= ffset, + int depth, const char *format, va_list ap) +{ + const char *addr_str; + int i, n; + int len; + + len =3D sym_name_max_len + DISAS_INSN_OFFSET_SPACE; + if (depth < 0) { + len +=3D depth; + depth =3D 0; + } + + n =3D 0; + + if (sec) { + addr_str =3D offstr(sec, offset); + n +=3D fprintf(stream, "%6lx: %-*s ", offset, len, addr_str); + free((char *)addr_str); + } else { + len +=3D DISAS_INSN_OFFSET_SPACE + 1; + n +=3D fprintf(stream, "%-*s", len, ""); + } + + /* print vertical bars to show the code flow */ + for (i =3D 0; i < depth; i++) + n +=3D fprintf(stream, "| "); + + if (format) + n +=3D vfprintf(stream, format, ap); + + return n; +} + +/* + * Print a message in the instruction flow. If insn is not NULL then + * the instruction address is printed in addition of the message, + * otherwise only the message is printed. In all cases, the instruction + * itself is not printed. + */ +void disas_print_info(FILE *stream, struct instruction *insn, int depth, + const char *format, ...) +{ + struct section *sec; + unsigned long off; + va_list args; + + if (insn) { + sec =3D insn->sec; + off =3D insn->offset; + } else { + sec =3D NULL; + off =3D 0; + } + + va_start(args, format); + disas_vprint(stream, sec, off, depth, format, args); + va_end(args); +} + +/* + * Print an instruction address (offset and function), the instruction its= elf + * and an optional message. + */ +void disas_print_insn(FILE *stream, struct disas_context *dctx, + struct instruction *insn, int depth, + const char *format, ...) +{ + char fake_nop_insn[32]; + const char *insn_str; + bool fake_nop; + va_list args; + int len; + + /* + * Alternative can insert a fake nop, sometimes with no + * associated section so nothing to disassemble. + */ + fake_nop =3D (!insn->sec && insn->type =3D=3D INSN_NOP); + if (fake_nop) { + snprintf(fake_nop_insn, 32, " (%d bytes)", insn->len); + insn_str =3D fake_nop_insn; + } else { + disas_insn(dctx, insn); + insn_str =3D disas_result(dctx); + } + + /* print the instruction */ + len =3D (depth + 1) * 2 < DISAS_INSN_SPACE ? DISAS_INSN_SPACE - (depth+1)= * 2 : 1; + disas_print_info(stream, insn, depth, "%-*s", len, insn_str); + + /* print message if any */ + if (!format) + return; + + if (strcmp(format, "\n") =3D=3D 0) { + fprintf(stream, "\n"); + return; + } + + fprintf(stream, " - "); + va_start(args, format); + vfprintf(stream, format, args); + va_end(args); +} + /* * Disassemble a single instruction. Return the size of the instruction. */ diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index bb0b25eb08ba4..991365c10f0e9 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -41,6 +41,7 @@ struct opts { const char *output; bool sec_address; bool stats; + const char *trace; bool verbose; bool werror; }; diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index f96aabd7d54dc..fde958683485f 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -66,7 +66,8 @@ struct instruction { visited : 4, no_reloc : 1, hole : 1, - fake : 1; + fake : 1, + trace : 1; /* 9 bit hole */ =20 struct alt_group *alt_group; @@ -143,4 +144,7 @@ struct instruction *next_insn_same_sec(struct objtool_f= ile *file, struct instruc =20 const char *objtool_disas_insn(struct instruction *insn); =20 +extern size_t sym_name_max_len; +extern struct disas_context *objtool_disas_ctx; + #endif /* _CHECK_H */ diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 1aee1fbe0bb97..5db75d06f2197 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -19,6 +19,11 @@ int disas_info_init(struct disassemble_info *dinfo, const char *options); size_t disas_insn(struct disas_context *dctx, struct instruction *insn); char *disas_result(struct disas_context *dctx); +void disas_print_info(FILE *stream, struct instruction *insn, int depth, + const char *format, ...); +void disas_print_insn(FILE *stream, struct disas_context *dctx, + struct instruction *insn, int depth, + const char *format, ...); =20 #else /* DISAS */ =20 @@ -51,6 +56,12 @@ static inline char *disas_result(struct disas_context *d= ctx) return NULL; } =20 +static inline void disas_print_info(FILE *stream, struct instruction *insn, + int depth, const char *format, ...) {} +static inline void disas_print_insn(FILE *stream, struct disas_context *dc= tx, + struct instruction *insn, int depth, + const char *format, ...) {} + #endif /* DISAS */ =20 #endif /* _DISAS_H */ diff --git a/tools/objtool/include/objtool/trace.h b/tools/objtool/include/= objtool/trace.h new file mode 100644 index 0000000000000..3f3c830ed114e --- /dev/null +++ b/tools/objtool/include/objtool/trace.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2025, Oracle and/or its affiliates. + */ + +#ifndef _TRACE_H +#define _TRACE_H + +#include +#include + +#ifdef DISAS + +extern bool trace; +extern int trace_depth; + +#define TRACE(fmt, ...) \ +({ if (trace) \ + fprintf(stderr, fmt, ##__VA_ARGS__); \ +}) + +#define TRACE_INSN(insn, fmt, ...) \ +({ \ + if (trace) { \ + disas_print_insn(stderr, objtool_disas_ctx, \ + insn, trace_depth - 1, \ + fmt, ##__VA_ARGS__); \ + fprintf(stderr, "\n"); \ + insn->trace =3D 1; \ + } \ +}) + +static inline void trace_enable(void) +{ + trace =3D true; + trace_depth =3D 0; +} + +static inline void trace_disable(void) +{ + trace =3D false; +} + +static inline void trace_depth_inc(void) +{ + if (trace) + trace_depth++; +} + +static inline void trace_depth_dec(void) +{ + if (trace) + trace_depth--; +} + +#else /* DISAS */ + +#define TRACE(fmt, ...) ({}) +#define TRACE_INSN(insn, fmt, ...) ({}) + +static inline void trace_enable(void) {} +static inline void trace_disable(void) {} +static inline void trace_depth_inc(void) {} +static inline void trace_depth_dec(void) {} + +#endif + +#endif /* _TRACE_H */ diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index f32abc7b1be14..25ff7942b4d54 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -97,6 +97,7 @@ static inline char *offstr(struct section *sec, unsigned = long offset) _len =3D (_len < 50) ? 50 - _len : 0; \ WARN(" %s: " format " %*s%s", _str, ##__VA_ARGS__, _len, "", _istr); \ free(_str); \ + __insn->trace =3D 1; \ } \ }) =20 diff --git a/tools/objtool/trace.c b/tools/objtool/trace.c new file mode 100644 index 0000000000000..134cc33ffe970 --- /dev/null +++ b/tools/objtool/trace.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2025, Oracle and/or its affiliates. + */ + +#include + +bool trace; +int trace_depth; --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 7E540344031 for ; Fri, 21 Nov 2025 09:54:11 +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=1763718853; cv=none; b=OT1X4UCI7fCQ0McgdA1ayNTw1zLf1oPvDNweQT9ja1TuAHEEpbb9cI5t+Og0sT44ywDM4bytr8d0hVqFfQ33B5WNpeJtgL4gvUr0qhXXsgVeSmB6wCaAXrEc+sQJq7wZbgBpah792sZ98t+VxO5bS2Pdb9eK/6LPGzXB1xCC4dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718853; c=relaxed/simple; bh=vh0GRZVlVEeA7W1dK7AFJ3L+PZ4+byzRcYFkNuJoBZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aJr3eVn/SKJet9pBV9JseRgR5llzceyC0vkqEsdqtE4PEnho3IWFQTgfO9xvlkCTKffTwh+Pkn1IUanCRxOSXsMh0Py/qm7mE3fC/id6tcsZhhP1GRiX8WfabwB1wkcfiOk/v9lchPL77Hu4fwXPPAxvHYTq1uwkx6a+K3gRtUE= 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=cU+LsiOr; 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="cU+LsiOr" 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 5AL1uj0x024789; Fri, 21 Nov 2025 09:54: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=52J1S eZm5vwekljiUGKBD5RCv9kbaKZnjN33R/4C9j0=; b=cU+LsiOrrtqWTEiduQTZy dk/DqI1A9VT8KQmAkhUf3WwmAzGMIha1wPIHLy/br50nneoCbvksZAeK+zFjpgJf mHMOvaR1pOEWWau4dk7dkzqCY6pMD8dzJYtp+B9pbY1b1Dptf3T+iwRi7OuAEE9M 44HXzjVc0yVqaqbHLMmWSe50lD5IxP7xYRKcAH10ClvM1vp4Z18YwKcik7j4tKT8 y0clQpPkN7ktTB2+YW8IxEZZpWaEpWb2GoC+nIdFvyZ8RXcIH5NTYQU6WAyRPKEX j54rftmqto+GV7Mc2MyGR2OxH6NeXoN6eXktkvj7pKUzQ0NYBKaBWqu/0NfvtZ1b 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 4aejbbk431-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:04 +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 5AL8s0K0004268; Fri, 21 Nov 2025 09:54:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4ukk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:03 +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 5AL9rgUQ021648; Fri, 21 Nov 2025 09:54:03 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-12; Fri, 21 Nov 2025 09:54: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 v6 11/30] objtool: Trace instruction state changes during function validation Date: Fri, 21 Nov 2025 10:53:21 +0100 Message-ID: <20251121095340.464045-12-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=692036bc cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=n0rf_ozDEmcaLxr6z3oA:9 X-Proofpoint-ORIG-GUID: IygU54V5A7CVZwIFvZcwz2l0ogvJYhHn X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfXxTejclaRbRx+ b3jzhLq2lrvaiyvdfzho/NGVsXB9b4LNBHRKVn1n9pY648kstz3g8hqtrb/cibH26FTuUuO4hmM DxKoudYUqgWsTskAW97cpjVROmhehlmM/nBm4LCP/egYRaGWU4ZQw9M/2v4JwKkMcet4KoIizNZ StD4LTDXfZC6tbLMdvL61TaET+OTqmtUQAWzvTQr8juezqiOwpLcsdbnCV6OiApPcD65IvT9oM9 h2cFADus9yzuuNiPdkOEiko0PpaXKaHI8OsMtiZNlrl+gkqQ/LIg4Ip2Q//KtuRea4jvkTS6nTQ k6kUOROVuSXckhqRZO8gbT7x+HzRlaGu7dI0h8Wp2OakZln70DEHi9JUoyp6UAbwiYr/SScbF9d hCOt9wTZxEyEUZnxUE0xZs/preF2BQ== X-Proofpoint-GUID: IygU54V5A7CVZwIFvZcwz2l0ogvJYhHn Content-Type: text/plain; charset="utf-8" During function validation, objtool maintains a per-instruction state, in particular to track call frame information. When tracing validation, print any instruction state changes. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 8 +- tools/objtool/include/objtool/trace.h | 10 ++ tools/objtool/trace.c | 132 ++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 2352b9668b126..e12dba144731f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3729,6 +3729,8 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, struct instruction *prev_insn, struct instruction *next_insn, bool *dead_end) { + /* prev_state is not used if there is no disassembly support */ + struct insn_state prev_state __maybe_unused; struct alternative *alt; u8 visited; int ret; @@ -3837,7 +3839,11 @@ static int validate_insn(struct objtool_file *file, = struct symbol *func, if (skip_alt_group(insn)) return 0; =20 - if (handle_insn_ops(insn, next_insn, statep)) + prev_state =3D *statep; + ret =3D handle_insn_ops(insn, next_insn, statep); + TRACE_INSN_STATE(insn, &prev_state, statep); + + if (ret) return 1; =20 switch (insn->type) { diff --git a/tools/objtool/include/objtool/trace.h b/tools/objtool/include/= objtool/trace.h index 3f3c830ed114e..33fe9c6acb4fd 100644 --- a/tools/objtool/include/objtool/trace.h +++ b/tools/objtool/include/objtool/trace.h @@ -30,6 +30,12 @@ extern int trace_depth; } \ }) =20 +#define TRACE_INSN_STATE(insn, sprev, snext) \ +({ \ + if (trace) \ + trace_insn_state(insn, sprev, snext); \ +}) + static inline void trace_enable(void) { trace =3D true; @@ -53,10 +59,14 @@ static inline void trace_depth_dec(void) trace_depth--; } =20 +void trace_insn_state(struct instruction *insn, struct insn_state *sprev, + struct insn_state *snext); + #else /* DISAS */ =20 #define TRACE(fmt, ...) ({}) #define TRACE_INSN(insn, fmt, ...) ({}) +#define TRACE_INSN_STATE(insn, sprev, snext) ({}) =20 static inline void trace_enable(void) {} static inline void trace_disable(void) {} diff --git a/tools/objtool/trace.c b/tools/objtool/trace.c index 134cc33ffe970..12bbad09d9c02 100644 --- a/tools/objtool/trace.c +++ b/tools/objtool/trace.c @@ -7,3 +7,135 @@ =20 bool trace; int trace_depth; + +/* + * Macros to trace CFI state attributes changes. + */ + +#define TRACE_CFI_ATTR(attr, prev, next, fmt, ...) \ +({ \ + if ((prev)->attr !=3D (next)->attr) \ + TRACE("%s=3D" fmt " ", #attr, __VA_ARGS__); \ +}) + +#define TRACE_CFI_ATTR_BOOL(attr, prev, next) \ + TRACE_CFI_ATTR(attr, prev, next, \ + "%s", (next)->attr ? "true" : "false") + +#define TRACE_CFI_ATTR_NUM(attr, prev, next, fmt) \ + TRACE_CFI_ATTR(attr, prev, next, fmt, (next)->attr) + +#define CFI_REG_NAME_MAXLEN 16 + +/* + * Return the name of a register. Note that the same static buffer + * is returned if the name is dynamically generated. + */ +static const char *cfi_reg_name(unsigned int reg) +{ + static char rname_buffer[CFI_REG_NAME_MAXLEN]; + + switch (reg) { + case CFI_UNDEFINED: + return ""; + case CFI_CFA: + return "cfa"; + case CFI_SP_INDIRECT: + return "(sp)"; + case CFI_BP_INDIRECT: + return "(bp)"; + } + + if (snprintf(rname_buffer, CFI_REG_NAME_MAXLEN, "r%d", reg) =3D=3D -1) + return ""; + + return (const char *)rname_buffer; +} + +/* + * Functions and macros to trace CFI registers changes. + */ + +static void trace_cfi_reg(const char *prefix, int reg, const char *fmt, + int base_prev, int offset_prev, + int base_next, int offset_next) +{ + char *rname; + + if (base_prev =3D=3D base_next && offset_prev =3D=3D offset_next) + return; + + if (prefix) + TRACE("%s:", prefix); + + if (base_next =3D=3D CFI_UNDEFINED) { + TRACE("%1$s=3D ", cfi_reg_name(reg)); + } else { + rname =3D strdup(cfi_reg_name(reg)); + TRACE(fmt, rname, cfi_reg_name(base_next), offset_next); + free(rname); + } +} + +static void trace_cfi_reg_val(const char *prefix, int reg, + int base_prev, int offset_prev, + int base_next, int offset_next) +{ + trace_cfi_reg(prefix, reg, "%1$s=3D%2$s%3$+d ", + base_prev, offset_prev, base_next, offset_next); +} + +static void trace_cfi_reg_ref(const char *prefix, int reg, + int base_prev, int offset_prev, + int base_next, int offset_next) +{ + trace_cfi_reg(prefix, reg, "%1$s=3D(%2$s%3$+d) ", + base_prev, offset_prev, base_next, offset_next); +} + +#define TRACE_CFI_REG_VAL(reg, prev, next) \ + trace_cfi_reg_val(NULL, reg, prev.base, prev.offset, \ + next.base, next.offset) + +#define TRACE_CFI_REG_REF(reg, prev, next) \ + trace_cfi_reg_ref(NULL, reg, prev.base, prev.offset, \ + next.base, next.offset) + +void trace_insn_state(struct instruction *insn, struct insn_state *sprev, + struct insn_state *snext) +{ + struct cfi_state *cprev, *cnext; + int i; + + if (!memcmp(sprev, snext, sizeof(struct insn_state))) + return; + + cprev =3D &sprev->cfi; + cnext =3D &snext->cfi; + + disas_print_insn(stderr, objtool_disas_ctx, insn, + trace_depth - 1, "state: "); + + /* print registers changes */ + TRACE_CFI_REG_VAL(CFI_CFA, cprev->cfa, cnext->cfa); + for (i =3D 0; i < CFI_NUM_REGS; i++) { + TRACE_CFI_REG_VAL(i, cprev->vals[i], cnext->vals[i]); + TRACE_CFI_REG_REF(i, cprev->regs[i], cnext->regs[i]); + } + + /* print attributes changes */ + TRACE_CFI_ATTR_NUM(stack_size, cprev, cnext, "%d"); + TRACE_CFI_ATTR_BOOL(drap, cprev, cnext); + if (cnext->drap) { + trace_cfi_reg_val("drap", cnext->drap_reg, + cprev->drap_reg, cprev->drap_offset, + cnext->drap_reg, cnext->drap_offset); + } + TRACE_CFI_ATTR_BOOL(bp_scratch, cprev, cnext); + TRACE_CFI_ATTR_NUM(instr, sprev, snext, "%d"); + TRACE_CFI_ATTR_NUM(uaccess_stack, sprev, snext, "%u"); + + TRACE("\n"); + + insn->trace =3D 1; +} --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 778463446CD for ; Fri, 21 Nov 2025 09:54:13 +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=1763718855; cv=none; b=BbEMuGj9gCGe0WfEWHay0gjkaHH5/v7E11Qk1QUgjl/BZILs4xsl1D5T/A1/5QttLsnVSi/X6t2JqKT4S1pkPX6d4KlexNNFvK+o4FDUa73AsMrNpiuzWLFO7MeRdHL5NmiYs/64ijYUbcJDEfcZRC3CTQf+tQotW2oAIO/mMUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718855; c=relaxed/simple; bh=NYnz5hOFes3oL2r2Y34xvzWnJji731N9eScyIbXsHzs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fcmL+zAaCoHHxpCPqgTJA7Tvl2euSDDbxIMC1zu0J2Eeu2fNPYGNrXB/VzX6qgZ/V7No7lF+lXE9qBwfqXZcBRoal0Cy8rOK+9ZGMTHMFXszFnnlz0e0HBbvJQDFk//7L2v9Koq5lV2ovoHKjujTHx3dSc2xLFhVqAtTfyxgD+s= 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=F8Oy19aA; 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="F8Oy19aA" 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 5AL1vHki021930; Fri, 21 Nov 2025 09:54:07 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=V2oAb 1syEJF+JDb59IZTa1SXUgBxlo3s+ewemjvM414=; b=F8Oy19aAlNb4Y+83Fm6gH e7+HA61PCCNAwvqF4hELV9RYSM8LCpFP8Ct2OkQyTZ8FhTpzqSdv1jB3lO7esTpZ jLTIk+xnokkSDO/tn8JPrkrjz1HWny6HttrgxRUjwf/NzqFGa6+ikgLUeR8P/OE+ Xzlb+RI6txr6BehaiyubMMHjAJwkDydg4i5RbqinDJ60OAwh5bs2kZv/K1p7gvsh U3g4dNPgul6Hcci10+Pvorj8OkOoUluZFb0z0QVZxhIlfWuyem2dKU4g3i5gI5nF ADbJC1QLji+tlOSdA0EfTF2mD6RIrO6Gg5rFoNEOwRw1WipMRpeppOrnX1Ldac+W Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aj5dtsjgt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:06 +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 5AL8s0K3004268; Fri, 21 Nov 2025 09:54:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4umu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:05 +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 5AL9rgUS021648; Fri, 21 Nov 2025 09:54:05 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-13; Fri, 21 Nov 2025 09:54:04 +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 12/30] objtool: Improve register reporting during function validation Date: Fri, 21 Nov 2025 10:53:22 +0100 Message-ID: <20251121095340.464045-13-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-Spam-Details-Enc: AW1haW4tMjUxMTIwMDA5OSBTYWx0ZWRfX8X6mFyBre5/g KYskTBg8w3t/idI2otC1QcToBp5qmAXO7Y/wZWDN7FXPoC6Nr5MVv0Gzy/h148bLyty+ENIpNcj rxEyUlY+vpZiLUWobnjMvhtK/Vr5owwX6le1M2lhfm/NXnvxXaN4ErAKpyeCjgDn9n5x2GmSY7Q duK7RsN1FT9qeUdd69Ui8rfR0bJcGmHYMQogdt9HJ4+IhaUnnHS+6e7LOfWsci2+laEg7e+gfgU 5eYlzphrFG/aJRgh7hCizj4MlJyclmVXVfKAqfc9+mnq9izNU6jEJR7ivcSBonFDnfqLNrvupiU rA60AJl/yXe3B2D9qTzZqJmR7icHX/G4nL0JI/eK6DXgnJ1G+ciDrPP97lI0glpk4c8poyz8Iw3 v8puUY4AixrljDQh/ERW4yNOVHT0wg== X-Authority-Analysis: v=2.4 cv=Dckaa/tW c=1 sm=1 tr=0 ts=692036be cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=SYeOCZSjma0EYi-zULIA:9 X-Proofpoint-GUID: ceiwmiAO2GsAPyOlFx6WYRG0kVFEDAr2 X-Proofpoint-ORIG-GUID: ceiwmiAO2GsAPyOlFx6WYRG0kVFEDAr2 Content-Type: text/plain; charset="utf-8" When tracing function validation, instruction state changes can report changes involving registers. These registers are reported with the name "r" (e.g. "r3"). Print the CPU specific register name instead of a generic name (e.g. print "rbx" instead of "r3" on x86). Signed-off-by: Alexandre Chartre --- tools/objtool/arch/loongarch/decode.c | 11 +++++++++++ tools/objtool/arch/powerpc/decode.c | 12 ++++++++++++ tools/objtool/arch/x86/decode.c | 8 ++++++++ tools/objtool/include/objtool/arch.h | 2 ++ tools/objtool/trace.c | 7 +++++++ 5 files changed, 40 insertions(+) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 1de86ebb637d5..6cd288150f495 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -8,6 +8,17 @@ #include #include =20 +const char *arch_reg_name[CFI_NUM_REGS] =3D { + "zero", "ra", "tp", "sp", + "a0", "a1", "a2", "a3", + "a4", "a5", "a6", "a7", + "t0", "t1", "t2", "t3", + "t4", "t5", "t6", "t7", + "t8", "u0", "fp", "s0", + "s1", "s2", "s3", "s4", + "s5", "s6", "s7", "s8" +}; + int arch_ftrace_match(const char *name) { return !strcmp(name, "_mcount"); diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index 4f68b402e7855..e534ac1123b33 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -9,6 +9,18 @@ #include #include =20 +const char *arch_reg_name[CFI_NUM_REGS] =3D { + "r0", "sp", "r2", "r3", + "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", + "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", + "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", + "r28", "r29", "r30", "r31", + "ra" +}; + int arch_ftrace_match(const char *name) { return !strcmp(name, "_mcount"); diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 83e9c604ce105..f4af825082284 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -23,6 +23,14 @@ #include #include =20 +const char *arch_reg_name[CFI_NUM_REGS] =3D { + "rax", "rcx", "rdx", "rbx", + "rsp", "rbp", "rsi", "rdi", + "r8", "r9", "r10", "r11", + "r12", "r13", "r14", "r15", + "ra" +}; + int arch_ftrace_match(const char *name) { return !strcmp(name, "__fentry__"); diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index 18c0e69ee6170..8866158975fcb 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -103,6 +103,8 @@ bool arch_absolute_reloc(struct elf *elf, struct reloc = *reloc); unsigned int arch_reloc_size(struct reloc *reloc); unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc= *table); =20 +extern const char *arch_reg_name[CFI_NUM_REGS]; + #ifdef DISAS =20 #include diff --git a/tools/objtool/trace.c b/tools/objtool/trace.c index 12bbad09d9c02..d70d47081e82d 100644 --- a/tools/objtool/trace.c +++ b/tools/objtool/trace.c @@ -34,6 +34,7 @@ int trace_depth; static const char *cfi_reg_name(unsigned int reg) { static char rname_buffer[CFI_REG_NAME_MAXLEN]; + const char *rname; =20 switch (reg) { case CFI_UNDEFINED: @@ -46,6 +47,12 @@ static const char *cfi_reg_name(unsigned int reg) return "(bp)"; } =20 + if (reg < CFI_NUM_REGS) { + rname =3D arch_reg_name[reg]; + if (rname) + return rname; + } + if (snprintf(rname_buffer, CFI_REG_NAME_MAXLEN, "r%d", reg) =3D=3D -1) return ""; =20 --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 2001F341AC7 for ; Fri, 21 Nov 2025 09:54:15 +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=1763718856; cv=none; b=hOcaKeh6Ie9AP9zyYx2l+u/oWZ99VH9M8/M3UkfF5QbB7gbhp8zj17EgDdghXW+ciB0woV5z9RF05FqhMiT1+mdgksy9t+zaH2SvifzTuR9uzsOPtBSMQc1SLKzzUHvcJxb5tcZkc8B9ctYRe4tMaH72j5E1CcKmxvlB6Pzm1vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718856; c=relaxed/simple; bh=C5sbEHKn6jcm4a+ljXx4lv7bk1N4cK2tB9CmkF4/AxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EChTvRFJomVUsLNCEBeW92htx2lB8NF2XWLZSjKrdY66lmMNx3eK8HL1NO1xgsGns6RVGxCZDXYtOmJ7M5PQ5dvqcRa0SqFj3QMDRrUNygdc0uiK0Ljy9VpwPCIxMnYe/FsSHXaagj1RrvO3R9+ow4Ba7NapCe3m6osKUDbdMpA= 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=gaMPQk+S; 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="gaMPQk+S" 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 5AL1uOCj030167; Fri, 21 Nov 2025 09:54:08 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=5BxR5 ActR3/A0/oKEIN3mwVnhgUTFl3OMMf2gKjR7Bs=; b=gaMPQk+SH3pddhFp3zoF7 vz8ReY+0R3b9VYmXfDaiWqi5Ds6Gtg2J3/ixeKHpfwGwBuNUhxcMbyiB2EKUkC1+ 8Z+II4C1yAFEDkNa3WtKVju/d/mnqL6S16pwPOXXKxWZ53zlkVl/qMJtEkHMSVfR 5iHfWZ4rGXadTiaa3vtsa1sApxEX7syf5Rk4Ic0SMGGDzw7O/m3Tn6ZLXWtIpNIo SJMCymvl4jTiDTC3XC7hsUDB2pd98R0/WxKJG4lRCfvBW0WsibgoyWvshPhsmotv HapKvX5kugwabhH5UsFFDZMf8aUV8sSFCtb/KxjYfSVIS/qaX4PCn4kmargrnLYN 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 4aejbc2nee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:08 +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 5AL98xOn004483; Fri, 21 Nov 2025 09:54:07 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4up8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:07 +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 5AL9rgUU021648; Fri, 21 Nov 2025 09:54:07 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-14; Fri, 21 Nov 2025 09:54:07 +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 13/30] objtool: Identify the different types of alternatives Date: Fri, 21 Nov 2025 10:53:23 +0100 Message-ID: <20251121095340.464045-14-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: KMp9_1-Nl64ikUPRN-ih_GEwbLkOhP7W X-Authority-Analysis: v=2.4 cv=JZyxbEKV c=1 sm=1 tr=0 ts=692036c0 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=RDt3PK5YzZswrGw8on0A:9 X-Proofpoint-ORIG-GUID: KMp9_1-Nl64ikUPRN-ih_GEwbLkOhP7W X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX8Ua01Ko1sKzW KFfLJTxl608UVkL6unCJn7RUYh48WqvET9MwwFpyq/6rp0MQNSRf3O8xjVFXaDeWkgooVMrM1fz DwaXx78/++1nRjp+InSI+5jzk8P1+F5J+Hw5CRseTIIFIDD2DfGUlPLSmz2orfu5AqydSBit8Am 5RC7WR7j94n5g3M2KTAYKVdBMQJ5nKZJNfOMOv2iQ48f4n5bQdPwX9EgxMYUJz4uTo2HqZi2gnW osHdE4opdradaVlf8rdZNXLS5RLVBftalDm9kbk+/mJp5hVLN8GQdmJJxruIZe7n2im1XfnNKjR ix6iJt4e/e1umxkPLeqSMHcaPzAgIP8SeYi0Fz9rOz9/t/A//Ev9RobY9noiihEiIfiLRkoQoFq HocTIkYXjOW+Mp4oA55mXocoEpiL5g== Content-Type: text/plain; charset="utf-8" Alternative code, including jump table and exception table, is represented with the same struct alternative structure. But there is no obvious way to identify whether the struct represents alternative instructions, a jump table or an exception table. So add a type to struct alternative to clearly identify the type of alternative. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 13 ++++++++----- tools/objtool/include/objtool/check.h | 12 ++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e12dba144731f..20630df83e85c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -27,11 +27,6 @@ #include #include =20 -struct alternative { - struct alternative *next; - struct instruction *insn; -}; - static unsigned long nr_cfi, nr_cfi_reused, nr_cfi_cache; =20 static struct cfi_init_state initial_func_cfi; @@ -1945,6 +1940,7 @@ static int add_special_section_alts(struct objtool_fi= le *file) struct list_head special_alts; struct instruction *orig_insn, *new_insn; struct special_alt *special_alt, *tmp; + enum alternative_type alt_type; struct alternative *alt; =20 if (special_get_alts(file->elf, &special_alts)) @@ -1980,9 +1976,15 @@ static int add_special_section_alts(struct objtool_f= ile *file) if (handle_group_alt(file, special_alt, orig_insn, &new_insn)) return -1; =20 + alt_type =3D ALT_TYPE_INSTRUCTIONS; + } else if (special_alt->jump_or_nop) { if (handle_jump_alt(file, special_alt, orig_insn, &new_insn)) return -1; + + alt_type =3D ALT_TYPE_JUMP_TABLE; + } else { + alt_type =3D ALT_TYPE_EX_TABLE; } =20 alt =3D calloc(1, sizeof(*alt)); @@ -1993,6 +1995,7 @@ static int add_special_section_alts(struct objtool_fi= le *file) =20 alt->insn =3D new_insn; alt->next =3D orig_insn->alts; + alt->type =3D alt_type; orig_insn->alts =3D alt; =20 list_del(&special_alt->list); diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index fde958683485f..cbf4af58e29b2 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -38,6 +38,18 @@ struct alt_group { bool ignore; }; =20 +enum alternative_type { + ALT_TYPE_INSTRUCTIONS, + ALT_TYPE_JUMP_TABLE, + ALT_TYPE_EX_TABLE, +}; + +struct alternative { + struct alternative *next; + struct instruction *insn; + enum alternative_type type; +}; + #define INSN_CHUNK_BITS 8 #define INSN_CHUNK_SIZE (1 << INSN_CHUNK_BITS) #define INSN_CHUNK_MAX (INSN_CHUNK_SIZE - 1) --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 5A5FF342145 for ; Fri, 21 Nov 2025 09:54:17 +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=1763718859; cv=none; b=JLLNefBabB1ZRxtc2+MMes/2PVVjUweBYtM6f2kurkJupDKI7UmGXgKLcqoz5gOPjfbgYKiDVfQNbSeJMwfRMVOcLmsmd3n03FdunG+KDcqz4URJkF2Q0LAUj0vKeJkVgoDwoNcNaxyHIonommoyM5PdKrKMxm5I02zWb+cSDbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718859; c=relaxed/simple; bh=4r2fnDbYLsWGf8TBITmoF2L6L72mfBIVJdl15PRCAQg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t9eYoIpTK2fHwQOqcZvlXR7JLQSSl0OmjjgFTyQhDhF/+AV7WOI//cIuFwXBphjMSKcNXRwkEFhXU576Qt2VqpM4VAEwwoxgHif9j2+sEnNoFC90yPdg+b4z5gbkL3PL4l8PT122ba7+ahlY4k5pHrMg1Lpdr44iP5vyTlkPnKE= 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=qvA1/kzj; 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="qvA1/kzj" 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 5AL1v4aD001757; Fri, 21 Nov 2025 09:54:10 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=WAU7Y N4+oqekL6Xpra6xul3Ker5oQk+wV5NYbPpSYfs=; b=qvA1/kzjomD2Ry2A8ZFKO djEPSkyovVn6cA9L9HNuICdqvGqu3+OaTMGJzv3ZDEI00K0kw/rgHQh9RC1ykzSK RD9XEhWR1Tjw4bpz147R1nUaMENIHPTf8iTOazXQA9TV18iYhQSpF9Z3tC3/z4mB ZcS287Qf39g2zLxgQs+P3dN+fMSmnb0tkD5yIHRhE+44mkZb0l1Bi3r9UTeJx+gD C+oxK1BHrIpxA2qAKrhAW73Abyi2Xn1GjgKlmR8fL+BDELTbribTkAOr0O1EPm0U umY1B8I9ImWMbG6Y7PTD6qCq4T7DVONqhVesA8useX6VRPjNQdkcCQhhv29VTRRi 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 4aej90ax08-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:10 +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 5AL71lif004488; Fri, 21 Nov 2025 09:54:09 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uqe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:09 +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 5AL9rgUW021648; Fri, 21 Nov 2025 09:54:09 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-15; Fri, 21 Nov 2025 09:54:08 +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 14/30] objtool: Add functions to better name alternatives Date: Fri, 21 Nov 2025 10:53:24 +0100 Message-ID: <20251121095340.464045-15-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=OMAqHCaB c=1 sm=1 tr=0 ts=692036c2 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=ejOSxiM7Qr7sFksKtvQA:9 X-Proofpoint-ORIG-GUID: 1SDRpGshSggyml6Jk47Wi5e7flmuFoEn X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX75J84tXDoJbE mntGQCriBUIfVcXxH1UihsGycN6CcWJqfZ9/k5hx/enevKKfogaXjWBoPUOsSple8qYaxkvVOI0 IWrRVa0cVgTZ4CPrqkNF+rVUM9JlXCMklyL8LHIuNddOkkABnYMrFheRqq/CadTyBEDBrdEZ1sd +gOM6vVh2K2lhcKC8VIGNpdevuaDyB6yzTW4/ljK2ymfzVXbtRcFAK4ZZY326PXTj8wP3E+4tQM 32ah65k1RPksIFVU4RTfcgphiKDs7i1oYiGI8mJ8BwY6AVaqWmCjGfGE4HK+/Xo3ed7D3KUDP2k DrJ+Arg8aJNN+3Wo8dPDUJgfMWo6w6XvPy65a4eUhOJhCV0qlQlLPF30D5GlQkT5nf2PsypqWBj tifcK55ldQaP71M6TNEF8pcF2MDMuA== X-Proofpoint-GUID: 1SDRpGshSggyml6Jk47Wi5e7flmuFoEn Content-Type: text/plain; charset="utf-8" Add the disas_alt_name() and disas_alt_type_name() to provide a name and a type name for an alternative. This will be used to better name alternatives when tracing their execution. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 72 +++++++++++++++++++++++++++ tools/objtool/include/objtool/disas.h | 12 +++++ 2 files changed, 84 insertions(+) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 0ca6e6c8559fd..b53be240825da 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -3,6 +3,8 @@ * Copyright (C) 2015-2017 Josh Poimboeuf */ =20 +#define _GNU_SOURCE + #include #include #include @@ -450,6 +452,76 @@ size_t disas_insn(struct disas_context *dctx, struct i= nstruction *insn) return disasm(insn->offset, &dctx->info); } =20 +/* + * Provide a name for the type of alternatives present at the + * specified instruction. + * + * An instruction can have alternatives with different types, for + * example alternative instructions and an exception table. In that + * case the name for the alternative instructions type is used. + * + * Return NULL if the instruction as no alternative. + */ +const char *disas_alt_type_name(struct instruction *insn) +{ + struct alternative *alt; + const char *name; + + name =3D NULL; + for (alt =3D insn->alts; alt; alt =3D alt->next) { + if (alt->type =3D=3D ALT_TYPE_INSTRUCTIONS) { + name =3D "alternative"; + break; + } + + switch (alt->type) { + case ALT_TYPE_EX_TABLE: + name =3D "ex_table"; + break; + case ALT_TYPE_JUMP_TABLE: + name =3D "jump_table"; + break; + default: + name =3D "unknown"; + break; + } + } + + return name; +} + +/* + * Provide a name for an alternative. + */ +char *disas_alt_name(struct alternative *alt) +{ + char *str =3D NULL; + + switch (alt->type) { + + case ALT_TYPE_EX_TABLE: + str =3D strdup("EXCEPTION"); + break; + + case ALT_TYPE_JUMP_TABLE: + str =3D strdup("JUMP"); + break; + + case ALT_TYPE_INSTRUCTIONS: + /* + * This is a non-default group alternative. Create a unique + * name using the offset of the first original and alternative + * instructions. + */ + asprintf(&str, "ALTERNATIVE %lx.%lx", + alt->insn->alt_group->orig_group->first_insn->offset, + alt->insn->alt_group->first_insn->offset); + break; + } + + return str; +} + /* * Disassemble a function. */ diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 5db75d06f2197..8959d4c455622 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -6,6 +6,7 @@ #ifndef _DISAS_H #define _DISAS_H =20 +struct alternative; struct disas_context; struct disassemble_info; =20 @@ -24,6 +25,8 @@ void disas_print_info(FILE *stream, struct instruction *i= nsn, int depth, void disas_print_insn(FILE *stream, struct disas_context *dctx, struct instruction *insn, int depth, const char *format, ...); +char *disas_alt_name(struct alternative *alt); +const char *disas_alt_type_name(struct instruction *insn); =20 #else /* DISAS */ =20 @@ -61,6 +64,15 @@ static inline void disas_print_info(FILE *stream, struct= instruction *insn, static inline void disas_print_insn(FILE *stream, struct disas_context *dc= tx, struct instruction *insn, int depth, const char *format, ...) {} +static inline char *disas_alt_name(struct alternative *alt) +{ + return NULL; +} + +static inline const char *disas_alt_type_name(struct instruction *insn) +{ + return NULL; +} =20 #endif /* DISAS */ =20 --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 39E963469EB for ; Fri, 21 Nov 2025 09:54:18 +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=1763718861; cv=none; b=hX5sgkk10RL5pErtwLtZrjxtnXnnMV0sXjH4yp/FMc5vZom9G03F413B1Rrz7GWQ7vktsOowysWrJHluPQbGeOgukUU9bJc3M44DRRVlsHF9o2jPsTydiRx7j+OvPjzZvS/iQL026xrpBM3QVNDnIpH4w8n/QFomsxjTolak6ak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718861; c=relaxed/simple; bh=5r9KPynWPNRi7pXiMJT2iAdw5FVZk86lKwvnqQr5dtA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TZusOrRfhp/ZKyzszcY5c40rvMXDAZdBtueXtQEbLzKQ7OJj8djJUhr/+8CrTfjffEbFGN8jeSfErxDtwXiXv67gB0CTHJMvfvuBPZEKyvGvUEQ5qisNcYQGGvlhTPAWDEiGPp1rEiUEQEJj05DnEcex3p9rpVJko28o8Klxu2I= 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=iBhOQza/; 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="iBhOQza/" 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 5AL1uK4j001191; Fri, 21 Nov 2025 09:54:13 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=0wILD QiVJau/1bpQTUwpwXYP2TrcZ1FsrRSvHvTMf10=; b=iBhOQza/cWxVL0pmexwFc Xt1FMEvNuAxRmVQKBRmu+J7jAAtZnhHttdSJACt6eesWHtfON2AGlNFTes25hYpw oLIIM9oGptu0jOvsf3XtQsB+BQpojyya7/1/e5jH+ch9T6E7Y33mTOcwnEkOunvs 6urLvBALJeC6FikQr1+zKJit9n6xfM4+9gs9sUUoaRXd0HFv9IzMflVHv7X7D0Ps DuEEa6ZbS4elr9H1ctOu/AoGoycPSi+441Ht0qY0tUxnqsTCuJbFNxmBan5MWzf1 sF8scWik02VlP3KasbwJK/BomwADTfBg4eOXw1uah01SVQBu2jsWqphgTxIAlVjL 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 4aej90ax0a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:12 +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 5AL74Exc004449; Fri, 21 Nov 2025 09:54:11 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4ur1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:11 +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 5AL9rgUY021648; Fri, 21 Nov 2025 09:54:10 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-16; Fri, 21 Nov 2025 09:54:10 +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 15/30] objtool: Improve tracing of alternative instructions Date: Fri, 21 Nov 2025 10:53:25 +0100 Message-ID: <20251121095340.464045-16-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=OMAqHCaB c=1 sm=1 tr=0 ts=692036c4 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=il4VveK9W3mU_z1A6oMA:9 X-Proofpoint-ORIG-GUID: 3E7DCwBgEGwXCVmMByepolS-QoWF2RLT X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX9Ijdran0F/2w HfdjwjMLenvrrVQfmWESQDl1fLFETFL5QU6vksNmq40BhIi5d20bttAUQi2zPZ8Gb6O5eqSrVQr qe/Mhkd27WoVcXcXkA9UV4FLCH8Btu9pBN6uWbFWIaXp4HA0VUwq+3e6BTc+epVbHv5O2EIsbtw 4t5Ushr0/6uomHQ/s95f2wpIOBUe6cgTFpUj2sSzys70b5bhgcKZ/5J18F5MnvIhjo/inHIIoYV 0tsE1HUR6eJo+GI+PDeWIRpXXxzdnp8vAGrnQLHhBIPA1Si/wWfDbiI3n6phMZ0nONoKeBBpws9 rRbmzvT35ari69oQcu/BAvsxX4JjHd8RkhM9mASH72ysLFdkOcOChFy6rSN/rWE4rxBE4v1yud0 HM3fK/Eat9JiGmhmc8XpPLULWb8wyA== X-Proofpoint-GUID: 3E7DCwBgEGwXCVmMByepolS-QoWF2RLT Content-Type: text/plain; charset="utf-8" When tracing function validation, improve the reporting of alternative instruction by more clearly showing the different alternatives beginning and end. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 18 +++----- tools/objtool/include/objtool/trace.h | 65 ++++++++++++++++++++++++++- tools/objtool/trace.c | 55 +++++++++++++++++++++++ 3 files changed, 125 insertions(+), 13 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 20630df83e85c..fb000923718dc 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3616,7 +3616,7 @@ static bool skip_alt_group(struct instruction *insn) =20 /* ANNOTATE_IGNORE_ALTERNATIVE */ if (insn->alt_group->ignore) { - TRACE_INSN(insn, "alt group ignored"); + TRACE_ALT(insn, "alt group ignored"); return true; } =20 @@ -3732,8 +3732,9 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, struct instruction *prev_insn, struct instruction *next_insn, bool *dead_end) { - /* prev_state is not used if there is no disassembly support */ + /* prev_state and alt_name are not used if there is no disassembly suppor= t */ struct insn_state prev_state __maybe_unused; + char *alt_name __maybe_unused =3D NULL; struct alternative *alt; u8 visited; int ret; @@ -3820,23 +3821,16 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, return 1; =20 if (insn->alts) { - int i, num_alts; - - num_alts =3D 0; - for (alt =3D insn->alts; alt; alt =3D alt->next) - num_alts++; - - i =3D 1; for (alt =3D insn->alts; alt; alt =3D alt->next) { - TRACE_INSN(insn, "alternative %d/%d", i, num_alts); + TRACE_ALT_BEGIN(insn, alt, alt_name); ret =3D validate_branch(file, func, alt->insn, *statep); + TRACE_ALT_END(insn, alt, alt_name); if (ret) { BT_INSN(insn, "(alt)"); return ret; } - i++; } - TRACE_INSN(insn, "alternative DEFAULT"); + TRACE_ALT_INFO_NOADDR(insn, "/ ", "DEFAULT"); } =20 if (skip_alt_group(insn)) diff --git a/tools/objtool/include/objtool/trace.h b/tools/objtool/include/= objtool/trace.h index 33fe9c6acb4fd..70b574366797b 100644 --- a/tools/objtool/include/objtool/trace.h +++ b/tools/objtool/include/objtool/trace.h @@ -19,11 +19,26 @@ extern int trace_depth; fprintf(stderr, fmt, ##__VA_ARGS__); \ }) =20 +/* + * Print the instruction address and a message. The instruction + * itself is not printed. + */ +#define TRACE_ADDR(insn, fmt, ...) \ +({ \ + if (trace) { \ + disas_print_info(stderr, insn, trace_depth - 1, \ + fmt "\n", ##__VA_ARGS__); \ + } \ +}) + +/* + * Print the instruction address, the instruction and a message. + */ #define TRACE_INSN(insn, fmt, ...) \ ({ \ if (trace) { \ disas_print_insn(stderr, objtool_disas_ctx, \ - insn, trace_depth - 1, \ + insn, trace_depth - 1, \ fmt, ##__VA_ARGS__); \ fprintf(stderr, "\n"); \ insn->trace =3D 1; \ @@ -36,6 +51,37 @@ extern int trace_depth; trace_insn_state(insn, sprev, snext); \ }) =20 +#define TRACE_ALT_FMT(pfx, fmt) pfx "<%s.%lx> " fmt +#define TRACE_ALT_ARG(insn) disas_alt_type_name(insn), (insn)->offset + +#define TRACE_ALT(insn, fmt, ...) \ + TRACE_INSN(insn, TRACE_ALT_FMT("", fmt), \ + TRACE_ALT_ARG(insn), ##__VA_ARGS__) + +#define TRACE_ALT_INFO(insn, pfx, fmt, ...) \ + TRACE_ADDR(insn, TRACE_ALT_FMT(pfx, fmt), \ + TRACE_ALT_ARG(insn), ##__VA_ARGS__) + +#define TRACE_ALT_INFO_NOADDR(insn, pfx, fmt, ...) \ + TRACE_ADDR(NULL, TRACE_ALT_FMT(pfx, fmt), \ + TRACE_ALT_ARG(insn), ##__VA_ARGS__) + +#define TRACE_ALT_BEGIN(insn, alt, alt_name) \ +({ \ + if (trace) { \ + alt_name =3D disas_alt_name(alt); \ + trace_alt_begin(insn, alt, alt_name); \ + } \ +}) + +#define TRACE_ALT_END(insn, alt, alt_name) \ +({ \ + if (trace) { \ + trace_alt_end(insn, alt, alt_name); \ + free(alt_name); \ + } \ +}) + static inline void trace_enable(void) { trace =3D true; @@ -61,17 +107,34 @@ static inline void trace_depth_dec(void) =20 void trace_insn_state(struct instruction *insn, struct insn_state *sprev, struct insn_state *snext); +void trace_alt_begin(struct instruction *orig_insn, struct alternative *al= t, + char *alt_name); +void trace_alt_end(struct instruction *orig_insn, struct alternative *alt, + char *alt_name); =20 #else /* DISAS */ =20 #define TRACE(fmt, ...) ({}) +#define TRACE_ADDR(insn, fmt, ...) ({}) #define TRACE_INSN(insn, fmt, ...) ({}) #define TRACE_INSN_STATE(insn, sprev, snext) ({}) +#define TRACE_ALT(insn, fmt, ...) ({}) +#define TRACE_ALT_INFO(insn, fmt, ...) ({}) +#define TRACE_ALT_INFO_NOADDR(insn, fmt, ...) ({}) +#define TRACE_ALT_BEGIN(insn, alt, alt_name) ({}) +#define TRACE_ALT_END(insn, alt, alt_name) ({}) + =20 static inline void trace_enable(void) {} static inline void trace_disable(void) {} static inline void trace_depth_inc(void) {} static inline void trace_depth_dec(void) {} +static inline void trace_alt_begin(struct instruction *orig_insn, + struct alternative *alt, + char *alt_name) {}; +static inline void trace_alt_end(struct instruction *orig_insn, + struct alternative *alt, + char *alt_name) {}; =20 #endif =20 diff --git a/tools/objtool/trace.c b/tools/objtool/trace.c index d70d47081e82d..5dec44dab781c 100644 --- a/tools/objtool/trace.c +++ b/tools/objtool/trace.c @@ -146,3 +146,58 @@ void trace_insn_state(struct instruction *insn, struct= insn_state *sprev, =20 insn->trace =3D 1; } + +void trace_alt_begin(struct instruction *orig_insn, struct alternative *al= t, + char *alt_name) +{ + struct instruction *alt_insn; + char suffix[2]; + + alt_insn =3D alt->insn; + + if (alt->type =3D=3D ALT_TYPE_EX_TABLE) { + /* + * When there is an exception table then the instruction + * at the original location is executed but it can cause + * an exception. In that case, the execution will be + * redirected to the alternative instruction. + * + * The instruction at the original location can have + * instruction alternatives, so we just print the location + * of the instruction that can cause the exception and + * not the instruction itself. + */ + TRACE_ALT_INFO_NOADDR(orig_insn, "/ ", "%s for instruction at 0x%lx <%s+= 0x%lx>", + alt_name, + orig_insn->offset, orig_insn->sym->name, + orig_insn->offset - orig_insn->sym->offset); + } else { + TRACE_ALT_INFO_NOADDR(orig_insn, "/ ", "%s", alt_name); + } + + if (alt->type =3D=3D ALT_TYPE_JUMP_TABLE) { + /* + * For a jump alternative, if the default instruction is + * a NOP then it is replaced with the jmp instruction, + * otherwise it is replaced with a NOP instruction. + */ + trace_depth++; + if (orig_insn->type =3D=3D INSN_NOP) { + suffix[0] =3D (orig_insn->len =3D=3D 5) ? 'q' : '\0'; + TRACE_ADDR(orig_insn, "jmp%-3s %lx <%s+0x%lx>", suffix, + alt_insn->offset, alt_insn->sym->name, + alt_insn->offset - alt_insn->sym->offset); + } else { + TRACE_ADDR(orig_insn, "nop%d", orig_insn->len); + trace_depth--; + } + } +} + +void trace_alt_end(struct instruction *orig_insn, struct alternative *alt, + char *alt_name) +{ + if (alt->type =3D=3D ALT_TYPE_JUMP_TABLE && orig_insn->type =3D=3D INSN_N= OP) + trace_depth--; + TRACE_ALT_INFO_NOADDR(orig_insn, "\\ ", "%s", alt_name); +} --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 46E2A346776 for ; Fri, 21 Nov 2025 09:54:20 +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=1763718861; cv=none; b=lX8jm+eapdWP3iTRiDxM4To9ezzjQrUWQalNeoabtCTtzTOwMbhIFgLVs7KKXQXRWuxozfJ1aqHHqdHrkMHZc5TvDW5rM7FHpfmjdK+NJVAobhH7Fd9bT/rBAnMkTQ/NYmmeBACZbo+GaNhIDI+Dk6M6G4oXg0hoe5kpejVMTbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718861; c=relaxed/simple; bh=02RaVWsCMLO3IjXi2CDNg/HOmBuYM/xwX2BOxOkNQSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i1oOFw64Ad42Lk6LmVJZG0QvpbrEZZK32txic17bWjAKHiF4z72sDSNkM0g/XbWcr5qUwHXz6VJTz/9Q9dNugk3lf1HoNtVMSvcF6YRoP7gA+EMz7By/6IvyHyHLe56z9bcd4auCneuOVkIQe5IgvkI8W/FiaKIImVR2wsyf7Ug= 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=kR9IhZTE; 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="kR9IhZTE" 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 5AL1uZcx020996; Fri, 21 Nov 2025 09:54:14 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=pCLG+ Vsf1dTcwsgtbF5+5cRW26mt6+hhLTpeL6eHa5Q=; b=kR9IhZTEgNJh/LWMUYXVX DIfqxPv6GB7LrGsR618PpX6MP+GJoRjx2YjH/r2jblGb8ej/eY+uaZZMibdx5vKl AnTqZEUCGkk9oDJyDjfuDXe7KhxcqwKDZ+4mcTk95Kudlc4fn9Mukd7VHBBzOxoH LZ4t1W+Cr0RO/E6y4rwyMNqFo+qqM7R0R/X0xIADpxOnci995Oojsdl40QE3kts7 5VSVM8dXxiIKIPhkvx7qWkgrsjUDPvOs2ckHYhniMN/+NNN3wLMBrXOFUJZ3lVYB gu47cWvsprEvud/Sj+3mPj+lGnfnBChbdM+3JR38LhXi3J7vUxYICYJQDL7GRX9S 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 4aj5dtsjhb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:14 +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 5AL7uBOP004315; Fri, 21 Nov 2025 09:54:13 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4us1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:13 +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 5AL9rgUa021648; Fri, 21 Nov 2025 09:54:12 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-17; Fri, 21 Nov 2025 09:54:12 +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 16/30] objtool: Do not validate IBT for .return_sites and .call_sites Date: Fri, 21 Nov 2025 10:53:26 +0100 Message-ID: <20251121095340.464045-17-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-Spam-Details-Enc: AW1haW4tMjUxMTIwMDA5OSBTYWx0ZWRfX+maX2iqYqU2d orEAMVL4S5Ao2dHWk5+b3XQG6MM55hPKlfeoohA/6COyf7LE+hWUuzg4LjIrSrYIrX+l1CmTNcb GKkd6LCntHC9xDzRWsi5cERcQhhGc7AMd1i1VagMLezWGbEgl39W73lfBpZwVYtySHgDiOPvP3w C9prXEl1Os2UMgUDjWMIh+eKIe6ynV3vI69UTtl69573lXyNcD9aoOuqfqP320waA6iFWulETUW ZY0mnTs5KPjHi3p+THZAJWBZYcTe6KQlTqBg8FXuSM9XJXnSurbZV2C+gdraCMG2QoE4JL68jDM 8dhhm5SDjJb3gKLqVQWBzWsJ7R4+he3AHPP2yjhdgj4at0ug9451cwVp3FKdR24K0+bX2rMu6qO qzwzQlBUUm3DyNG5KnB+nLtN9wkjXw== X-Authority-Analysis: v=2.4 cv=Dckaa/tW c=1 sm=1 tr=0 ts=692036c6 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=yvIqsss6GtJD96b7xZoA:9 X-Proofpoint-GUID: eZJHDbaG21xf8muVF7stNLyT92rwfWfe X-Proofpoint-ORIG-GUID: eZJHDbaG21xf8muVF7stNLyT92rwfWfe Content-Type: text/plain; charset="utf-8" The .return_sites and .call_sites sections reference text addresses, but not with the intent to indirect branch to them, so they don't need to be validated for IBT. This is useful when running objtool on object files which already have .return_sites or .call_sites sections, for example to re-run objtool after it has reported an error or a warning. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index fb000923718dc..0da86834ab2ab 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4805,6 +4805,8 @@ static int validate_ibt(struct objtool_file *file) !strcmp(sec->name, ".llvm.call-graph-profile") || !strcmp(sec->name, ".llvm_bb_addr_map") || !strcmp(sec->name, "__tracepoints") || + !strcmp(sec->name, ".return_sites") || + !strcmp(sec->name, ".call_sites") || !strcmp(sec->name, "__patchable_function_entries")) continue; =20 --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 From nobody Tue Dec 2 01:28:38 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 08006342519 for ; Fri, 21 Nov 2025 09:54: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=1763718865; cv=none; b=i1GITFcrgWcC144BCKcv+lmVzzFE00F7zjsztao2XRWFHL6o+yI6BX0B5BTf78k98aBdW0t8YKPBGDhANzh6qwlWCAIrGj74zFiAALwE+CAXWYNxU82eNy4ia3zHjuVrOi5Lz2wTcI8lGD0NgBc3QNgL6OwfTuxzGSy05SCIZb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718865; c=relaxed/simple; bh=qxlVETB9k6E9YlB10GmWvaFDDM+MCgrwkRBWIdB62LU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SkqjtWbytN8IDYXiktQ2t+Jo5h3ktm4hnFEn/HnHqiYbam48xNTcGt5xEiK5Tct3Uxq41WIVqtf4i7pgAsw+bYTFzauYvs/JhO9Qj3jq2b6UzHdg3+iGCHLXMwkuycJ1eu1n+2XH0cTSglLszKHSCfh1OLxyZzMw3D1jdAth41Y= 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=cq4G4kZZ; 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="cq4G4kZZ" 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 5AL1urlw031045; Fri, 21 Nov 2025 09:54:18 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=DDhzv SgDSur0SqFwPxZuqmAIipYf6Nj8GnAsYkfXqV0=; b=cq4G4kZZGBz59Grx2oUeX LuBUXhfPlNckqkSXBBji/I09t3ZnenZ6QR0OnHFxfl3epr+I2I8SBg5dBwi3Grxz pHQe4wc3n0SGQCnEf5g0rC4J1oDYjHBPXwS4j9N1En2qm1aFc/Q2V6mSxv72lVol 4acYjOHkrnq8f4zhl8kFWFdnO52wclld1jd8PzCBfqBQJpQIAuzuhYIpbtezLOnb hPBDYSNVsL4SPwM3sbmXM64ZpxnwLrYU0R2eorj0ld/BaJ4anKUbyL2jPLHxHP1X 71cFLtVzJ92A7ELXtm84+7Hz6OCj6rKXZBRRYj7Pv3oih8yo03cfCkBo1EJtOzG9 g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbc2nes-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:17 +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 5AL83bqT004518; Fri, 21 Nov 2025 09:54:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:16 +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 5AL9rgUe021648; Fri, 21 Nov 2025 09:54:16 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-19; Fri, 21 Nov 2025 09:54:16 +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 18/30] objtool: Preserve alternatives order Date: Fri, 21 Nov 2025 10:53:28 +0100 Message-ID: <20251121095340.464045-19-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: _T_Fj4V5x4bwCgs3mYdAl7G1fJu36_BJ X-Authority-Analysis: v=2.4 cv=JZyxbEKV c=1 sm=1 tr=0 ts=692036ca cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=bp1g5Iz1D7c7guLF1_8A:9 X-Proofpoint-ORIG-GUID: _T_Fj4V5x4bwCgs3mYdAl7G1fJu36_BJ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX9DSlPx3TBtiW ELBeISfC93qFVzWlndhzjnzga6RGI19PCcpjK3IKYA2QR8ndytMFfUlt/8LMPmKmDtVYISEQzUC gU8MyTjC0h9+7BBU8K8p8Ke10IvF8Gf5xYMMSMkl3M254Hz6k7lsU0yZKCXJPGhto28Cgz2Mw+2 2/lRg22Aw8g7QgDDhIQUvtGLbh6MQzdWtiCnUyjFeWDX0BkV06XEa8/XTQ7HASigyCI9uM1hy2r lvXA9F+XW1866y9VX1PY7tMBGyIyiVsI7bWQPjd1sGsxGnCXQsC+R1Oz0N+eKi6FOBpN7OFbYbs q1jiPY46RwXQkCGW3Yb1bndZDUTBbl9EDJ/C9ueKDM1EGxtYb3HSR5e9k/nIna586JygK5pMf3i 9QBTjselNL1s1vXu7CjF6c1zMFFWLw== Content-Type: text/plain; charset="utf-8" Preserve the order in which alternatives are defined. Currently objtool stores alternatives in a list in reverse order. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5bb932f211f6b..25839c3950a3c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1942,6 +1942,7 @@ static int add_special_section_alts(struct objtool_fi= le *file) struct special_alt *special_alt, *tmp; enum alternative_type alt_type; struct alternative *alt; + struct alternative *a; =20 if (special_get_alts(file->elf, &special_alts)) return -1; @@ -1994,9 +1995,20 @@ static int add_special_section_alts(struct objtool_f= ile *file) } =20 alt->insn =3D new_insn; - alt->next =3D orig_insn->alts; alt->type =3D alt_type; - orig_insn->alts =3D alt; + alt->next =3D NULL; + + /* + * Store alternatives in the same order they have been + * defined. + */ + if (!orig_insn->alts) { + orig_insn->alts =3D alt; + } else { + for (a =3D orig_insn->alts; a->next; a =3D a->next) + ; + a->next =3D alt; + } =20 list_del(&special_alt->list); free(special_alt); --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 5DDEC346FA8 for ; Fri, 21 Nov 2025 09:54:26 +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=1763718868; cv=none; b=XxRcAisCj9RgYU83tWMtQqesBhE7xSptUuOoW9cDgwL6AemiGV14swD+cUrlC/taWnINgE+pb9dpO7mmwrriZNwrYt3O3uGFVVKPZN2Uyu3m2yp6LVQ2D0taUN3QzZmA/R8j3SG9E9kVFzo/qS/fRmHiioj5LmpsYK+ncQE3zoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718868; c=relaxed/simple; bh=4gR3n3Q2aooI6nrAsVpxqgc8JbuVtN/ajXz/x7Lv0Dw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rdYBmbHLAliKa57lqbviJL/NlaJA6ZlDDhSklhb+Z5SYJ00vm9yQxQ/7jH9jWjsYrHpnJq0rj93QUTKGVUr1TI+A80DB6K/8pgE5EQ4f5y9fnGnwrDxtAmUqpJD6jD7un/niRFNIxS6c8KSCZzgnVvVMj7SDqYfZK4H779/L1Tk= 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=NhX2RORQ; 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="NhX2RORQ" 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 5AL1uObN001242; Fri, 21 Nov 2025 09:54:20 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=iJt6Z LDtjG7kdqEpwDTKDYQzW+5G9ZFpQq1otIuVuYA=; b=NhX2RORQ0GQoeqvdIh9B0 unNqLwCpdGx5YnYtaz9+UT6QNVyjMMg8CQ2TMnOYD2/RHWvOphaBOG9+Bq+MVX4F lVw++uVpVqFa4v2Smkj4XvTH/ZGCpQ5pQ2UKjVlBF2KpQ4JCg1xxdeoKmvn3LiPV ncSv744htCzfcIzhTpfsF0uCP5WnX/5dGjlmd0WFPu+eSo+RO56QpxciWwD7P/55 gyNsiYxgUNv3Ryr1sdDTRA9OZMyL8C2hkfqCQJx6K5yXKR8nV5+UeOn6eVQ1Idww EwWArGAnWHfnL6qGI357PBK/LsE4kQqNH4GDrzSUpnuheThzToHR1d8C96x6w/+G 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 4aej90ax0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:19 +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 5AL8s0K9004268; Fri, 21 Nov 2025 09:54:18 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:18 +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 5AL9rgUg021648; Fri, 21 Nov 2025 09:54:18 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-20; Fri, 21 Nov 2025 09:54:18 +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 19/30] objtool: Print headers for alternatives Date: Fri, 21 Nov 2025 10:53:29 +0100 Message-ID: <20251121095340.464045-20-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=OMAqHCaB c=1 sm=1 tr=0 ts=692036cb cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=oPn5hVstRMuPe18koHEA:9 X-Proofpoint-ORIG-GUID: LTAzrfn7FDrM4fWP0e9Xs4L0zpD7lyKE X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX1QK7wiAGRTgB 7fo1+wtRccHJWy+EJMEYJbGR1Bo+krcONws8j/K6O/v0xk8EleecpjJ8wfLdNDwcDFZnaprApHg BN45DI9uIPI1HznUrjm2IjvVk8xigSC1zQPH5ZbXgg8m1VujLGY+E+tmNdVSaBq+31VEfWdUyqU y8YT+sNX0UQdZY65P6q29QxMAXecVYpCs36IPrIRbH0lveRStJh3HXYNWFIb6hpswSYzRppb1gF VGBd0oQiheIjJqnnVAbeSxDF9HSMXpVQlomPaoXqe2iQz6NVwxmZtmCOwr/DrqZiGPKMf0m3Gt6 wIHz8y4Rk1ADyWW1mAn/Ccm8aDrbcRGnJWtx2QK4DbwJ7Pb0hYyv/VELycnUXRYEeYPzniJlEm/ QqiKLGxHIQ/nEesB/sCo/YrHQMHQDw== X-Proofpoint-GUID: LTAzrfn7FDrM4fWP0e9Xs4L0zpD7lyKE Content-Type: text/plain; charset="utf-8" When using the --disas option, objtool doesn't currently disassemble any alternative. Print an header for each alternative. This identifies places where alternatives are present but alternative code is still not disassembled at the moment. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 188 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 182 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 9cc952e03c356..f9b13d56acab7 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -29,6 +29,43 @@ struct disas_context { struct disassemble_info info; }; =20 +/* + * Maximum number of alternatives + */ +#define DISAS_ALT_MAX 5 + +/* + * Maximum number of instructions per alternative + */ +#define DISAS_ALT_INSN_MAX 50 + +/* + * Information to disassemble an alternative + */ +struct disas_alt { + struct instruction *orig_insn; /* original instruction */ + struct alternative *alt; /* alternative or NULL if default code */ + char *name; /* name for this alternative */ + int width; /* formatting width */ +}; + +/* + * Wrapper around asprintf() to allocate and format a string. + * Return the allocated string or NULL on error. + */ +static char *strfmt(const char *fmt, ...) +{ + va_list ap; + char *str; + int rv; + + va_start(ap, fmt); + rv =3D vasprintf(&str, fmt, ap); + va_end(ap); + + return rv =3D=3D -1 ? NULL : str; +} + static int sprint_name(char *str, const char *name, unsigned long offset) { int len; @@ -314,6 +351,9 @@ char *disas_result(struct disas_context *dctx) #define DISAS_INSN_OFFSET_SPACE 10 #define DISAS_INSN_SPACE 60 =20 +#define DISAS_PRINSN(dctx, insn, depth) \ + disas_print_insn(stdout, dctx, insn, depth, "\n") + /* * Print a message in the instruction flow. If insn is not NULL then * the instruction address is printed in addition of the message, @@ -354,6 +394,19 @@ static int disas_vprint(FILE *stream, struct section *= sec, unsigned long offset, return n; } =20 +static int disas_print(FILE *stream, struct section *sec, unsigned long of= fset, + int depth, const char *format, ...) +{ + va_list args; + int len; + + va_start(args, format); + len =3D disas_vprint(stream, sec, offset, depth, format, args); + va_end(args); + + return len; +} + /* * Print a message in the instruction flow. If insn is not NULL then * the instruction address is printed in addition of the message, @@ -523,21 +576,144 @@ char *disas_alt_name(struct alternative *alt) return str; } =20 +/* + * Initialize an alternative. The default alternative should be initialized + * with alt=3DNULL. + */ +static int disas_alt_init(struct disas_alt *dalt, + struct instruction *orig_insn, + struct alternative *alt) +{ + dalt->orig_insn =3D orig_insn; + dalt->alt =3D alt; + dalt->name =3D alt ? disas_alt_name(alt) : strdup("DEFAULT"); + if (!dalt->name) + return -1; + dalt->width =3D strlen(dalt->name); + + return 0; +} + +/* + * Print all alternatives one above the other. + */ +static void disas_alt_print_compact(char *alt_name, struct disas_alt *dalt= s, + int alt_count) +{ + struct instruction *orig_insn; + int len; + int i; + + orig_insn =3D dalts[0].orig_insn; + + len =3D disas_print(stdout, orig_insn->sec, orig_insn->offset, 0, NULL); + printf("%s\n", alt_name); + + for (i =3D 0; i < alt_count; i++) + printf("%*s=3D %s\n", len, "", dalts[i].name); +} + +/* + * Disassemble an alternative. + * + * Return the last instruction in the default alternative so that + * disassembly can continue with the next instruction. Return NULL + * on error. + */ +static void *disas_alt(struct disas_context *dctx, + struct instruction *orig_insn) +{ + struct disas_alt dalts[DISAS_ALT_MAX] =3D { 0 }; + struct alternative *alt; + int alt_count =3D 0; + char *alt_name; + int err; + int i; + + alt_name =3D strfmt("<%s.%lx>", disas_alt_type_name(orig_insn), + orig_insn->offset); + if (!alt_name) { + WARN("Failed to define name for alternative at instruction 0x%lx", + orig_insn->offset); + goto done; + } + + /* + * Initialize the default alternative. + */ + err =3D disas_alt_init(&dalts[0], orig_insn, NULL); + if (err) { + WARN("%s: failed to initialize default alternative", alt_name); + goto done; + } + + /* + * Initialize all other alternatives. + */ + i =3D 1; + for (alt =3D orig_insn->alts; alt; alt =3D alt->next) { + if (i >=3D DISAS_ALT_MAX) { + WARN("%s has more alternatives than supported", alt_name); + break; + } + err =3D disas_alt_init(&dalts[i], orig_insn, alt); + if (err) { + WARN("%s: failed to disassemble alternative", alt_name); + goto done; + } + + i++; + } + alt_count =3D i; + + /* + * Print default and non-default alternatives. + * + * At the moment, this just prints an header for each alternative. + */ + disas_alt_print_compact(alt_name, dalts, alt_count); + +done: + for (i =3D 0; i < alt_count; i++) + free(dalts[i].name); + + free(alt_name); + + /* + * Currently we are not disassembling any alternative but just + * printing alternative names. Return NULL to have disas_func() + * resume the disassembly with the default alternative. + */ + return NULL; +} + /* * Disassemble a function. */ static void disas_func(struct disas_context *dctx, struct symbol *func) { + struct instruction *insn_start; struct instruction *insn; - size_t addr; =20 printf("%s:\n", func->name); sym_for_each_insn(dctx->file, func, insn) { - addr =3D insn->offset; - disas_insn(dctx, insn); - printf(" %6lx: %s+0x%-6lx %s\n", - addr, func->name, addr - func->offset, - disas_result(dctx)); + if (insn->alts) { + insn_start =3D insn; + insn =3D disas_alt(dctx, insn); + if (insn) + continue; + /* + * There was an error with disassembling + * the alternative. Resume disassembling + * at the current instruction, this will + * disassemble the default alternative + * only and continue with the code after + * the alternative. + */ + insn =3D insn_start; + } + + DISAS_PRINSN(dctx, insn, 0); } printf("\n"); } --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 7C27F346E66 for ; Fri, 21 Nov 2025 09:54:29 +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=1763718871; cv=none; b=lMK5N7E+5NYmPYZbDT37yw9Z38i/ti+eDXMNEzeL1c0M5L61iB2LqsEQjERQ5iERkTCdpcFrOUfaemgkCQedM7tdhPQRa5h1PBAkyWus9IodlDPzqljHNop6qqitHDTYhjMG+t+xOwF6ZjmyqnRJmVtVF12E7GtKUc0rIgN/XVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718871; c=relaxed/simple; bh=bXqTHg1x2Dr5B4buJd9aKu5euqZBgL7fuAf+ufwlcyI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pgT6Wh//PF5WgSSFPoE3TnSHMR0VPXG7H9yiGRVxXkihtBq3Nu5C7iPV2mA6RqnIAf3AnxbGYug2WqALvfI/UHBWWeaBcCxMPL5VAwF27q8+7gazjj/mPfRZnTPUbtAhmB1SOyQjPeUdFKIR8iHm0wMyDFt5XW0YOtmG+rFy0Sw= 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=QwhK4A1Y; 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="QwhK4A1Y" 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 5AL1uJC1030155; Fri, 21 Nov 2025 09:54:22 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=u/Bhr 4URxntszJbGWLGpAiWG85vJrt5EbSFEopmaJ9Q=; b=QwhK4A1Y+f1RsvNDHCOR+ 47SWF+nYTSJmPWshP3pl4rrSx2ay5xcoYn8TRYoGS5ngzqsEiTai7RQXUeLl8dYy FU7K3NWtnRovm1q/Z+yERGx4Y+YcwNUzTcdttU8t5CfbPG68wFQGZXd9hk58aGWp QhAacbwl8G7GFdvj8MysB8WPe4cKsm8kD80XYuU76XxdlpPL7c7gXn5+uHG2PFl1 iOIauURPtWhxgnsx9GmAz1eG/F0ELbGApD9/FBb0otHsN13EzMhOtbyflgeL0XQz rZWaFY5Dj3SqeylChdfiJ/HYFJ4GSp6SJVgaKvud1TtEA+5Td2ABcltqB4+pZTgg Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbc2new-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:21 +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 5AL9pSQP004274; Fri, 21 Nov 2025 09:54:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uuv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:20 +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 5AL9rgUi021648; Fri, 21 Nov 2025 09:54:20 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-21; Fri, 21 Nov 2025 09:54:20 +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 20/30] objtool: Disassemble group alternatives Date: Fri, 21 Nov 2025 10:53:30 +0100 Message-ID: <20251121095340.464045-21-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: MvCeNNJ7tkz9UJNq88TNR27s2P-Iw9Gk X-Authority-Analysis: v=2.4 cv=JZyxbEKV c=1 sm=1 tr=0 ts=692036cd cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=Jt4dBLFmlIf84eIfz1kA:9 X-Proofpoint-ORIG-GUID: MvCeNNJ7tkz9UJNq88TNR27s2P-Iw9Gk X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfXypeAG7HbAXaB KejrlwL7bJP5LuZ6+eIia6Kkk9hUJ12XVkg/dGWfq/bVPNkQ960CXS1akE1WOPu2fNhl8+hjIt2 g6nLsQwriTpsSSf8Y593xvyGjKhgk/rJjZ/Gxq59hYIagl36wH/VfcBV4db404rC5zrFiC//IQM 33l7rn2Y4AFKcrY0GLdv/2oN83FKJeILVpT7JWZlcYjxKouEpZMHfCMzY3FnPIeNowORj9zW7Ri GvYNCUIIHq2ocPcZyG9bldbeW0Nr/ZQ3Wp0oYxsDG2B8MsUE+ZuqYUpkhUGO4dCdaJPfXs9CgXm 7dBNRgtJc7YqByNChiO7FcuGJWIFFpYA5S3kcwpuGNuspuFYZxWuC10fBDaKB9uBM8MAqco1BNc 1sfvjaVLPM0xMAny5VTRnI4RHcO24w== Content-Type: text/plain; charset="utf-8" When using the --disas option, disassemble all group alternatives. Jump tables and exception tables (which are handled as alternatives) are not disassembled at the moment. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 166 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 149 insertions(+), 17 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index f9b13d56acab7..ae69bef2eb37e 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -47,8 +47,14 @@ struct disas_alt { struct alternative *alt; /* alternative or NULL if default code */ char *name; /* name for this alternative */ int width; /* formatting width */ + char *insn[DISAS_ALT_INSN_MAX]; /* alternative instructions */ }; =20 +#define DALT_DEFAULT(dalt) (!(dalt)->alt) +#define DALT_INSN(dalt) (DALT_DEFAULT(dalt) ? (dalt)->orig_insn : (dalt)-= >alt->insn) +#define DALT_GROUP(dalt) (DALT_INSN(dalt)->alt_group) +#define DALT_ALTID(dalt) ((dalt)->orig_insn->offset) + /* * Wrapper around asprintf() to allocate and format a string. * Return the allocated string or NULL on error. @@ -506,6 +512,21 @@ size_t disas_insn(struct disas_context *dctx, struct i= nstruction *insn) return disasm(insn->offset, &dctx->info); } =20 +static struct instruction *next_insn_same_alt(struct objtool_file *file, + struct alt_group *alt_grp, + struct instruction *insn) +{ + if (alt_grp->last_insn =3D=3D insn || alt_grp->nop =3D=3D insn) + return NULL; + + return next_insn_same_sec(file, insn); +} + +#define alt_for_each_insn(file, alt_grp, insn) \ + for (insn =3D alt_grp->first_insn; \ + insn; \ + insn =3D next_insn_same_alt(file, alt_grp, insn)) + /* * Provide a name for the type of alternatives present at the * specified instruction. @@ -594,23 +615,107 @@ static int disas_alt_init(struct disas_alt *dalt, return 0; } =20 +static int disas_alt_add_insn(struct disas_alt *dalt, int index, char *ins= n_str) +{ + int len; + + if (index >=3D DISAS_ALT_INSN_MAX) { + WARN("Alternative %lx.%s has more instructions than supported", + DALT_ALTID(dalt), dalt->name); + return -1; + } + + len =3D strlen(insn_str); + dalt->insn[index] =3D insn_str; + if (len > dalt->width) + dalt->width =3D len; + + return 0; +} + +/* + * Disassemble an alternative and store instructions in the disas_alt + * structure. Return the number of instructions in the alternative. + */ +static int disas_alt_group(struct disas_context *dctx, struct disas_alt *d= alt) +{ + struct objtool_file *file; + struct instruction *insn; + char *str; + int count; + int err; + + file =3D dctx->file; + count =3D 0; + + alt_for_each_insn(file, DALT_GROUP(dalt), insn) { + + disas_insn(dctx, insn); + str =3D strdup(disas_result(dctx)); + if (!str) + return -1; + + err =3D disas_alt_add_insn(dalt, count, str); + if (err) + break; + count++; + } + + return count; +} + +/* + * Disassemble the default alternative. + */ +static int disas_alt_default(struct disas_context *dctx, struct disas_alt = *dalt) +{ + char *str; + int err; + + if (DALT_GROUP(dalt)) + return disas_alt_group(dctx, dalt); + + /* + * Default alternative with no alt_group: this is the default + * code associated with either a jump table or an exception + * table and no other instruction alternatives. In that case + * the default alternative is made of a single instruction. + */ + disas_insn(dctx, dalt->orig_insn); + str =3D strdup(disas_result(dctx)); + if (!str) + return -1; + err =3D disas_alt_add_insn(dalt, 0, str); + if (err) + return -1; + + return 1; +} + /* * Print all alternatives one above the other. */ static void disas_alt_print_compact(char *alt_name, struct disas_alt *dalt= s, - int alt_count) + int alt_count, int insn_count) { struct instruction *orig_insn; + int i, j; int len; - int i; =20 orig_insn =3D dalts[0].orig_insn; =20 len =3D disas_print(stdout, orig_insn->sec, orig_insn->offset, 0, NULL); printf("%s\n", alt_name); =20 - for (i =3D 0; i < alt_count; i++) + for (i =3D 0; i < alt_count; i++) { printf("%*s=3D %s\n", len, "", dalts[i].name); + for (j =3D 0; j < insn_count; j++) { + if (!dalts[i].insn[j]) + break; + printf("%*s| %s\n", len, "", dalts[i].insn[j]); + } + printf("%*s|\n", len, ""); + } } =20 /* @@ -624,11 +729,15 @@ static void *disas_alt(struct disas_context *dctx, struct instruction *orig_insn) { struct disas_alt dalts[DISAS_ALT_MAX] =3D { 0 }; + struct instruction *last_insn =3D NULL; struct alternative *alt; + struct disas_alt *dalt; + int insn_count =3D 0; int alt_count =3D 0; char *alt_name; + int count; + int i, j; int err; - int i; =20 alt_name =3D strfmt("<%s.%lx>", disas_alt_type_name(orig_insn), orig_insn->offset); @@ -639,7 +748,7 @@ static void *disas_alt(struct disas_context *dctx, } =20 /* - * Initialize the default alternative. + * Initialize and disassemble the default alternative. */ err =3D disas_alt_init(&dalts[0], orig_insn, NULL); if (err) { @@ -647,8 +756,14 @@ static void *disas_alt(struct disas_context *dctx, goto done; } =20 + insn_count =3D disas_alt_default(dctx, &dalts[0]); + if (insn_count < 0) { + WARN("%s: failed to disassemble default alternative", alt_name); + goto done; + } + /* - * Initialize all other alternatives. + * Initialize and disassemble all other alternatives. */ i =3D 1; for (alt =3D orig_insn->alts; alt; alt =3D alt->next) { @@ -656,35 +771,52 @@ static void *disas_alt(struct disas_context *dctx, WARN("%s has more alternatives than supported", alt_name); break; } - err =3D disas_alt_init(&dalts[i], orig_insn, alt); + dalt =3D &dalts[i]; + err =3D disas_alt_init(dalt, orig_insn, alt); if (err) { WARN("%s: failed to disassemble alternative", alt_name); goto done; } =20 + /* + * Only group alternatives are supported at the moment. + */ + switch (dalt->alt->type) { + case ALT_TYPE_INSTRUCTIONS: + count =3D disas_alt_group(dctx, dalt); + break; + default: + count =3D 0; + } + if (count < 0) { + WARN("%s: failed to disassemble alternative %s", + alt_name, dalt->name); + goto done; + } + + insn_count =3D count > insn_count ? count : insn_count; i++; } alt_count =3D i; =20 /* * Print default and non-default alternatives. - * - * At the moment, this just prints an header for each alternative. */ - disas_alt_print_compact(alt_name, dalts, alt_count); + disas_alt_print_compact(alt_name, dalts, alt_count, insn_count); + + last_insn =3D orig_insn->alt_group ? orig_insn->alt_group->last_insn : + orig_insn; =20 done: - for (i =3D 0; i < alt_count; i++) + for (i =3D 0; i < alt_count; i++) { free(dalts[i].name); + for (j =3D 0; j < insn_count; j++) + free(dalts[i].insn[j]); + } =20 free(alt_name); =20 - /* - * Currently we are not disassembling any alternative but just - * printing alternative names. Return NULL to have disas_func() - * resume the disassembly with the default alternative. - */ - return NULL; + return last_insn; } =20 /* --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 453C434A76B for ; Fri, 21 Nov 2025 09:54:33 +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=1763718874; cv=none; b=tMoAS6Unvuj6wCPHqRICKaEpiiJcYMil58aKLEIm+qRv2yJe4Hb65sfTb/eD9b0pLPSW61mTBWPB3enOy7445HwfZW1CBiA6+iRe9226/Fc0H/72kRJtZJLn2L36xWHWtTjEp/zho1+vNFMT9Sv90vsHnwXb7gq9PZGhAbpVk1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718874; c=relaxed/simple; bh=RPTX3kGz79mBxVb9u/CEo7szFCC65oiuzYR5QmRLTiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aZo7TU4xvfLKj5bR/Z4G86meFJ/xghOCpQvI0+sv5fH2BDglyheWHv/6ukzXmaF8Vf/pYEliEqj8kXIlzxHaLlVLBppejJrcrM+no70qj6nyFZtJiKmBxJFSoL+4GKaI6xrxm3pBM8mw4JRAAq/vuYvZ/M7K65w0TWBEhapkUQM= 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=RUWVTBr7; 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="RUWVTBr7" 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 5AL1uP8B018210; Fri, 21 Nov 2025 09:54: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=FQU5N WryaqfnzfgFWnDZOWxT64H75yJFRcbp9t2CNfs=; b=RUWVTBr7sUfH3G7ZOx+IG Kwyawb3Jxg+7meoDx5xnUmwLhjqEoAp4EharOFbOjdhi8i6+EQCQaoyrlfht9wqa j7S8wVfR6vrtYuDKVZ0KaO5XVZXRt8L8aZGmhTKeyBOWyYXyKyZiawAzUVRBJOiq xejQ5XupxBknywuURd78p9YKxioOqLvFnQVbPzuKlaEN5cmph0jxLbA41/wJeVHY Ro1AX7WOIQIrWMULPbEJUe1YLuSA96rAB3KnmG3WDk5lRVOucHhyJQi5TTfYD4TM V0K4RYErbCAzEQbfTruZEqQcL2EY82D1Jyz/6Tp6j3KXwojDI+FPUszHFy4gIvzo 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 4aejd1jts7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:23 +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 5AL8q8sQ004524; Fri, 21 Nov 2025 09:54:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uv6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:22 +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 5AL9rgUk021648; Fri, 21 Nov 2025 09:54:22 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-22; Fri, 21 Nov 2025 09:54: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 v6 21/30] objtool: Print addresses with alternative instructions Date: Fri, 21 Nov 2025 10:53:31 +0100 Message-ID: <20251121095340.464045-22-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: i0zKLgSh43ye4vXjrPbhRbKETeHor4Zy X-Authority-Analysis: v=2.4 cv=Z/jh3XRA c=1 sm=1 tr=0 ts=692036cf cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=S3f6In5oQaLI2rDuRkMA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX68Z8H0h7OatP upQMlufupWSHT/S+7seluFxtoV9yIoUrBJN8AxI99u0O0SL3EobPQzN631IzYhC3Sooam27JCxn 00fEPzUzAjTLdLCXwczrg5SEL21uhWoM4afmpI4qqp6I5ac7UbaeXKS6xCGwqz2olo0hsUtSi4B Hvj2Lfcv6s0EeTyc6eZg+fidJyqQxUjPCpsf5RTHBpP8CxGXOQLs/YCH/eDSIrs/B51dLkBuU6N 4ZQGqEqII55S43kxkp+Cv1AqkI2IDIyOhdvofFkpFydGjvIFzUfRl8AwdgqnWnMY2YtqlgXnXjv duaGyEWvBJZk53wYhykNrF/TzaC5INSXFlqk/h+dIoK8L//Ic4GSRSxY1S4p/o3uZhdxJnBSGKD 2QXPgxD1vshxG0IZgbMFy4mDY5T+HQ== X-Proofpoint-ORIG-GUID: i0zKLgSh43ye4vXjrPbhRbKETeHor4Zy Content-Type: text/plain; charset="utf-8" All alternatives are disassemble side-by-side when using the --disas option. However the address of each instruction is not printed because instructions from different alternatives are not necessarily aligned. Change this behavior to print the address of each instruction. Spaces will appear between instructions from the same alternative when instructions from different alternatives do not have the same alignment. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index ae69bef2eb37e..6083a64f6ae49 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -47,7 +47,11 @@ struct disas_alt { struct alternative *alt; /* alternative or NULL if default code */ char *name; /* name for this alternative */ int width; /* formatting width */ - char *insn[DISAS_ALT_INSN_MAX]; /* alternative instructions */ + struct { + char *str; /* instruction string */ + int offset; /* instruction offset */ + } insn[DISAS_ALT_INSN_MAX]; /* alternative instructions */ + int insn_idx; /* index of the next instruction to print */ }; =20 #define DALT_DEFAULT(dalt) (!(dalt)->alt) @@ -361,10 +365,9 @@ char *disas_result(struct disas_context *dctx) disas_print_insn(stdout, dctx, insn, depth, "\n") =20 /* - * Print a message in the instruction flow. If insn is not NULL then - * the instruction address is printed in addition of the message, - * otherwise only the message is printed. In all cases, the instruction - * itself is not printed. + * Print a message in the instruction flow. If sec is not NULL then the + * address at the section offset is printed in addition of the message, + * otherwise only the message is printed. */ static int disas_vprint(FILE *stream, struct section *sec, unsigned long o= ffset, int depth, const char *format, va_list ap) @@ -607,6 +610,7 @@ static int disas_alt_init(struct disas_alt *dalt, { dalt->orig_insn =3D orig_insn; dalt->alt =3D alt; + dalt->insn_idx =3D 0; dalt->name =3D alt ? disas_alt_name(alt) : strdup("DEFAULT"); if (!dalt->name) return -1; @@ -615,7 +619,8 @@ static int disas_alt_init(struct disas_alt *dalt, return 0; } =20 -static int disas_alt_add_insn(struct disas_alt *dalt, int index, char *ins= n_str) +static int disas_alt_add_insn(struct disas_alt *dalt, int index, char *ins= n_str, + int offset) { int len; =20 @@ -626,7 +631,8 @@ static int disas_alt_add_insn(struct disas_alt *dalt, i= nt index, char *insn_str) } =20 len =3D strlen(insn_str); - dalt->insn[index] =3D insn_str; + dalt->insn[index].str =3D insn_str; + dalt->insn[index].offset =3D offset; if (len > dalt->width) dalt->width =3D len; =20 @@ -641,12 +647,14 @@ static int disas_alt_group(struct disas_context *dctx= , struct disas_alt *dalt) { struct objtool_file *file; struct instruction *insn; + int offset; char *str; int count; int err; =20 file =3D dctx->file; count =3D 0; + offset =3D 0; =20 alt_for_each_insn(file, DALT_GROUP(dalt), insn) { =20 @@ -655,9 +663,10 @@ 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); + err =3D disas_alt_add_insn(dalt, count, str, offset); if (err) break; + offset +=3D insn->len; count++; } =20 @@ -685,7 +694,7 @@ 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); + err =3D disas_alt_add_insn(dalt, 0, str, 0); if (err) return -1; =20 @@ -710,9 +719,11 @@ static void disas_alt_print_compact(char *alt_name, st= ruct disas_alt *dalts, for (i =3D 0; i < alt_count; i++) { printf("%*s=3D %s\n", len, "", dalts[i].name); for (j =3D 0; j < insn_count; j++) { - if (!dalts[i].insn[j]) + if (!dalts[i].insn[j].str) break; - printf("%*s| %s\n", len, "", dalts[i].insn[j]); + disas_print(stdout, orig_insn->sec, + orig_insn->offset + dalts[i].insn[j].offset, 0, + "| %s\n", dalts[i].insn[j].str); } printf("%*s|\n", len, ""); } @@ -811,7 +822,7 @@ static void *disas_alt(struct disas_context *dctx, for (i =3D 0; i < alt_count; i++) { free(dalts[i].name); for (j =3D 0; j < insn_count; j++) - free(dalts[i].insn[j]); + free(dalts[i].insn[j].str); } =20 free(alt_name); --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 30B56342C94 for ; Fri, 21 Nov 2025 09:54:34 +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=1763718876; cv=none; b=L/LB020cBRqWG35FM4KIqNQ9mMPaj3hoSjBwz+7r1fAmcWWCesfywH0t6fHk7kfcu6zgugM1d1uW0TQ0dSDHZvXTGdHNKotZOlDvhVKgaBC06bQVSVMxoXcLVsEQTDLnJrXtcvH2nEBCI9BXhx9djKiBWlnGZpw2+r+nOs2mkKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718876; c=relaxed/simple; bh=u00xFU4aVAd8qPYKiROKsfCV2pKcQtnI5UluccGO/98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DVaTngfJum9ZpGR5cZvQXyeURXN105KggdMs4TZ6J6u3tn8TzSWrJ7e3juXQYJJuASbCq2VGwEzXOoh2YPap6MzNOADcF6yeXqPkn09eHF2u2+sJTlKqoEqJktdh5dsGCZ3PpKPR2s18pbHQ8NrTsD3lpPAqZj4W5z1GhZl74Ik= 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=TN5usDq/; 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="TN5usDq/" 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 5AL1uOpl020661; Fri, 21 Nov 2025 09:54:25 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=dZAJB XykXzZaViQVzFjjS7/95/jwrvIP034HEzSn86Y=; b=TN5usDq/n/d/fHxPOoqLu u32R/vwAuJtToaOzruZ6B3937cSNY4vPvoc14TLf+wVOFPdK0p4D2qrIQN1JXhu5 ybUGkkRlzF3KruO7uPLcVHpVyG8T+T7fpGmTY2BqQxEblKXwklwyRudupr/tWCm3 zwPBGnIHh8GqmiyGlTEDXSy6F+aGUUqcb8l6MV7gLxe9CWnHLlGh5UiEQtr+saK6 j6ssgaEUx+yrSbKnyTzg8N83gUvxendogaJUCQBb6vBElUwxMaDTm38xInwijKTT QFl8THTWXPehDnyWkHEhQcEBgwDmQuRSyEvkcTbBIK0x1Fu9UaqOrdsKA8NEpn4S g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aj5dtsjhk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:25 +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 5AL83bqW004518; Fri, 21 Nov 2025 09:54:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uvn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:24 +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 5AL9rgUm021648; Fri, 21 Nov 2025 09:54:24 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-23; Fri, 21 Nov 2025 09:54:23 +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 22/30] objtool: Disassemble exception table alternatives Date: Fri, 21 Nov 2025 10:53:32 +0100 Message-ID: <20251121095340.464045-23-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-Spam-Details-Enc: AW1haW4tMjUxMTIwMDA5OSBTYWx0ZWRfX6AW49ms8+Gbk PA55h12co5CU2/5Xypyey9bYdnoLWHYdwKmOaFEmi8FwAQ5xUyt3yOkour0ihJNOwVoaOK1pnC5 QBHe/kBuOxaKeHtxvRV+ll2wsdKufXa0dpghwFojXJ5fWBxAHE9oZs8Q0Hk9WKHAptXuxpY9HlH niJ0ba8AMoGyKBxYQRmuxieVR2qAWHnum84vuFNza7c8tEqWnQQibkjy+swePgJyCSRoOSDLQgL E0o3SfGaZO/nbzSlgemSpqq0ZGB4W47CDdNkGgrsNo/5G6sYFt2vR4M0kVte2icpU2m04aGdgWa /kOELzOLq/0S32gfvVJ1LGsIfcBrMbiS+L3l+G+NoY9ZYiNH0ymKGFENVaiUMYK+o6oBC7Gfgn5 EKwlOSE4KCn4JUGQ9xKqqDCOlDHurA== X-Authority-Analysis: v=2.4 cv=Dckaa/tW c=1 sm=1 tr=0 ts=692036d1 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=YV0YETl46AI6N2r6LvgA:9 X-Proofpoint-GUID: i0MLvUxH6M6bdRt1q5BxNseW611mu4xL X-Proofpoint-ORIG-GUID: i0MLvUxH6M6bdRt1q5BxNseW611mu4xL Content-Type: text/plain; charset="utf-8" When using the --disas option, also disassemble exception tables (EX_TABLE). Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 6083a64f6ae49..018aba37b996b 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -639,6 +639,26 @@ static int disas_alt_add_insn(struct disas_alt *dalt, = int index, char *insn_str, return 0; } =20 +/* + * Disassemble an exception table alternative. + */ +static int disas_alt_extable(struct disas_alt *dalt) +{ + struct instruction *alt_insn; + char *str; + + alt_insn =3D dalt->alt->insn; + str =3D strfmt("resume at 0x%lx <%s+0x%lx>", + alt_insn->offset, alt_insn->sym->name, + alt_insn->offset - alt_insn->sym->offset); + if (!str) + return -1; + + disas_alt_add_insn(dalt, 0, str, 0); + + return 1; +} + /* * Disassemble an alternative and store instructions in the disas_alt * structure. Return the number of instructions in the alternative. @@ -790,12 +810,16 @@ static void *disas_alt(struct disas_context *dctx, } =20 /* - * Only group alternatives are supported at the moment. + * Only group alternatives and exception tables are + * supported at the moment. */ switch (dalt->alt->type) { case ALT_TYPE_INSTRUCTIONS: count =3D disas_alt_group(dctx, dalt); break; + case ALT_TYPE_EX_TABLE: + count =3D disas_alt_extable(dalt); + break; default: count =3D 0; } --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 F080434A78C for ; Fri, 21 Nov 2025 09:54:34 +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=1763718876; cv=none; b=uD3MPS/vBnjzaaLiFfe/0xnUAzMAaraa8eir7oDv8X6atcawqyshFCN/ObBEynTXujoGZirmF3XvrUJDNAcT6QSgWYsLEC+6wJjx51vntNVDeWN/2NpZSVCKrY1JJzHzLdIrlQFUleGW6NELKtySeD7rbIL0AHoDvIjtNIGbTsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718876; c=relaxed/simple; bh=VSRwr8V/7WahARxm0l2cp+eYniyqbnvgBsM9+YC8eYs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DN9a7yH7zBEyZV7X5+eedDx+TCqGPi2aTCR+ZH4LBTaZalKn5h3yC2TZtu3xJJ8IWbaMbRLcO30WFzlo/EijqcpFOhxIJTtE3wn5lrmSt8uPkKx05J0kBUChFPXA65cVn5bCRvQ38nEQnxsL+tk7wCb9Ci2jmER6RnIx1Q/u9Ys= 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=GZc3LVC0; 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="GZc3LVC0" 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 5AL1uHZl001183; Fri, 21 Nov 2025 09:54:27 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=XWd10 3ciLsFUYpP6CbBqCVjgAZ6xGCyk47DuudaL3RY=; b=GZc3LVC04oWB5/ECyNvAk uKBRECWSvjuSSzU/6CmVpTrOizTuBht7j935a7LvMwWge35618l9VmyelHDfeTpV yBHlOB7Bdhp9CwZBqY9VLtNdnowdqgVFzPnSb/HhPMwBQH+FDvLYat+gWeWlXmoD QqyzTShrAp3dP8sstUs4L/MsGOF7l3aS5/Fu+NopezgO+XdQMublyaQb5TI4pzF0 Z7dmn5ZS6B6/D4+RZWKl2A9izI4rvHsY4Cr/M3EzLPanpyJ/QeY2VkbBcMOor12i RKRqWoT4C7IlnLXVgUBJtKN8y+o/76OjHzQElw9pwQE8OQQkiJsfB5nL2VsoYF+P g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej90ax0m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:27 +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 5AL7uBOU004315; Fri, 21 Nov 2025 09:54:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uwd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:26 +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 5AL9rgUo021648; Fri, 21 Nov 2025 09:54:25 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-24; Fri, 21 Nov 2025 09:54:25 +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 23/30] objtool: Disassemble jump table alternatives Date: Fri, 21 Nov 2025 10:53:33 +0100 Message-ID: <20251121095340.464045-24-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=OMAqHCaB c=1 sm=1 tr=0 ts=692036d3 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=AdQ-_Nrh4r4Z-zFpdEsA:9 X-Proofpoint-ORIG-GUID: AX4Igz5VEcn_ZM0bvfo9T8w5htNNrPVW X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX01TxbTD1tiie 0osFJH8KfuE+8HPnA/Uh8BxFZNW6o56MgdYBUpc5ohQuIDEXukz2lyOcSkP/MEuTEKn758UAjX/ 1Jp9vZorg1x27zaDmY+kuHdv7cWhXr4BDSVYVdx6lfQYUR7K2Xxsy8B67cS5EjZ6KXKiU27y0Vc qTo7JYgYjaU82q8xCyRH7/afz5XW+4b3T03uD/raKHFyBd/T5EJs7HTa133XfNKD+i7kC8qniW5 KWx3xFs9snAzaGiuwJo9o0Y9GAKHfnNfx+YvFMqqobwym+woEpphfNucYOtSuTIMQIeNirSZwbb PJNasnTFobRNgfbWZx2X1AvxU753EkFr6/qztzorzdj/XFKZ8rMm6WIxGg1XWBZfwydwOY9zDi5 gG5NcRDaYwviZi58i+jnueSHMIGNcA== X-Proofpoint-GUID: AX4Igz5VEcn_ZM0bvfo9T8w5htNNrPVW Content-Type: text/plain; charset="utf-8" When using the --disas option, also disassemble jump tables. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 018aba37b996b..326e16c9f30a8 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -639,6 +639,34 @@ static int disas_alt_add_insn(struct disas_alt *dalt, = int index, char *insn_str, return 0; } =20 +static int disas_alt_jump(struct disas_alt *dalt) +{ + struct instruction *orig_insn; + struct instruction *dest_insn; + char suffix[2] =3D { 0 }; + char *str; + + orig_insn =3D dalt->orig_insn; + dest_insn =3D dalt->alt->insn; + + if (orig_insn->type =3D=3D INSN_NOP) { + if (orig_insn->len =3D=3D 5) + suffix[0] =3D 'q'; + str =3D strfmt("jmp%-3s %lx <%s+0x%lx>", suffix, + dest_insn->offset, dest_insn->sym->name, + dest_insn->offset - dest_insn->sym->offset); + } else { + str =3D strfmt("nop%d", orig_insn->len); + } + + if (!str) + return -1; + + disas_alt_add_insn(dalt, 0, str, 0); + + return 1; +} + /* * Disassemble an exception table alternative. */ @@ -809,10 +837,7 @@ static void *disas_alt(struct disas_context *dctx, goto done; } =20 - /* - * Only group alternatives and exception tables are - * supported at the moment. - */ + count =3D -1; switch (dalt->alt->type) { case ALT_TYPE_INSTRUCTIONS: count =3D disas_alt_group(dctx, dalt); @@ -820,8 +845,9 @@ static void *disas_alt(struct disas_context *dctx, case ALT_TYPE_EX_TABLE: count =3D disas_alt_extable(dalt); break; - default: - count =3D 0; + case ALT_TYPE_JUMP_TABLE: + count =3D disas_alt_jump(dalt); + break; } if (count < 0) { WARN("%s: failed to disassemble alternative %s", --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 78D4834AB14 for ; Fri, 21 Nov 2025 09:54:36 +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=1763718878; cv=none; b=LzD6L55nOQ0UMeaAJrkabDpMlI4WuSGGR2mUx87oDjtCxXJI+V0OURpsyRaPg+Rn6Uu72NhqslYdaEkJqs8cQNpSxLIAU2x0yiUqKl1C/LZxIgmXewW4eiSYPdRjwxLNtW7WxHe/ErZ5RfDEzmsrpTRKDsDM4GCC+g00KGpYjFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718878; c=relaxed/simple; bh=+V8GrtPKTKMDzjmAow5mqPg998QnTvapVwC4WQpnh2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZaSPtRF8WwblB3Ih9CklG41gAyClTNnrcAN2JpwIrJAr+vV2gq93zmShQNBxylLwLy7u3cESpnY2VDTkeGkxB3a2N+J79JXpr72onSTbKsuQMp+8NdgFkEXSXUlSy5CCWAHCn0biQRknL2qTfLYwTJwAvOUr9FJxS11WF1mpheE= 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=lT8ZRyN4; 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="lT8ZRyN4" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL1uakr015688; Fri, 21 Nov 2025 09:54:29 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=wjq6E CWSIeQCBEREJQ0CYHuWyPifXpXJ2bvL4Cu2AVs=; b=lT8ZRyN47UkyVFyc515Aj BHNOzU4fStVrkINvyMV/YxMMkIHdasDrGGsE3a9zqO6vQrBvdp1w8b0myc+uc/Ke KeaAmJcM0E8F8iuYsHFFWKVXru234qzcvtzk0EYjBi8nuwGL64xtwDWy99n4A9Sp LAXU42OE9UL2CjqVHgKIvNS+49DxUVI3Y3pg1pYBy+c0Jmy/1apkzrQe0QR22TFY gl65TXn5SUKaQUOfKDEdTkY1VGwHsS8/xGG95KxzaXmopjvigX6TkLc0/vMdIphl opyhTzOi1VN8pyRy9LZootV3pwe7rFu6CCPD5SiDCUd6KhNNvBNy1dFR/KvNwS/R g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej96atg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:28 +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 5AL8T30n004363; Fri, 21 Nov 2025 09:54:28 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4ux1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:28 +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 5AL9rgUq021648; Fri, 21 Nov 2025 09:54:27 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-25; Fri, 21 Nov 2025 09:54:27 +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 24/30] objtool: Fix address references in alternatives Date: Fri, 21 Nov 2025 10:53:34 +0100 Message-ID: <20251121095340.464045-25-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=DYoaa/tW c=1 sm=1 tr=0 ts=692036d4 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=YtZ4u2YuLOXz1tegIYEA:9 X-Proofpoint-GUID: RWucRz5PlF5RBJe0Rf3FPaXU01OE4H1x X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX2lQrZ0tvbnWC Y7vrMcpGvY32C9+4gRCTvl7Vzm9oXeiHlbDb6UUNbFY3j9C94eARIll6xe7tk/9q6S+6Hb0dfS5 yJeKCZzO8CJHsKpustfllMbgjJXDwvMEGZm32m6A/P59f4ALPgxCX94Rg60ZMyogAkKN+J6hxgk VZ+FAc5eAdm/v8RlNBGErzVklfLK9RFXuPgiuyBD+HYQii7wVdCME690UavUCGdpPoo2S36/iCv o2rO0syY/55yqYxjOfOqAYxwBGGHjHsTjUIgfCpbHhnIJDq7H8a92G2eriiJV+Jx8djPV9hiWox 96YeUF9W1iBLNO8O3OnarFNxVy1Q0jUABJZg6O2krDVlEXSz+mnCKv7mEulYUFG0nMzvNGtiqrG X1xPKdOdh/CKV0Oybyi+oy6zO79t9w== X-Proofpoint-ORIG-GUID: RWucRz5PlF5RBJe0Rf3FPaXU01OE4H1x Content-Type: text/plain; charset="utf-8" When using the --disas option, alternatives are disassembled but address references in non-default alternatives can be incorrect. The problem is that alternatives are shown as if they were replacing the original code of the alternative. So if an alternative is referencing an address inside the alternative then the reference has to be adjusted to the location of the original code. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 70 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 326e16c9f30a8..f8917c8405d32 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -24,6 +24,7 @@ struct disas_context { struct objtool_file *file; struct instruction *insn; + bool alt_applied; char result[DISAS_RESULT_SIZE]; disassembler_ftype disassembler; struct disassemble_info info; @@ -160,6 +161,43 @@ static void disas_print_addr_sym(struct section *sec, = struct symbol *sym, } } =20 +static bool disas_print_addr_alt(bfd_vma addr, struct disassemble_info *di= nfo) +{ + struct disas_context *dctx =3D dinfo->application_data; + struct instruction *orig_first_insn; + struct alt_group *alt_group; + unsigned long offset; + struct symbol *sym; + + /* + * Check if we are processing an alternative at the original + * instruction address (i.e. if alt_applied is true) and if + * we are referencing an address inside the alternative. + * + * For example, this happens if there is a branch inside an + * alternative. In that case, the address should be updated + * to a reference inside the original instruction flow. + */ + if (!dctx->alt_applied) + return false; + + alt_group =3D dctx->insn->alt_group; + if (!alt_group || !alt_group->orig_group || + addr < alt_group->first_insn->offset || + addr > alt_group->last_insn->offset) + return false; + + orig_first_insn =3D alt_group->orig_group->first_insn; + offset =3D addr - alt_group->first_insn->offset; + + addr =3D orig_first_insn->offset + offset; + sym =3D orig_first_insn->sym; + + disas_print_addr_sym(orig_first_insn->sec, sym, addr, dinfo); + + return true; +} + static void disas_print_addr_noreloc(bfd_vma addr, struct disassemble_info *dinfo) { @@ -167,6 +205,9 @@ static void disas_print_addr_noreloc(bfd_vma addr, struct instruction *insn =3D dctx->insn; struct symbol *sym =3D NULL; =20 + if (disas_print_addr_alt(addr, dinfo)) + return; + if (insn->sym && addr >=3D insn->sym->offset && addr < insn->sym->offset + insn->sym->len) { sym =3D insn->sym; @@ -232,8 +273,9 @@ static void disas_print_address(bfd_vma addr, struct di= sassemble_info *dinfo) */ jump_dest =3D insn->jump_dest; if (jump_dest && jump_dest->sym && jump_dest->offset =3D=3D addr) { - disas_print_addr_sym(jump_dest->sec, jump_dest->sym, - addr, dinfo); + if (!disas_print_addr_alt(addr, dinfo)) + disas_print_addr_sym(jump_dest->sec, jump_dest->sym, + addr, dinfo); return; } =20 @@ -490,13 +532,22 @@ void disas_print_insn(FILE *stream, struct disas_cont= ext *dctx, =20 /* * Disassemble a single instruction. Return the size of the instruction. + * + * If alt_applied is true then insn should be an instruction from of an + * alternative (i.e. insn->alt_group !=3D NULL), and it is disassembled + * at the location of the original code it is replacing. When the + * instruction references any address inside the alternative then + * these references will be re-adjusted to replace the original code. */ -size_t disas_insn(struct disas_context *dctx, struct instruction *insn) +static size_t disas_insn_common(struct disas_context *dctx, + struct instruction *insn, + bool alt_applied) { disassembler_ftype disasm =3D dctx->disassembler; struct disassemble_info *dinfo =3D &dctx->info; =20 dctx->insn =3D insn; + dctx->alt_applied =3D alt_applied; dctx->result[0] =3D '\0'; =20 if (insn->type =3D=3D INSN_NOP) { @@ -515,6 +566,17 @@ size_t disas_insn(struct disas_context *dctx, struct i= nstruction *insn) return disasm(insn->offset, &dctx->info); } =20 +size_t disas_insn(struct disas_context *dctx, struct instruction *insn) +{ + return disas_insn_common(dctx, insn, false); +} + +static size_t disas_insn_alt(struct disas_context *dctx, + struct instruction *insn) +{ + return disas_insn_common(dctx, insn, true); +} + static struct instruction *next_insn_same_alt(struct objtool_file *file, struct alt_group *alt_grp, struct instruction *insn) @@ -706,7 +768,7 @@ static int disas_alt_group(struct disas_context *dctx, = struct disas_alt *dalt) =20 alt_for_each_insn(file, DALT_GROUP(dalt), insn) { =20 - disas_insn(dctx, insn); + disas_insn_alt(dctx, insn); str =3D strdup(disas_result(dctx)); if (!str) return -1; --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 44A0D34B1A6 for ; Fri, 21 Nov 2025 09:54:37 +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=1763718878; cv=none; b=hW5TyYl0Bsq2texNgMcA7Np7XpV0pCnn2O4hhaCeh/HZBufqwavLSTFOQjenqGx8Me3n5PeH67iGrwdpZHFOw1PFez5Crh7/Fi3ICm47cUtHBSA2K0EUVvzTzxxbAuSxOZGVlw9aiMygPwrpMr2eRjpvF5Dhog38riYJyu0MCOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718878; c=relaxed/simple; bh=pdxEiZdMkwdFgBnIeb+S5BsPE/KqcplJ6rjPO1rjHSs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TzPB1EsO+DbkI8r9g/vMDCzOqC3y07CsTnpP0GnR2sXpLkE9LxFNqfFbbn0PMr+REpgLRBlxie5j8XYojWnktutoMZvUvqiPdlQX0LxIMqr/C8a5lM8kwKDCeTD2TwAQsBw8qAkUNmuC5Iaok9RcBWWrpkwyD+nYWUPbUOmD0+M= 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=GvdS3nBt; 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="GvdS3nBt" 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 5AL1usx0018570; Fri, 21 Nov 2025 09:54:31 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=bOZ6s Y/iY5ZyfDO1paHU4rBJMOX/jxuO8yWY61yRy3I=; b=GvdS3nBtsjNeWGseaHb8O w78Bh4Ju/JtFh1mLBqM4q7nsrrgPGzAAZ1TZYTvaqoL7cNR59LUJGmGjSksKkbhs Ls+TC3AfhLFUoTwcbj/sqQqjXOSSuvihVYz8Pwh6UW5n4P9vmCBYRB2EBRdtLjgR j/zSEMQYEEqlljTtrE8z7rLoaEHm8W+oNtSAAADkKEMtItZKjiZZMhu3QA79Fgqz zqD30vAOdtRJcU9G3i2jkWcc9EhZt0Y0kA8qnNiz+CKK6EqzIvXTgZ287pGIDwv8 ZRtkgxB/m99fK5CYqKbq8KAhKHTkF66idCsazoDihXhe5Scr7ayeVZyX3LpIFaFa 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 4aejd1jtsc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:30 +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 5AL9i7k6004267; Fri, 21 Nov 2025 09:54:30 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uxs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:30 +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 5AL9rgUs021648; Fri, 21 Nov 2025 09:54:29 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-26; Fri, 21 Nov 2025 09:54:29 +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 25/30] objtool: Provide access to feature and flags of group alternatives Date: Fri, 21 Nov 2025 10:53:35 +0100 Message-ID: <20251121095340.464045-26-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: HDM0lR-Ni6SDoa_xHjz4frTRReJpdOdw X-Authority-Analysis: v=2.4 cv=Z/jh3XRA c=1 sm=1 tr=0 ts=692036d6 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=OMdgKRDbd2JaGKt5H5wA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfXzMLcBSxJTHdE 7gsvGo9dxR8C0XuQHCKT0D9xFd7Ldyiy99//zWe4ZPcV1un4D1FaNwbpMktxa5BpLhisgd5NEFg fmlMxpgk4iHS6vP06360suHQdK2fqPfZ/0XSKRc60T4Q9fTmcssVqM1bnxhVpxvAHfrCRPxR/w+ QTDQI0gMAzlBxqbm3PCzysuh2t0x/je9SfXYJEFCnFxteppCEnbT3ZomuZU2j+OoPvNsju9A5SQ 7GC7G1XqZIaOMO/ld8FFPV81HSWIFpwdhixTuT3HLv0FDy5PO5UOBTyjopzRXP5H+Nzna79msFD xvaYr/xS0VcNy8t7yGvn7TGcWSepZUJ/uTYSbjBLh4aSk4Qny9qV8gRnVLBEnJqNbwdf4OrXdCB ovW0vsMPIuH4uYzOUA9X23Gg52W32A== X-Proofpoint-ORIG-GUID: HDM0lR-Ni6SDoa_xHjz4frTRReJpdOdw Content-Type: text/plain; charset="utf-8" Each alternative of a group alternative depends on a specific feature and flags. Provide access to the feature/flags for each alternative as an attribute (feature) in struct alt_group. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 2 ++ tools/objtool/include/objtool/check.h | 1 + tools/objtool/include/objtool/special.h | 2 +- tools/objtool/special.c | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 25839c3950a3c..ddc5ec74d9c99 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1772,6 +1772,7 @@ static int handle_group_alt(struct objtool_file *file, orig_alt_group->last_insn =3D last_orig_insn; orig_alt_group->nop =3D NULL; orig_alt_group->ignore =3D orig_insn->ignore_alts; + orig_alt_group->feature =3D 0; } else { if (orig_alt_group->last_insn->offset + orig_alt_group->last_insn->len - orig_alt_group->first_insn->offset !=3D special_alt->orig_len) { @@ -1876,6 +1877,7 @@ static int handle_group_alt(struct objtool_file *file, new_alt_group->nop =3D nop; new_alt_group->ignore =3D (*new_insn)->ignore_alts; new_alt_group->cfi =3D orig_alt_group->cfi; + new_alt_group->feature =3D special_alt->feature; return 0; } =20 diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index cbf4af58e29b2..2e1346ad5e926 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -36,6 +36,7 @@ struct alt_group { struct cfi_state **cfi; =20 bool ignore; + unsigned int feature; }; =20 enum alternative_type { diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/includ= e/objtool/special.h index 72d09c0adf1a1..b22410745e4a1 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -25,7 +25,7 @@ struct special_alt { struct section *new_sec; unsigned long new_off; =20 - unsigned int orig_len, new_len; /* group only */ + unsigned int orig_len, new_len, feature; /* group only */ }; =20 int special_get_alts(struct elf *elf, struct list_head *alts); diff --git a/tools/objtool/special.c b/tools/objtool/special.c index e262af9171436..2a533afbc69aa 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -81,6 +81,8 @@ static int get_alt_entry(struct elf *elf, const struct sp= ecial_entry *entry, entry->orig_len); alt->new_len =3D *(unsigned char *)(sec->data->d_buf + offset + entry->new_len); + alt->feature =3D *(unsigned int *)(sec->data->d_buf + offset + + entry->feature); } =20 orig_reloc =3D find_reloc_by_dest(elf, sec, offset + entry->orig); --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 9527434C123 for ; Fri, 21 Nov 2025 09:54:39 +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=1763718881; cv=none; b=SZRtJb5FggjZL8mWmUSXRNY5B++HdA/GQI7zqaELHvVqyBW2wDprXLsfQZGTAZO/qS5HaiPZi3/aFDkfR6aC9xl43bUuac+VAFmpj6A/mJtj9BWc992BIIPM8eFmnVJU6P61j2CdKied/EZ9OscTOu2RxDAP9DQV9H0LB6yEZzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718881; c=relaxed/simple; bh=mkTSat9T0TXUZhCk0DRFnZ/bVGDiC9bN6Y8k+oLfKGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T09zh1jxSvTJ+xa79t6VbvwD3qwscP+OnynGDiaFEYo7vq+FJvm0AOoJDHT7bmxjCk2uk/7I+n6LJCqRvgZhxMa/tpQjQYMTTIJCacq1TLwpBvu8/Wup1YgA6R0Tgh/6vQrsGbN4sE7oKv9Clm8uDBIOazTSq4Yz/KZP+kWeVH0= 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=bOq+XNVZ; 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="bOq+XNVZ" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL1wUIH007472; Fri, 21 Nov 2025 09:54:33 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=NzRLi 7y50Qfmsqt99Mh3K31v75M9OR3yLrxv0EtfNVY=; b=bOq+XNVZgPZ/H9uBKMYUt G7/w+5E0pDdCi/CVYGpMmva0aKmVIRlh5j5tPQ49m3piipoA2Xu4ohN9RdvM3COE IgqQQxU6NsYs9BstNKFHZl4UUTCgm9zUDEEwSYxLXxammiJodQCMEBMz/5FptsuC zJJeLtN8FrXOlRPcLq+eJP+Xf+3gHqDM4AEJPOZYD0qVE1ewyTmiYd28y4OeVNrV CG+o2oI2Qlz6GSnE0Kcat7z+NU7exPeKQtB05F7b3J6hJXc4wgUmV4Po9BSvQz44 8723XWfyXiYl3g1QPtHQvapVLOEaIFR5GSykMzpv/oHTehyFkw96xuYGacg3o8FY 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 4aejbq2w49-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:32 +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 5AL9pSQS004274; Fri, 21 Nov 2025 09:54:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4uyp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:31 +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 5AL9rgUu021648; Fri, 21 Nov 2025 09:54:31 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-27; Fri, 21 Nov 2025 09:54:31 +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 26/30] objtool: Function to get the name of a CPU feature Date: Fri, 21 Nov 2025 10:53:36 +0100 Message-ID: <20251121095340.464045-27-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-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX7Qv8x8CU2qwy PalBo2bcAer4NIYYY4oMkAfWInOqjwDQ0E3+GKGkAUxEvdTVZVNwDdqbsvZXHdleuBz0eLUatoc EN0jONXFVR6JctGg3OF3wD5fg58xHlcL0X6swL+LscjbTVJcvPL6bZswjMqQ83zZ0jb8wEzafhj sdLquIlOxHQfBqgc6i2yPp4f/YJxFrW5eodMUQx2qZ6YGm8XfOosoWD+fvV4+WEaC0aVstu1eYJ 9JKxEkH4vsvoq9nJui0dZzOlKhwxlSub8TC319fs5t6HwuEDSj+nGaHKYw6OCV5h71UGkDsyGIB 8SzJPp3e0XthGwLEUILtgY7hSBipwQgsrXnVWeMP88FFRoQaGB8m03uW4RF9X/YI6nUz2KJUN5E 61q/aaYnqBPCKZV19tRG/FNuZ3HNLg== X-Proofpoint-ORIG-GUID: VGCj73orxFZlvpIDiZ4RsGL6cLPwfX3c X-Proofpoint-GUID: VGCj73orxFZlvpIDiZ4RsGL6cLPwfX3c X-Authority-Analysis: v=2.4 cv=a+o9NESF c=1 sm=1 tr=0 ts=692036d8 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=BmP2q_L__UogPSo-:21 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=pMlTRUUgVTb7_b65wjsA:9 Content-Type: text/plain; charset="utf-8" Add a function to get the name of a CPU feature. The function is architecture dependent and currently only implemented for x86. The feature names are automatically generated from the cpufeatures.h include file. Signed-off-by: Alexandre Chartre --- .../x86/tools/gen-cpu-feature-names-x86.awk | 33 +++++++++++++++++++ tools/objtool/.gitignore | 1 + tools/objtool/Makefile | 1 + tools/objtool/arch/loongarch/special.c | 5 +++ tools/objtool/arch/powerpc/special.c | 5 +++ tools/objtool/arch/x86/Build | 8 +++++ tools/objtool/arch/x86/special.c | 10 ++++++ tools/objtool/include/objtool/special.h | 2 ++ 8 files changed, 65 insertions(+) create mode 100644 tools/arch/x86/tools/gen-cpu-feature-names-x86.awk diff --git a/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk b/tools/arc= h/x86/tools/gen-cpu-feature-names-x86.awk new file mode 100644 index 0000000000000..1b1c1d84225c2 --- /dev/null +++ b/tools/arch/x86/tools/gen-cpu-feature-names-x86.awk @@ -0,0 +1,33 @@ +#!/bin/awk -f +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2025, Oracle and/or its affiliates. +# +# Usage: awk -f gen-cpu-feature-names-x86.awk cpufeatures.h > cpu-feature-= names.c +# + +BEGIN { + print "/* cpu feature name array generated from cpufeatures.h */" + print "/* Do not change this code. */" + print + print "static const char *cpu_feature_names[(NCAPINTS+NBUGINTS)*32] =3D {" + + feature_expr =3D "(X86_FEATURE_[A-Z0-9_]+)\\s+\\(([0-9*+ ]+)\\)" + debug_expr =3D "(X86_BUG_[A-Z0-9_]+)\\s+X86_BUG\\(([0-9*+ ]+)\\)" +} + +/^#define X86_FEATURE_/ { + if (match($0, feature_expr, m)) { + print "\t[" m[2] "] =3D \"" m[1] "\"," + } +} + +/^#define X86_BUG_/ { + if (match($0, debug_expr, m)) { + print "\t[NCAPINTS*32+(" m[2] ")] =3D \"" m[1] "\"," + } +} + +END { + print "};" +} diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore index 759303657bd7c..73d883128511f 100644 --- a/tools/objtool/.gitignore +++ b/tools/objtool/.gitignore @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only +arch/x86/lib/cpu-feature-names.c arch/x86/lib/inat-tables.c /objtool feature diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index df793ca6fc1a1..66397d755fe4b 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -125,6 +125,7 @@ $(LIBSUBCMD)-clean: clean: $(LIBSUBCMD)-clean $(call QUIET_CLEAN, objtool) $(RM) $(OBJTOOL) $(Q)find $(OUTPUT) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -nam= e '\.*.d' -delete + $(Q)$(RM) $(OUTPUT)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep $(Q)$(RM) $(OUTPUT)arch/x86/lib/inat-tables.c $(OUTPUT)fixdep $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.objtool $(Q)$(RM) -r -- $(OUTPUT)feature diff --git a/tools/objtool/arch/loongarch/special.c b/tools/objtool/arch/lo= ongarch/special.c index a80b75f7b061f..aba774109437f 100644 --- a/tools/objtool/arch/loongarch/special.c +++ b/tools/objtool/arch/loongarch/special.c @@ -194,3 +194,8 @@ struct reloc *arch_find_switch_table(struct objtool_fil= e *file, =20 return rodata_reloc; } + +const char *arch_cpu_feature_name(int feature_number) +{ + return NULL; +} diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powe= rpc/special.c index 51610689abf72..8f9bf61ca0899 100644 --- a/tools/objtool/arch/powerpc/special.c +++ b/tools/objtool/arch/powerpc/special.c @@ -18,3 +18,8 @@ struct reloc *arch_find_switch_table(struct objtool_file = *file, { exit(-1); } + +const char *arch_cpu_feature_name(int feature_number) +{ + return NULL; +} diff --git a/tools/objtool/arch/x86/Build b/tools/objtool/arch/x86/Build index 3dedb2fd8f3a0..1067355361b56 100644 --- a/tools/objtool/arch/x86/Build +++ b/tools/objtool/arch/x86/Build @@ -11,4 +11,12 @@ $(OUTPUT)arch/x86/lib/inat-tables.c: $(inat_tables_scrip= t) $(inat_tables_maps) =20 $(OUTPUT)arch/x86/decode.o: $(OUTPUT)arch/x86/lib/inat-tables.c =20 +cpu_features =3D ../arch/x86/include/asm/cpufeatures.h +cpu_features_script =3D ../arch/x86/tools/gen-cpu-feature-names-x86.awk + +$(OUTPUT)arch/x86/lib/cpu-feature-names.c: $(cpu_features_script) $(cpu_fe= atures) + $(Q)$(call echo-cmd,gen)$(AWK) -f $(cpu_features_script) $(cpu_features) = > $@ + +$(OUTPUT)arch/x86/special.o: $(OUTPUT)arch/x86/lib/cpu-feature-names.c + CFLAGS_decode.o +=3D -I$(OUTPUT)arch/x86/lib diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 09300761f1085..b6b40c56da896 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -4,6 +4,10 @@ #include #include #include +#include + +/* cpu feature name array generated from cpufeatures.h */ +#include "lib/cpu-feature-names.c" =20 void arch_handle_alternative(struct special_alt *alt) { @@ -134,3 +138,9 @@ struct reloc *arch_find_switch_table(struct objtool_fil= e *file, *table_size =3D 0; return rodata_reloc; } + +const char *arch_cpu_feature_name(int feature_number) +{ + return (feature_number < ARRAY_SIZE(cpu_feature_names)) ? + cpu_feature_names[feature_number] : NULL; +} diff --git a/tools/objtool/include/objtool/special.h b/tools/objtool/includ= e/objtool/special.h index b22410745e4a1..121c3761899c1 100644 --- a/tools/objtool/include/objtool/special.h +++ b/tools/objtool/include/objtool/special.h @@ -38,4 +38,6 @@ bool arch_support_alt_relocation(struct special_alt *spec= ial_alt, struct reloc *arch_find_switch_table(struct objtool_file *file, struct instruction *insn, unsigned long *table_size); +const char *arch_cpu_feature_name(int feature_number); + #endif /* _SPECIAL_H */ --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 32DB834CFA7 for ; Fri, 21 Nov 2025 09:54:41 +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=1763718883; cv=none; b=fjyb6cSFPYG3MjFKgxQroudgQewymhR7B8RuILaMIP39yCLcykLft3s4Vt1iUZtJZGmsL3DZQUu/9p9huKp2Zh6bapVfXguXdjJz/BZVjzEwphe4MTEe4A8mGZFHbUsuFqMuMNtkTokmOz6HKp1hd7XRAy5v5WxvxghqJnTGGx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718883; c=relaxed/simple; bh=j0UFQe/zatzGyV/XI0TBtLjfIPSfPmjVlSCrJkq8fwU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OMY4r7MV1AfWN5Dgr3T8jAh+7qzIZLxHfzRElRpJ00X/K3T8Cx7GDooedeOcN5M+wrubTY2sclSw3SYwYjR4RNIZNt2zeecFPG6kOy9WeyNYqg0E38knZCkGOwqJyx/y9LcHQatdaB12zE+qgDXrkZ8D62AOPbr/2kAv81sCuK4= 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=APYo/BcB; 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="APYo/BcB" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL2e7g5011486; Fri, 21 Nov 2025 09:54:34 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=/kuhG To8sDWyQRCvOpw7TWxtCfp+nNZhJlYPvbbuVwk=; b=APYo/BcBl+jw9G0hHp4Yi grxaC+4y6cy1Ky5DPpsfp5z1kvmc41v+1Kk+f/bHxYw2pR4Pb/U9xWOB1Njdy6Vv aqhFb0btiENDiOniCIYTSN9wN+AWgN0BnPhpj2oKvhA99WYR8m5fC5JBVSlkMbVR Lm0nXPa7E0NyOXI+a8xfcc5YkIQm4tn9UuLrVQTIZilofyEUp6rxZMl4I4xrSviU mTrd5N43OmdUfP+rZqQZwYbNNRWLZ8j+A+fDrt9zwRaBAS4fAr6flwqV4wOjYseL zFLfya+mguySAq/BAWddg9Q11yZ6sfUSW8gnbktp8tvGjd12yIFhwAkI+JKDHU1w 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 4aej96atgc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:34 +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 5AL7uBOV004315; Fri, 21 Nov 2025 09:54:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4v0d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:33 +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 5AL9rgUw021648; Fri, 21 Nov 2025 09:54:33 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-28; Fri, 21 Nov 2025 09:54:33 +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 27/30] objtool: Improve naming of group alternatives Date: Fri, 21 Nov 2025 10:53:37 +0100 Message-ID: <20251121095340.464045-28-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=DYoaa/tW c=1 sm=1 tr=0 ts=692036da cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=NTSbjWyVqMqnbLcvqKcA:9 X-Proofpoint-GUID: -GYeDqLTB2z87co18IffxJtosKmTBpZ0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX2VzkNadGbJfh PsajjRdtH7zhPpXR77shg6+m4v8Hi06Phtp2Wca042Tv2uMXzn0cZDeBty37d7MiZpXP55qd0ch Z6iDQFx+liGlg+RHvokp9Bd2E531GiKHHThv2xFBQZF5pdvRZj85dWOVXAKxO2rBBociYqJggrj 3EDB7cQbmQjg4qQSq4qI3ChjmfLwFu5Pn4AZj/m5snMIKDI+np+8TW8P6yRFu/jblDsNW7I3sQM B0KaaJMcAXJLufdo+VMNemBxzrvFWRvPOI0tNUNNNAFHMIcAJpWZHaRpE7YQx9q10ZYe4j2OaqN eyDy/zCC87g5aodHgRiRB6TMOU63PDU2tu5p2xYSIQIgPpTSbahsxGACkL76uGN5iklTKCb2mqf n6I2kIjuT8McLpRSfxqw73W/XZswLA== X-Proofpoint-ORIG-GUID: -GYeDqLTB2z87co18IffxJtosKmTBpZ0 Content-Type: text/plain; charset="utf-8" Improve the naming of group alternatives by showing the feature name and flags used by the alternative. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 58 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index f8917c8405d32..731c4495b53c7 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -9,6 +9,7 @@ #include #include #include +#include #include =20 #include @@ -60,6 +61,21 @@ struct disas_alt { #define DALT_GROUP(dalt) (DALT_INSN(dalt)->alt_group) #define DALT_ALTID(dalt) ((dalt)->orig_insn->offset) =20 +#define ALT_FLAGS_SHIFT 16 +#define ALT_FLAG_NOT (1 << 0) +#define ALT_FLAG_DIRECT_CALL (1 << 1) +#define ALT_FEATURE_MASK ((1 << ALT_FLAGS_SHIFT) - 1) + +static int alt_feature(unsigned int ft_flags) +{ + return (ft_flags & ALT_FEATURE_MASK); +} + +static int alt_flags(unsigned int ft_flags) +{ + return (ft_flags >> ALT_FLAGS_SHIFT); +} + /* * Wrapper around asprintf() to allocate and format a string. * Return the allocated string or NULL on error. @@ -635,7 +651,12 @@ const char *disas_alt_type_name(struct instruction *in= sn) */ char *disas_alt_name(struct alternative *alt) { + char pfx[4] =3D { 0 }; char *str =3D NULL; + const char *name; + int feature; + int flags; + int num; =20 switch (alt->type) { =20 @@ -649,13 +670,37 @@ char *disas_alt_name(struct alternative *alt) =20 case ALT_TYPE_INSTRUCTIONS: /* - * This is a non-default group alternative. Create a unique - * name using the offset of the first original and alternative - * instructions. + * This is a non-default group alternative. Create a name + * based on the feature and flags associated with this + * alternative. Use either the feature name (it is available) + * or the feature number. And add a prefix to show the flags + * used. + * + * Prefix flags characters: + * + * '!' alternative used when feature not enabled + * '+' direct call alternative + * '?' unknown flag */ - asprintf(&str, "ALTERNATIVE %lx.%lx", - alt->insn->alt_group->orig_group->first_insn->offset, - alt->insn->alt_group->first_insn->offset); + + feature =3D alt->insn->alt_group->feature; + num =3D alt_feature(feature); + flags =3D alt_flags(feature); + str =3D pfx; + + if (flags & ~(ALT_FLAG_NOT | ALT_FLAG_DIRECT_CALL)) + *str++ =3D '?'; + if (flags & ALT_FLAG_DIRECT_CALL) + *str++ =3D '+'; + if (flags & ALT_FLAG_NOT) + *str++ =3D '!'; + + name =3D arch_cpu_feature_name(num); + if (!name) + str =3D strfmt("%sFEATURE 0x%X", pfx, num); + else + str =3D strfmt("%s%s", pfx, name); + break; } =20 @@ -892,6 +937,7 @@ static void *disas_alt(struct disas_context *dctx, WARN("%s has more alternatives than supported", alt_name); break; } + dalt =3D &dalts[i]; err =3D disas_alt_init(dalt, orig_insn, alt); if (err) { --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 BC7E934B1A6 for ; Fri, 21 Nov 2025 09:54:42 +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=1763718884; cv=none; b=jVxpFQs4vxZ1g782va3ajOuSfBJZ/ozxQm+fRaLyYqASGyVkDFYAcMzYVcdxA27U/M/mm20MRvkLsLtKKrtV+SPIK/Pgj/9oM0+sj4g5UNzn2lSAiU4ul8+UWV2l/A8lh/jAirgpCDs/l9b86ZaY0CIa9QmkH81axln6cjSP9uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718884; c=relaxed/simple; bh=bJrU0v15i68NWxbfSFEiqQ6IK3kd0rHoV26uN49ZtLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nsVDpfHW53fykl42vlqwCgeOIal8O1E7Ntor2eLl4BZUsek7JdI84NFwpWn9ODMPv8MyIECTh+cizxSjROLcqMb8bJo2PCGct36lrwZ9Khqc84UHf5cdl40k0tAg9iy/Jn7SMAyiHz4wjHS+s27Df/RP+FNj73IR0nxyUHuQsNk= 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=jPUpdLK5; 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="jPUpdLK5" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL1vTu6032720; Fri, 21 Nov 2025 09:54:36 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=gDFAF NT+czOlxrsSeEW+rT6Hi2+OtuUa9itEXh07WtY=; b=jPUpdLK5zh6BWVHeY5yde mrQnK6+jZPugtZfTyDzhOF+Ha/6IO9t3wBOQo8Mw1JbyCFfIT7KfDasp8tS2lUKH QayFBgdMaO9LD8GA/t2zzqoZoZ/m/chyED+z2tZT+SCKfC0mEfkjO+TaRccK5xAz kYmwF2FrpNtmrW9UN6cKsmdBEAhJlIdQTSgK0QxsiO0APC4Yubm30k7vsr73ylNp 2TFGK39mXH8gYX4+ctRNzEAjDPdW9I9HQ8dMySkF4l0bNkFl04op9J5PMExbfy+O 3yVOHO5MqXeYCPpkhuhaxxHHcQWxXHnwxh0d/XtpxsUba8q3kNtgmTcislWXCHyA 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 4aejbutn83-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:36 +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 5AL9sED4004512; Fri, 21 Nov 2025 09:54:35 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4v0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:35 +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 5AL9rgV0021648; Fri, 21 Nov 2025 09:54:35 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-29; Fri, 21 Nov 2025 09:54:34 +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 28/30] objtool: Compact output for alternatives with one instruction Date: Fri, 21 Nov 2025 10:53:38 +0100 Message-ID: <20251121095340.464045-29-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-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX2WmdVENsKvat 0dMLjiTP5/BaDCau+ATC8trPgvBQzajJEBdGmmAweNjTAzQMbCG0tMghj3KGnG07DYCEPVjQco6 fcs4JWqbyWmh58zx6gsODbcLfCO3d8NV9Q7X3y8u6iiRrv/vckD/0EmhM/sE0DdYRfFWYAU7wrX pp9QnwX36TxKY2bG5xhE35Ih+ihsBK0uEddrYGMUwJ6tlG/CKegMd7bFl5rbHfDI+u+ZCSRmpMA U0DBa/MdQAct8pPE/pLfi9PTfpKWs/dHc+cEJ8j2dN04GKjY2rqXNWfecRMcmLks2RCbJ6m4i/n vTCXEjHpxPXvKucfdrPV1w9Hxc2SwNBhr/2EENVvUbc4R0SC95f2GdBQz/GSFcUve5J6hy/yWC3 0PzKjBkRTXeltnKGOHGp+s1MKnuLfA== X-Proofpoint-GUID: jtuzeD0kLBzle-2LEKX7HKc-rkxq4fkG X-Proofpoint-ORIG-GUID: jtuzeD0kLBzle-2LEKX7HKc-rkxq4fkG X-Authority-Analysis: v=2.4 cv=Rdydyltv c=1 sm=1 tr=0 ts=692036dc cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=eaZXao46RdKAZoVW1j8A:9 Content-Type: text/plain; charset="utf-8" When disassembling, if an instruction has alternatives which are all made of a single instruction then print each alternative on a single line (instruction + description) so that the output is more compact. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 731c4495b53c7..a4f905eac4e63 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -863,6 +863,7 @@ static void disas_alt_print_compact(char *alt_name, str= uct disas_alt *dalts, int alt_count, int insn_count) { struct instruction *orig_insn; + int width; int i, j; int len; =20 @@ -871,6 +872,27 @@ static void disas_alt_print_compact(char *alt_name, st= ruct disas_alt *dalts, len =3D disas_print(stdout, orig_insn->sec, orig_insn->offset, 0, NULL); printf("%s\n", alt_name); =20 + /* + * If all alternatives have a single instruction then print each + * alternative on a single line. Otherwise, print alternatives + * one above the other with a clear separation. + */ + + if (insn_count =3D=3D 1) { + width =3D 0; + for (i =3D 0; i < alt_count; i++) { + if (dalts[i].width > width) + width =3D dalts[i].width; + } + + for (i =3D 0; i < alt_count; i++) { + printf("%*s=3D %-*s (if %s)\n", len, "", width, + dalts[i].insn[0].str, dalts[i].name); + } + + return; + } + for (i =3D 0; i < alt_count; i++) { printf("%*s=3D %s\n", len, "", dalts[i].name); for (j =3D 0; j < insn_count; j++) { --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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 DB71334D382 for ; Fri, 21 Nov 2025 09:54:44 +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=1763718886; cv=none; b=Gqf95uYMTDIdeyCxdJ/EpicaJ8fFNHWVFc5PzVB3BfRLt/mwdS4HFCLxPFtGSisLq5YaaOENPES+ZZPP6N3T2JOrd01hjU5PEWwaG5CHJ0AYsgjxpyxX0z8qDhcDetCTu+xisZN96/ixTnOV17hK+ctKoRfE0Kflm7oJIyGvN+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763718886; c=relaxed/simple; bh=+r/2Hr+jrGYm50/IqRhI1RVGbgq/iE28DdKqzy4ujec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m1q6UI46BHGwAYHUAvjBsZksjcdh7QRqz8KNTEhKx79xWDFoWspJnvTgT5WRcPxGAtVupvzdOwzsYuEc/Hznae8MGSvBzD3NP9bUHzzQ6Z+rXxnvwaZX2SJEytafdzD1rykiYYepfxHtVnePdw1hSyldkNpLfxxEaSimtVcvgLw= 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=lx5q02RN; 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="lx5q02RN" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AL3WkBV021210; Fri, 21 Nov 2025 09:54:38 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=4puCA yG2mdzr3fE9NDstitoSNl84omIWbI3hFzgiGRk=; b=lx5q02RNpIDIiLqIJmJcg WMinJ3RiydMgqHtOzKYi3QnfqB9iBtWfFgBMOyC1pPFmXr2B0oiDdKDtJ2usmb02 fnCFKtA1yXh3tv6RNJUcIIiVmEGzLSdVruRuj3TguJ+1DLX+F6bxQ6X3th0jipuY EUk0kUfhTMjDbhkS/iGFjKLsHWVBUboI0hZrS//BDRYArMenMv9hO6zUtvx5bjvK kaDvrDXH/jXW2winVzMi2B2pz9R9yX91PR0qEvhiBNSLuDpjGyru4OGr7DyA9dHG RaLfz0Mb4NjvVQnhRRFFqWlnyOhOyvabUjd5DoP33fCImopDq+9p4Nv5MM/G7aEH Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej96atgh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:38 +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 5AL7t9bR004348; Fri, 21 Nov 2025 09:54:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyd4v1m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Nov 2025 09:54:37 +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 5AL9rgV2021648; Fri, 21 Nov 2025 09:54:37 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-30; Fri, 21 Nov 2025 09:54:36 +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 29/30] objtool: Add wide output for disassembly Date: Fri, 21 Nov 2025 10:53:39 +0100 Message-ID: <20251121095340.464045-30-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=DYoaa/tW c=1 sm=1 tr=0 ts=692036de cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=L9MrgM4xBs1gnZH-f1IA:9 X-Proofpoint-GUID: aQuq9Cdv0swYADPPwX6FiXt8lsMchSup X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX1uzC6wuBe++y 5DINdzfOyWuQbj+3Zdc2/kpgsrM4ojwnTnpnJocwN9qgNU+AaEU5tVNJB5EU82ctdnVgIPjqItc 1wTa5mrizpK5jYFjhxPvL4kDKmHR+p8XyiyoQDvSap4CbfwK+2bpbyasGA5nMHJJudRdRjJof3M 0KEGnDfObFyagCp1nDc6PjBcFZcXrZcwiJrS9WWO3mJBMvle3bcSG/3nzVA4EX+TlFizvtozpk6 8VE/rW9QoeZamp7A+cXFXcLZWa/g/0ziWHjp0jwkOUxSbQdWxM2cRHba55jgQ6xVC4B4bQRMxad 9EKpG70C+EmbQArH40481DGg4bT5zxJkhWiyqwQqcaezdW99I6u9eNVjQf/MLFf1Le1umxGRPhs gOLBjGyN3uzLNFvJqX8mw7XrD6CTeQ== X-Proofpoint-ORIG-GUID: aQuq9Cdv0swYADPPwX6FiXt8lsMchSup Content-Type: text/plain; charset="utf-8" Add the --wide option to provide a wide output when disassembling. With this option, the disassembly of alternatives is displayed side-by-side instead of one above the other. Signed-off-by: Alexandre Chartre --- tools/objtool/builtin-check.c | 1 + tools/objtool/disas.c | 95 ++++++++++++++++++++++++- tools/objtool/include/objtool/builtin.h | 1 + 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index a0371312fe55a..b780df5137152 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -107,6 +107,7 @@ static const struct option check_options[] =3D { OPT_STRING(0, "trace", &opts.trace, "func", "trace function validation"= ), OPT_BOOLEAN('v', "verbose", &opts.verbose, "verbose warnings"), OPT_BOOLEAN(0, "werror", &opts.werror, "return error on warnings"), + OPT_BOOLEAN(0, "wide", &opts.wide, "wide output"), =20 OPT_END(), }; diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index a4f905eac4e63..f04bc14bef39e 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -856,6 +856,95 @@ static int disas_alt_default(struct disas_context *dct= x, struct disas_alt *dalt) return 1; } =20 +/* + * For each alternative, if there is an instruction at the specified + * offset then print this instruction, otherwise print a blank entry. + * The offset is an offset from the start of the alternative. + * + * Return the offset for the next instructions to print, or -1 if all + * instructions have been printed. + */ +static int disas_alt_print_insn(struct disas_alt *dalts, int alt_count, + int insn_count, int offset) +{ + struct disas_alt *dalt; + int offset_next; + char *str; + int i, j; + + offset_next =3D -1; + + for (i =3D 0; i < alt_count; i++) { + dalt =3D &dalts[i]; + j =3D dalt->insn_idx; + if (j =3D=3D -1) { + printf("| %-*s ", dalt->width, ""); + continue; + } + + if (dalt->insn[j].offset =3D=3D offset) { + str =3D dalt->insn[j].str; + printf("| %-*s ", dalt->width, str ?: ""); + if (++j < insn_count) { + dalt->insn_idx =3D j; + } else { + dalt->insn_idx =3D -1; + continue; + } + } else { + printf("| %-*s ", dalt->width, ""); + } + + if (dalt->insn[j].offset > 0 && + (offset_next =3D=3D -1 || + (dalt->insn[j].offset < offset_next))) + offset_next =3D dalt->insn[j].offset; + } + printf("\n"); + + return offset_next; +} + +/* + * Print all alternatives side-by-side. + */ +static void disas_alt_print_wide(char *alt_name, struct disas_alt *dalts, = int alt_count, + int insn_count) +{ + struct instruction *orig_insn; + int offset_next; + int offset; + int i; + + orig_insn =3D dalts[0].orig_insn; + + /* + * Print an header with the name of each alternative. + */ + disas_print_info(stdout, orig_insn, -2, NULL); + + if (strlen(alt_name) > dalts[0].width) + dalts[0].width =3D strlen(alt_name); + printf("| %-*s ", dalts[0].width, alt_name); + + for (i =3D 1; i < alt_count; i++) + printf("| %-*s ", dalts[i].width, dalts[i].name); + + printf("\n"); + + /* + * Print instructions for each alternative. + */ + offset_next =3D 0; + do { + offset =3D offset_next; + disas_print(stdout, orig_insn->sec, orig_insn->offset + offset, + -2, NULL); + offset_next =3D disas_alt_print_insn(dalts, alt_count, insn_count, + offset); + } while (offset_next > offset); +} + /* * Print all alternatives one above the other. */ @@ -993,7 +1082,11 @@ static void *disas_alt(struct disas_context *dctx, /* * Print default and non-default alternatives. */ - disas_alt_print_compact(alt_name, dalts, alt_count, insn_count); + + if (opts.wide) + disas_alt_print_wide(alt_name, dalts, alt_count, insn_count); + else + disas_alt_print_compact(alt_name, dalts, alt_count, insn_count); =20 last_insn =3D orig_insn->alt_group ? orig_insn->alt_group->last_insn : orig_insn; diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index e3af664864f30..b9e229ed4dc05 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -45,6 +45,7 @@ struct opts { const char *trace; bool verbose; bool werror; + bool wide; }; =20 extern struct opts opts; --=20 2.43.5 From nobody Tue Dec 2 01:28:38 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