From nobody Sun Feb 8 08:48:45 2026 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 9006123909F for ; Wed, 12 Nov 2025 16:04:06 +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=1762963448; cv=none; b=AN1zhvq/kwQqDeyHZpJ7nrFKQ7E+7aCCbZD6GygqB3JR7O8bSGojCuqonCIm9YbTWwmZciT3IoVssMYgHwu0VTvDui4NHoG8biCeFhHbZUtzRNqL/qCoG/Mg2YmlGn52B+M4gPbCin9UdcxsbKPNInMWQ4g2gsgeuEFBrvT1vRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963448; c=relaxed/simple; bh=NW9ODej7ximkTYrc6vBqdXhJRqxG5v0OGwgjDFKhrUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VLdrLFN+tQlZhbaPIZZybG+QjQ/q5Gsd36EweDH4rzQ/HXsj48NOtPeDsflyp/ljR9bhdlx9YB1O0Kw879ZzOHWabJR5vHPIbkoZE0ALQkBJ0IBHrc1KEhA0Mn2LAwVg8fa5kuLJiGj1NluhGbS4clxdCcMXwV+wAoYk4sVlfoc= 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=dZ3I0KFH; 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="dZ3I0KFH" 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 5ACFRN9t007907; Wed, 12 Nov 2025 16:03:54 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=h8SBH nvcaPR/IKOBM+v6EDFM9OxNcNCr5nG/59SC/gI=; b=dZ3I0KFHf3Xp8427rZVk+ CGdWtL4EXVh7CidQ07MHuE/7o3gsuPKsebV1wg5mXy2CIZGUG+XORZBdnzxx5G+X JeQIza6Ct6HxOVTU23YjOvbfBIz3e9ie3F0ry5q8rUN+cPK2YUH6f5RmFi5/Kv/w DYMARWuXrGjis9zds+ilutRgzRG40NtjeE0oCUH0bw3e60OtshoTQKvTw2YUslzI eKbBZUa71UK+LCCFyFC/OhkgCQtXjaY45R7kMMUK+EEQMjXPsySo59kvqUHjfT5t QCrGHzfgEGvHKWhYaJrsvj9ILFx0MVRBL0QvC0fxxGIS+ZyIju0jjwchtPhtLxVn Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acu650dhs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:53 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3mU018584; Wed, 12 Nov 2025 16:03:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavps2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:52 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3I004655; Wed, 12 Nov 2025 16:03:48 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-2; Wed, 12 Nov 2025 16:03:48 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 01/28] objtool: Move disassembly functions to a separated file Date: Wed, 12 Nov 2025 17:02:48 +0100 Message-ID: <20251112160315.2207947-2-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEwOSBTYWx0ZWRfXxUX8xqqL1Gtm Rx/xtP3U2ZeZExyTIjzNst4h8u+5F4FQfTwRwL67kQS5xXJPigxIhUDzWmYKt5pmZSPyjEqtYD/ UK17CmFbJJOPgCQYGggGZRkjiKzYy5q0iYt26tHzQjaC7HPh1bXYC0uXjyA9XVsFf0RTdTDM8Fh 2nPFdOY5W6Gj1+ICTkMQR0kipUzxg9ztZIL8nkJGUdFXrS1i41IJfYVBr3ftCYTL3w4Re36kHQS eaTvPlRvJBXRpTnG1aAYzGlgVLdZKi2NGcsoTrftUwLFiESWAfVzwwcIjWLh/1GTglrqFiYqqPl Pks9lLinKt41rBBCl2Us7E6GwoS7gyPS+4gPS5IbmUg4YqnDPVO6I+2WUKzgBVRrueO07VjR1WH zFJDWiuLFr5yvEf5hUspq/bVpzafjA== X-Authority-Analysis: v=2.4 cv=UvFu9uwB c=1 sm=1 tr=0 ts=6914afe9 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=dBVU6wt392Vc8wzyTJAA:9 X-Proofpoint-ORIG-GUID: F4t_c0DKCze1eDbvUAWZdafTn0bsvzIX X-Proofpoint-GUID: F4t_c0DKCze1eDbvUAWZdafTn0bsvzIX 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 a3cdf8af6635a..677bf9148cba1 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 objtool-$(BUILD_ORC) +=3D orc_dump.o diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 9004fbc067693..5207e62ab690c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4601,87 +4601,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, 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..77de46beb496c --- /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, 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 c0dc86a78ff65..4d3e94b70fd84 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -47,4 +47,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 Sun Feb 8 08:48:45 2026 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 2DD4F277CB8 for ; Wed, 12 Nov 2025 16:04: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=1762963447; cv=none; b=i8hu9xBCaGTJfRlyxefYdavrtJJ1I2/dvtSv13vya8np5jTf595lS6EtLv9LXqWyEeshkh+SBGSM9x+yWnS9qteLmeEDZZ+2dFIJU9ORuYY87S1LzYzUqSrtoObCxrgNI77wK4FVH9ieP7pJuUNOJNTdnhuCxl3jeaYss3QcEMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963447; c=relaxed/simple; bh=8RtqaxDHlrQUHgvilvJPUgfHiqU6XiXvPA6YKdJMFiA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m6aQj3fNnqeITeLAem/iQlnnojfU9L1bm9qcs9Xz8a5tM1cLfRHD82xw6UlqurlilV+Ylkpuwer0YvgAgW9aZM9zj8XlBLST1JsihGcOjD6rMEI1iILD1Gy7bGY0U4FnHBnWz/5Zc5YD71iPNeJsTnVBf7ecJHohJiAU/cNBZhY= 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=Mpa4YKhW; 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="Mpa4YKhW" 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 5ACG02t8013321; Wed, 12 Nov 2025 16:03: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=CAQP1 9TFDDxrt0SkXNzDO71RH+/FAyrNChWX1/wVvdY=; b=Mpa4YKhWIY/PS8m+fTr1e Fz8PpF96CV3Aokb6x6gD5gtAkZUr1rGD/DhvyD6b5S7H2cFUnznTHerJcVWERiIg A6Q3ceIFNfZABAblu2chuJ+vwPXzBpAP6JxeB+6UeIuYxJJPnKPi0Csk9225BUGk D3AgBaU1SNOGSrMncOQexyu+wPvLVg0ET+XHqrzsPvz72u9g/Ecs74MdZW648IdB lhkeusihDOHnhEp/AR73SSh/Lk+vOyPgUcvo4/2jqIF+2mm8coRdLdpbijoptTeu VkBG0l2IwvlZ2HFjg185hxq054fo8sl6whcEyEc44yE23J/WIAGajWVjRu2zCvS0 w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acwcg007v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:55 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4ln018761; Wed, 12 Nov 2025 16:03:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavpv0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:52 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3K004655; Wed, 12 Nov 2025 16:03:51 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-3; Wed, 12 Nov 2025 16:03:51 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 02/28] objtool: Create disassembly context Date: Wed, 12 Nov 2025 17:02:49 +0100 Message-ID: <20251112160315.2207947-3-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=XL09iAhE c=1 sm=1 tr=0 ts=6914afeb b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=-R_vEHidSSj7PnaEDHgA:9 a=EBa_rOYxF3VBboPlVeQ_:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyOSBTYWx0ZWRfX2bGbMv3wNCd/ rMfWHkoFghxE8NMOFVtA1mWcuLhd26jrpx7KKeivE7xwLRb+HoPYpu6qcA8IszVp7FhAgeCYr+Q uxDB3+dAHGhqYIBPNLEho6G8jysvG26nHZdPB2joWUOl7Nguz57c9ZXbqqytFDmIDTVrlpHzZKT ABBZP7UuBJjodDUE0mgmRN0YXhL4TFk/SOvXLe8t5z7yV0R8liVppOjAWR8pxXz3X9G5yc5z+b5 mM9oykqdsMC3clmRx2KYP7rdNJXB6LJB8p5uxDdrHMf4B7NQwrM6S76zkFGzycLFI0S8SfPQFId gG00Od5zVcSVGEwf6jF8B1OXf0nJ1EQlVPvTxxUhiqgu+8V9exAtPWINNCFk9LlOT0vAMkixrCF J/qbS4KzfW6MELhwqZxdhu48Zd9aaA== X-Proofpoint-ORIG-GUID: 0HjqzmgaKFUb3hRBYrBrECI-Em7JrFPf X-Proofpoint-GUID: 0HjqzmgaKFUb3hRBYrBrECI-Em7JrFPf 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 5207e62ab690c..7b6fa1e3e9aac 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -4672,6 +4673,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); @@ -4804,7 +4806,9 @@ int check(struct objtool_file *file) if (opts.werror && warnings) WARN("%d warning(s) upgraded to errors", warnings); print_args(); - disas_warned_funcs(file); + disas_ctx =3D disas_context_create(file); + disas_warned_funcs(disas_ctx); + disas_context_destroy(disas_ctx); } =20 return ret; diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 77de46beb496c..8c751f3394865 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, sym) { + if (!dctx) + return; + + for_each_sym(dctx->file, 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 4d3e94b70fd84..c0dc86a78ff65 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -47,6 +47,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 Sun Feb 8 08:48:45 2026 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 548D02D9ED1 for ; Wed, 12 Nov 2025 16:04:06 +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=1762963449; cv=none; b=Y6cMn0ztfqwS+jrpUfuv4DiOxMCB8QiwOUQXL9+qGgp5rhKLJldHxPpLYc/oAimENqU46wnhD/jjcQsFga8p+lrzDzbD+Me01SvgjA78TWXntQz+8BMdSGtdHdjKrIGezR9cgQ7KYKfgH80+Dm3iB6Lfl5OtfhwbNmXzEi3ls1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963449; c=relaxed/simple; bh=YMbw6/nENvpM45mmzHzORWdsMnSBo77/yZqJf9BU/I8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DXrsGdktXKPGrJs0Q0W7D7h9NnwCm6u6nJwnoAAfW4D8cwKwokpPYpAFvr7cMedCjQDYCgttijRPAyeRa/P8BPxNdAiOJKcylM8e7XvRRLFSLvA96Oqbfny32ouFnPtAeKZLxfi5FautNee4CA8SNpekdrE67y/0OqemuRu6iPA= 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=bYGCguLR; 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="bYGCguLR" 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 5ACFWJh0012803; Wed, 12 Nov 2025 16:03: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=Dfx1t 7Iz5C+Oq8EsuENpgoY4JktmC9uWXKMsptLUWF4=; b=bYGCguLR12C9JYDgPgiPA 41S8w+lqoPcqbyCpkVq/tzfCw8t6kc7n+qd7CnRB6tBnIY4opPSyXS3KnizffwVY a7hAPMaiGHeTKFgnzYpSFxGlD4Icap11gtsroPZO/BsaBA4Ajga8FeZLGEroq2hh SQj5dQEzzQT4hw38MLwjPll8t13vptlgI28jIvcUc/6hISTsQPzlECvSbPN//XOb QG83gDoKrEpx/r177cNYyOXX4203Tmtzt4TVni+4Ane4e1NJ2MKU2DIApGZpi/3S LiD7q5o5Jbfxlipz3WEzk7Z3NfCLksLX5bXYcFY1J/41ZI7I6BfNKAsvFu5rSyuA w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6cg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:55 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACG3g0F018703; Wed, 12 Nov 2025 16:03:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavpww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:54 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3M004655; Wed, 12 Nov 2025 16:03:53 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-4; Wed, 12 Nov 2025 16:03:53 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 03/28] objtool: Disassemble code with libopcodes instead of running objdump Date: Wed, 12 Nov 2025 17:02:50 +0100 Message-ID: <20251112160315.2207947-4-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914afeb b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=qB_9k6UZtangfgbWIO8A:9 X-Proofpoint-ORIG-GUID: 49bPFJC2_arvh2xBbIPTSjiVDGen9-Y- X-Proofpoint-GUID: 49bPFJC2_arvh2xBbIPTSjiVDGen9-Y- X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfX5/v6E2ZB3TkG UMj9j1P0Rb7HpyYRZOmFq3A+6Ov+AsCW4YzjtFLN7rDp+ci+xe724hLDi+EhVQ/nHJQ3UbFgCRi BLQL4XGIJOn8Lavnz0dezotJEWKGHwf+TCY/P9N9DpdKk1DPJIN46ZzUNopOH4N5SbxmyPDCJ3G 5h/X2YegKyDYA621u2i9U19vF6o/umiD7NecsEDy8gnz6M7nbdSDIya/zwW/DaF8cailbuW0X4h ZvHIC49D0oL08iencw12ke8PmOPaxcu8wKv5c5YJrcG2JtP9gMhcLgTjyTMO4QN/BjxBsnJI1Jn eoXv9qYv7Q5sSvNndW9zCU00FIlRAcR+U9TnTM/LJ8RlEHeT3Nr+O4WHkow7gDwmh5zIin8RRzP YYWJ3Kwm/gqSdrMXLi+iy+qfihcUMg== 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/Build | 3 +- tools/objtool/Makefile | 22 +++ 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 | 10 +- 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 ++++ 10 files changed, 230 insertions(+), 71 deletions(-) diff --git a/tools/objtool/Build b/tools/objtool/Build index 677bf9148cba1..ee04fba8c9d16 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 objtool-$(BUILD_ORC) +=3D orc_dump.o diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 8c20361dd100e..9fb83979ca890 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -7,6 +7,15 @@ srctree :=3D $(patsubst %/,%,$(dir $(CURDIR))) srctree :=3D $(patsubst %/,%,$(dir $(srctree))) endif =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 + LIBSUBCMD_DIR =3D $(srctree)/tools/lib/subcmd/ ifneq ($(OUTPUT),) LIBSUBCMD_OUTPUT =3D $(abspath $(OUTPUT))/libsubcmd @@ -40,6 +49,18 @@ OBJTOOL_LDFLAGS :=3D $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUIL= D_HOSTLDFLAGS) elfshdr :=3D $(shell echo '$(pound)include ' | $(HOSTCC) $(OBJTO= OL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr) OBJTOOL_CFLAGS +=3D $(if $(elfshdr),,-DLIBELF_USE_DEPRECATED) =20 +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 + # Always want host compilation. HOST_OVERRIDES :=3D CC=3D"$(HOSTCC)" LD=3D"$(HOSTLD)" AR=3D"$(HOSTAR)" =20 @@ -56,6 +77,7 @@ ifeq ($(SRCARCH),loongarch) BUILD_ORC :=3D y endif =20 +export BUILD_DISAS export BUILD_ORC export srctree OUTPUT CFLAGS SRCARCH AWK include $(srctree)/tools/build/Makefile.include diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 2e555c4060c5e..9fd88431e8f48 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 c851c51d4bd35..3c6fced37bcca 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 @@ -128,3 +129,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 0ad5cc70ecbe7..2f7045e1accc0 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 @@ -892,3 +893,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 7b6fa1e3e9aac..86cd5385a14a0 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4786,8 +4786,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); @@ -4807,9 +4805,13 @@ int check(struct objtool_file *file) WARN("%d warning(s) upgraded to errors", warnings); print_args(); 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); + return ret; } diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 8c751f3394865..e9e7cb21b2a4b 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, 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 be33c7b43180a..02e6e385f174b 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -102,4 +102,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 00fb745e72339..5290ac1ebbc1f 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -125,4 +125,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 Sun Feb 8 08:48:45 2026 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 7703D33A026 for ; Wed, 12 Nov 2025 16:04:08 +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=1762963450; cv=none; b=VV6tXJBainm06MlO6TeIGNs0K8ZzX0vBZzSp7UVcG/fXWaSUjkex593DTepcIcIIsEYFM6KL+2InFq84slfwsp/hCbwZTZV7M5loOao6xnGT6td+x3zhxRe1s7KAH/hWG6+Jz+spPj/yNPNX6lQD5n4RF6u6xoSQzwqweF8YUYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963450; c=relaxed/simple; bh=y+f42A7JvxwlCYs9lZRBZaYEuUvBOM/jlbSPz3pra4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vC0IxW3h73er20XQUxH/9t2bj+yfgyrIcuZtVG+IVYWtf13elz40H5xqkYdh3ieStS7Tqf85CSNqBluKpF2KjBEdBmdGv69yt4RiCxOixMENzHh5sMU91QaL5DaNYbYmO9g42LjqRkbCBpvomppFr2E1pyXvnWEgYAisyCdamOE= 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=Ikr+xjLf; 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="Ikr+xjLf" 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 5ACFWJh1012803; Wed, 12 Nov 2025 16:03: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=4P/PW B6DyanXCLPNsd1extPQtV24iAUr4mJbjPckT0M=; b=Ikr+xjLfLeNF3CfAtUWQQ k35cpTz0dQCaLRusiitiZIasFfapmYqaOsb29I+jFXXi2CKbLkgueemxNmxo3xRW ynvAcyqQcjlSzHONSWATzrtoSQqPOcvsplUBVx+7xgslfeIF5g5/o+i88BKr70aR UTLlGZzfMqZW6361msU7HZvVo4UtaLnAkH0fH99jCI4pP5Dby8sN4x/RFBkvqJfR UG4VG2rCIXb4TvWWJwnHmchy3FsmEsy0jN85zlRGJDa7qHGhDUVfKYB+PxbvNlnX eVpgzVwekpm17Rwfw3hSWbfW6LI1e++iJ7i4UVPdQ67Wn+e7jZY5+9ck028jhLg3 g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6cn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:56 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3Av018617; Wed, 12 Nov 2025 16:03:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavpym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:55 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3O004655; Wed, 12 Nov 2025 16:03:55 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-5; Wed, 12 Nov 2025 16:03:55 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 04/28] tool build: Remove annoying newline in build output Date: Wed, 12 Nov 2025 17:02:51 +0100 Message-ID: <20251112160315.2207947-5-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914afec b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=gaUgYgG710qbGCIvUrAA:9 X-Proofpoint-ORIG-GUID: W9EQ5nRsRFEeWuw_G9oMYX4bFAMKcNTk X-Proofpoint-GUID: W9EQ5nRsRFEeWuw_G9oMYX4bFAMKcNTk X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfX8+omib4eXBgk HBJNiJITdlRjTLRDnd3yKPGsHN5QUKfJpeiLE2Wi0LUs+ExPBzpHCk0X4CMOK1YCEptA98iGuWw hAKalHGkzENCIfKdoGQx4TZ7OF1vwgyGZpmYHd0f4PJN8CJDpoH7OJkPT/ML/xjs+eY4cCK0nS6 /CW5Ogi8KwYnmtUVw9kq/QnezKWK7ACl+z4MtcSwK2tW2EUBYzJVjG9Ee+WTlbF3nJwSOj5duaK vptyJpuZgC7wlcbEVbbiV5ZxZ2WsYnmy5kLqPtkbbP1RRVl8kbTXkfRSst6nA6OO0nyuovN7Yqh /thFXtKmFbpvUkcJX8agBBcYIwzw40sR+QgQARZQW60pJhxjjyiAkeNgM1aVqmNc/JA90F2LDMz eD6gt+qxyTcIVhYsunwMDG58Md9rEA== 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 Sun Feb 8 08:48:45 2026 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 1291C341661 for ; Wed, 12 Nov 2025 16:04: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=1762963452; cv=none; b=qKwK61jZ7NA7o4uDl5euWAZ884e1nEB/5kZ8w5saVXmJPRUcU2n7d2BlhV3VVK+uAeh7OiUKuAnHgq84mj7wChyDOInFdud+cS4aY5tblgsRe/RzF39ivjaYdzKxqqTuk3NnL9xa4Bm8hZkTHuLAEIwuKWeUBQmDzPtRBJWUDoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963452; c=relaxed/simple; bh=xJ40DZV+4vMGHO5HtINfSwqnca7k1lZVUatwhzkjfcA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DLAWltiRl9+mmmo/2kzLKILgtgrPp8AWQMrD2sln8QZwxSy+mVUnYasxvZN9UK9gNo8neho+tnpo/fITw+TI3ioFVtk/7ZfEfpY68P1zrRjHov88gU+LH8lKUFT5RnjR2XhKol69pQrhW50SaroE9enZLyc9P2X+6NtDfkUkHko= 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=O2nSykFk; 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="O2nSykFk" 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 5ACG0QxX013501; Wed, 12 Nov 2025 16:03:58 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=sYCNg YJDk1WQPTGoV2aiM0amkBCQQLPK3sXxUobzV2U=; b=O2nSykFk+89G/4eX4ItGb 4wL7GwF8vIPVj1MdXkCU7r9t1hgQiqz20Jd7NC63de4R7A0szPhn00Z9WmO4Kfl5 /AiZAx9U4wx9FryKg4dyNx/EcpGfYkLcQi39UtCtoh0pzdxPgUOioFqOI7gtC6+n 8w+3pbaz70X3tz4OkUYot1Cwc199qfPtkNjDiSPRVMtPE1AL+xYyGFEdYNNFOLDA f5eKdHtMqAvsDKAmbITcOXw2doC37x/8sZWm2IxMsjAkj8utQihpA9a8Yyw8pXq1 NqXbNkZUwmkknVrioLy3HxgxZ6zX/uvVmgQOnh/opGoO5OHY3bjSQxN/uhrVoB/+ Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acwcg0086-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:58 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3mY018584; Wed, 12 Nov 2025 16:03:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavq18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:57 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3Q004655; Wed, 12 Nov 2025 16:03:57 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-6; Wed, 12 Nov 2025 16:03:56 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 05/28] objtool: Print symbol during disassembly Date: Wed, 12 Nov 2025 17:02:52 +0100 Message-ID: <20251112160315.2207947-6-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=XL09iAhE c=1 sm=1 tr=0 ts=6914afee b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=UkdhLtt80R9bjKZQdAcA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyOSBTYWx0ZWRfX7G5NK9OOoAiS E/SPNdetvhoI9FgQvLLWDLA+PikxrYGWGBWNThq29vnDSp/jHSlMRjZ4oRMafdYM7xbZ14ExABC XzuJwiT3jwTbcNtfY+GxNVxvCG9AZnCEBYcrjSM6l7261+pxb943FHzoDmijLinmlychjUVzViP 7OWky4IuoLobxa62oMD5fHtZjm0ax4S88dfwmhKElXxrwQdDK72yn0jiDXb7vSE14jhz5Y8B4a+ ZFZpKlfDsb7cHd2q0QLl41JwYpbcACMlObjOY/jdJqCz8Ruxh7VHxSF5CK0zD7pbZ1Lm/CUofhB ecD+KY2IKBcLYzY5V5emLko0Il/jXsCcjdquTdHlaIDYhRR1JceWF1f9XRlbATSvBxxKfM7MU3Z EJ5AfJuXvr8/yTfqzbwNsQ1R5tweCg== X-Proofpoint-ORIG-GUID: jJRrL5SFFnOnOxDD9pQWPyAoCWR0_OEM X-Proofpoint-GUID: jJRrL5SFFnOnOxDD9pQWPyAoCWR0_OEM 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/arch/loongarch/decode.c | 7 ++ tools/objtool/arch/powerpc/decode.c | 7 ++ tools/objtool/arch/x86/decode.c | 14 +++ tools/objtool/check.c | 9 -- tools/objtool/disas.c | 137 ++++++++++++++++++++++++++ tools/objtool/include/objtool/arch.h | 3 +- tools/objtool/include/objtool/check.h | 9 ++ 7 files changed, 176 insertions(+), 10 deletions(-) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index 9fd88431e8f48..7645409918f5b 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -28,6 +28,13 @@ bool arch_pc_relative_reloc(struct reloc *reloc) return false; } =20 +unsigned long arch_pc_relative_offset(struct instruction *insn, + struct reloc *reloc) +{ + /* no PC relative relocation */ + return 0; +} + bool arch_callee_saved_reg(unsigned char reg) { switch (reg) { diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index 3c6fced37bcca..9c3f49c455871 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -20,6 +20,13 @@ unsigned long arch_dest_reloc_offset(int addend) return addend; } =20 +unsigned long arch_pc_relative_offset(struct instruction *insn, + struct reloc *reloc) +{ + /* no PC relative relocation */ + return 0; +} + bool arch_callee_saved_reg(unsigned char reg) { return false; diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 2f7045e1accc0..7bd874871c31b 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -103,6 +103,20 @@ bool arch_pc_relative_reloc(struct reloc *reloc) return false; } =20 +unsigned long arch_pc_relative_offset(struct instruction *insn, + struct reloc *reloc) +{ + /* + * Relocation information for a RIP-relative instruction is + * based on the RIP value at the end of the instruction. So + * to get the effective relocated address, the reference has + * to be adjusted with the number of bytes between the + * relocation offset and the end of the instruction. + */ + return reloc_addend(reloc) + + insn->offset + insn->len - reloc_offset(reloc); +} + #define ADD_OP(op) \ if (!(op =3D calloc(1, sizeof(*op)))) \ return -1; \ diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 86cd5385a14a0..f67a77b77c263 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -132,15 +132,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 e9e7cb21b2a4b..d1b1c215e7f25 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -14,13 +14,147 @@ =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; + } + + if (arch_pc_relative_reloc(reloc)) + offset =3D arch_pc_relative_offset(insn, reloc); + else + offset =3D reloc_addend(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 +203,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 +256,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/arch.h b/tools/objtool/include/o= bjtool/arch.h index 02e6e385f174b..2bd7a76f053d9 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -98,7 +98,8 @@ int arch_rewrite_retpolines(struct objtool_file *file); =20 bool arch_pc_relative_reloc(struct reloc *reloc); bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc); - +unsigned long arch_pc_relative_offset(struct instruction *insn, + 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 diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 5290ac1ebbc1f..4adbcd760c6f6 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -115,6 +115,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 Sun Feb 8 08:48:45 2026 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 2975F341AC6 for ; Wed, 12 Nov 2025 16:04:10 +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=1762963452; cv=none; b=F6TBGn/koiXmzhE+2mxcr0cXlkqJRp0vwOzuAKxu/73953swLIkHCVMi4tVx2yjHpWtwfwsx4BhpTBSrn5IByHb0ZEXfB0PteXh6YRP+ltqoytl+7Nq6JWAku8+LdWgdRaUq5h+wlDhebxA1EBG0dS0MZzFjsDWS8tnpg7Px18E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963452; c=relaxed/simple; bh=gbvnhYzubzx7H/BNj1qdsqisuuBReqtUkoUxNeKZ5+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dr7FZy7x7qSC9e1ZEi3ngJH47hWk1jtrqyuZLq9X6br22P6YItRRwzlC8M2MBpEchM6DFIkWyvdPiyGXUFbRMF1hqYxoH0SFJydhWWSUq5bdvAg1lYJeBBijczPVPIK3qsFLs7+bsF/E0kgEzQlocQPpQz8eA7uyBETFBIXOj7M= 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=LxfKl9B/; 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="LxfKl9B/" 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 5ACFVxV5012517; Wed, 12 Nov 2025 16:04: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=VCjhb Xg8e8BhVZxWVj3eoHY4yrmjKQhyPe9SZQIpC4o=; b=LxfKl9B/v4at3dSik1fIJ K0AUMjgzavXHI0l4H/YVqEZY7qEcRCWe2cB+ClsCYuPPWMrb5R64BWxX9HR1vUEM 8n41whRRr8mdk/l16uWAAppCsuaGPs91SKwJRmPqnqBEfgYaCKW0HLAZAs2jbjU3 ha0/ZqNSGWGingN392sTQ7f3um+SJNdx9tKvo4wvHmh6vrMZWWAJtnCxh14jkRPO aqXp8C8zB8+7hRMUuvT32MvUFtNw28DpVVm6Ukw9I6FlW1jYoeo12vovRjurdbkH rwLh0YMxk+fuHC4+nZTazB/fiZL6cckzGn+TFcpEIw32MwOMCcaqrWXO/zBbyAHf Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:00 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4lr018761; Wed, 12 Nov 2025 16:03:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavq2g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:03:59 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3S004655; Wed, 12 Nov 2025 16:03:58 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-7; Wed, 12 Nov 2025 16:03:58 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 06/28] objtool: Store instruction disassembly result Date: Wed, 12 Nov 2025 17:02:53 +0100 Message-ID: <20251112160315.2207947-7-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914aff0 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=jcmHYjYDc9FjrwFKAggA:9 X-Proofpoint-ORIG-GUID: WPaAo5DS0xNLZW_V6DOlEG5OghyBh8Gh X-Proofpoint-GUID: WPaAo5DS0xNLZW_V6DOlEG5OghyBh8Gh X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfX7yf9UAykp8Ur 8bLWGKh0Tl2oy4um0Dwg0tV+ls8DzWO7kue5Hr95IzvmuLsdrMzIqj+dWLaR2E6XsSb+qXH9CfE LSDUv2E7g+V+NBOWHoXk1joIXeWCD6abwTGbYoOcsggffH/7kZQupiYLUZW/VHR1D+IuWSA8ab1 qa69tMYjGqedMM4FGDzbCoNheBPfbsrHoDt5/g3VsjPv2emKKrRXcZ3DB7gync1H7hjufGneFmN fom7smZRZ5VDI+0AisbK3fe0u/ovV5DjgUnMp1qsrQVukwMJU+9KFjRX+Qm08A5oxVA9sVh/BFI ClPGXo5LYGHBehijXYpSSRJlA3M9WbQDsutvmcGig7+ilM8Ku3nH2ZkK2v5J0Z6JnosqYeXXXx9 4D9A3h7+hEDr6645nToMBU27QHvgYQ== 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 d1b1c215e7f25..aad5bc3651b8c 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; + size_t 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) { @@ -198,9 +258,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; @@ -247,6 +306,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. */ @@ -257,6 +321,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); @@ -285,10 +350,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 Sun Feb 8 08:48:45 2026 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 E4B50342521 for ; Wed, 12 Nov 2025 16:04:10 +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=1762963453; cv=none; b=oU9M933UBlpF/budbQ/fERJt9asxnq3xm5nTXH23+2n6ZTRiOZN1E1ecMfZxi5ma/fWMZWt+liqo2dilhr7a9odxcVBkjU0jUWbasCxS+DaE5+/gHJqwKAjb+KpMQiUK3Slz8LZL6YI7evREG2Bu67wQBYlsfKV7bF6Plt3jYnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963453; c=relaxed/simple; bh=4hrHY49p9+jbWESBW7pSI6F3H9G9eX8s16Cs7s3rUac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TZh4lS+nci3jvz+fmhJVwmHqCjmCqHX/mhEGDj4LYGoJswTOqCwtPfEpKCX2513oqU70NVS6YACcNbSzOso+P2jNMufOKruThQ5OZ82QnYOGgsTtK8O5m4ht1op4cAVzJpq5ce8///Qiy0A5UhrptGaKck24Zj6L/QIQq/qWnwA= 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=cBBhmCBD; 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="cBBhmCBD" 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 5ACFRG6n008617; Wed, 12 Nov 2025 16:04: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=k3X8y b+pwCuo0yCIKuiGoFOoEdoTjh02qOmId7PF+q4=; b=cBBhmCBDzYm5Wa8EKPdQB C59wePJERp2eBxYUakU3ZlttRSda5nL4BoNNFajzmY7BNk+Ee4WUJRti1i35ybm/ f39RPiO/08xF9YYDLKnsQSxIB7bCAsvbfeAWxocsslr8Dev3YIBueJ7mudZodab9 0LqdXAhiBK890JjNXYIPS3utl9E8RRCnVZQVIQvvahLzwCV9y2SY8CPGIETy3cX2 3APgWS5C4ah0RVcg4l58retuNf7r3uWexXuDhzREHNcG0873ylW467HLSDuy3v5L PafWcpJG92hMC/1TUVgK5gurGoDqkQbVOQRk81asAPSz/ZGGa7joPMCOogKeyqBz w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvssr4ma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:01 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3ic018605; Wed, 12 Nov 2025 16:04:01 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavq41-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:01 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3U004655; Wed, 12 Nov 2025 16:04:00 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-8; Wed, 12 Nov 2025 16:04:00 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 07/28] objtool: Disassemble instruction on warning or backtrace Date: Wed, 12 Nov 2025 17:02:54 +0100 Message-ID: <20251112160315.2207947-8-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=6914aff2 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=49cdYLv4DVxkACFpF8YA:9 X-Proofpoint-GUID: Bju5RNc2GNrMr39fnXYD8kEnyLJHcjrg X-Proofpoint-ORIG-GUID: Bju5RNc2GNrMr39fnXYD8kEnyLJHcjrg X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfXwG83WHCmt371 qhPzUejdYs++riBwuoR1dwEmpfieDpDJjZyYH5QsEj4zKhe3M14EFKYDlA7937csyx/mGD0pQrT Y1uBnksUwplLQ2cHTHBhYGogDfxb9egKne0c0xhng0kpNnI2e2uVi5LGZraXChbA2LXxoxd+gHu TEwP4PWkIn90gbUe8zWE48EyM0Cw+uNHiP6oOJKOF69oXVYHN1z+/Zij0fju+Hc6V6qZM6Ugaww iuIX+bdeXcLLKNuYqF8QZTK56Uj7kjmwBNSP1edUS19Ip5+v8XApMNsg4iv40LsxpfjsFiDEPt8 FaBke+QZYYaZT4bKwd1Ti6AH7oVngUQ8mLGlbue7AHcdTkHEYa4cajCA+KKGOxWr4S0zSLsMWDT zHmZDxtp51P7fxwqr3KzEU+4rdJnCA== 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 f67a77b77c263..5b977bdb5512f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4662,11 +4662,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); @@ -4795,11 +4818,12 @@ int check(struct objtool_file *file) if (opts.werror && warnings) WARN("%d warning(s) upgraded to errors", warnings); print_args(); - 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 aad5bc3651b8c..c8f3fad086faa 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -306,7 +306,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; } @@ -314,8 +314,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 4adbcd760c6f6..f3ea144d4746c 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -139,4 +139,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 cb8fe846d9ddd..8be02483823dc 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 Sun Feb 8 08:48:45 2026 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 56342343207 for ; Wed, 12 Nov 2025 16:04: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=1762963455; cv=none; b=dYhNdVCQBjW03djrPlorn4ZiBfxODHMW9TIqBrGBNXSyJIRB/tQB3xdVxcLkQl/tJ9gNWc8cl10IWP+/aDjxKmTWKTB0YLwCup5ajq8xbKX9z1cXZh9CHZVrUyRc7Ru59pXg8SsfHXbPjJaNHmf7BbYtCgAkOwUzvMwAHKjBvCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963455; c=relaxed/simple; bh=jnb+jw4cJX0KYewnHVML539qHFFynflD2IXsBim5+Hk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PJP0d7pdQHcUg/9rgr81iLPg5gMexFiHEtfl0FWYfnlrLnJNjqmUawC0rNtnJfMzj1qSuKUGm+GF4YPWvBW5C0+haF2tyvj1cRp5Z2FgcijS2WNhblLhoIHhYa/g7ZaHBG7MwTz6oA9uvcIVpCLrmrGsMP2v7xP6BnzZ7xx1vHk= 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=IzE7jqVH; 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="IzE7jqVH" 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 5ACG0T4u013512; Wed, 12 Nov 2025 16:04:06 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=HGtNP jlJ6RQLlQzEl+bxrsWOw+SssZH+N/YbRTfEQDA=; b=IzE7jqVHOm4UiUQCJNn1I SlmPDNTPfuttK2xb5SolOgw+USopI2vpmH01bV3lbBUheERXUtcTMx0RitZGzRLh 3EZQaL1LQKDQTnr9NQNpfYYePgdlPFjAlmgaiRXSrUZ1WdV+n7dNukOiRc/wSPj4 1Wk6azKWuJ22IPFhnxiytnIlnRvidRaneHhScKOWVyIvDcCYCnvGdjgbszyepgBR I/qXcYB2PotY3ibXdzxLZfSpt9/VmTu1WLDZ0fy7efGzf3AzK//8cX+8UK2v3PGt L3ZlB16cbraIQX77YymGXzKUeseg74wAUzD0nhoY11U5hZqON2PT/cjlEL8XGHOI g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acwcg008a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:04 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3id018605; Wed, 12 Nov 2025 16:04:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavq51-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:03 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3W004655; Wed, 12 Nov 2025 16:04:02 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-9; Wed, 12 Nov 2025 16:04:02 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 08/28] objtool: Extract code to validate instruction from the validate branch loop Date: Wed, 12 Nov 2025 17:02:55 +0100 Message-ID: <20251112160315.2207947-9-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=XL09iAhE c=1 sm=1 tr=0 ts=6914aff4 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=45N9rFkX92oTsxCXvtEA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyOSBTYWx0ZWRfX0gbpHD0/DiVZ L9NZg8PIu7YL085j5W7caDTBgMdmoeseJBnLJh5zXcnt0XcNTcSoxCpI7ggMMnq+2FBtB8lwarw wqHJCvgXNel4YowMXeVt5SDc9reNrnqG3KRFUeVB4UMne4xIzaZnzQ+gsgrI+oetv/BN90a63o6 uKlWVlu0wA9t/zkZNbcqar3lqysWzcoE2Jl0k5kHFl8lmXfXmZmR9MkzsJUM4kPpHIZMIwPziki 0C7VUS3tSNM8yQqx3IS2Lanu/LObZNMRskRI1nDZaS3QFwsDxX7FeAOWQIYj5w0bySYgn3tKdC4 4pTznEAy5NwGmkzJhYqfZ+ZSH8u/1dP3/z8QJ29wQnNVhSGaanfv32/y730AbCkZjbXLh9ya3RW AHrclTLuW1wqiC6l5dTiQoIQ37szDw== X-Proofpoint-ORIG-GUID: CULLMPBRoTcsMgdeVzAKYXMKHEVeaejl X-Proofpoint-GUID: CULLMPBRoTcsMgdeVzAKYXMKHEVeaejl 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 | 392 ++++++++++++++++++++++-------------------- 1 file changed, 208 insertions(+), 184 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 5b977bdb5512f..609994ad6ab41 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3535,256 +3535,280 @@ static bool skip_alt_group(struct instruction *in= sn) return alt_insn->type =3D=3D INSN_CLAC || alt_insn->type =3D=3D INSN_STAC; } =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; - struct section *sec; 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 - sec =3D insn->sec; + visited =3D VISITED_BRANCH << statep->uaccess; + if (insn->visited & VISITED_BRANCH_MASK) { + if (!insn->hint && !insn_cfi_match(insn, &statep->cfi)) + return 1; =20 - while (1) { - next_insn =3D next_insn_to_validate(file, 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 (!strncmp(func->name, "__cfi_", 6) || - !strncmp(func->name, "__pfx_", 6) || - !strncmp(func->name, "__pi___cfi_", 11) || - !strncmp(func->name, "__pi___pfx_", 11)) - 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; + } =20 + return 0; + + 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; + struct section *sec; + 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; + sec =3D insn->sec; =20 - case INSN_CLD: - if (!state.df && func) { - WARN_INSN(insn, "redundant CLD"); - return 1; - } + while (1) { + next_insn =3D next_insn_to_validate(file, 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 (!strncmp(func->name, "__cfi_", 6) || + !strncmp(func->name, "__pfx_", 6) || + !strncmp(func->name, "__pi___cfi_", 11) || + !strncmp(func->name, "__pi___pfx_", 11)) + 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) @@ -3802,7 +3826,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 Sun Feb 8 08:48:45 2026 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 93C89337BB1 for ; Wed, 12 Nov 2025 16:04:10 +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=1762963453; cv=none; b=MKWCew0UcYQzaIAgkjt+jk6Ah0x0CIRXQZ35twP272rItm1eSWskVNwk0Usf4cPQhDTbY2IVglV9dm4p95yQKEPdxjdK2XMgIcVr7VKoEWFsBPH0nM+hr/T42aApgisWucjBNWan+5ExVrIQCk0hdocNkYVxu1IDxlwyO43HwFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963453; c=relaxed/simple; bh=CVdUBf+Wgi7dxn66PVbR1h3zdfzGRUACq+X+Gsf7sSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LQ2x6BhIVmmqbxXvF9I2cyEsa9CP0nj27J2qJaLQ6xUXKCsTzaigOB2f8oPsHcn+OlKQBE+AAwkW0uIDiMcFTdrjHUG1YqW4G2RAZc/Mq3oAr6JYaCGGuD5/+84wJIxAzLUQTObc4WOgXDfrftuQhWl6nn2EzS1cU0XF+7u18aA= 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=YYmxw8iq; 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="YYmxw8iq" 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 5ACFRCJA008527; Wed, 12 Nov 2025 16:04:05 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=2Pvki wZj0+fyLZUdBNms87y9ptFPtvpYZhWD/2eW3+w=; b=YYmxw8iq7JKtyhukDPNgc UfONEx70MQvXfVltIkv6nuaohrLJSHAcpdTRkpmplzD+ESQGs2YRIkl8OqsheaJ5 ZHiZM3CbSu5EbYS7+1cU2n8WImkbEIvdPa37ShhyeE/836EYx17RWcFCI8YmUUi+ RSK9bgNlNran7qLaJkhOGLS9eUmPzpgc4G2QxUnNUbDvaHs8JtTTI7oye3MMVPwV XZLuRlR8eo8+XQMyMctqs4Yk0+aQZlP9Fd2Z1/+uwL6zTzN0R9zqy0mpMN9/jifb 07bh8JB7p5pRjz2iqVxFicCxtXQSqCYlN1Ea1vTCGHekrWpdWRPfO76ef2p3G2w7 Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvssr4mj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:05 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG2sF018577; Wed, 12 Nov 2025 16:04:04 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavq5v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:04 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3Y004655; Wed, 12 Nov 2025 16:04:04 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-10; Wed, 12 Nov 2025 16:04:04 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 09/28] objtool: Record symbol name max length Date: Wed, 12 Nov 2025 17:02:56 +0100 Message-ID: <20251112160315.2207947-10-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=6914aff5 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=xKpiAcmDGk3KfUQPlkUA:9 X-Proofpoint-GUID: 8De_ji-LV9oh_AgFoJaz5XmltULPJMRu X-Proofpoint-ORIG-GUID: 8De_ji-LV9oh_AgFoJaz5XmltULPJMRu X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfX7l/KGPmIjPeg 78UZKjWE95kQVKy0MnIK5cf7+UhlczduPDRQCcAjONxOWwsveq8IDeBPUnSfq0bT2SIRObd2uvd 8kLHLVxQ4GRD4fPmg45w7nCq4AX6KEhqPAMhMDON0+KxswJtY34oVbfEm1ImGFOk8BzXGvSQLAY 5S+rSHzva/Xmtr3QBqIrnwmEAuKAPxuIRRpzNpo0ygMeg4mEOHS1ZQS5dKd2Ndj8ZfZ4zdDfPil RyrUThDhiOCVBTtpKZQ9t5QJf3VTfTM45mwR3LrVX65bFZaLUaorSMctE1b4KeeNSJdZoeAxA6R iNVRgIr0Gr+VRlCapfvFT1HivnqXhpiws4KsLJttjfu7Sndlm3pEurjvuRw721ilpzoDq11ASX4 UhFfwyeyw35uHByrT+jXeJTWcOHLpQ== 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 609994ad6ab41..1fd56e8afbfc6 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -35,6 +35,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) { @@ -2463,6 +2465,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, func) { if (func->type =3D=3D STT_NOTYPE && strstarts(func->name, ".L")) @@ -2489,6 +2492,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 Sun Feb 8 08:48:45 2026 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 191A7345730 for ; Wed, 12 Nov 2025 16:04:15 +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=1762963458; cv=none; b=tJZE89wITHw8GQ2peQp7KieRqcnxNHlWAmwMJhuse+DWvij3C/U2awsQWztpHkgTJYCFcf8hCSBTJ82gCzO9AaxdCI5po1keseAf4f5Th2ygeSEKUO2ZixW3dyk7RfA9wP17OVIWpHvEto+fT0OflMnBdBu7wg1W1gwJxjUItCo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963458; c=relaxed/simple; bh=IFwJFcZiuuz+FhuZr+Gu8S/HF/N2dyr6EohjkrgVBQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LkMz665IjkGcF6qYDAykCmkmcJ9JOBDrIljccdQrAsLZrw8hyHc3J95d9Ao8Kg1xd1Y3PjJNkLwKUdJGoD58TbOWsqYaXC/cGTSUQbuNHATROJvKecgcWASbB5a6jZxFkL0Mm1AHiP9snbZQacTRkOI5F/VAF7myw/lbUKZ5ec0= 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=V2IiX/3s; 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="V2IiX/3s" 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 5ACFRE1n008567; Wed, 12 Nov 2025 16:04: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=YZWmZ 4ZXB0Msaovq4srMHeSz1mpLuFlCt+fLwzcWWsM=; b=V2IiX/3svnrksw6IGzOe0 RcGxzxAhRX9Wpu1y5DrMYzmqQgb+8k8jpQi1af5TMpo/HRa9DLrm53h9QlPM+3La ubdZnttHGo8jPzXeYVQmy7VhsRVGwQw1IruK+lfy7wt6KvMbzbp+IIzhmx8UhiNW lxxyVMSRY6eP0b0XQkQORzGqYRCz6lTfwfl4cClChZqGvx8VfHMl4iPX7fFWdQAi Oo3YzQxWqkA1lQ88L3NpprW0VinRvZDpCqRaq6+gyyvKQJLXwR2hmJmYUTPF+3/s 61C67bHTDtP2jB0jbXgM2NjrUZxBsC5bxNjvNEHwbtGAkLLjORs7UIfc2Gu7d6Z/ A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvssr4mk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:07 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4Ba018719; Wed, 12 Nov 2025 16:04:06 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavq7a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:06 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3a004655; Wed, 12 Nov 2025 16:04:06 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-11; Wed, 12 Nov 2025 16:04:05 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 10/28] objtool: Add option to trace function validation Date: Wed, 12 Nov 2025 17:02:57 +0100 Message-ID: <20251112160315.2207947-11-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=6914aff7 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=7nqSK5V4zRp-Hs5t_LEA:9 X-Proofpoint-GUID: SpKTG47wAF5UkldVEZuMiUiahFpzbTzc X-Proofpoint-ORIG-GUID: SpKTG47wAF5UkldVEZuMiUiahFpzbTzc X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfX5d5U1T8TJP+A 8BuYNCJIIqFVmkLZa5iHvpC+ZZZODRS50zQ0agVFJwaGWHnZfIgD9jdG89DmNoRgXmOAF5sOTe+ 3Ou6eIZpOwQQ17+paoP94H7hFgNHItNzJY05dXXXC0qz6l6QhV5Rc16vCMSRhp5r7WPtWH340Sk UfZhAaQldi7lzQoYylog9DpNvqLSLUAHOC5ichLxXGChp/O8s3oXwSmk1m8AQAR8eSVq3BhJmV7 074cyWhH/luOZTAGqF2HuaCMJs2uW57rvD8CpRVwbwnAv2dPKAfalPao9yJ/bsd5gXKmEJEa3+l 30x84kYzjNyVeWWcymBSN/3FfZZmLcIjaTp1ixZeg7DFmVQVMjkworQbDkzDKWEP8ne4QmqvD50 Xc7MD/pw1SBSE6FCbVN5+s9fDzzpww== 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 | 108 ++++++++++++++++++++---- tools/objtool/disas.c | 89 +++++++++++++++++++ tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/check.h | 8 +- 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, 278 insertions(+), 19 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 ee04fba8c9d16..6e62ffd407926 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 objtool-$(BUILD_ORC) +=3D orc_dump.o diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 0f6b197cfcb03..7c95d3d263d72 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -100,6 +100,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 1fd56e8afbfc6..e047cf12f0ddb 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3,6 +3,7 @@ * Copyright (C) 2015-2017 Josh Poimboeuf */ =20 +#include #include #include #include @@ -14,6 +15,7 @@ #include #include #include +#include #include #include =20 @@ -35,7 +37,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) @@ -3519,8 +3523,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 @@ -3544,6 +3550,8 @@ static bool skip_alt_group(struct instruction *insn) =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, @@ -3565,8 +3573,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++; } @@ -3603,8 +3613,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; @@ -3632,13 +3644,24 @@ 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 orig"); } =20 if (skip_alt_group(insn)) @@ -3650,10 +3673,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; @@ -3669,13 +3698,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; @@ -3685,10 +3719,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) @@ -3701,6 +3737,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; @@ -3709,6 +3746,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; @@ -3717,6 +3755,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 @@ -3729,6 +3768,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 @@ -3746,6 +3786,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; @@ -3755,6 +3796,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; @@ -3767,8 +3809,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 @@ -3778,8 +3822,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; struct section *sec; @@ -3791,7 +3835,10 @@ static int validate_branch(struct objtool_file *file= , struct symbol *func, =20 sec =3D insn->sec; =20 - while (1) { + do { + + insn->trace =3D 0; + next_insn =3D next_insn_to_validate(file, insn); =20 if (func && insn_func(insn) && func !=3D insn_func(insn)->pfunc) { @@ -3814,10 +3861,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) @@ -3831,7 +3883,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; } @@ -4277,9 +4342,18 @@ static int validate_symbol(struct objtool_file *file= , struct section *sec, if (opts.uaccess) state->uaccess =3D sym->uaccess_safe; =20 + if (opts.trace && !fnmatch(opts.trace, sym->name, 0)) { + trace_enable(); + TRACE("%s: validation begin\n", sym->name); + } + ret =3D validate_branch(file, insn_func(insn), insn, *state); if (ret) BT_INSN(insn, "<=3D=3D=3D (sym)"); + + TRACE("%s: validation %s\n\n", sym->name, ret ? "failed" : "end"); + trace_disable(); + return ret; } =20 @@ -4693,8 +4767,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; @@ -4716,8 +4788,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 c8f3fad086faa..181e4ce975d36 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -311,6 +311,95 @@ 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. + */ +void disas_print_info(FILE *stream, struct instruction *insn, int depth, + const char *format, ...) +{ + const char *addr_str; + va_list args; + int len; + int i; + + len =3D sym_name_max_len + DISAS_INSN_OFFSET_SPACE; + if (depth < 0) { + len +=3D depth; + depth =3D 0; + } + + if (insn && insn->sec) { + addr_str =3D offstr(insn->sec, insn->offset); + fprintf(stream, "%6lx: %-*s ", insn->offset, len, addr_str); + free((char *)addr_str); + } else { + len +=3D DISAS_INSN_OFFSET_SPACE + 1; + fprintf(stream, "%-*s", len, ""); + } + + /* print vertical bars to show the code flow */ + for (i =3D 0; i < depth; i++) + fprintf(stream, "| "); + + if (format) { + va_start(args, format); + vfprintf(stream, 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 ab22673862e1b..e79a52c098883 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -38,6 +38,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 f3ea144d4746c..e5f97acb62522 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -64,8 +64,9 @@ struct instruction { noendbr : 1, unret : 1, visited : 4, - no_reloc : 1; - /* 10 bit hole */ + no_reloc : 1, + trace : 1; + /* 9 bit hole */ =20 struct alt_group *alt_group; struct instruction *jump_dest; @@ -141,4 +142,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..ea0904a0ce001 --- /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 8be02483823dc..08540baa02126 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..bc3113ba72fdb --- /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 Sun Feb 8 08:48:45 2026 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 DB82933E369 for ; Wed, 12 Nov 2025 16:04:16 +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=1762963458; cv=none; b=vAlU7dxPG1Wu3H7hn0NY4d3FCU7hMqlp6fhY2S/wrbsdij3HxtMZPdzi+9pcPDIWRadUnNZ6GidkGc1aydc95vR4cQuSq9XgK/pq7ogxOm3I88+4IlFkQENqXankBRiftwqXpT4D7IdFDmeey95LGrO1RSH/ixv//H+bWZz8t6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963458; c=relaxed/simple; bh=pC2WAUV+iU0LWoW084h3U8rs1dj6nF7sKXuysdtnOkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eqe5rEkIS4XpHfxUi7e7PgG1JGoalv+10pycCHbxkOm5662+/hAfv2pZCoVTvB7WolBD+cBhABTx+D6SUW0/vhVA870PuNpkPRtwPZOcIEAKbpt3KEhzHZoiHJayM3SNmbTco2YV+Cs6hMh1JxDraQ7pLnBbKfV+7YvT7FlgD8s= 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=liBIAkNZ; 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="liBIAkNZ" 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 5ACFRHnf007874; Wed, 12 Nov 2025 16:04:09 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=9902H Q+6qpXwpG+/+fELpIj/HjoLqWNfspd3VuptgbM=; b=liBIAkNZwWzOEDdG1YZ3z jN/wQuk0aX9c33DDlTxHzHgz49k+ykKdwss1ue6BaHFi6rAfOInrR/75hu1iL3j7 HlJ3O4FRz0Sf+j61HAeAjkuffCn23fefakDR7UmRiKAZyqpy+WKxwock5eUITXoo nZ74Fo5DXm6/nu5mYRCHwPujtWG2DwnGJoP37Nyvo70QlbqUae8QpUkLaTXTe5Oj w4jxUpsFanB0iZbVMsUqR/m6z7Q3dnvsxJrObMqj8Vucy8SDLDY85k9+iVAWncc8 1cJHVBuESYjrJHkEGgWd9S6RowkkevYVQ+pPHLCF2QOKuMsItJJ15jDwTOAQWi2Z w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acu650dje-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:09 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG5XJ019012; Wed, 12 Nov 2025 16:04:08 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavq8y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:08 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3c004655; Wed, 12 Nov 2025 16:04:07 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-12; Wed, 12 Nov 2025 16:04:07 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 11/28] objtool: Trace instruction state changes during function validation Date: Wed, 12 Nov 2025 17:02:58 +0100 Message-ID: <20251112160315.2207947-12-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEwOSBTYWx0ZWRfX4GjDoVpdHSia aQVjxxmlhmePXH5+WlBO/d7l0sqYt92cbfYcgy6aM809Fr4GeUE1DkaEa7oV4GqMBatui6DSH+M qp9C4d12s3drImy1+2XGVGaMMJVKn84LS9wuKFHzSh1kulSjNvxf+tsPHt43nAYen9RMDOqn+Z9 m6KNlvYymp9hY6LkrlYLKOk3dYjRHcYX5crxUUIzQ187Lr8iBuHaj8JHrpDCInv6u7sG7iHcTp6 eho8wlncTJ//4G5LL6v6jFLqp4SO+vSTIT1Vk2JafZgsxuAaHVWZr/dONrE6IYGTkdVwtEs96/m 23r52VAD90GCPSxXI4j0cjquUa0cJ3R1zNa9QGoVDUkI4ROXkslZugvhe1+PlcsrA2mL4k4GImy EK2GPmMCKBH/EphsMD5zNCIepDwKrQ== X-Authority-Analysis: v=2.4 cv=UvFu9uwB c=1 sm=1 tr=0 ts=6914aff9 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=n0rf_ozDEmcaLxr6z3oA:9 X-Proofpoint-ORIG-GUID: 35udzCi9Sz6olUUbnrhxYcVdAExBzxDx X-Proofpoint-GUID: 35udzCi9Sz6olUUbnrhxYcVdAExBzxDx 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 | 133 ++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e047cf12f0ddb..26682ac0185ec 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3558,6 +3558,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; @@ -3667,7 +3669,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 ea0904a0ce001..5b8abdb9b09fb 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 bc3113ba72fdb..f45ae3e88d428 100644 --- a/tools/objtool/trace.c +++ b/tools/objtool/trace.c @@ -7,3 +7,136 @@ =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 NULL; + + 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) +{ + const char *rname; + + if (base_prev =3D=3D base_next && offset_prev =3D=3D offset_next) + return; + + if (prefix) + TRACE("%s:", prefix); + + rname =3D cfi_reg_name(reg); + + if (base_next =3D=3D CFI_UNDEFINED) { + TRACE("%1$s=3D ", rname); + } else { + TRACE(fmt, rname, + cfi_reg_name(base_next), offset_next); + } +} + +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 Sun Feb 8 08:48:45 2026 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 77C4F34676E for ; Wed, 12 Nov 2025 16:04: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=1762963459; cv=none; b=lugX0shxPA8lOS5IXj52LXfK2uS9mzHkkflqbHiRUP95xLjxycae3hkGxmniBHXzGdnTar7yDmJs/MkxZKcktLx7eX1qjLJCf2C2anrxFF3h4slprgk/R48orAcuOWmyqNFiRk6uoumqE/6zRI0jPKOok4JljxZqOK8knJ/GdwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963459; c=relaxed/simple; bh=XHxubh2Ex6f1fNjOHyxSKBBVuRAcupgCiMdiGQQ8YlM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ie7WjiLYJIqDit4DnIxsUuTV3KEP9e3uKL6Su3yeAq/896T7SnKot7nyF9TJ7tof95NiX77H8JhwNgPsg4GClNFRSxaP47MYgLHmmtYYJQz4zGpmxevVe0kH899Hpou8uzJcJl2BMMms3j9lemTgSn87J1THkuKYSPrq+Dlflk8= 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=CjC0fYF2; 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="CjC0fYF2" 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 5ACFVv00012507; Wed, 12 Nov 2025 16:04:11 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=C8PDU hjr06wv8rRe2HDeqvlGwH4SkM+T43NMmoaRcYQ=; b=CjC0fYF2EC4cTmcqNeUh7 +KnsXgTHa13scRl0IdSpcn1BYoIxfNx+N0jjxE2GxN15BBbVxT3lHPvtvvWKF6mO 9q2Ox5menzKFWpsHVQhe1zMZk4Nac3lIGOCIY1R3s10Wv1JHjgzaiIR7hJsa8foa XHqe2dKgJSuMI6e5No7njZXS7lrNVoXdSQJoS+eR3MpXc2vHI9zfdUbL7ziXcA8K CunE/UoIIHq+0lTvVQe3TSo3tTRhYt3gz2LrdZSztFC/QAR8/HnECd1cialBzQdn zlj3tBRwZ09kLYcrAJQMW3Q0BkFRJB6LBpNeSrvjw+s4F9HuImj3aysKz4ubMvCN A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6cy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:11 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4WS018708; Wed, 12 Nov 2025 16:04:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:10 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3e004655; Wed, 12 Nov 2025 16:04:09 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-13; Wed, 12 Nov 2025 16:04:09 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 12/28] objtool: Improve register reporting during function validation Date: Wed, 12 Nov 2025 17:02:59 +0100 Message-ID: <20251112160315.2207947-13-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914affb b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=SYeOCZSjma0EYi-zULIA:9 X-Proofpoint-ORIG-GUID: EmJLTHF4VeqE7mSKJsraZf-GB8jBduoB X-Proofpoint-GUID: EmJLTHF4VeqE7mSKJsraZf-GB8jBduoB X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfXwWOQEbfRKFOh 0cMJYVafvWqoln7pBV3U3bI/ojpQavkIYhAVDSbDLZDt/rT8XhUDprGYxmIJL5/Yv1KTQiP5NUq axhEjev0mCV5uS00f8LEc7sH/NJ3In2w1cwpzghCOTGW2/pk2DYnTS4VvY22zpX7ZVX2AfusYOI ecUbgMGMIbSEcfzoVEMFcgzz48SvEj4R/dHQ1ZzagB3RbK9U5ckUdx1iJIIUfs78YJYPBjiKnWy soIlgVI4YARwyFTw1qj1joowu3OWM/Zi/m8O0Gq9VKBpNiROLxC18F9lg7Am8yd3gBDUeAF2Oxx MqjR5kEQBu14vnmm6W7NZsIjF+ITU/+hP6SIPdTLNjfjKqAnrqXJouZtT1b4tJNONI5j0Tf3jKf yL/7T39Z3RMcUYTNF/Lh074SMI9uTQ== 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 7645409918f5b..2c1a6cb61f76f 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(char *name) { return !strcmp(name, "_mcount"); diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index 9c3f49c455871..74d1a8603535a 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -10,6 +10,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(char *name) { return !strcmp(name, "_mcount"); diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 7bd874871c31b..d651d8921ab47 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -24,6 +24,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(char *name) { return !strcmp(name, "__fentry__"); diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index 2bd7a76f053d9..5bcd0df5d8b61 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -103,6 +103,8 @@ unsigned long arch_pc_relative_offset(struct instructio= n *insn, 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 f45ae3e88d428..ef9250d4646bb 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 NULL; =20 --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 E579A3469EB for ; Wed, 12 Nov 2025 16:04:18 +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=1762963460; cv=none; b=mT5Fdpz9mJ9DItK9Y0WpYL3qN/RQugZHISxxvgiRHU/XJlDwLOAoargun3QE6yEsRwq7Tt3Suyv0ygLJcKbCPLj5q5sozYVcQdrOZZ+RCAuKyW/nr/Zdnip9sPABKIgq+R9Nkp7LoaEtKVJPLjuXFBqpVELAG1uSOt9iJHkClqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963460; c=relaxed/simple; bh=XUAXAF74DOhHMef9jBz0QJoaQApmYe65pyFCdnksUbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=osdA0H26kRUz+nZa0OMNHgfiwZm/WW9z9KRWmaQZFplTiukPmv7sq9pJXNKT6cimmMNtoSKYSMTCMmBHPXPTH62gIvAaRVx5IRMvTUJJ+II1x3Fi1zhxXADa1Ef56soAb3v/l21+/WC/TbiOnj5yX+NfweL+jwC7o8lGp0fhj7A= 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=lPrheImo; 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="lPrheImo" 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 5ACG0Vt9008495; Wed, 12 Nov 2025 16:04: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=ncNzw JPhFH+djZbeGtAnKcG8QPze06VheaySiwD/GOk=; b=lPrheImom9pTq0Aqv9Z36 O5VuUgy7MZPnOHXxMXpOY2mCRkk15KykZZNwJnBV5onVlS8Y41AXHdsDrefPvHdc 6Dv8fixHLHropw1CKyjrpUePsj+CH71V32vgQuPesaU6FU6dhc+yOak+AFWEKN7S jlc7P/+IURLxGetbzBW7ElMfUyUDKr1Mj9YPCPvMELQI3TEXoDV0CZLad8nmNVXj WAFlIQt9mAoTKhOGGqxvqzUt4P0mfp4//wg4a7gKWlz8BJTBT7/g6FZzWEfab/K0 7fftwAp5QAxfAOa+ucGxne+5kgorVVjvl/k6q9Irz3i4cyFzLzNgzrWf4SFqcwdC A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acwcg80g0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:12 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG42T018660; Wed, 12 Nov 2025 16:04:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqch-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:12 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3g004655; Wed, 12 Nov 2025 16:04:11 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-14; Wed, 12 Nov 2025 16:04:11 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 13/28] objtool: Identify the different types of alternatives Date: Wed, 12 Nov 2025 17:03:00 +0100 Message-ID: <20251112160315.2207947-14-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-GUID: mBB2jVSSo0h8ZQEm8Ag8HC6rXiqSBOgJ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyOSBTYWx0ZWRfX7waKF1dIa6Fb BeCLWymoYirQ74ANKKRPsBWd6+S61OmXyh1RtsWKe0w2pN1suTxLoN+tKvPTigGvWRRmGX7Gslx oMDSy2+mDBedt2RhVi46zxBsTcvaREAk3332gzi7gceICvImWisQVMZhPL/XH9du9+4UrE9PkJ/ bdHeb+prfmTs8DjPFg4Mdri1P8J0inpGjiijiYiDjxv0L3bJj9L5WhTc+40GGCEAShaBP0LNAP2 USvWSWxHSXpy5WPGZnz9I8DbfMpN8HmetBu9s5sJtLZizbdzXLPu6/Af0QzoccFweA2vMD504em cdGMxyUNKgAIhWxIayew9CQyFHUSUaU5/+IN/SdtGhmoPF2ZI8Hl3+61Edk+qvT4CxoDuWsBEi/ OoJVRkSrbGqZu48ZklMrUqVA+ra4Pw== X-Proofpoint-ORIG-GUID: mBB2jVSSo0h8ZQEm8Ag8HC6rXiqSBOgJ X-Authority-Analysis: v=2.4 cv=LewxKzfi c=1 sm=1 tr=0 ts=6914affc b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=RDt3PK5YzZswrGw8on0A:9 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 26682ac0185ec..93268b7c015e3 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -25,11 +25,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; @@ -1910,6 +1905,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; int ret; =20 @@ -1948,11 +1944,17 @@ static int add_special_section_alts(struct objtool_= file *file) if (ret) return ret; =20 + alt_type =3D ALT_TYPE_INSTRUCTIONS; + } else if (special_alt->jump_or_nop) { ret =3D handle_jump_alt(file, special_alt, orig_insn, &new_insn); if (ret) return ret; + + alt_type =3D ALT_TYPE_JUMP_TABLE; + } else { + alt_type =3D ALT_TYPE_EX_TABLE; } =20 alt =3D calloc(1, sizeof(*alt)); @@ -1963,6 +1965,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 e5f97acb62522..73310c56e91b6 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 Sun Feb 8 08:48:45 2026 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 EF983346FDF for ; Wed, 12 Nov 2025 16:04:20 +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=1762963464; cv=none; b=Xh/rqLRg1SeXHGwgfmO+rjzNiM/5BCM4yWFUz5rkT9mPLCwZOxWN17z2BCczPymwSjiTnVRsOGqQZEwmh9grfISoK4g5S+5P9mUgJVb7ZaOXPMyeKTpIYGOayx/tx+yX/WisrzoMRPN7yDljoG97rY71dbQNz8qhLm1MhvI/UbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963464; c=relaxed/simple; bh=U4YmAHAqUsk2vmaZzCvqqz+pFd9Yqbw0D9d2dntS7yw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bPS+lIaRKm9Js6Lw3/GMsOsL/EQSZHWTpEfP5JGV7imQrIiVz0zUDNsQAvWffzW71F8txdhdMGqnan/6pE2E7AsukcnNmLWNm5eok1gA3b42l0fpqB8vbOXOAL5NiVnlYqHBd0isAqf85fIUZHm9k+w8nVeUfkSobCSRbdwQx8A= 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=m7uRa4CH; 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="m7uRa4CH" 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 5ACFjfgY007432; Wed, 12 Nov 2025 16:04: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=FZ7nl D6N6Udn03mUeikBcFiZ1ON0KIm8+5xiOGBr4+A=; b=m7uRa4CHqrCBtChF778lW 3ILfbxmjPmCP31ucu3DFBtMu7xgkqVvsCo7Kp0rXfBWjSrAV0zMwlxTdPJk0GD7c wzpXEbBvDak8cikKmz8LKWnPY2tMaZsHu3SdX7N363OUoJDTpZYQA/R98wVhlcIO vatoyvPCy3ptuH+MMJP+4gF5cQQOJzolefVXi3xdTyj8lGlWFFqPErofSPK1wKd9 109Dq9nzWdKzoK3sD+wwx8J2c1ADgW7waJDcrFO1xERkmDJt3283Sysajns9dje7 i2jqGrSqDx71W9BNpfT/pmZSZ4Tv1JXVroyKf8HpRlgogf5XeA4S8WZAIduXOmHe w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acw5f01xs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:14 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG2sO018577; Wed, 12 Nov 2025 16:04:13 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:13 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3i004655; Wed, 12 Nov 2025 16:04:13 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-15; Wed, 12 Nov 2025 16:04:13 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 14/28] objtool: Improve tracing of alternative instructions Date: Wed, 12 Nov 2025 17:03:01 +0100 Message-ID: <20251112160315.2207947-15-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyNiBTYWx0ZWRfX9QPS5CblpSYb uQ/LwTkBHpskuFuN2yaa0SPAmSN3/KW/VJg3ItIEx1tY2mAbRdrHFUxK8sAG+e4C+dyvRMvcLXS 2gL/WGd97xxXjklo6JRingii7l89mkcHk7JZnWN25lIW9g57INoPx6hssi0f6qHy1ZIXIxeTXJq Qk2tsFARCUdl9TyvYv0i+WEQHmMbb2qFAfQ7cTbQXMh/VxrN6QtmGrygDKlTTFSjFq0cLnw8uI9 +RUWKxpNmoi1e923lr5+AfY6GjXRfA8l1DGIOO4D461oAATSpTH9GL/ASOOro+dalc0QGQdlvNH 0wXjYRG2W01BJqILruxO7EHimcuere9+CTiRJKEo86421JQdsO9IBg5OnCIUuYhzjHDUilz6+XE 3x3qT4RZGixwZ9CACr8GH72kQ1FpPg== X-Proofpoint-GUID: Tx1pD_j-goHxM7BZ8RB42E1YiwrVL63u X-Proofpoint-ORIG-GUID: Tx1pD_j-goHxM7BZ8RB42E1YiwrVL63u X-Authority-Analysis: v=2.4 cv=Ju38bc4C c=1 sm=1 tr=0 ts=6914affe b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=oY-bwSMoxZf-G2JThcEA:9 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 | 32 +++++++++++++--- tools/objtool/include/objtool/trace.h | 43 +++++++++++++++++++++ tools/objtool/trace.c | 55 +++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 6 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 93268b7c015e3..de3ddb0fd6198 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3527,7 +3527,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 @@ -3649,24 +3649,44 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, return 1; =20 if (insn->alts) { + char alt_name[35]; int i, num_alts; =20 num_alts =3D 0; - for (alt =3D insn->alts; alt; alt =3D alt->next) - num_alts++; + for (alt =3D insn->alts; alt; alt =3D alt->next) { + if (alt->type =3D=3D ALT_TYPE_INSTRUCTIONS) + num_alts++; + } =20 i =3D 1; for (alt =3D insn->alts; alt; alt =3D alt->next) { - TRACE_INSN(insn, "alternative %d/%d", i, num_alts); + if (trace) { + switch (alt->type) { + case ALT_TYPE_EX_TABLE: + strcpy(alt_name, "EXCEPTION"); + break; + case ALT_TYPE_JUMP_TABLE: + strcpy(alt_name, "JUMP"); + break; + case ALT_TYPE_INSTRUCTIONS: + snprintf(alt_name, sizeof(alt_name), + "ALTERNATIVE %d/%d", i, num_alts); + break; + } + trace_alt_begin(insn, alt, alt_name); + } ret =3D validate_branch(file, func, alt->insn, *statep); + if (trace) + trace_alt_end(insn, alt, alt_name); if (ret) { BT_INSN(insn, "(alt)"); return ret; } - i++; + if (alt->insn->alt_group) + i++; } =20 - TRACE_INSN(insn, "alternative orig"); + 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 5b8abdb9b09fb..3282f3bc3a275 100644 --- a/tools/objtool/include/objtool/trace.h +++ b/tools/objtool/include/objtool/trace.h @@ -19,6 +19,21 @@ 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) { \ @@ -36,6 +51,20 @@ extern int trace_depth; trace_insn_state(insn, sprev, snext); \ }) =20 +#define TRACE_ALT_FMT(pfx, fmt) pfx " " fmt + +#define TRACE_ALT(insn, fmt, ...) \ + TRACE_INSN(insn, TRACE_ALT_FMT("", fmt), \ + (insn)->offset, ##__VA_ARGS__) + +#define TRACE_ALT_INFO(insn, pfx, fmt, ...) \ + TRACE_ADDR(insn, TRACE_ALT_FMT(pfx, fmt), \ + (insn)->offset, ##__VA_ARGS__) + +#define TRACE_ALT_INFO_NOADDR(insn, pfx, fmt, ...) \ + TRACE_ADDR(NULL, TRACE_ALT_FMT(pfx, fmt), \ + (insn)->offset, ##__VA_ARGS__) + static inline void trace_enable(void) { trace =3D true; @@ -61,17 +90,31 @@ 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, ...) =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 ef9250d4646bb..1c3d961b5123a 100644 --- a/tools/objtool/trace.c +++ b/tools/objtool/trace.c @@ -147,3 +147,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 end", alt_name); +} --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 5E05D347BB5 for ; Wed, 12 Nov 2025 16:04:22 +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=1762963464; cv=none; b=DH/RC8B+pG5ybe+XWRY6YSVbiPNuUSxNBnHStGNp4fLQSLXe2JskH4QGvtv/kqVS3nN9Co1UiOM6A3LPwXgTsig6S6uJYb8IRyxCZo8uKyCY7vvjbb1r4pswvyvvSOJ+IhXO7QrPYnHV8Ckk8zCr++2jX1OZt+9krPIYpuKaucA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963464; c=relaxed/simple; bh=kh4isedaQC7r2sc6Zjcf8tsxC1mVuPPsYRKKcCEg44g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qhqoA0bDIBMrpztoWNV08SQwBcerFiJDUKfYHC+UHghj2KqUS1aATXlSzglEoyDvfQ83z+EL0AWgGOsGOLzhNESYTMJZ4RLPH10AXQF6Ps5HYIeKaJ2+ez/lfJ2x7sCG2nt4SpAsHZNsRj0VFig//uWGPbzM9h5+tAGiS7bdKqM= 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=B50epT69; 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="B50epT69" 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 5ACFj7KL006355; Wed, 12 Nov 2025 16:04: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=+hDPt atHAjbURZ8hT3mb5FGrLiADvXzdJWmrLzarRSc=; b=B50epT69sadi7UmdF38wP yYYa2AmW1fsqL29etwWLoVmaC776NXB4QbX6NeQFqKpjfqbe6ciw9kjf8qPXTAaM WT1cfvutmikfTM213dLM8IApYb01cfaQbk6PrgRIL/MwV5QKmNqlUktZ6f+cqKA3 cUvn4ABdgb/C36Tabk5hXwJIGm9apcMM5gPHGcYls7rusIi290dHgbHF2ewBMzu7 YyfRTKw44UxfbT180nGlzrG+LvKBV0PRXKuS71cyKc20rV+6Vi3Jz4nR2rTh1pCe apDui7jEbDVfGF79WM0cOGVK2Gvc7Myqtjm9nqxKUH7ckcEpKbRdaZ11Net0Vw50 Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acw5f01xu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:16 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4WZ018708; Wed, 12 Nov 2025 16:04:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqfv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:15 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3k004655; Wed, 12 Nov 2025 16:04:15 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-16; Wed, 12 Nov 2025 16:04:14 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 15/28] objtool: Do not validate IBT for .return_sites and .call_sites Date: Wed, 12 Nov 2025 17:03:02 +0100 Message-ID: <20251112160315.2207947-16-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyNiBTYWx0ZWRfX97+Ikv38wxv4 UUwtMWfhBLV8BPm+algUCEspkTZge+UYTTxd442aMIlTgXaBas33O8jOs+yYMrn6DfEOblvVEUC IrzHb7qJcf0j1NBajig7r6NVnt8FErfjBS47bEPhSbrBQ36/PFFUpUZr1Hs8QnFasqXkqRxOVlU aFrBwT1/h94XzK9B7cE5oTvhP1Tmfi8+l1DzQAwUQz9AEuen9x5Rg8J4hyD9VbCGaUD7IPLda5Y DRgotcgWfveiLjNf+96jbcoV4f/ztJz7VOIHVBq07DZI++CyprWWWlkRxU7wBUFv7zauNN/SMrx zEGNauCIBCFY7B8s1ZyJJN5+bgZrCayDC2TtJUkjo9atEqsXLucF7S2mj9J0bJ4FhLm9wX8I0cK KKoj81q6phel7cDBU0O6o8+5DdT84w== X-Proofpoint-GUID: rjKbl-oc68metcYyDYtlOOhGOWAl2jOo X-Proofpoint-ORIG-GUID: rjKbl-oc68metcYyDYtlOOhGOWAl2jOo X-Authority-Analysis: v=2.4 cv=Ju38bc4C c=1 sm=1 tr=0 ts=6914b000 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=yvIqsss6GtJD96b7xZoA:9 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 de3ddb0fd6198..14b9220c1058c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4653,6 +4653,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") || strstr(sec->name, "__patchable_function_entries")) continue; =20 --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 AC8B2347FDF for ; Wed, 12 Nov 2025 16:04:23 +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=1762963465; cv=none; b=igIPmtLlBIaBf+yBAgOVvW9WclzeKmMN7sEqE/Yt70Q9FGYUROwW50svrMiSB8LVyvMAvlUwCceiH8j+pZei/H9/89X8rnjm68+jLF4/NgV3tMjqPZOPyHwrcIyQq020+JPX40sAfE8VtjjG4/uu81E4lf/ahp+TFka1nMq9azA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963465; c=relaxed/simple; bh=82F9kJU7gTRjL+gFHNCgewGPKv2/RebjEuUvurBNQrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=STqVxyvcx0ubb9nPwUdioBeyqBnR9xdYoIKNri8q/Qc+4sq6z6UiBGhfpNRS3qzbcpjS+c1GjfePvhvRbTIx3bU0H9Z0zcn8iXHGHhpV1P9TIIcre+5XW1GLp9GNjyaPZnEfvbMTlvc7y0Dvw+v33FECkLQ9DHvBeIkdt8sQfjo= 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=ptXy5Fmf; 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="ptXy5Fmf" 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 5ACFjaAX007112; Wed, 12 Nov 2025 16:04: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=gzqRW zZBDDYIEv3/sw4STDqkkZK/2yJeEMQonuBuLRk=; b=ptXy5FmfqjZMT6hQr3pEc NkVIS5NOhszRXIeg7rxjWtx0z8xlgSNxKmMgAV1mqHBo8zL1VFNWdRqXFUOqUqlQ 7jcNTmJOdvK7bFD9Z+9rNEuMqNO8f1RrQAiHpjR5ICMC4UltaY6fqewwBbgJIe6r dD7UUbXjNZ8mgqW2GLYC9OBz3gYNq3MGJYrQ/1ZmPXV74KDp44Dkm12+8RdIQKZb VFXe6d98fZbC1LCAnJvjZIU18xx+Izip3le1ypk1AZrWpI+Wcpv6IEDJlJSXI26G Xr1qA83yvdwrgp7Ux/29wzY2eDyeg1WS9cpnUO7RFwBgBvQdKopiYRGiohWnfWR3 w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acw5f01y6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:18 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3xQ018591; Wed, 12 Nov 2025 16:04:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqj1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:17 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3m004655; Wed, 12 Nov 2025 16:04:16 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-17; Wed, 12 Nov 2025 16:04:16 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 16/28] objtool: Add the --disas= action Date: Wed, 12 Nov 2025 17:03:03 +0100 Message-ID: <20251112160315.2207947-17-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyNiBTYWx0ZWRfX87YJhx/hi06d DBMJkVyOcWOlUfnMnhUHxVnUUVmfJJfskLsaNC1KiIZ3IUV8d+IJmfMIQpEQiTdJtlTFSJLCeKl B1XL15+EHOHynDNgZOzJmcmoiTDcbUli0GgkEs2lwMq2ooTccwR10XMNPuauh6gFO0qWI277o4Q P58IxgoG89GCGurrsG4Ao3ohIEMhNQKdhMFGdTHi6fNN85xZhDVU3Ldbj3oqPzn3pyUhYGnQTTw 3jiYEQuBuGyLRPGTagmt41EaNkQB6hka4P0u4ObnYRKdOJkjllkyR2zYegCyT9TeBJWk/AB7n8y vl0Ii0942k9YL63wb+3NxG3+tfhiRhaHHQOKv+DMWL925BVUYRHGH/G6Sd8AY++W8PozdQaYTdN TeW+bhczh8zBVuN46KCjGhFQdacXxA== X-Proofpoint-GUID: RQnn3kYB1mZFftLArcdf2MyQmtt9EFrc X-Proofpoint-ORIG-GUID: RQnn3kYB1mZFftLArcdf2MyQmtt9EFrc X-Authority-Analysis: v=2.4 cv=Ju38bc4C c=1 sm=1 tr=0 ts=6914b002 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=Yos37rPc9-vhJleOp_oA:9 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 | 4 ++- tools/objtool/check.c | 35 ++++++++++++++----------- tools/objtool/disas.c | 28 ++++++++++++++++++++ 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 7c95d3d263d72..7ce49a00bdabc 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -73,6 +73,7 @@ static int parse_hacks(const struct option *opt, const ch= ar *str, int unset) =20 static const struct option check_options[] =3D { OPT_GROUP("Actions:"), + OPT_STRING_OPTARG('d', "disas", &opts.disas, "function-pattern", "disas= semble 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 fo= r ftrace"), @@ -160,7 +161,8 @@ static bool opts_valid(void) return false; } =20 - if (opts.hack_jump_label || + if (opts.disas || + opts.hack_jump_label || opts.hack_noinstr || opts.ibt || opts.mcount || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 14b9220c1058c..f4e419c895a74 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2570,7 +2570,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 (opts.stackval || opts.orc || opts.uaccess || opts.noinstr) { + if (opts.stackval || opts.orc || opts.uaccess || opts.noinstr || opts.dis= as) { ret =3D add_special_section_alts(file); if (ret) return ret; @@ -4815,14 +4815,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 @@ -4944,19 +4945,21 @@ int check(struct objtool_file *file) } =20 out: - if (!ret && !warnings) - 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); - print_args(); - disas_warned_funcs(disas_ctx); + ret =3D 1; + + if (opts.verbose) { + if (opts.werror && warnings) + WARN("%d warning(s) upgraded to errors", warnings); + print_args(); + 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; diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 181e4ce975d36..cb7e0c7ba165a 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -3,6 +3,8 @@ * Copyright (C) 2015-2017 Josh Poimboeuf */ =20 +#include + #include #include #include @@ -461,3 +463,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, 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 e79a52c098883..cde9474b57820 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -27,6 +27,7 @@ struct opts { int prefix; bool cfi; bool noabs; + const char *disas; =20 /* options: */ bool backtrace; diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 5db75d06f2197..5d2149ffac335 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -14,6 +14,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); @@ -37,6 +38,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 Sun Feb 8 08:48:45 2026 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 4C5CE33F371 for ; Wed, 12 Nov 2025 16:04: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=1762963468; cv=none; b=K1wsGrIAPgdYpdoQQ85ZOdvyKNClpHcNNyVi+81pwNdcrdHMzur3JkZ+1MbkvBOD7muI5ryAwOEVZBqpF3sM1tvTuXTbs8QyUaBUMMxUEitNbtq3Bo392EqKwbPeVk2ABfegfo1vVPQwsHXoNTew0lAHM15Bar00vT0roKTw86w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963468; c=relaxed/simple; bh=UeJC7A8yySa2jJk5mj+Xf5wFPcalhbRb2J1/db9X0S4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ITZOaPa88tzZB//kIxjxlZi4Pyj9n1Llw2oXx4rQHDBTNnGm8+UNtbDb4z45JUDQot5zdPbq3Yzl69MDSP2pspdxoBsP7GWacG9KA/DS8TyU+5C8/HWSInqR6lZsu0+apFNOvI+sSMNGtYn/yNESvqD1QWF83z/B+gG8KfqIv6o= 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=XmAW3iep; 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="XmAW3iep" 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 5ACFVU3j011666; Wed, 12 Nov 2025 16:04: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=Cv5Oe /SwAi5Jd6gACqUVIeySjoXHjenLha5Q3HYStGk=; b=XmAW3iepqpbz2r3bRl2Hw /bv8Gb1PL6jRyGxyESYo2cXR9FRrcin3y5WTtQGeBy34QDHCedBJTdHGEWZKYPwJ a4qPoMFd0EnrJvWWQK9e19kLk4g1jyhaHAu8/B6B10Jrgq+eB0xRyXWKUlISPDwj C/yl4YHITLHMXQZFUGgUPUMhFGO/kneU3FO4tactWnfhEW5AL4DrGLAEAdMqiRHj C+uns3ggUcYr4TCdUNQ5JtRj91ObRY9gOzh9DRz3q3hdSBqprjB5tZXXtvvojd3B 7tBKyYqa4G1PDBCCOySgIFdhgIvrraM5XGGIFU/GglH3ttlEY38JQ7B0qL4VHU2I w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6dp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:20 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4oB018707; Wed, 12 Nov 2025 16:04:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqkr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:19 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3o004655; Wed, 12 Nov 2025 16:04:18 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-18; Wed, 12 Nov 2025 16:04:18 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 17/28] objtool: Print headers for alternatives Date: Wed, 12 Nov 2025 17:03:04 +0100 Message-ID: <20251112160315.2207947-18-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914b004 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=RozQtDkvD__u-kIZZ1wA:9 X-Proofpoint-ORIG-GUID: ui_9dKVEdadQbscG6j8-wS6LjYba6ZII X-Proofpoint-GUID: ui_9dKVEdadQbscG6j8-wS6LjYba6ZII X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfX6jyXDDBrNOP0 BLnHb6hTXrTFblaXiGzkDwSemz96farxyxjwYy04+5l2arHT9f47bmgSKf5NOyTWe6ED/Uh/SGv 37LXx8iDyKTixfTGVHNTC81m5ofuK589HmDBxVC0lfvcfy6XIKiMUxp40ZUPh2oK9OYSAgnKX9d Fd4mgYSq1CvZbqB7cWR7GaSp23zMXbZCuHQPINTvO2Rkmw+LEzLzNIzL4fckEHUsNCdovHcsqNI zW5AJ9SH8w6oOkhgZT/+qCWv01KDIMLBIC0A5q95g/rWwDmpnWidildw+udsEd/W6kZ6ZQ19DZB 2I6U4nOFOyCukTmjvQkq9Wl3gCmG1rcKR8Py++Yc5TLm6nUhh70iqnNCEfDbLFCqP1OujzJLtiR Ar4uXd9FsPCHaizC+4oMlzlT/x/o/Q== 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 | 155 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 149 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index cb7e0c7ba165a..43dc51f614f1c 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -3,6 +3,7 @@ * Copyright (C) 2015-2017 Josh Poimboeuf */ =20 +#define _GNU_SOURCE #include =20 #include @@ -28,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; @@ -316,6 +354,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, @@ -429,21 +470,123 @@ size_t disas_insn(struct disas_context *dctx, struct= instruction *insn) return disasm(insn->offset, &dctx->info); } =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, + int alt_num) +{ + dalt->orig_insn =3D orig_insn; + dalt->alt =3D alt; + dalt->name =3D alt ? strfmt("ALTERNATIVE %d", alt_num) : + strfmt("", orig_insn->offset); + if (!dalt->name) + return -1; + dalt->width =3D strlen(dalt->name); + + return 0; +} + +/* + * 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 alts[DISAS_ALT_MAX] =3D { 0 }; + struct alternative *alt; + int alt_count; + int alt_id; + int i; + int err; + + alt_id =3D orig_insn->offset; + + /* + * Initialize the default alternative. + */ + err =3D disas_alt_init(&alts[0], orig_insn, NULL, 0); + if (err) + goto error; + + /* + * 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("Alternative %lx has more alternatives than supported", + orig_insn->offset); + break; + } + err =3D disas_alt_init(&alts[i], orig_insn, alt, i); + if (err) + goto error; + + i++; + } + alt_count =3D i; + + /* + * Print an header with the name of each alternative. + */ + disas_print_info(stdout, orig_insn, -2, NULL); + for (i =3D 0; i < alt_count; i++) { + printf("| %-*s ", alts[i].width, alts[i].name); + free(alts[i].name); + } + printf("\n"); + + /* + * 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; + +error: + WARN("Failed to disassemble alternative %x", alt_id); + + for (i =3D 0; i < DISAS_ALT_MAX; i++) + free(alts[i].name); + + 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 Sun Feb 8 08:48:45 2026 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 CD89834AB03 for ; Wed, 12 Nov 2025 16:04:28 +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=1762963470; cv=none; b=AecphASkZWwLCPVcwqGFCa3z+nDTfkQwyrTSmVjzCPfx3DHDIy8CLcNaRHWeNUZcLOR8khK9HVBre7sAHxjtGs6ICknp41Rm0Din9c1XmZMbFO/U9mowF/QZSRdHpALElyYhbwa4JnNMI9DUhjBnanUvZ98BESqx9zbt5AGOZE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963470; c=relaxed/simple; bh=ku/+OqRRYJmOqfxHIS/dfuY3pj18QT7pndOO7gvVbdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FwUlZ2IUGyTEubM9WmE4LJT+WxWNqz/kbPctuxvPrIrkXgEQQwd1WnUj/MfelUsk5DWv92AzQOhR2K22tOTVlJV4wPJwcqv8ldcSu5i3TKSNWnH+tj6hYdXy/8EFDkm6ervJ+/VNYxLcFt7BYA3pH3XCe2dQxxLD7+2LeoK8hPs= 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=Jq4hYyWO; 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="Jq4hYyWO" 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 5ACFjbol007206; Wed, 12 Nov 2025 16:04: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=D0sFP +ZGOAx8ChM2bzSKXGKXtPMGODiE8h83xtluZA8=; b=Jq4hYyWOC2Ncv7v4y3fBj IyAV3eZNIABLEa8TXcxBQPj6nSvA3MiXJEAVryuYi0pW1uxuMl/lwZocwL19MSwb Op2unFp6dO+6yTq2qbdEvxHrKGuxxcTebzDmdjzaqtn1UOK96xQaE9BKx8Nii+9u KeK8DiLb7aOnpmuQHFU+iB/FfDntrqakpnH9xXAohh9KFF2RT0Tx0aqQb4lsbNNi 9+/+Te8RJR/fXYFOt7+nF/3cUcUc69cimXrgr+yXlpMai5g86G05diupTcMqEtnj zALvxqo0pRowQ3CG3H66bYMIkWt7s+vlmgoU07iwvun7rnrnVKogmzB2BkmZ+cAv Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acw5f01yp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:21 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4YQ018650; Wed, 12 Nov 2025 16:04:20 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqmr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:20 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3q004655; Wed, 12 Nov 2025 16:04:20 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-19; Wed, 12 Nov 2025 16:04:20 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 18/28] objtool: Disassemble group alternatives Date: Wed, 12 Nov 2025 17:03:05 +0100 Message-ID: <20251112160315.2207947-19-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyNiBTYWx0ZWRfX06LY6MoYNS0b Vouw/KXvLNivUhQG+frbManoO/iIBPyLN4s9QPkgY985KlSQD8MNQwzfTGSWvEOhK70wOHOHNbr 8tgeo8kTELwIdTuWZLo/gj7QZqXnz+mE9IgSHmT5qUWW8T9rFDRFW89eI/YJrwFDnfWIQu8w6F3 O3Wz2iQ0CitbhV92YkdjOa03DnCPvgDAb57CjCVCwRwRQiGBhGCyzTnTUPZWCr+7oDE7wu7fqY+ Fc2QbmLXDOSmP+biD2h1UNbrVqrlydIMnQ+GPHy2hQ3Wjr/ocJp308zMlakTj0YvKEg81rl1fBd 5eHENJXb2LzMZre6Dd/vcuKjUs7YpSSYK+cxq3BlCqYY22R63eeKMvmYLhUUe9QrWlj3ZFovC6g Y/KtD5NqFfD3RWDhRp+TQ83W6hwXzw== X-Proofpoint-GUID: cgrS_5Q4hNkwy63NNwALIfkifoBPQXXD X-Proofpoint-ORIG-GUID: cgrS_5Q4hNkwy63NNwALIfkifoBPQXXD X-Authority-Analysis: v=2.4 cv=Ju38bc4C c=1 sm=1 tr=0 ts=6914b006 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=BZlt5mrdIDfIrSVFCwQA:9 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 | 146 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 138 insertions(+), 8 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 43dc51f614f1c..28c77762b1bd5 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. @@ -470,6 +476,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)) + /* * Initialize an alternative. The default alternative should be initialized * with alt=3DNULL. @@ -490,6 +511,83 @@ 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; +} + /* * Disassemble an alternative. * @@ -502,22 +600,30 @@ static void *disas_alt(struct disas_context *dctx, { struct disas_alt alts[DISAS_ALT_MAX] =3D { 0 }; struct alternative *alt; + struct disas_alt *dalt; + int insn_count; int alt_count; int alt_id; - int i; + char *str; + int count; + int i, j; int err; =20 alt_id =3D orig_insn->offset; =20 /* - * Initialize the default alternative. + * Initialize and disassemble the default alternative. */ err =3D disas_alt_init(&alts[0], orig_insn, NULL, 0); if (err) goto error; =20 + insn_count =3D disas_alt_default(dctx, &alts[0]); + if (insn_count < 0) + goto error; + /* - * Initialize all other alternatives. + * Initialize and disassemble all other alternatives. */ i =3D 1; for (alt =3D orig_insn->alts; alt; alt =3D alt->next) { @@ -526,10 +632,25 @@ static void *disas_alt(struct disas_context *dctx, orig_insn->offset); break; } - err =3D disas_alt_init(&alts[i], orig_insn, alt, i); + dalt =3D &alts[i]; + err =3D disas_alt_init(dalt, orig_insn, alt, i); if (err) goto error; =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) + goto error; + + insn_count =3D count > insn_count ? count : insn_count; i++; } alt_count =3D i; @@ -545,11 +666,20 @@ static void *disas_alt(struct disas_context *dctx, printf("\n"); =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. + * Print instructions for each alternative. */ - return NULL; + for (j =3D 0; j < insn_count; j++) { + disas_print_info(stdout, NULL, -2, NULL); + for (i =3D 0; i < alt_count; i++) { + dalt =3D &alts[i]; + str =3D dalt->insn[j]; + printf("| %-*s ", dalt->width, str ?: ""); + free(str); + } + printf("\n"); + } + + return orig_insn->alt_group ? orig_insn->alt_group->last_insn : orig_insn; =20 error: WARN("Failed to disassemble alternative %x", alt_id); --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 04BA334AB18 for ; Wed, 12 Nov 2025 16:04:29 +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=1762963471; cv=none; b=M4CIiXt/PphupTvTOcNL5zCyBwWOj722ZZFG2VgEryrSSpAb8THVPlTelOo9j9oSAyz30Y+iWYBsPb/5VMJppriVoa1S3ufpqcydkjbQ14i9y8aWzqpRJQGPGK/Lo4Kk30jh3PTnR+dJRO/65zM5gmK+Ndx6irS5pn/G1XvtbTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963471; c=relaxed/simple; bh=6EJ98B4JqQMBzEuAKbzZlN0UjYeA5mkvLlGhpF4/wIk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G57oah08xJ34I/iFfc0IlzfZjJTJIN69YQNOLLghvCbNu2BaRsgOQ8kODQ1w/wW4/IyLog6D4tdYmZwicUT/4Ulm5E2UgoC173/oDFm7gyqF8NcOfVT3Dsu3f+74DpQVbUekdhl0Aw5B3hz5pU8tO/dxq01WQZWdRjmyBhr0wUA= 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=M+1afVG8; 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="M+1afVG8" 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 5ACG0OmJ008381; Wed, 12 Nov 2025 16:04:24 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=TCQUr 4DREFS+7R++57ZBXFr0tLhz1BZePCi/aCKDPRk=; b=M+1afVG8gJANAR6VfcZXH 9StwOKQ35cxmLjvcieE1e2fsqvMweYG9X/v+lOmwqn+4hF15xo5n+DMoXk7IH1Nd MosnIGs5XLyIbawo/hYwj1C+rkiXB0Cs5OmWO2XOTW0NbTPzqxmBgfY9wR7S7Fsr 8gaRrqE4o1saheEHp1RHORM8PvvjKFCbchN63Eu9qF0ps2yXPQRDLdtc6opSNOjJ k819EE26pg7HYyZSHvhG6l5FFJ6JTFrhBXgS0azsoqeHNvunwIwFc1i837H2ioye 86BdVJzxtEqmVgIkgfs7htuIJjMDmhdsx/OGM7+jOyewPbRyX+3OkV8MY+fow91I Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acwcg80hk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:23 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3P3018594; Wed, 12 Nov 2025 16:04:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqn7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:22 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3s004655; Wed, 12 Nov 2025 16:04:22 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-20; Wed, 12 Nov 2025 16:04:21 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 19/28] objtool: Print addresses with alternative instructions Date: Wed, 12 Nov 2025 17:03:06 +0100 Message-ID: <20251112160315.2207947-20-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-GUID: 95EPsvnR7eeQQ7a1gtIc9FZ5you_4PvX X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyOSBTYWx0ZWRfX+bswGnWlSiJE 3botO2/NCV1bDQCtdJPFsI0RPMjHBaPFe6Sj5qOiKLEmiOiEoVv4Qo60RL0vXdd0GacrDNiJTYC jm8LSfJnAbIuTmJEsubTdjvVhZP8sOGOZG5jJMhPLYjJo++ObL5llzFm7oUPm7r96nRRzYImfZr X+1c8JeGc9y2H5jUdh9IhMNplaMLVJg/dtqJheLztdi5/e5nKyr3hhmK4R7WAqZTUtLbLGiCgeD 4gNpP2m0PPFiSRpqq+dKXy2sN+2BaRpWEGiisnMrMWadeE4dccvAe/q2jxrmHJP+FHjBM/yZvp8 DIvjuwjzMzbyI2ckDNVXigd7TMDSTCsOVDySjC9Mu90qcjY2P8JHKS5b/U8wvTHCIIOMz3pPiky sKVEmxZPWsYd2CdvfV376RA16AsoVQ== X-Proofpoint-ORIG-GUID: 95EPsvnR7eeQQ7a1gtIc9FZ5you_4PvX X-Authority-Analysis: v=2.4 cv=LewxKzfi c=1 sm=1 tr=0 ts=6914b007 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=WFXfjiaBZm73b8CXPiEA:9 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 | 152 +++++++++++++++++++++++++++++++++--------- 1 file changed, 121 insertions(+), 31 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 28c77762b1bd5..dabf2340e9ccf 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) @@ -364,16 +368,14 @@ 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. */ -void disas_print_info(FILE *stream, struct instruction *insn, int depth, - const char *format, ...) +static void disas_vprint(FILE *stream, struct section *sec, unsigned long = offset, + int depth, const char *format, va_list ap) { const char *addr_str; - va_list args; int len; int i; =20 @@ -383,9 +385,9 @@ void disas_print_info(FILE *stream, struct instruction = *insn, int depth, depth =3D 0; } =20 - if (insn && insn->sec) { - addr_str =3D offstr(insn->sec, insn->offset); - fprintf(stream, "%6lx: %-*s ", insn->offset, len, addr_str); + if (sec) { + addr_str =3D offstr(sec, offset); + fprintf(stream, "%6lx: %-*s ", offset, len, addr_str); free((char *)addr_str); } else { len +=3D DISAS_INSN_OFFSET_SPACE + 1; @@ -396,11 +398,44 @@ void disas_print_info(FILE *stream, struct instructio= n *insn, int depth, for (i =3D 0; i < depth; i++) fprintf(stream, "| "); =20 - if (format) { - va_start(args, format); - vfprintf(stream, format, args); - va_end(args); + if (format) + vfprintf(stream, format, ap); +} + +static void disas_print(FILE *stream, struct section *sec, unsigned long o= ffset, + int depth, const char *format, ...) +{ + va_list args; + + va_start(args, format); + disas_vprint(stream, sec, offset, depth, format, args); + va_end(args); +} + +/* + * 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); } =20 /* @@ -502,6 +537,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 ? strfmt("ALTERNATIVE %d", alt_num) : strfmt("", orig_insn->offset); if (!dalt->name) @@ -511,7 +547,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 @@ -522,7 +559,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 @@ -537,12 +575,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 @@ -551,9 +591,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 @@ -581,13 +622,63 @@ static int disas_alt_default(struct disas_context *dc= tx, 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 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 *alts, 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 &alts[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 ?: ""); + free(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; +} + /* * Disassemble an alternative. * @@ -601,13 +692,14 @@ static void *disas_alt(struct disas_context *dctx, struct disas_alt alts[DISAS_ALT_MAX] =3D { 0 }; struct alternative *alt; struct disas_alt *dalt; + int offset_next; int insn_count; int alt_count; int alt_id; - char *str; + int offset; int count; - int i, j; int err; + int i; =20 alt_id =3D orig_insn->offset; =20 @@ -668,16 +760,14 @@ static void *disas_alt(struct disas_context *dctx, /* * Print instructions for each alternative. */ - for (j =3D 0; j < insn_count; j++) { - disas_print_info(stdout, NULL, -2, NULL); - for (i =3D 0; i < alt_count; i++) { - dalt =3D &alts[i]; - str =3D dalt->insn[j]; - printf("| %-*s ", dalt->width, str ?: ""); - free(str); - } - printf("\n"); - } + 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(alts, alt_count, insn_count, + offset); + } while (offset_next > offset); =20 return orig_insn->alt_group ? orig_insn->alt_group->last_insn : orig_insn; =20 --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 A61EF34B1A2 for ; Wed, 12 Nov 2025 16:04:30 +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=1762963472; cv=none; b=BXG4wchOkC5xJukY+RdPytNs9UjTRtmu/X9aNcaTcUw8cG243Vf/6Xm/eDhvcbBucUH4cjcIvnvkp/HKr++WoVjjc40bWpEoXgu2TC5qatEYiStpguPK/iaCOtPryOnuYK7eou9Bz8wJgs2UPW8JqVznPeoR7aGTgWmb41k49aQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963472; c=relaxed/simple; bh=TVlCGa6GV92+xYOqZDO+z6v/96TqDiytNb7hpvtpK3s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RtaZCyZqzUUgSY81A7IZUfixP9mjlJZRIqUsLDR+3pqLNNKAmgR1I/x9VN0jPuT5fWNHje8ytWscCVyKJEo/Ohb4o1N8ZSulSMfhCOXfMhTeMwxP/mIq3bgBkj6CCk5Xc+mI76isjD+nTu0qnl0nuVMoCWEetRLuKWzKMlwnkuY= 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=X9NBfDO/; 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="X9NBfDO/" 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 5ACFRDk7008543; Wed, 12 Nov 2025 16:04: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=5LgQ2 f+rSDmiAonxwWPjQhXnmpPT9QWpdX3ApHmQH/g=; b=X9NBfDO/itwwHk2d+KXrx hE+N5aeYKFFbpACVW9UkCzLaQD0lr9mmCm8F6C0ShVhFS3s3MdAHri6ZL8LZW8bK G/nYsVolvrihKh7zpLIXd5n+50v4CNXzGkMuWZjKAd4O/117XvCzXlwjf4gVUHmK hu7RzfDx2Ix2qg/wJroi3nuTQwML4PuN0BBeFNQZFCuFQkOwjdiXi+lpjA4Z467V Y4/Tr/qAMakVI8YmKRFSUse/diZaUV0Xxp8r9DELYtxHxzyIYo/RqOHly3Xx3UO8 d6HAh57BC31ihOrwEXO5X1jJpsDj3F0J62/R4AbtqdjDRFREMtrl8gdwrc0WSHNl A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvssr4ns-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:24 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4Vg018640; Wed, 12 Nov 2025 16:04:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqnj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:24 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3u004655; Wed, 12 Nov 2025 16:04:23 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-21; Wed, 12 Nov 2025 16:04:23 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 20/28] objtool: Disassemble exception table alternatives Date: Wed, 12 Nov 2025 17:03:07 +0100 Message-ID: <20251112160315.2207947-21-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=6914b008 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=UEfQvUvM895RRNYFhMwA:9 X-Proofpoint-GUID: qEBhNCEoyTKa_oQB7_xgxOhCehPENlAm X-Proofpoint-ORIG-GUID: qEBhNCEoyTKa_oQB7_xgxOhCehPENlAm X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfXwNe4saDL0dIv R8KCMSKyhfwPd0O3VLQrnf1V2STA/K2ZbFeNJpeZXq/Kg3SQThGVZleIOpDqN8nvZK/ET4uBoRb ky3G8iURPHfq/vyvcsmIUkzNSh0jhQOdhy7dysMpc4rFmV0zOIMT+4KYUE1SYWMS9FRJmapYJXY wGLmaTXucZYKap/RIJkya4X3YuOWsUI7Md42B6lKhRU+d8ZIavhGWreJUg7qyjy/DfZDTjreVEq WbUyLjYCgriQYWhVKdWKUp5SjdNPa9W59v6JAKs+PJblHVKBrv5QrH1zUs1dAdyXzNuAdzQpC1M 42uIvka3cy529RMNj3Zmv0GxzUO3Qbnwo6/iBxIS/ySDb9f6IKZ0B5dOkOAsZLgMK671CYdNxdi S0oEltuU+U1YRLkXCEkqd31In4Lkdg== Content-Type: text/plain; charset="utf-8" When using the --disas option, also disable exception tables (EX_TABLE) Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 45 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index dabf2340e9ccf..42f3bf310b033 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -535,13 +535,26 @@ static int disas_alt_init(struct disas_alt *dalt, struct alternative *alt, int alt_num) { + char *str; + dalt->orig_insn =3D orig_insn; dalt->alt =3D alt; dalt->insn_idx =3D 0; - dalt->name =3D alt ? strfmt("ALTERNATIVE %d", alt_num) : - strfmt("", orig_insn->offset); - if (!dalt->name) + if (!alt) { + str =3D strfmt("", orig_insn->offset); + } else { + switch (alt->type) { + case ALT_TYPE_EX_TABLE: + str =3D strdup("EXCEPTION"); + break; + default: + str =3D strfmt("ALTERNATIVE %d", alt_num); + break; + } + } + if (!str) return -1; + dalt->name =3D str; dalt->width =3D strlen(dalt->name); =20 return 0; @@ -567,6 +580,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. @@ -730,12 +763,16 @@ static void *disas_alt(struct disas_context *dctx, goto error; =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 Sun Feb 8 08:48:45 2026 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 144D234B410 for ; Wed, 12 Nov 2025 16:04:31 +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=1762963473; cv=none; b=DhH1NLCMKxh7wVIqwUuByFERVB13cFpZ7swLpscICD3mAy/CYyyOhAvXi/09mooZCvqwkRzg446s0nHDjdmeINutcQyw7OyqAmZRGbEWQfYXUxlfSHcUlAfDRJUTHpob4lcjAI8DneUcRgKSA0uzBBn/Ce7jNzljdO4Wc/rhgG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963473; c=relaxed/simple; bh=bdY34+Hk+iO6II3DlvBr0qmzUTdVLbu3xcJKQGcFbGw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=agVHz/I7epEFOyUA3AeWMNa2C7nmaLR4uDBjdCQVGhZ5nzRBmG53PNnVc/XOTXLrP+5XJ1XUrscmtpp4bDauykAlbL8RiNpsMpjc6jR+IGOkDIXPPSKsh0iHsYHzhii2H9nDvPfiu3jqvUVQVE8jGBpuUoPFySktzRlNJ8A4bAw= 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=ptjLiXEZ; 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="ptjLiXEZ" 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 5ACFRHv5008644; Wed, 12 Nov 2025 16:04:26 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=UFlCn 5Lj55QJAeI6msqkpGV89L9woRHvuDucSYgSwT4=; b=ptjLiXEZY6Mc9AxRj+rvk N37y2eSRr4iHaNrlIvDgpKCkGEE8qlb8BW+9IUV5yk1rGnvTU1p9JL8iNOgFhD4C Xr4buLDEEcrJcQ4+vIlHCdOdMed7sdLnbMK4GPKEAXG7kM6guSn+YVxlsWufQ7r0 7Z+ErbijAWWX2YVrqRJ2jGDz5TJI32pHQcol9+uxhL8RdA4nsK5sLq5CNf9qBCFQ 3MyE8/49vWYnaOBT1/J8UvucmRdlyUdzFlNyvD+GIJlswywXnZtfLkkRnxCm2VcQ X6UjsOVI6CW/zHJtQO+JIqNV6CqZtXvgj69pwwAjH6y/CfughLS8Z4/mSNOczk3q w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvssr4p0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:26 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3BJ018617; Wed, 12 Nov 2025 16:04:25 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqp5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:25 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw3w004655; Wed, 12 Nov 2025 16:04:25 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-22; Wed, 12 Nov 2025 16:04:25 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 21/28] objtool: Disassemble jump table alternatives Date: Wed, 12 Nov 2025 17:03:08 +0100 Message-ID: <20251112160315.2207947-22-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=6914b00a b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=lcG_xirucoqnFA0wguoA:9 X-Proofpoint-GUID: hsdOicLNgVhBevOXSRQUNa_FPBE2LXKz X-Proofpoint-ORIG-GUID: hsdOicLNgVhBevOXSRQUNa_FPBE2LXKz X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfX8l7edgIap+tZ kWDOA27MR7BGFoR06nM5n924saegBM1et4vBr+9pmihfL6shFLqeX6zndygwI+KnKq/rNhB1U0S 80U2Dimi68N/i20nCGHvh3bCd6qfOhCOIjD2ZNzPMaU9tUDF3DXMRwFu0qbdX2yzCJ+8OOfKL1O I9Fklksk4X4DvIG19yQoaKlv33+HO5kENGpIKTYBIsdt3g2cO4qI0fiYj124iuTh5DD4s6Aw4PS Z2NbmITYmKp0d5PzAe6whRdkKlpPZYc2VtSXi2mS2XnUUbrbF3K3wfh5gdAgII0x82GrmzdU60s ArrfpL3Zp3oJHFN3rkX6bFgM0aoIm2RQAxb/AQFlJ4JakNPBiCh5awYeqxhtS9Ta9/h56yGGzzU OQH1AWWZCcxNYRlI8vqaKNmZG8gpKw== Content-Type: text/plain; charset="utf-8" When using the --disas option, also disable jump tables. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 42f3bf310b033..96056e873f97e 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -547,6 +547,9 @@ static int disas_alt_init(struct disas_alt *dalt, case ALT_TYPE_EX_TABLE: str =3D strdup("EXCEPTION"); break; + case ALT_TYPE_JUMP_TABLE: + str =3D strdup("JUMP"); + break; default: str =3D strfmt("ALTERNATIVE %d", alt_num); break; @@ -580,6 +583,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. */ @@ -762,10 +793,7 @@ static void *disas_alt(struct disas_context *dctx, if (err) goto error; =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); @@ -773,8 +801,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) goto error; --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 06A7634C83D for ; Wed, 12 Nov 2025 16:04: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=1762963477; cv=none; b=GnM0W2j2RFBnIzlYQCV0SRFZZeI3a4wc1VEwSo+TRrSN3CiO1YUxxiczZY37ixwoA9ORLxnzRdpfTpWYymyDtc/7z7nXtytq0ocDN4O1bJN95Ec5cBl4LdZa17LnG2Mx9HIzbMKLMY6jWfZ4JQDB/tYCgUlLikvAYsabVQTFY1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963477; c=relaxed/simple; bh=yRzA5r9quI7nVyYMB+t8z7utEWhtDEOOIgw7FUm5s/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cO7fYtHFeseL4q2ywSb3bwJtDb4xcYK2rwnBMrQd54vCHkFjWJzNkAHxnasaYWg2T6k8hVTpuNFYchJP8RtzJ03PDqvhV9mrwxJhhfr6R8qkfVvj7Y+oeqwm9tPloGfjf3E3gz5NTRAuKQCzS5Qhio5eSCz7/GAPu7O9dP3Bt8Q= 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=RD0X5Q0f; 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="RD0X5Q0f" 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 5ACFVxVD012517; Wed, 12 Nov 2025 16:04: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=ymVly uQaTrVjUo4txup8Oi2/8ezWlxbKYxIzvD5DqgM=; b=RD0X5Q0fU0RT+GePF77OB QcCdoYzIZbR4c08XlxKZBP0HgxVCwbi2TVZu4iN5erVAGOsdK7X3ybnmuEe1WmLA 3bvjAx8c2qhk/xUjfulxOy1N1ywTZjILZxSyAlb6Yam2/7KUvLlwu0hebxfejhpq vOCtnzl7NtdaWPPBn6QcSypFygyx9OAToTyAvLMLSV7bE3ri9yhxe4eEjxd+BZLe eb/QQd47rgxNFMJ5NV3JTR3O6w+Zo+KRxhKK61FeMREefILQhV9r7Hl08NISjdZJ DM8ducYWPbgP5OalrqrLnixCwTiuG9WlVrzLnU5303GijrfBxjgpBwyVzl3preI0 w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6e2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:28 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG55Y018953; Wed, 12 Nov 2025 16:04:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqpp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:27 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw40004655; Wed, 12 Nov 2025 16:04:27 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-23; Wed, 12 Nov 2025 16:04:27 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 22/28] objtool: Fix address references in alternatives Date: Wed, 12 Nov 2025 17:03:09 +0100 Message-ID: <20251112160315.2207947-23-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914b00c b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=YtZ4u2YuLOXz1tegIYEA:9 X-Proofpoint-ORIG-GUID: fBp2FsgQ7hbmDa65e62A7TRyBRvu-W-3 X-Proofpoint-GUID: fBp2FsgQ7hbmDa65e62A7TRyBRvu-W-3 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfX5FsQqfMM0+KA vYJFB8NkgznUHSxRiiWqXUIwociK5J9cPEtBnPM95mp0K1A8gKRDzrFxTUcXwVILlyM2Y2CO3og 4d8sWLrmoUVxbxP2FXURCLLhXTF3yP60Tqqe9YHJcvpzKdloSLnTkPOaePgdV9UZBuKC9P6GntK UwmQ+57kMCSoPiAG04z0Xkw+s0OHq4t9HzqcGcuCVm8Zytc9hK8Yz91r7KpHbxZDlAoenKhNx/n OIMZyqlSNjMus61xhEyoyX4oUQZIHBphGZ9tiGu4n6Yj7rPkq60lk3vRo4xsrWs8zC5uNScnSjZ 4FpOhCJqtyUs9LIrA3kHi1Xohu+FzzRVKzfdWLWkKPjyGJYVEwGpqxusQeYpeDvi74rL7vLZY7c xXT1wDed76Ec1SG7yG8yDdH1+EdC/A== 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 96056e873f97e..ae3b4d20cf35c 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; @@ -235,8 +276,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 @@ -486,13 +528,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) { @@ -511,6 +562,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) @@ -650,7 +712,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 Sun Feb 8 08:48:45 2026 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 79C0A34CFCF for ; Wed, 12 Nov 2025 16:04: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=1762963479; cv=none; b=Y/yh7sSEZYMjtxreqz1p0IImxgJMQvuRJnDTwLUYmbg48aFfxg4RO77EowxhZVDyG87goixG4umP5jYBMkU2TUvDKyTNOFVJOA7dpO/1drqyUkieiuJNuojr9slZeuprl0ZLkV1OkuJOgRtpcSeF/6ufzNfQbhcQvu7aEBhPtHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963479; c=relaxed/simple; bh=8iH5b/8bHsd6ulPC09Rvbti0ZLSraHYLpRBYKqf4eyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AcLIav+2wdN/4pXLE8FIdMqEjsRPzs8AkqiCvJhHY2QXfrE8S6eo8m3bz7pkY55bQFWSVYBvyUklUMkEbvYvxzelHf2TS40MA6oRO9agqePAUA6eE+wAggKx98LvJFJ95LJw7/0x/kZC72VDq4TLEfOforBSofgWEfn2y7cwtzE= 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=G2cUgzcV; 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="G2cUgzcV" 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 5ACG0RR5008396; Wed, 12 Nov 2025 16:04:30 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=sTxhO yc7Y9UCmdDybOr6o/rtgJgzfv5J44tqBQ//aGk=; b=G2cUgzcV3PduywxKdzrp4 JfAW5Q56bNRDVIXHpi4haoxaJHOYB2R+700FcoXWa6IuYsm8v6LT8Qtwjmj80wBQ 8TcjRsIkMxdVYDEw0W6BfL+lURS6qLs7aY1Ucm5ZSd8PukyV6FykFeIKCJzy1yk9 rKv3WJE1K8f9CYbmaBUS6T0w/5tMqqtWxpSKLcr1tfaf9IkrK40xB94g0SKyQvlS RVLsejua7IRJVHJHd5yVAPJA9qn7THN+XuJ09KC/UNZ89Z9LKKQFwqHlx65Ofk/E Qru+k0D2HXUNMklatd9ne0noUmN2kaUSTObJVpXVaxdoO1lzg9dOy6qjcLxjM+3w A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acwcg80jc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:30 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG3LB018598; Wed, 12 Nov 2025 16:04:29 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqq5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:29 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw42004655; Wed, 12 Nov 2025 16:04:29 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-24; Wed, 12 Nov 2025 16:04:28 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 23/28] objtool: Provide access to feature and flags of group alternatives Date: Wed, 12 Nov 2025 17:03:10 +0100 Message-ID: <20251112160315.2207947-24-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-GUID: inKBDMY1iE1e0TydUAehKb37EsgdCJTV X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyOSBTYWx0ZWRfX7E0WnEgmLW8s 0UCA68NOhJz+YLwTNueE3JiloGqPiMb7hzkmkiUuqPnElooDWtPiyyyhVWHmhT97e1kl9m5i9Pd sxWewSiv0xURSs5JWpZ83MzHQsnDdf2VbIkklH21ZAlvDmt//f6gt+l1LQk+hJFt0HyOXxlg3Ve ZvponVMGLVUpOnpc4NST1gT2ju9sKF1BoY0Hq25yvAd3lCgHmsPk0YnMcQu7Mo2Ado6G0TniLXh jxEKr2W2FFa+ATArYlW5uDGrAB3WGhP3ioZvLFdRVHtu36POiPkVSDU9ZlAETjbakDTUvlD8Wyv 8IBPu/pHRm5wxFrIA4NwN3ZLP+WKDuiJ2jJ0qSF2N183X5hvEFqKZ3lKGJSp4pR37Z3e9dbGB9n WplQZ0wiQz+X3zp+BvVu2a4T+LdpPg== X-Proofpoint-ORIG-GUID: inKBDMY1iE1e0TydUAehKb37EsgdCJTV X-Authority-Analysis: v=2.4 cv=LewxKzfi c=1 sm=1 tr=0 ts=6914b00e b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=OMdgKRDbd2JaGKt5H5wA:9 a=OtpQxBYiIDA4NW_S:21 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 f4e419c895a74..89b35e8a068d0 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1738,6 +1738,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) { @@ -1841,6 +1842,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 73310c56e91b6..c54dd0aae1f60 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 c80fed8a840ee..93fb371b05207 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -82,6 +82,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 Sun Feb 8 08:48:45 2026 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 D318734CFDE for ; Wed, 12 Nov 2025 16:04:39 +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=1762963481; cv=none; b=jtk2mtaTIk6gWp68QoczOk3N8/6QfjbGjwOegBjiRrgAku89kFJDryqAwqG22gySEZNvtpvgNvhi9V8ZWo2NyDjuoNtE6kR479cb7bqBF/vmRGEK3HQ6iM9sktqwvCP7R+pM49dBWBj31oiYsvbQJesKdnehHHm8G3u6l1K4JYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963481; c=relaxed/simple; bh=q1IEGmTiexs9Ib6qyK8SgppppMOswulClNlfSmS4lmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oSyMOYgvbBLbsCp3qysXJ2t3eP6CFbz3N92dviACQLNr69QsQg80OzKtSswOmbo1Qd3c9tllHLAXAso0L6zd3toH+1Er9XDtAgX70ceJSxmOGqxQaoft6shLjuvgPwFSX6ZroVo/+0blrT3nZK5iflZAE3Z09mFfJZ6ua9T0ARo= 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=nz1GCaaR; 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="nz1GCaaR" 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 5ACFWJh5012803; Wed, 12 Nov 2025 16:04:32 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=l6fvk GqlkRFWHMJjPFKdouisSAMlA/D3Tt8Ck13xsB0=; b=nz1GCaaR61zT2GtKlXNQk MmoGBpQ9lwaTUybZ91xa3eyu6XVHQVccMeyvOWbN7pIqh+657q2XjAe/mUAMPdyz QIR2q2+nL34AJMlr49k4rGJANT0K+MBtXWmuxmAG9OPxr9eCpJmU+oNPX+bkSNMd /AVFCTEnHmQmO/wEAqXgUw20cMZnLzI5vFR2v2zpyTfkjqDbnZvvA83OWG+4ji2C yULj/dPi9NMlefhpeq0xoGYE8NH7zzzRjjf5naPpsyLbfWxSsKojIPamq2TqbKkZ UGqOQDbH7zab91ya3ZwNw4H2NoJgNVqpeeBIcfTKwbn8GFdsaqlgT4c43Aa/y0Sn A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6e8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:32 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG2QO018581; Wed, 12 Nov 2025 16:04:31 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqqs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:31 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw44004655; Wed, 12 Nov 2025 16:04:30 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-25; Wed, 12 Nov 2025 16:04:30 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 24/28] objtool: Function to get the name of a CPU feature Date: Wed, 12 Nov 2025 17:03:11 +0100 Message-ID: <20251112160315.2207947-25-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914b010 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=BmP2q_L__UogPSo-:21 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=pMlTRUUgVTb7_b65wjsA:9 X-Proofpoint-ORIG-GUID: j617Vnm3WrcdUjovh55_dhzV2N-q74Hi X-Proofpoint-GUID: j617Vnm3WrcdUjovh55_dhzV2N-q74Hi X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfX5//vc4PG7dY0 89R7+8PH39lz0d9oVqdFQN8PpECDlHFC1YVASTUJn08m9WCfZSizbICo/h5Iay+WpeDV6Eg75x/ 6KLN29hv9OVg7VTSkJHGBbLmnj4nNyhlmjcsN+RxPTxYDx82NmkSUo58wUDtVlLMyqGA6KWyoAf sw7b8gxkfbhsn8vygs7MiNwa3UoQzv7WPxaVCevkkNOnJj9FyBXmB4wrtdYVWEn7mgrtwqWOFB9 lJfr8vz102c0mTAIjWa2Z4ZNfGFh6UAtkiNy4nGZJGSs9GaDb/BRyRgR6UpOfyMN0i56JswLvBm QnVn4w3Lff9lQz13FIjvo86Pvnxh8+Vv6uAZXaTKWZ8ZFW1QQAD1PQGk2n3A0vdPOZ79TNwLCdP fq1uQSnHnWWAUmt3nr/79U2x2xE0Uw== 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/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 ++ 7 files changed, 64 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/Makefile b/tools/objtool/Makefile index 9fb83979ca890..b6df180121589 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -109,6 +109,7 @@ 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)arch/x86/lib/cpu-feature-names.c $(OUTPUT)fixdep =20 FORCE: =20 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 06ca4a2659a45..720127fd4d025 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 Sun Feb 8 08:48:45 2026 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 D1F6D34D915 for ; Wed, 12 Nov 2025 16:04:41 +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=1762963483; cv=none; b=hj2Xmw3ZoLDmj/Uu/On8yIFq+8eIWDXjYpS+YfATAPyjU7byMhwoJxdqo/ibMWAf72jHDEa66T/pYGnqNw6IUKED5+p30lheVlJ0cn99QALWD7Wqo0W0tIgZNngCY9ctqPyP/i5T34zjnWVa3niR2rqMBv7lbICUd7zPUeEBYLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963483; c=relaxed/simple; bh=eIxCYhHSOL+oNmbEIGu94KL9sV5D9lg2Tv2ttjN8frE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XOsxq5c9uTbpXsyCb3R8v0EWziDxZYLZU7ONEGDZHsQW8zD4uEzVhbQHuaQZ3ATagd7n5fVDFU3lqisJX0+sXLJEeEP96mnvrIBr08NuqCIh/iaAFo+5RDfYrUZIRy4fLB/c0UrelRmZRV0HWkcjPogkRnBN2aDNZqh1R0SecX0= 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=gtsEr7kN; 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="gtsEr7kN" 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 5ACFVq1K012427; Wed, 12 Nov 2025 16:04: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=S1Egb 1+ME0q8V4/JrKMkVaBg3nzb4w/nBbivIVSR9OA=; b=gtsEr7kNQmKMuO0mV3ubF RAEpYTQPzTsOHHVUt+f08fyUl0f+Mm4bd1dsgbh6O290t87BBZIwnl9zq/dQhBZw 4o7VajPQ0NpvjU9NXcchs7m62PE0nvjlhdJyT+2WNTuDptVZAVIGbGIA5VbXXWle 4rlbxnnzdPDB6++6Vs3QDFoepZh+PdcVax95JCpah1sXR6AFvSLQcpgmperl7wfP C3eRe8JfPdesw+eSZlXThXKdklHq7GxUE15fcprP4RzL9gfPtrGrJUpj3wK4KJ6T HWeQk89KRtLlVE+rVIeXgZC1q6Y756R31J1lEokAwCA1Fi/Dwfd9O8+60/aXXmZD g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6ed-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:33 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACG4ESw018676; Wed, 12 Nov 2025 16:04:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqrf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:32 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw46004655; Wed, 12 Nov 2025 16:04:32 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-26; Wed, 12 Nov 2025 16:04:32 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 25/28] objtool: Improve naming of group alternatives Date: Wed, 12 Nov 2025 17:03:12 +0100 Message-ID: <20251112160315.2207947-26-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914b011 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=kqIM495-9hGHbGdz7BEA:9 X-Proofpoint-ORIG-GUID: ttJgmGjVXxLkLk6QE2x2TTTo3MTrjMOY X-Proofpoint-GUID: ttJgmGjVXxLkLk6QE2x2TTTo3MTrjMOY X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfX0ltuWNwZL3uq LEXxFdfAcycPJyf2Bz70/YDM4ah/pgJ9VTrowIyDxsgVRAWKdlsuufBw3Gdynn9SuJj2+AH3DhK NUJSH5/xuQaAhtlZQ4/q8xqC98RnvlYGT0gvv5YsEOzfCor8kJkuPn02tUcIa8iwJ5cEiyTDz8d tuDliidsqXHx636lAw9tPNz57sV5qguxaD4UeeFS27qtzzhOOVznDjm3W9kviT5FLaXCbkiEwOB 3hZOC6hLUN/Shy3xl2SvXc0P+1iPsBrta6FGWGtmbTsk+IMNQvnTEsZje72OWPMhBZuYt0OSGEw xyxlKBCVG02B6lqQUagE47s9qJADM979JX8LcfNpNygJ1NtZ3yslwTjFRimNnRk/0UDRH+p6CU3 rVKW18d88joRy3kTdgDM0FoBcV8fnw== 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/check.c | 31 ++------ tools/objtool/disas.c | 106 ++++++++++++++++++++------ tools/objtool/include/objtool/disas.h | 2 + 3 files changed, 90 insertions(+), 49 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 89b35e8a068d0..1aad636a8d630 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3566,6 +3566,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, /* prev_state is not used if there is no disassembly support */ struct insn_state prev_state __maybe_unused; struct alternative *alt; + char *alt_name =3D NULL; u8 visited; int ret; =20 @@ -3651,43 +3652,21 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, return 1; =20 if (insn->alts) { - char alt_name[35]; - int i, num_alts; - - num_alts =3D 0; - for (alt =3D insn->alts; alt; alt =3D alt->next) { - if (alt->type =3D=3D ALT_TYPE_INSTRUCTIONS) - num_alts++; - } - - i =3D 1; for (alt =3D insn->alts; alt; alt =3D alt->next) { if (trace) { - switch (alt->type) { - case ALT_TYPE_EX_TABLE: - strcpy(alt_name, "EXCEPTION"); - break; - case ALT_TYPE_JUMP_TABLE: - strcpy(alt_name, "JUMP"); - break; - case ALT_TYPE_INSTRUCTIONS: - snprintf(alt_name, sizeof(alt_name), - "ALTERNATIVE %d/%d", i, num_alts); - break; - } + alt_name =3D disas_alt_name(alt); trace_alt_begin(insn, alt, alt_name); } ret =3D validate_branch(file, func, alt->insn, *statep); - if (trace) + if (trace) { trace_alt_end(insn, alt, alt_name); + free(alt_name); + } if (ret) { BT_INSN(insn, "(alt)"); return ret; } - if (alt->insn->alt_group) - i++; } - TRACE_ALT_INFO_NOADDR(insn, "/ ", "DEFAULT"); } =20 diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index ae3b4d20cf35c..2a6c3708ec315 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 ft_flags) +{ + return (ft_flags & ALT_FEATURE_MASK); +} + +static int alt_flags(unsigned 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. @@ -588,38 +604,82 @@ static struct instruction *next_insn_same_alt(struct = objtool_file *file, insn; \ insn =3D next_insn_same_alt(file, alt_grp, insn)) =20 +/* + * Provide a name for an alternative. + */ +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; + + 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 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 + */ + + 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; + } + + return str; +} + /* * 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, - int alt_num) + struct alternative *alt) { - char *str; - dalt->orig_insn =3D orig_insn; dalt->alt =3D alt; dalt->insn_idx =3D 0; - if (!alt) { - str =3D strfmt("", orig_insn->offset); - } else { - switch (alt->type) { - case ALT_TYPE_EX_TABLE: - str =3D strdup("EXCEPTION"); - break; - case ALT_TYPE_JUMP_TABLE: - str =3D strdup("JUMP"); - break; - default: - str =3D strfmt("ALTERNATIVE %d", alt_num); - break; - } - } - if (!str) + dalt->name =3D alt ? disas_alt_name(alt) : + strfmt("", orig_insn->offset); + if (!dalt->name) return -1; - dalt->name =3D str; dalt->width =3D strlen(dalt->name); =20 return 0; @@ -832,7 +892,7 @@ static void *disas_alt(struct disas_context *dctx, /* * Initialize and disassemble the default alternative. */ - err =3D disas_alt_init(&alts[0], orig_insn, NULL, 0); + err =3D disas_alt_init(&alts[0], orig_insn, NULL); if (err) goto error; =20 @@ -851,7 +911,7 @@ static void *disas_alt(struct disas_context *dctx, break; } dalt =3D &alts[i]; - err =3D disas_alt_init(dalt, orig_insn, alt, i); + err =3D disas_alt_init(dalt, orig_insn, alt); if (err) goto error; =20 diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 5d2149ffac335..5272acd61dd03 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 @@ -25,6 +26,7 @@ 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); =20 #else /* DISAS */ =20 --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 D8A7F34D916 for ; Wed, 12 Nov 2025 16:04: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=1762963483; cv=none; b=kE93NVjcYAe+14On1FiZNVYtk5Lx9jGpPhZwDmj0jln+vUcYdYvkeB1AMCqPQH2PB/4aZelNmGLMpZD7tieOx1Ggru5N2+8pXKuRv2+S2iyJWifXZ2fLTy/OdkYmoMqHiCkX1/5pn3gau3hWVmmPYkWvqbX2Na/a5L+5065K/jo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963483; c=relaxed/simple; bh=gyZRXrZXtHHwJud4E/H8c2wggv1DSZKUECRh1zwD+jY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HUTnl3SaKsS0kD/hq/7h/63SLVIP3F3u989falaS5Ypn02JUZIqh/2oO1FRR5T5+xPWeVdUHPxLgaLIK8+9kiM8g1ajlJkGq57Z1pc6aP8/lljeURsXJff/LkWUzUo9Gy2j1SJ54TBhYl47+7/FwEpTyI10wV7QArbPTqZ1Z49c= 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=HH1xibLm; 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="HH1xibLm" 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 5ACG0XmO008500; Wed, 12 Nov 2025 16:04:35 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=pUhSs bCJ+uF3BC+fsRZXzhHiFeXxezmq6B60CYKgKlA=; b=HH1xibLmUio3rTE3iMYrN 4ghyww8Fvi4HCSWOvxWftDvf+v9/ycq4TUKoAiPWpNrIh95ACqIRxKIcwddHi5Ko 3yQP3MUuwO1xqWbhPSfoWtA4lZS4JEspE+jPNGz1r6Qfu/GoCJ9/OyItxdZDWsWN h+nJkAdSuPG1fsqz8MgOZKk9sOWrUQzrz5d/X3vWF0XFtBBmPPWYSIHpSa6s90Kk 5FvwJVMFQuGjAkKtsHLoeZVtWEqUeNYSAMYZOM03fjWJeU/HvxQTfXVU0cx0mxfM KqwsXPxFx3kmqJLMzXrvr7o564mVLP+faCdEDuIHqboyJ+NHJdV2Tj7TAkz1cpAM w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acwcg80k6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:35 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG4oE018707; Wed, 12 Nov 2025 16:04:34 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqs0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:34 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw48004655; Wed, 12 Nov 2025 16:04:34 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-27; Wed, 12 Nov 2025 16:04:33 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 26/28] objtool: Get the destination name of a PV call Date: Wed, 12 Nov 2025 17:03:13 +0100 Message-ID: <20251112160315.2207947-27-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Proofpoint-GUID: 9rGdJiFWLJ3mP6mscOHvYyoJ5KJ4kxDh X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyOSBTYWx0ZWRfX6+LfQH8IyK9l QFWdvtYCNv8v7whbS1B/6+POjcUFF4m12ufDHiwGE8RY7uuSKxYhjItmV11C+kgcdlZG477O9GT Otr5w3szXdLrJq2ha5xhGqpCCxefokfil5Hr8r9tSDV6KE/j8OWLfJtOuj0CT9u80MvB/FKf0hI 4rC48Z9kG5H8Qzu6LxE0F6at/7aZ+I1/f0279vcYXa+qjXK0XmnkItBgOmGc1nyFmJfFW1CMLEi Mj8XAqkMaC7IP/RP0U8XVNgRUHm7SbdObEcV0v8ccie0UieUc6zQvqIkp96mg0Bjv3nCZhT7fo/ m8lOPOtx+fScChGitV2J/qTxwRmPaQLFAEWQRvbdaV2CzT6B/oIJ1f5IC2Rnbu8YN+9OPvrHRWe I60N5wFGqQGMHOtR70bA6jUmgMp9CA== X-Proofpoint-ORIG-GUID: 9rGdJiFWLJ3mP6mscOHvYyoJ5KJ4kxDh X-Authority-Analysis: v=2.4 cv=LewxKzfi c=1 sm=1 tr=0 ts=6914b013 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=JgagiIEfrknqXQomSD8A:9 Content-Type: text/plain; charset="utf-8" Add a function to get the destination name of a PV call. The destination depends on the content of the pv_ops[] array which can dynamically change at runtime. However there are cases where we can speculate on the content of pv_ops[] and provide the function name corresponding to the call. For example, when an alternative depends on the X86_FEATURE_XENPV feature then we know that the corresponding code will be using the Xen pv_ops[] values. If we can't figure out the exact content of pv_ops[] then provide the function name from the default pv_ops[] array. Signed-off-by: Alexandre Chartre --- tools/objtool/arch/x86/decode.c | 2 +- tools/objtool/check.c | 99 ++++++++++++++++++++++--- tools/objtool/include/objtool/check.h | 4 + tools/objtool/include/objtool/elf.h | 7 ++ tools/objtool/include/objtool/objtool.h | 6 +- tools/objtool/objtool.c | 27 ++++++- 6 files changed, 129 insertions(+), 16 deletions(-) diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index d651d8921ab47..9fef0d94517ca 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -685,7 +685,7 @@ int arch_decode_instruction(struct objtool_file *file, = const struct section *sec return -1; } =20 - objtool_pv_add(file, idx, func); + objtool_pv_add(file, idx, func, PV_MODE_DEFAULT); } =20 break; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 1aad636a8d630..7978b3feb0cb2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -538,7 +538,8 @@ static int decode_instructions(struct objtool_file *fil= e) /* * Read the pv_ops[] .data table to find the static initialized values. */ -static int add_pv_ops(struct objtool_file *file, const char *symname) +static int add_pv_ops(struct objtool_file *file, const char *symname, + enum pv_mode pv_mode) { struct symbol *sym, *func; unsigned long off, end; @@ -568,7 +569,7 @@ static int add_pv_ops(struct objtool_file *file, const = char *symname) return -1; } =20 - if (objtool_pv_add(file, idx, func)) + if (objtool_pv_add(file, idx, func, pv_mode)) return -1; =20 off =3D reloc_offset(reloc) + 1; @@ -584,24 +585,27 @@ static int add_pv_ops(struct objtool_file *file, cons= t char *symname) */ static int init_pv_ops(struct objtool_file *file) { - static const char *pv_ops_tables[] =3D { - "pv_ops", - "xen_cpu_ops", - "xen_irq_ops", - "xen_mmu_ops", - NULL, + static struct { + const char *name; + enum pv_mode mode; + } pv_ops_tables[] =3D { + { "pv_ops", PV_MODE_DEFAULT }, + { "xen_cpu_ops", PV_MODE_XENPV }, + { "xen_irq_ops", PV_MODE_XENPV }, + { "xen_mmu_ops", PV_MODE_XENPV }, + { NULL }, }; const char *pv_ops; struct symbol *sym; int idx, nr, ret; =20 - if (!opts.noinstr) + if (!opts.noinstr && !opts.disas) return 0; =20 file->pv_ops =3D NULL; =20 sym =3D find_symbol_by_name(file->elf, "pv_ops"); - if (!sym) + if (!sym || !sym->len) return 0; =20 nr =3D sym->len / sizeof(unsigned long); @@ -614,8 +618,8 @@ static int init_pv_ops(struct objtool_file *file) for (idx =3D 0; idx < nr; idx++) INIT_LIST_HEAD(&file->pv_ops[idx].targets); =20 - for (idx =3D 0; (pv_ops =3D pv_ops_tables[idx]); idx++) { - ret =3D add_pv_ops(file, pv_ops); + for (idx =3D 0; (pv_ops =3D pv_ops_tables[idx].name); idx++) { + ret =3D add_pv_ops(file, pv_ops, pv_ops_tables[idx].mode); if (ret) return ret; } @@ -3379,6 +3383,77 @@ static bool pv_call_dest(struct objtool_file *file, = struct instruction *insn) return file->pv_ops[idx].clean; } =20 +/* + * Return the name of the destination of a PV call. + * + * The destination depends on the specified pv_mode. If an exact + * destination cannot be found then the name shows the position of + * the destination in the pv_ops[] array, and it is followed by + * the operation name for the default PV mode. For example: + * "pv_ops[61] ~ native_set_pte" + * + * The destination name can be followed by a '*' character if there + * is code that can override the pv_ops[] entry. + * + * The function returns NULL if there is no call and the operation + * is a NOP. + */ +const char *pv_call_dest_name(struct objtool_file *file, + struct instruction *insn, + enum pv_mode pv_mode) +{ + struct symbol *target_default =3D NULL; + struct symbol *target =3D NULL; + static char pvname[64]; + const char *note =3D ""; + struct reloc *reloc; + int idx; + + reloc =3D insn_reloc(file, insn); + if (!reloc || strcmp(reloc->sym->name, "pv_ops")) + return NULL; + + idx =3D (arch_dest_reloc_offset(reloc_addend(reloc)) / sizeof(void *)); + + if (file->pv_ops) { + + target_default =3D file->pv_ops[idx].target_default; + + switch (pv_mode) { + + case PV_MODE_DEFAULT: + target =3D target_default; + break; + + case PV_MODE_XENPV: + target =3D file->pv_ops[idx].target_xen; + break; + + case PV_MODE_UNKNOWN: + break; + } + + if (file->pv_ops[idx].target_override > 0) + note =3D " *"; + } + + if (target) { + if (!strcmp(target->name, "nop_func")) + return NULL; + + snprintf(pvname, sizeof(pvname), "%s%s", target->name, note); + + } else if (target_default) { + snprintf(pvname, sizeof(pvname), "pv_ops[%d] ~ %s%s", + idx, target_default->name, note); + } else { + snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx); + } + + return pvname; +} + + static inline bool noinstr_call_dest(struct objtool_file *file, struct instruction *insn, struct symbol *func) diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index c54dd0aae1f60..e352ed64f9edd 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -138,6 +138,10 @@ static inline struct symbol *insn_call_dest(struct ins= truction *insn) return insn->_call_dest; } =20 +const char *pv_call_dest_name(struct objtool_file *file, + struct instruction *insn, + enum pv_mode pv_mode); + struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset); =20 diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index df8434d3b7440..1d55f5da16932 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -46,6 +46,12 @@ struct section { struct reloc *relocs; }; =20 +enum pv_mode { + PV_MODE_UNKNOWN, + PV_MODE_DEFAULT, + PV_MODE_XENPV, +}; + struct symbol { struct list_head list; struct rb_node node; @@ -72,6 +78,7 @@ struct symbol { u8 ignore : 1; u8 nocfi : 1; struct list_head pv_target; + enum pv_mode pv_mode; struct reloc *relocs; struct section *group_sec; }; diff --git a/tools/objtool/include/objtool/objtool.h b/tools/objtool/includ= e/objtool/objtool.h index c0dc86a78ff65..cb25bf502f2b2 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -17,6 +17,9 @@ struct pv_state { bool clean; struct list_head targets; + struct symbol *target_default; + struct symbol *target_xen; + int target_override; }; =20 struct objtool_file { @@ -41,7 +44,8 @@ struct objtool_file { =20 struct objtool_file *objtool_open_read(const char *_objname); =20 -int objtool_pv_add(struct objtool_file *file, int idx, struct symbol *func= ); +int objtool_pv_add(struct objtool_file *file, int idx, struct symbol *func, + enum pv_mode pv_mode); =20 int check(struct objtool_file *file); int orc_dump(const char *objname); diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index 5c8b974ad0f9d..95dfef07a530f 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -44,9 +44,10 @@ struct objtool_file *objtool_open_read(const char *filen= ame) return &file; } =20 -int objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func) +int objtool_pv_add(struct objtool_file *f, int idx, struct symbol *func, + enum pv_mode pv_mode) { - if (!opts.noinstr) + if (!opts.noinstr && !opts.disas) return 0; =20 if (!f->pv_ops) { @@ -54,6 +55,28 @@ int objtool_pv_add(struct objtool_file *f, int idx, stru= ct symbol *func) return -1; } =20 + if (opts.disas) { + switch (pv_mode) { + + case PV_MODE_DEFAULT: + if (f->pv_ops[idx].target_default) + f->pv_ops[idx].target_override++; + else + f->pv_ops[idx].target_default =3D func; + break; + + case PV_MODE_XENPV: + f->pv_ops[idx].target_xen =3D func; + break; + + default: + BUG(); + } + } + + if (!opts.noinstr) + return 0; + /* * These functions will be patched into native code, * see paravirt_patch(). --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 C763833F8BE for ; Wed, 12 Nov 2025 16:04:43 +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=1762963485; cv=none; b=ooYlVaIb6KH2NxjORV0XwJjaXy9EfOaRkcsAiyHFhont3Dh8iiXLl/cE0HH+tZYvihllNs9c0cx8gaPsG66k3+cBIOZEK9vSuWA2z9AMHkBkjISyfmA7AwBmgxAWYGwaDH71ajgOhtgmaPLWrGMtolFQSD4aoxZNjDWLN7Q0fos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963485; c=relaxed/simple; bh=Y3RgpzdLv8DcizmWss8orCI0E+29f4IgMygjmCW0QD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OroqPiAZTkT9k68CfKxZkqQRHJWUGHleZdr4nNLioBgYUCwVwA1GJHYqO06BSZ+cGhMPmV5KytovJuMyA1kRehb5JoQE7TXUjgIxfC+nqbTcuPo9CunqmZs3sKS5OTQQnMWOE4xGcBLbGdo1+E/IGD1My4OGfE3SvyiyWpzb7aA= 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=KalFP18L; 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="KalFP18L" 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 5ACFWJh7012803; Wed, 12 Nov 2025 16:04:37 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=UXRRB xRUvb8DGbk9rGxPY4YhNOEmQqlz8hEYYwTqgyQ=; b=KalFP18LeCSklD4zLd5Hb mia/ONmfjPvwSvN2b9Sf4WCrborDK1Uky2R4ORJGAG38B68X86dgmnGNYDk0Rx2L WE0iI99hVAMLtKG4fC+jjeeJpN4RUiieso/g6l2JMjw28D5QKAlPdeM8bo0pjCLN nfXUlqjbX1j1lH4BfPRQkNXFdm3zWY/RUDWFZLYXKgQKoFppZvcKoGiuWaVVt0rS mu665sRs+2iRm2kLAcQkRXjqUlKEnynXTczr2xR1taEJ+xE7GkM7A0cTdh9wibKQ j9ycOkJcqqjH8Ax6wKPF9Fd/WMYNuuG4vWkxpQGnv6TXHVjrniumg7EMr+OuIubE g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6ej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:37 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG42h018660; Wed, 12 Nov 2025 16:04:36 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqsp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:36 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw4A004655; Wed, 12 Nov 2025 16:04:35 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-28; Wed, 12 Nov 2025 16:04:35 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 27/28] objtool: Improve the disassembly of the pv_ops call Date: Wed, 12 Nov 2025 17:03:14 +0100 Message-ID: <20251112160315.2207947-28-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914b015 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=tMX4VmICG43G860zTSsA:9 X-Proofpoint-ORIG-GUID: iOCOm898BormwCnF3xNOMF1JVktQIAw3 X-Proofpoint-GUID: iOCOm898BormwCnF3xNOMF1JVktQIAw3 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfXwgE8lTCErftG 26qW42oJMuSlM0sqPCwZc+zx5/x5TwTkurmMrjHPia3J/GtVfL0dqoEKwHHTcGShMkycSOM0yJ1 8QswZ5BTBV5Jmf464+8BT06BJ6LlFTO6Xr16Zi7Po86ymjhqp0dowXImvU4zrLC60oqbcJf2qN+ jVsYRYhn5s6VwLOW8+f/iUSivPE05jszeVLVbdO72oWH1M0z44I+9jQAL2yZxpZJlDVH8Sz5Ev4 IaNi2SVNFxaxUCB7b4u/erV2wLFrGKP5Yy50n8gIuFTvP4U2Q2zUKTg1ajab6kqV7v82t69XeIK 38wa1TjvBZQDDcri1R/qjqrhwaYRSHlZ7FOpFBVmThCTgHMXBcJC9KHzGRKfDWL+i79eTPaloQa MBA47tAm0LGuHrX6I2FxOFZORPuVxA== Content-Type: text/plain; charset="utf-8" When using the --disas option, print the destination name of pv_ops calls when we can figure out if XENPV mode is used or not. If the PV mode can't be predicted when print the default pv_ops destination as a destination example. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 101 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 89 insertions(+), 12 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 2a6c3708ec315..20d64b58182ce 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -12,6 +12,7 @@ #include #include =20 +#include #include #include #include @@ -54,6 +55,7 @@ struct disas_alt { int offset; /* instruction offset */ } insn[DISAS_ALT_INSN_MAX]; /* alternative instructions */ int insn_idx; /* index of the next instruction to print */ + int pv_mode; /* PV mode */ }; =20 #define DALT_DEFAULT(dalt) (!(dalt)->alt) @@ -665,13 +667,65 @@ char *disas_alt_name(struct alternative *alt) return str; } =20 +/* + * Set the PV mode for the current alternative and return the PV mode + * to use for next alternatives. + */ +static enum pv_mode disas_alt_set_pvmode(struct disas_alt *dalt, + enum pv_mode pv_mode) +{ + struct alt_group *alt_group; + int feature; + int flags; + + dalt->pv_mode =3D pv_mode; + + alt_group =3D DALT_GROUP(dalt); + if (!alt_group) + return pv_mode; + + feature =3D alt_feature(alt_group->feature); + flags =3D alt_flags(alt_group->feature); + + /* + * The only PV mode we identify is the XENPV mode which is + * enabled with the X86_FEATURE_XENPV feature. When we are + * sure that XENPV mode is not used then assume that the + * default PV mode is used. + */ + if (feature !=3D X86_FEATURE_XENPV) + return pv_mode; + + if (flags & ALT_FLAG_NOT) { + /* + * This alternative is not used with XENPV mode, so + * it is used in default mode. Then next alternatives + * will be used in XENPV mode. + */ + dalt->pv_mode =3D PV_MODE_DEFAULT; + pv_mode =3D PV_MODE_XENPV; + } else { + /* + * This alternative is used with XENPV mode so next + * alternatives will apply in default mode. + */ + dalt->pv_mode =3D PV_MODE_XENPV; + pv_mode =3D PV_MODE_DEFAULT; + } + + return pv_mode; +} + /* * Initialize an alternative. The default alternative should be initialized * with alt=3DNULL. + * + * Return the PV mode to use for the next alternative or -1 on error. */ -static int disas_alt_init(struct disas_alt *dalt, - struct instruction *orig_insn, - struct alternative *alt) +static enum pv_mode disas_alt_init(struct disas_alt *dalt, + struct instruction *orig_insn, + struct alternative *alt, + enum pv_mode pv_mode) { dalt->orig_insn =3D orig_insn; dalt->alt =3D alt; @@ -682,7 +736,7 @@ static int disas_alt_init(struct disas_alt *dalt, return -1; dalt->width =3D strlen(dalt->name); =20 - return 0; + return disas_alt_set_pvmode(dalt, pv_mode); } =20 static int disas_alt_add_insn(struct disas_alt *dalt, int index, char *ins= n_str, @@ -753,27 +807,50 @@ static int disas_alt_extable(struct disas_alt *dalt) return 1; } =20 +static bool disas_alt_is_direct_call(struct instruction *insn) +{ + return (insn->alt_group && + (alt_flags(insn->alt_group->feature) & ALT_FLAG_DIRECT_CALL)); +} + /* * 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 instruction *orig_insn; struct objtool_file *file; struct instruction *insn; + const char *name; int offset; char *str; int count; int err; =20 file =3D dctx->file; + orig_insn =3D dalt->orig_insn; count =3D 0; offset =3D 0; =20 alt_for_each_insn(file, DALT_GROUP(dalt), insn) { - - disas_insn_alt(dctx, insn); - str =3D strdup(disas_result(dctx)); + /* + * An alternative direct call initially has the + * "call BUG_func" instruction but it will be + * replaced with a direct call to the target of + * the pv_ops call in the original instruction. + */ + if (disas_alt_is_direct_call(insn)) { + name =3D pv_call_dest_name(file, orig_insn, + dalt->pv_mode); + if (name) + str =3D strfmt("callq %s", name); + else + str =3D strdup("NOP"); + } else { + disas_insn_alt(dctx, insn); + str =3D strdup(disas_result(dctx)); + } if (!str) return -1; =20 @@ -876,6 +953,7 @@ static void *disas_alt(struct disas_context *dctx, struct instruction *orig_insn) { struct disas_alt alts[DISAS_ALT_MAX] =3D { 0 }; + enum pv_mode pv_mode =3D PV_MODE_UNKNOWN; struct alternative *alt; struct disas_alt *dalt; int offset_next; @@ -884,7 +962,6 @@ static void *disas_alt(struct disas_context *dctx, int alt_id; int offset; int count; - int err; int i; =20 alt_id =3D orig_insn->offset; @@ -892,8 +969,8 @@ static void *disas_alt(struct disas_context *dctx, /* * Initialize and disassemble the default alternative. */ - err =3D disas_alt_init(&alts[0], orig_insn, NULL); - if (err) + pv_mode =3D disas_alt_init(&alts[0], orig_insn, NULL, pv_mode); + if (pv_mode < 0) goto error; =20 insn_count =3D disas_alt_default(dctx, &alts[0]); @@ -911,8 +988,8 @@ static void *disas_alt(struct disas_context *dctx, break; } dalt =3D &alts[i]; - err =3D disas_alt_init(dalt, orig_insn, alt); - if (err) + pv_mode =3D disas_alt_init(dalt, orig_insn, alt, pv_mode); + if (pv_mode < 0) goto error; =20 count =3D -1; --=20 2.43.5 From nobody Sun Feb 8 08:48:45 2026 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 53A8D34DB6B for ; Wed, 12 Nov 2025 16:04:45 +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=1762963486; cv=none; b=gpZjJNVpW0aAt9rKjYZzk4QWaOGO5Zum7qbOhz8EdqIoCCu5t2Ip//PPnAByD4EKcjy7LJwbFc/5BDMBs3pWCH6h4XRRdhg0Op+KX3J90vRppJyGTdN7r/onBRo0796b73ARdAEzUhYwlPFRlMyfz2rGtuRqsGTMvz3HNuhAe4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762963486; c=relaxed/simple; bh=MJuS5aI6TBpNEWLOH7jEJKhRGwaG4j0xhrR0PIheg7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IHTaKYUiEd8E9fiyW7Td1t54sEgaU12Yf/4aplcWjrCqh7VznbOQ03F/s+nBeyl4Yop83ifLttb5J+uULYHofR/DDNFfNMnOSZo76W1LRzpzOkIbFdKDo2ERsjslYSOxVdsshbj8dG3AxwjNrIHfIuti4rUA/1FzEzeTk6wV3eE= 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=TM25zDic; 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="TM25zDic" 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 5ACFVv05012507; Wed, 12 Nov 2025 16:04:39 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=4kujL WXKftYa98GKfPFWNDHJWBntxAXJo2f1Yvze3I0=; b=TM25zDicCVbyqN3IIQlNl YNDoMHIqTLqythFym1PmynHFUZiPe7lxSq4n8casd79k3jJpsRJSYggaePZYZnqA 0vgHcv+KmpzQJpW2Z8oLKT4x9qLw9LpP2eJ4daqlzasp4PVHF9bGOUQ/CN1a33QP DglFCAQcrBVj1iGjYL9IGLNdP12iATQ865x8kfi/92J4CD4ntsuqsy90aTHuuDFZ HWPTsfL0swgH+rgIse+ZocqWtM1TkoEAQrl1BiktW3mWyhXiP2pALcSBUkKLwOMc vH4Q8lpElRRkTe5gcTiKbBNqXjhnvz+DSPuAPVnde737aTVYjenNLAOWX7Ghm/nf g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acv97r6ek-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:39 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ACEG2sZ018577; Wed, 12 Nov 2025 16:04:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vaavqtb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Nov 2025 16:04:38 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ACFxw4C004655; Wed, 12 Nov 2025 16:04:37 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-173-131.vpn.oracle.com [10.154.173.131]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vaavnq6-29; Wed, 12 Nov 2025 16:04:37 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [PATCH v3 28/28] objtool: Print single line for alternatives with one instruction Date: Wed, 12 Nov 2025 17:03:15 +0100 Message-ID: <20251112160315.2207947-29-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251112160315.2207947-1-alexandre.chartre@oracle.com> References: <20251112160315.2207947-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-12_05,2025-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511120130 X-Authority-Analysis: v=2.4 cv=Cseys34D c=1 sm=1 tr=0 ts=6914b017 b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=C75Ug1cDibOJfFcMQNQA:9 X-Proofpoint-ORIG-GUID: Zh4pv0rpcI8yH77xF_BnZqVJqsustsyM X-Proofpoint-GUID: Zh4pv0rpcI8yH77xF_BnZqVJqsustsyM X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDExOSBTYWx0ZWRfX+wYLuxfVqCFy 3h0ncKvao1PqbggGXvtRS3/s7NzdR3WLanVj9tDgfBy/daPTeqXUP0hfiMdr1dGAGepQ7Ge8b63 flO6uqsp4G26g9iFKRxkbDWsx9nPR+RR0ldmNr6U8csramzsIx2cvzEkajzc3fd10s/G92QG8MN riCd12kYqYmW5wgtYoNnEkCwg3gszlgqMqfNexG6rGRU++khQSx2XmmHewqRHiciZ3s6Ep04W4D TiQm5K/RtSC+GF3mmAB/nLQzdD34CPKTa+CQcimnUm1XvbxRkARB4vL10AUA6PPCt8nqLegur0D 7bKumcPLRo0/LEOXVv7abyPT1AetTdAcNJlRbcCOGTK9QlTtRC0ZpV9WkSqofnjyqwJ6MqP5Ooc eYHC4dEEYYhTxhqWm1IY0CPtxBSOBQ== Content-Type: text/plain; charset="utf-8" When disassembling, if an instruction has alternatives which are all made of a single instruction then print the original instruction and alternative instructions on a single line with no header. Alternatives are described in a comment on the same line, after the different instructions. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 20d64b58182ce..2fc5821acbc3f 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -1012,6 +1012,24 @@ static void *disas_alt(struct disas_context *dctx, } alt_count =3D i; =20 + /* + * Print default and non-default alternatives. + * + * If all alternatives have a single instruction then print all + * alternatives on a single line. Otherwise, print alternatives + * side-by-side with an header and a line for each instruction + * of the different alternatives. + */ + + if (insn_count =3D=3D 1) { + disas_print(stdout, orig_insn->sec, orig_insn->offset, 0, NULL); + printf("%s", alts[0].insn[0].str); + for (i =3D 1; i < alt_count; i++) + printf(" | %s (%s)", alts[i].insn[0].str, alts[i].name); + printf(" # \n", alt_id); + return orig_insn; + } + /* * Print an header with the name of each alternative. */ --=20 2.43.5