From nobody Sun Feb 8 06:55:49 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 AE16D363C7A for ; Thu, 13 Nov 2025 16:49:53 +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=1763052595; cv=none; b=ECoVbU/uJLwBENqg3/v+gyh9/YwMYG87SQ6Y6O/2EGnzmRO0G6PhBcTmutCoaDL9FHEE/XKVgY0MfhV2Aty8LwqiHpet98l8eADTDqQVmN7mzC3pX3m1g1k5/aHbGMYXHQb1u8H/TGpMjwN433jprslk+icbnQHcGz0MO4KPFxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052595; c=relaxed/simple; bh=NW9ODej7ximkTYrc6vBqdXhJRqxG5v0OGwgjDFKhrUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MkVM4wTIQgp6JbMOKTVVyYqkNaPRopiMrFwRBa9eciGNfn7Ga2wVJz9hr46jiXXFPMcLYPBP3F49fqJC2npYEC9YFQSlF08PT1AqmHCRZc+OSduOrKaZnp9XzNRfjid5BLR7R11SwkrsEzjsnp7FJrZuJMSeKVnWMOjhfObAHgk= 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=mLiu5CKL; 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="mLiu5CKL" 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 5ADEAVwH006599; Thu, 13 Nov 2025 16:49:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=h8SBH nvcaPR/IKOBM+v6EDFM9OxNcNCr5nG/59SC/gI=; b=mLiu5CKLsQ01sAsA9LCI0 refscuYtqNy0CoXJYJqPT+t3uq70ZXvFWY2F5O//pKyZqzcqbbMx8QHgwzGLhvhm d+GT5qOf5MCdS3I0N8njnDTZ64ROpd8Y31Rz7WAZdWV+H31AxbIOmbphioyDVf5d DwW9ECDW0JrLvEC1YZililQgUIW73B7zH5RtF21PYfb4ExjKab6I9Nj20Hy71J3h VZx+bwTTW7/NALQdU7atfn56yyQffIJNsFDSumyzC4/nHqvdg2eMTOKpKxGsMTRW r66cWqIsiBtPJx8l1O0II+Hw2ccUV4K8jrjngS6ILzvRj2zYa1F1IYQR5+wP3an2 Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyraa66n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:23 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG3wQB039231; Thu, 13 Nov 2025 16:49:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc39p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:22 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnK9l008288; Thu, 13 Nov 2025 16:49:21 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-2; Thu, 13 Nov 2025 16:49: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 v4 01/28] objtool: Move disassembly functions to a separated file Date: Thu, 13 Nov 2025 17:48:50 +0100 Message-ID: <20251113164917.2563486-2-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE1MSBTYWx0ZWRfX56jwZbLvRQxX gV5dMfp0MSNsucAQ+DT3PKissVgM2kcjE6MTdc5rtyj4LbU/jt4Aa3Gbt3R6hU0Y+K5gLeFpEX3 5ewgXqY7BO8pdJCED03e1yUIAhtzAT9h1ltyymvvboNBv0EPNbjz5InmvHLXABy479ZcDloN2m5 ikacLo4nSn8Tkz4tM+NEqH+W23JNnyzrZzgEbrullPj2/Cj2DLI9+M638ostVmJU8U11SDlWjN9 f+5iyJeNQBh8HRf5uTcJV+cSTyihzihcOL7QnLbeCc6biz4d2uW48AVY+oseodYLnaWkM6MtTQe BkfIZSM9iysJkI4acueRNyG0kM72ZLSTtM7v19XqsNw+GImy002PNG0fmSiV3SXdaHlXGS3rLcj 9WJWPJs01n/pNOrxbWC8VNzSuNYv1Q== X-Proofpoint-GUID: EOKiHZgIwTi_6pIzQE-SK8C34Y_E1PK7 X-Authority-Analysis: v=2.4 cv=ILgPywvG c=1 sm=1 tr=0 ts=69160c13 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=dBVU6wt392Vc8wzyTJAA:9 X-Proofpoint-ORIG-GUID: EOKiHZgIwTi_6pIzQE-SK8C34Y_E1PK7 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 06:55:49 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 AE090342C9E for ; Thu, 13 Nov 2025 16:49:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052595; cv=none; b=nCtAA04VRq42CWYW5phkb8BHU8kzZyJtI60Xb4tZbfIGotQtLfs03obqBqN1nrgaUNdh3h6auGhXpZjhr0X+m6/Owtv2wFvB3FyuXjdHiZtlnM7NBvdl2x+LpXjhYWmMSBXaiB/4E4Kyk3Y9WXqbL6Y4+mE9zUMoREudFknob6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052595; c=relaxed/simple; bh=8RtqaxDHlrQUHgvilvJPUgfHiqU6XiXvPA6YKdJMFiA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PYVSzImMLCC+DdItj9/9NgtgSUgyr87FI4TDy1yD6hCg2/ltar7qEIfKarUckCBdg7uqApyORR0qQbjhvky1H8tqZ/Ze2b3wrSUpKfVUZLLi6w2dLJ4MSCh6epOA3PEM7BV3BzOOQ5bIvtN6/dtH369bJ5M5lXoq75Q5cbHU+NY= 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=Vy056PJ3; 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="Vy056PJ3" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADE9wLj024388; Thu, 13 Nov 2025 16:49: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=CAQP1 9TFDDxrt0SkXNzDO71RH+/FAyrNChWX1/wVvdY=; b=Vy056PJ3wvWNWaKEaPeiS 0FIXzTQTv+O7/mBHFrQQVTKi0veOi532VzLpN+Oyb9RXdKPZUV8FVHA5vdYvVwH4 LOgmXqfb7u8KSyDo37lGwJBBV/XxEKF2esH18M3VXN5V46n18MiRDe1HS9MWNvUB iIWcoe8CIpCiFm1WSXjJlMXXn9NrHcJoWcBHHWsPkyiXaUCDHzlTXNPMPqdxNnZG hs9XG1QJ/beMrlXE+fda7KKh1SmyG/WXRK+R9zgObCytcF2co7LIXERratF+9PW/ AUe5GpSCINciZzCwk5I/D+1TLh/PNwp/xREb/6fgvcYf0kjBukGAhcJKNAmDR5nd A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyjta46s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:24 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG6dhv039063; Thu, 13 Nov 2025 16:49:24 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3a8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:24 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnK9n008288; Thu, 13 Nov 2025 16:49:23 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-3; Thu, 13 Nov 2025 16:49: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 v4 02/28] objtool: Create disassembly context Date: Thu, 13 Nov 2025 17:48:51 +0100 Message-ID: <20251113164917.2563486-3-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0OSBTYWx0ZWRfX4whS+0LZjeWn DJIPYtAZetHpsasaqWHOgbW+Qi7Oi5zVEizSPssRPT+WNLuz6JEkrqpmXRSjhWWoth4ki4KfSyx HToYjBpCF3w9kIEA3/eBlU7EgYhFB0kcj+A0umJqpGs7Sw/qOtibT7PguozgqSkvYdMSANcZtYe TjUgor9XFNdm5WASvj8vJjl2oKjI8pL7vGZhOQHkqcjkcAimiU/P6sDcf1PGfgLDDZcQxfYjbwI fTiFciSPGe3ScwVZg11e+X4+g3UktuumDSbq3d6WrUXFVAa8Vgns7Hv/Mnydv7Y+n3Gg7NxT3lU aBIkuS9d59K41/4rf9ZXprcCwOAmPN2HpjzxPil94ol2h9zHoN1N7tvfQ1TFPl6OQLOo8A6oxAx oGCG+BTHy2dxdYUAXIzfgN8iJvB/jw== X-Authority-Analysis: v=2.4 cv=S6/UAYsP c=1 sm=1 tr=0 ts=69160c15 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=-R_vEHidSSj7PnaEDHgA:9 X-Proofpoint-ORIG-GUID: uk20vdrOyobfYaLBDAxhXmFlY89uGQ-0 X-Proofpoint-GUID: uk20vdrOyobfYaLBDAxhXmFlY89uGQ-0 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 06:55:50 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 E8C8D363C6D for ; Thu, 13 Nov 2025 16:49:49 +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=1763052592; cv=none; b=WGuw6n8XN7axhcFv8T/WZ9LO1QhTr50Ajrwsy7nlbhcO60O1rdvMd9nb7lyqjWSIkZAoXTAXdmTNYCl+1YZFRE0AVZszkKXU5Z4Q01g+D5DMddocMWzXioO8yEIPEfd3eNRQLvrEUBkv6jhQyWH/5g7Fro6MyJ9PPahT6VOUQ4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052592; c=relaxed/simple; bh=YMbw6/nENvpM45mmzHzORWdsMnSBo77/yZqJf9BU/I8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RAz2whE9OCn22eWQAHZmcv/s1H3OphYcoMLmudKJomewaxAqasP67ZbGHEkHHV/iU/DS9IV8KmUGubKNHrfHYxDHqAb//nkbQ9kiEt2SPIMJXsG4mKpR5nDM5aH6qlSxjTIrOOUUbEADNps+CTIQRXgiVvhsjUPWzYeuRW0f+M4= 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=isDSMpq8; 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="isDSMpq8" 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 5ADE9tE2023875; Thu, 13 Nov 2025 16:49: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=Dfx1t 7Iz5C+Oq8EsuENpgoY4JktmC9uWXKMsptLUWF4=; b=isDSMpq8v6YktR7jIRlTK jppFAurxPreuXIpbabQ+J7NrCS6b2GV+bVU8YgbcKZSxDUu4G7Yl007D+k4n1D8Y l6MLrqDymXCyphb8q+Xo/ZnwD6c7x7bVQD8ia2z6ty95Lk59wn7ukhMCrQmWhMFS 5VCZTcT+8sjYhV1foMgjsW9a34/OkXxBzRHMUtMXOlkdvV3uDBGWQ3G8b3SVQyZw smbFB6B+WLRF7kYN9xolXNmI+rEZ2Zo222lHQfLHgyGlMHfH+sbRB1/AG7AQPx0q +Lw1al46K/8kpplNVU0G5/GjmsuJVqVjZ/1GIJY71pQK2uCgAGuY7s3I7l+bqXkk Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvsstnme-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:26 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGH8Pe038719; Thu, 13 Nov 2025 16:49:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3ak-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:25 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnK9p008288; Thu, 13 Nov 2025 16:49:25 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-4; Thu, 13 Nov 2025 16:49: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 v4 03/28] objtool: Disassemble code with libopcodes instead of running objdump Date: Thu, 13 Nov 2025 17:48:52 +0100 Message-ID: <20251113164917.2563486-4-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=69160c16 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=qB_9k6UZtangfgbWIO8A:9 X-Proofpoint-GUID: -E_HcVmkPhMpTqU7aLZTPNLNJiGlTK6w X-Proofpoint-ORIG-GUID: -E_HcVmkPhMpTqU7aLZTPNLNJiGlTK6w X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfXwJZFSB+ILfD4 jHPkMoHi6YhKDhXfWscodQjphmna6C5ycpzXTO8xTOZsduQtHm+9oe+MVzg+1aICploAN9zYpVa uSz4aXl4Y6TvzpdZ9pO3W6unRQupCnk/Wcp1+XgJyvkLA9dFJVPl1iKzhrvjiBV4+pxaPPDbKJg rcqeeN3UjMdklSvByUyPdGxhJHS0A+ALEqhEKnU961Z2SEanPrDdRpd1ch2XuR9YjOhDqkezzmZ t72AzdK70sHpEij52/rPbApyQFBTWVifz3qpgB7RkUMFKLy+XMb6DWwPEJk+cAN6zl/doHvzVuv 3kwyuBuiqG3JKZGCt83pMgxgAqiyFe/PY4Y5sktYpzBAJUboaZonuMLXlIge8oDl7fJ/JH8uMHf 3K8G6/YbWQor5nybFfa4VaFeDqtNvw== 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 06:55:50 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 8F8202FDC50 for ; Thu, 13 Nov 2025 16:49: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=1763052579; cv=none; b=pi+Z+GkoQTyP8NlgeLB5XY4rOjvM8NMAPQmIV5ybOGGYzXsxiDbRMaKA8z69/J8NH5OdKyqpx4FR2Qi3FCLHqjn2G9YDLNQR87+ZmPMHtPAmEXEGO5LTPzuTm4tkiqarxouhCHRWeZU+myffTpD6dIJ7kOTX9unNsi74oohvYFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052579; c=relaxed/simple; bh=y+f42A7JvxwlCYs9lZRBZaYEuUvBOM/jlbSPz3pra4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q9ykXzY+PowFmvb54oUe7zL8wIda5gfy2lKZZ7yC/I6mj9KXRkRPxYKIWHPT0flVDUSB5rwAYDXsZ/9OSub1O6ZWXa1lrnqMYwOsXzCEd7dWkcyr4XzLd+nB5+2T2FAvSfkJiB3ywHP9Pqz4BDKWdGhwAXWd/D38F+jr1srpb14= 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=Jfu7wevT; 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="Jfu7wevT" 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 5ADE9utE015549; Thu, 13 Nov 2025 16:49:28 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=Jfu7wevTEa0hGuT2patKF Dx9M577AGVPwM1G1slj56HuzD7y2G8WrgxZdDoa3dViAJ6tBcnRuXpqd4xY3NXvZ wqcm5IYNuiPIEqyIYYUhH7CjyLqrBAm3OzCO0p0bLyaHb7dgklw3BHVHnDxgNhaf m4Szlo3I9FBMkEJvuElzPE1TNbXhPIZrVdjLBMjO4x4Sz0osj83FUouHbKtyJyif Ma/XCgn1sKzEO3YwIjCu5w71y5QDSaMhJdjZBDyh+v9a0WVaa2l60OUQYteyo4ma b9GTgo/z6lFHyXMM/Z8XycbXjwAF+xqt/wRoLbXgvBZw9WigCfI9QcCsm7AW5nOi g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxfvjak2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:28 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG7MWs039422; Thu, 13 Nov 2025 16:49:27 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3b0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:27 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnK9r008288; Thu, 13 Nov 2025 16:49:27 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-5; Thu, 13 Nov 2025 16:49:26 +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 v4 04/28] tool build: Remove annoying newline in build output Date: Thu, 13 Nov 2025 17:48:53 +0100 Message-ID: <20251113164917.2563486-5-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEzOSBTYWx0ZWRfX1tMbs1nIVDxH WGyR4y5oHawMEaq7SaSvi8iwjIaTqCEJv6kgN7su6eLMcIfQmSkOJfcKRlZM5wEo27Twxf8lrZg Z9K5Ikgb4otYUBYFVdzkqn/N9NInycbqP4IQIbtHR6bwg6nrwjuE6NTiiFYPSnPiz+Lq3o3Qtxb Jucn+QNS3l9tY/GqIob/SCWUdfm6OLGrssUP+3l4G0LPRefHx570AMWuX1IKl25kQRGVqDY02sQ 5i0qyCp1i80E2iJQkTVM60TeEu3aXtggNCEkiZEfLzuaQtwJcIQSlmZmkPWeR41W2MGRRp3ZNN4 OE1+FUtNWGW2sle3I9BJ/Z1op/zjS5T9r2PAMCCE9tJKgTqAcSIigRJlZ3iykk2kOsPJNIKzTFh xw+zpBj1W9jTzTcCWS1DY9Vc6vbKEw== X-Proofpoint-ORIG-GUID: zTN9VgTbzq13LngoH82GKvp7upzTT9ir X-Proofpoint-GUID: zTN9VgTbzq13LngoH82GKvp7upzTT9ir X-Authority-Analysis: v=2.4 cv=FKYWBuos c=1 sm=1 tr=0 ts=69160c18 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=gaUgYgG710qbGCIvUrAA:9 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 06:55:50 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 84D6F346FB8 for ; Thu, 13 Nov 2025 16:49: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=1763052581; cv=none; b=tvw0/y+ZsSCsJx9/+21p+2sQoLItIkOH0suICHPPF7nx9JcYnriU6H5AA+l6U8qlKcdz9PPYL0YxxpoABNYi3ZndigTRA1+i4JuXa+m1j1aLHF40Fn8kLgO/1X6cJzsJECjaW/inDIjkIDTDTVVpJltVnZez5Uu+R+2pmUQE5uM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052581; c=relaxed/simple; bh=xJ40DZV+4vMGHO5HtINfSwqnca7k1lZVUatwhzkjfcA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kVrgHry+yxADazo29qC3bcaLvMn8Gre7Pcdua8fz7PdWciQ2IoUfChRTFHgU160XPCvHQF2WR4JnJ6OmPG2TSf1Jw9EhxX1tdwCElZ8dhI3hLt+SmV2c69wzlbgYZSdyLGXWckB3GqU4hCJblZ47zqEu0CWP7ri8tXmNW0d2r7g= 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=LSSXcBZq; 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="LSSXcBZq" 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 5ADEAHlB028921; Thu, 13 Nov 2025 16:49: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=sYCNg YJDk1WQPTGoV2aiM0amkBCQQLPK3sXxUobzV2U=; b=LSSXcBZq1vS2hNX5+Jehy 7aiA+GT9w2ld4ZiIoiCmbxltH75r1ROntBAnNHeME6Nd9r3TG+NZ64viWTcXoQcz aUlQKCSlC0Wt4JAyB3tYXCXQekNiwmh6zKhr7avRailCNC6OrmsObcKZRydqWs1P oXs5miYNhPRe7Yiv7fquzkwx95KuC77Ywp1Py1yvUZC3qwtO02vSd7luMtbiXyzR yymRk3EfMSvJFmzEDJ9eVtbj772CZMDwxOLjRyY11FFe4pwFHcMW6b7Pr8dPTjwW yaJdQmy2Piyxo/QKY4AEEMRzF9ZoQf85aipGQ3jXN46LHixd+xMO+KOkIkTz5RrI Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxpnjay9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:30 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGDUdS038611; Thu, 13 Nov 2025 16:49:29 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3bk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:29 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnK9t008288; Thu, 13 Nov 2025 16:49:28 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-6; Thu, 13 Nov 2025 16:49: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 v4 05/28] objtool: Print symbol during disassembly Date: Thu, 13 Nov 2025 17:48:54 +0100 Message-ID: <20251113164917.2563486-6-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=Criys34D c=1 sm=1 tr=0 ts=69160c1a cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=UkdhLtt80R9bjKZQdAcA:9 X-Proofpoint-GUID: __2B3vh6ONqgQdY-ZG5WnqgSjyGc3mOm X-Proofpoint-ORIG-GUID: __2B3vh6ONqgQdY-ZG5WnqgSjyGc3mOm X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0MSBTYWx0ZWRfX+oQxrDfdUi1J Xq1RLZ3ISuFXg+oyhXhpwmLw2GUtOWLLhxnEAWD+HTbi3+npfa+g3KRmhvEmMUHnFwhW93cLf/e X2ORbgq69/b8dwlbTUI9h6VWzs7btz6cwazC0qgjVTkNQFD4snNceheceWiYUcZLYkOoZgEBA7F wRMX05Hnj1k1Z0W9mA0mCkk5i2KAlMOXs+plWEg2uJ90KaJO4sCUcC+uX9PwWJJ0qgMEI6/3IE3 vUcUyduzXPoXZPs947y5/FLxdWbDKx7mmMNbK50jGVXEFnLYYcLMHiuVttZx5Qg5rBgwrllaBDl Dpatwv1AH+YEMxpXiXIuUQY6ZKNyuCCuy5B3Xml1Dp8Vm0UFJ7hieonwD7AAXFjjeVcTY/CPKZA 1F43FceG9iTSZB22Il7I9H+WTWBDwA== 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 06:55:50 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 2C75535CBBD for ; Thu, 13 Nov 2025 16:49:38 +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=1763052579; cv=none; b=S7MsnlVC+GUDMGg+TyIUbuue26dgOjHNdHuBLUCDib6R90bozkOtSqVWp2BofCtQJcNpLHWjFQAcXbaytDXJyZYdO6jGQjfHGaISJb5a94Qaw+bYXBllvk61oFGwZQHir4X/z/QPUdfNaugs/xufKbVY2XY7wSLqGCKx9KbAlpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052579; c=relaxed/simple; bh=gbvnhYzubzx7H/BNj1qdsqisuuBReqtUkoUxNeKZ5+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RtHG7O+Goqiq7sGyv5I6HfMoA3w9OQ0zHFUHQJZuK5yDRECEh1ZiavaCcp57p3e3JqcwmkJOq4wRwr/pQevKotbWw+0HLztAFFGFKUGUng9rmUmjqMYrRp1SNc16GvUxoEu4KBx0fiNIeZo+XetI4UYPa6Fbwa+Tcqlz2g1Q2ug= 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=pfcPPP3j; 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="pfcPPP3j" 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 5ADE9wwa014756; Thu, 13 Nov 2025 16:49:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=VCjhb Xg8e8BhVZxWVj3eoHY4yrmjKQhyPe9SZQIpC4o=; b=pfcPPP3j4Fh637EflvjAd dwsmgFlJzCHYHSDt2pmyQDA8gj1oR+oQM/vqYo8Eda5/qGL5mV+s8Z/ORncrK3FW 5bjD3NsPwUz2ad8xbmEQSJOydCnZN2I8troH8pbu/7bYvkiuH6X0nEbNUOGxkS0Q 1YtbEHE0512sfIptswZpYVLn3MH7ZlbP6ak+RG2edi+/mKil5lws3p5WbPIrp56p dkfbvC7no3OD3VKIab9trSJoyQ04g4qj9NYkTj/4xRypwyfoMmjySA+BHwVcFjrF +C9FprM/4XzNeh4Vvmpvy6xxzU1YWGzQEyElqj50oeHkCEkFgHoFs6oldpgtEb30 g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxwq27sy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:31 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADFrVQW038513; Thu, 13 Nov 2025 16:49:31 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3ch-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:30 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnK9v008288; Thu, 13 Nov 2025 16:49:30 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-7; Thu, 13 Nov 2025 16:49: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 v4 06/28] objtool: Store instruction disassembly result Date: Thu, 13 Nov 2025 17:48:55 +0100 Message-ID: <20251113164917.2563486-7-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0MSBTYWx0ZWRfX7y0S2x2c/ziI ko9gIVQyCLHEERwQBHG2qp2B7g3j+x4jKlE7j1TMkhIwPl0MlATAc/50GsgZMN7ccVLpEsQVC+1 3zorQ38x5a5e3ZCUW3g2or5LywEoXApMVJW5AoKO5rYmhslGSQ79TkV4yVn+WhZ8BlSCPR75UuV AVNSjmGqJsJtVGF/5eqJw65KHIFfTUMqIiEcOcjuRgzZhLGB2U0eEu1I0LYeN+gYNGWnAaab30q /D6SLeWucPvzR7cqboRAQCF+a31nG5Kawvu4EjNnJufhLdmhPrBTUYt119o0zYCg4CBgACOkRms jWc68Xm8UJQitf0L4IN21MdhhVfgtchh3PKi0wbF7u/ErY4GcZaO9v1Sq4A6hIUCNUoctbQwJg1 BJBVF6zlBt6eW85+5xsPfC8Wd7b4HQ== X-Proofpoint-ORIG-GUID: qCDvkfczIcC-_8b3e1x4t3jVr4Nhfr1Z X-Authority-Analysis: v=2.4 cv=RrjI7SmK c=1 sm=1 tr=0 ts=69160c1b cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=jcmHYjYDc9FjrwFKAggA:9 X-Proofpoint-GUID: qCDvkfczIcC-_8b3e1x4t3jVr4Nhfr1Z 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 06:55:50 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 64F3A35293B for ; Thu, 13 Nov 2025 16:49:40 +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=1763052582; cv=none; b=aP6ZbZfu9FDYLsF89DlQWYoRDv1jbxD9gkxQtccaHK4H/KnD9zBtPFN+rUIos3y7iORxRfEY2KJI+eyFs4PZuhNfsXtU/TD6LCB6Dz2qoppOX1+DQiB2hvhrMnHei/EdjITWoPiPGueKWcdZei3jWus55xKReDzUM9JV7Db50qM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052582; c=relaxed/simple; bh=4hrHY49p9+jbWESBW7pSI6F3H9G9eX8s16Cs7s3rUac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KfPKe3qw2/11RahkXfJoOTg7kVpBoltCrpzQviBzght4QFs7XULZwAg8Q8IE6rOye+SamZNZioAWjirua5tNLVq96jklNVb5d6sVjALaK9ypECfM/0IIZTdUQ+VbF0X7Yx9uRLZJoedw2daURXtIrdyDSci97hoqfaI7ZufXwHY= 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=m6A05MW6; 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="m6A05MW6" 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 5ADE9w1I012345; Thu, 13 Nov 2025 16:49: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=k3X8y b+pwCuo0yCIKuiGoFOoEdoTjh02qOmId7PF+q4=; b=m6A05MW6D/utuXnjlQjz6 c4s+xye8akH9t90KwbkHONL2N3fPfPwN5dVVQYxnPplTryhxFHuP0J/4QDmZNQYg LG3ABX0VBwbAXuYlXUVXvcanRlFlDaEVhXoRX76MwHcHHtLjBGMC2kNf1BQUZ+xa i2M74f56OzDAjdfHwi2iaynUZO9/89lssdtXnOu50+klFomgJ/y97mpqGs1It8em 5UdoWjFJ2/8iuu1cyrxxaBe/VMUaNKaz4VP7E87djlWq12MN4ZcD4brzyq3b1sSQ B3+RpsMfwHDUaYOLV46BpO/fL7EtmcZuJb5mvEldG34LNCLXhTvqOxJw18OaAnOF A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acybqt8k1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:33 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG4I8F039272; Thu, 13 Nov 2025 16:49:33 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3d9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:32 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnK9x008288; Thu, 13 Nov 2025 16:49:32 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-8; Thu, 13 Nov 2025 16:49:31 +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 v4 07/28] objtool: Disassemble instruction on warning or backtrace Date: Thu, 13 Nov 2025 17:48:56 +0100 Message-ID: <20251113164917.2563486-8-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-GUID: nOfYYsE6WyRe6P_PoYIcWlJ70fpzwlGi X-Proofpoint-ORIG-GUID: nOfYYsE6WyRe6P_PoYIcWlJ70fpzwlGi X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0NyBTYWx0ZWRfX7kDf4UK7J/gZ jTbBQBGoerbqRDKKdUmq6tgd2PYOeWV8BUN1oG8NnbRBU6hUBjfSUlNeWSgfCY39JKuwp0HJ53W 1Rh5jWJnqPdsVWIq8g5cAryOYJ4VUxTX175ltWw5y3HLecID8+dxpmT6bikMv+cuHfCRnapj1Bl bpW9FzfUmf6JnZL0jtdHljfImrOA3Jr/HosHP7EV+GUV3Fu8FQNQmp6bgGQXW1fYRy4WXnYl1rl 2UwIVZTp8qQay0L6+M1FqcdSF1vl+grJ9OFSXfGYGm7+B1LZA+UGa1qqOmbV0cExl63XF480CK5 CCgelJgqzPjgkcewtyTy1nUzNHZ4g9IgbFxnfDAbKCb3atQwg+QhDyolwidFUldBczTI440lWyb Q8TeJxtvGmoiPXMEq7cf3QFgqjWUSA== X-Authority-Analysis: v=2.4 cv=X7hf6WTe c=1 sm=1 tr=0 ts=69160c1d cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=49cdYLv4DVxkACFpF8YA:9 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 06:55:50 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 C1A1E33BBCD for ; Thu, 13 Nov 2025 16:49: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=1763052585; cv=none; b=ml679+BSMFMwXFZkO+/YWwftqjpDVaeqX7ANtdCqSeOrmQOZxRN4pesaORw+C/pyNyWcAOVws4E4E94kCqVvEslnTX856jy0YodG1KvajcSS6gBkdjzBb9reTH8zparsQq+YaeSXAoDUIPGE3/ApH+wqaq6qAjr1tbqC75iuSJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052585; c=relaxed/simple; bh=jnb+jw4cJX0KYewnHVML539qHFFynflD2IXsBim5+Hk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sji/eP47l7gurVyYXyzCrjT818/s7j8krkMUJjdjAknE5I4Hp2G1XfES9fPb793/BTqIfBUPGHpQKqrEGgRqivuvbjb1VgUSqnQJcZvDaO64roJI8IwpNx9AHjIvdyi4ZnT8dkDxpAIUA3iuSQqsnoozMpztoaRM7ustDmJxLaE= 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=SiDNlWAh; 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="SiDNlWAh" 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 5ADEAVwJ006599; Thu, 13 Nov 2025 16:49: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=HGtNP jlJ6RQLlQzEl+bxrsWOw+SssZH+N/YbRTfEQDA=; b=SiDNlWAhUqbCcIJuMd0e2 c3TUDRXpk2Bt+5emWJtIXt/j7VlywtWknfEl6fdBivLsc4nT0DhDVGZb8kzqP50w PTh/US0sO8TsnMIyYS0fkxz5jrWI7QHtdvTyB5ChXbxu0/Bw90CsASWMKV/Wj7a2 GC151/hPkla++09Bg8ZZ6Eq8GORl6cReXaneZW8OVJUpoQoZ4eZh9z7S5UNHhbY8 PZ4QR+g8ZmJEyEgaYbHTA05TbGIoC/dzC0vIU9JEdMH87HLa1YnQF62tLhgC5bl+ EjF7xKwlQmWvuz7uSf7Ob5uYyOv/DQb8p3Jq/28ld/No3c/qaYL7CwdN+DbLKF8g w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyraa674-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:35 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGGeLg039056; Thu, 13 Nov 2025 16:49:34 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3e2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:34 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKA1008288; Thu, 13 Nov 2025 16:49:33 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-9; Thu, 13 Nov 2025 16:49: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 v4 08/28] objtool: Extract code to validate instruction from the validate branch loop Date: Thu, 13 Nov 2025 17:48:57 +0100 Message-ID: <20251113164917.2563486-9-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE1MSBTYWx0ZWRfX0xCfDh8y6NVQ 17bxwz2M8F0tVPS/GM0XUOW6ZV/iUnFvXEAcTmUBpmZXEhcLyO1OM1lcK8upAJ1fNcaHVeDStKJ vYyOh1Mq60Nx72C0tyrUdMzh+uiYT+NWxkJGym0nJ5rTRw6ZRA1HN9NVbSKCsz/fYieZvwfbIpO D/l80DEhFHe4sN3JfrpbJ7jcot/JUNAE6W5Fb5KIkdAnR7H4F4DoHrOT6mFyIndUZtBPJqpbqS8 9UuU8bEfCCJZ1+t6nh2u9yvb6/kvRpHvRdK1Jgy09wo5nsThXnfb7Ctod5R5t5ZOu/KwjHBuu4r 4SaovKGLofE9bfhF5hfudYUvHYCe6KslAIyZ+nXh25ZZ8/8uykWXDPkcNl8zS8EXTv2BGXNnMKZ ocW2UslPregtOol5XLrctJCDnc2hhA== X-Proofpoint-GUID: cUm2NIBAWXYO3CwI99kfcfnKeiEZ-Bo8 X-Authority-Analysis: v=2.4 cv=ILgPywvG c=1 sm=1 tr=0 ts=69160c1f cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=45N9rFkX92oTsxCXvtEA:9 X-Proofpoint-ORIG-GUID: cUm2NIBAWXYO3CwI99kfcfnKeiEZ-Bo8 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 06:55:50 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 99CD3361DD5 for ; Thu, 13 Nov 2025 16:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052584; cv=none; b=AuHWtDY9AC+TLAInRg8SGLuzCjU+NRkrTr6kNNbccKxJcXVLhZYqLv4bJXBM14GKb+MZFDZhamHZOis6d/toCuyb2iLwtUuw/NGuE83vj2aYnJJfYmSMXoQOYRW0KtCl84WXgeF2h+cJj+tiUF4tJIN1FJAkdE7h7MHVtHlt280= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052584; c=relaxed/simple; bh=CVdUBf+Wgi7dxn66PVbR1h3zdfzGRUACq+X+Gsf7sSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k3pIUDyt/6ebsjGIbETS8HH3FKNyFkzN1e4RM85vQHtuOYC71vSHe3SGac1+BmLBzQul31rKBjyZplaJKZlJPzC9FM6kD+RwuyN1NKCl+UXBt6BclNO+nV4UUfLw/lBnBOdJJWJUWPjvGvFQLbm6BiyE6qNrQrQ7QjMmu2Hpl1w= 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=OqiyAS1j; 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="OqiyAS1j" 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 5ADE9uWr023921; Thu, 13 Nov 2025 16:49:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=2Pvki wZj0+fyLZUdBNms87y9ptFPtvpYZhWD/2eW3+w=; b=OqiyAS1jj6MH1t0SyhemE QgLvYUh0q2yL6lnXXsfkGdoRLKAwpN7ybBzGmu12cw6C9HSglaK3AiKSzeQC5pnM wSGQZpV2mHjO6ZfK9YEVDwuMI5b7koXXrCG6GUDLw6K39/Z86X2LU7kyinRR/X9r duO2eONa3Cl5H/lMPFYG/Dp2wkF5RZJ6EVl+kZHgUYnC48g7CEUD6QrVfWw3KIRb Ptxn5ZtGxfPXGfxyL9u5ZqJXy0xnINH3RVwIFoHaOk96dZddbdkQBpGhNJgnmeBf cXupZoc/IlanKLhKPl+wz10dOex52gArTsFnViZHVCd0h9rYtFBzubcLnQllaRfw A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvsstnmp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:36 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG9pRF038873; Thu, 13 Nov 2025 16:49:36 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3ex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:35 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKA3008288; Thu, 13 Nov 2025 16:49:35 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-10; Thu, 13 Nov 2025 16:49: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 v4 09/28] objtool: Record symbol name max length Date: Thu, 13 Nov 2025 17:48:58 +0100 Message-ID: <20251113164917.2563486-10-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=69160c20 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=xKpiAcmDGk3KfUQPlkUA:9 X-Proofpoint-GUID: 0nDhnBPX1aNScVLej6p86VcyKB8ZDolL X-Proofpoint-ORIG-GUID: 0nDhnBPX1aNScVLej6p86VcyKB8ZDolL X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfX5sKgLh06ipIv +vzSolBqXkdQgQ4J1nAQAASFr6x8IDfUa4RdkrTZWn3qlvIuwwDrKkZsvorFpKtB6oQNJxIbsEc 3Y45OnRbQABNJS+uLb671n8spQsduxnrDCWKCi7giBIGnwGd+Hh+I66YzFr+jmwdInkUiLHB2g4 mj4w+mLifxS/YKFoNcf1ertSIWbzOKYvulPqO9CgdiGwXG3vnXfIAAFHlOmIYbCCPqMVY6vq17U iG859vJmMQ2bu9V2uXYQiLVsutCfC3Wi7Rjl7fxkzgGeV5mj616wqXWsTIVjqfNkeM8G+5BEU4x P0vfr6hfVrJNLHlxf+9PaIEzPa9TCAI+RXa8cFALolMUp+xJvEnxAiouh5frIZ6NADUNXNVCpDl 7Ld3/z1m3OQWItIwVWJY1fxmfZWjuA== 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 06:55:50 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 850FE3624CC for ; Thu, 13 Nov 2025 16:49:47 +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=1763052589; cv=none; b=oRLnwK0zaWEEBFQBshjXSJ7bDMoBClXndQbD0e6KuWx3TJj7FW30mfIKoWSFzlMqbawIIt/GOH4Hgh8mwI6UwZt190R7PEc8EU8sUXpV74Yir286BDJ2INvy4ppeLAAYLMWIvZCPA8re0Ao2e+PGYQuFdN0NSWRnUH4PtQYvoik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052589; c=relaxed/simple; bh=IFwJFcZiuuz+FhuZr+Gu8S/HF/N2dyr6EohjkrgVBQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gTLO9/NZgNHok1/dDTunpCaXa/Z+qYEgWaa02ix3fMnQ5c7TOZGUyJsKRRR0Z+Y2DGQy/55QfA0AiStufBJ05+KFNmpZKGWdt8wZmr95fBF/LCcLCOr91Q6NfiFcXzxM1XJcVafKxOSbLbfy/fQo5KZNxLS2iTJC1aWJmQ0fAFw= 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=mzf1EMb2; 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="mzf1EMb2" 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 5ADEAMvF006389; Thu, 13 Nov 2025 16:49:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=YZWmZ 4ZXB0Msaovq4srMHeSz1mpLuFlCt+fLwzcWWsM=; b=mzf1EMb2O7cLUx5Co6Bp5 BpQdbyQp8B2l7cTrDB9xXdLTv94z7K+SQ+PIkKcKpLi5URyRcDX/S6/kjqCHGyqo isaQr1OGslJQpZZBxqF4tTrfnkMAIr9Ic/Eob67/sR0by45fBqL2XrG4ZNbszIzh Rioo7lntMBEtt31/K2VQFALRTCUZDBX3BHm1FmMmA+PrbBw4YHdn7QqOpjYau+FV OzO75fDJHYm1yJ4Gl5o2nuSnvHL1efQcO6UXrsjVesIrWcu+IoPyrzFIZUHHTFzC X+tyOQDKZiz9JIxCPiprUaYrMAq4PPKCOB7cvLZlCGYPhs6DUzBB3lHhTNc+Sbx5 w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyraa677-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGC5pk039018; Thu, 13 Nov 2025 16:49:37 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3fp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:37 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKA5008288; Thu, 13 Nov 2025 16:49:37 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-11; Thu, 13 Nov 2025 16:49:36 +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 v4 10/28] objtool: Add option to trace function validation Date: Thu, 13 Nov 2025 17:48:59 +0100 Message-ID: <20251113164917.2563486-11-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE1MSBTYWx0ZWRfXwNTD7OBgwzmZ 3AlwNYGbYRzhttvPT841UcZLTbJhXDAw8FEA/HaclydMYbLaxncI23K8xYHbnRPB1MKxWstxg9L AaCCKnte0eXmUimbYMvm+OJo7qlv4Qbo64N87pbLKNABHEYugWXnm7YP4qbBFeCLuvdLAR40KGF d2vhj+CMLYx6r9MD90+5F1axt/b/1EKta9S8BMYU7nUKeBeGyXRGx7Hu69An/EWUnFO9nf2BATe x94m/cJUOrk7qe0ypfm/rX8RTwJhxqaN9iIfA9VQJhq/3RhUt8LJ/93Fcw0HRiepwAsozhbKGDw TyozUgAn96n2cV+TjKzl+XcwpL2jz0tvozwxWHn6DVlqFspdUD2ZudVIhOnfmFe0p2Pp5IpNzjH cQ8pyIDeOc47I7s0Qd8BICYKhnMfJA== X-Proofpoint-GUID: 8-x708JXy0rPGz18voOHmwjeCmcExXvk X-Authority-Analysis: v=2.4 cv=ILgPywvG c=1 sm=1 tr=0 ts=69160c22 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=7nqSK5V4zRp-Hs5t_LEA:9 X-Proofpoint-ORIG-GUID: 8-x708JXy0rPGz18voOHmwjeCmcExXvk 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 06:55:50 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 73FC0363C6F for ; Thu, 13 Nov 2025 16:49:48 +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=1763052590; cv=none; b=DwObwtHgkAgQQB8eUj/EyGKurjvQyro7wCrXBYjJFLVKxDVKrwR+V4N9KzXzMHxSZ1ElPh4sOIHHX8WumM/5R/K/xJbrhz88VMZXdUXuosMmGf9ml6pSaBMll3764SRx50IVg/j15Y0liYipahBlPhohQsi17G5wWhwwX0EV7p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052590; c=relaxed/simple; bh=pC2WAUV+iU0LWoW084h3U8rs1dj6nF7sKXuysdtnOkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SNksZQIAP4KsL4IDot0Lr8JOLRXv/yaNJEMr3krEFTDbqeGriygZxJbsMg2pRufsSpnXMPELAXExZjQWfDt0o7TutpUyG6B02ML5K244bnC913+EXTyRd96FbhGoN9usRqtKvfMkULembUyyl0wqNhw0GuUfVU9ZK71yR9Yf6xw= 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=CRTyErWU; 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="CRTyErWU" 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 5ADEA222014886; Thu, 13 Nov 2025 16:49:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=9902H Q+6qpXwpG+/+fELpIj/HjoLqWNfspd3VuptgbM=; b=CRTyErWUFP+E7qgPr180g KgI4NJvmuH+IGntOx1MJeZnw7UA9A020Z4ZSXjpwa4mFhGUiO66WRNWkpjGwFK5B ZxR3KJFWfORtXom+G6rwRrx1zPe+hKIsjrrEE+JmJTiSraQx74GW4ca4WRi2Ysx0 hvtlXpOFNMGci2QiI2qHP3Mtxg8RvZzUrmEzTNWKS7mo8jmODXoeYsCUc02y4ppB mvN3iu/F/UMA41MsRUYYbYS2a8WmsffXQ/uYeqo4qEt7ka3WPR5rcyRR4XgnvF57 J4kzBln3vaugDPidi7lo0RiAj+CEwZaltCmDF+PQEU4IE95+MfHzAxx+/G3lUh9b Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxwq27t8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:39 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG9QWs038522; Thu, 13 Nov 2025 16:49:39 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3gb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:39 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKA7008288; Thu, 13 Nov 2025 16:49:38 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-12; Thu, 13 Nov 2025 16:49:38 +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 v4 11/28] objtool: Trace instruction state changes during function validation Date: Thu, 13 Nov 2025 17:49:00 +0100 Message-ID: <20251113164917.2563486-12-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0MSBTYWx0ZWRfXy+1R9a1EonjH BQfZIf36e3WgOeMalJsgQyDyNhlF8jNmSmBhgY1vLGDDY1CBU1AESpQjrtsf0oxjiz+vkgMBqDq /A4FKRm4nfpahwKhifdygmdBJeeLbDEaGqFbWTStm6RTOf6Yq2cWjMrvCzssn1zisdkrsQQl0zT gM/nYFQcCzA6miGzuK6GFYjTlCkOXRG2yOA4lsVjVr5F2edwuBecvXbV5V28wK4rVGlipom0f7Z zMhogW2RZrZIzw2TPpTIQjPhMnqgpAO4KLhRaQ1uCZJt/HZHLt2pfzxgf9VZL5i9UARgQxvQ6I+ QRLCI2uxgTWEUaPKm/J++T1n3ZGJFBa+QeBPo9bOsmc+aGJgGBy/7UaRElp3J10qd4Nm12xA9zP eMC76gm/E4OvaOXpB/3qNZbSbdWhrw== X-Proofpoint-ORIG-GUID: dDw6cacN8LjCpdtFPaWWxE-WKgEQla19 X-Authority-Analysis: v=2.4 cv=RrjI7SmK c=1 sm=1 tr=0 ts=69160c24 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=n0rf_ozDEmcaLxr6z3oA:9 X-Proofpoint-GUID: dDw6cacN8LjCpdtFPaWWxE-WKgEQla19 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 06:55:50 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 4EB8E364025 for ; Thu, 13 Nov 2025 16:49:50 +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=1763052593; cv=none; b=VZH/tljIRT2XFSZ3/WY/1aLwzDG1ZwF8D4yvMbQi8Ox3uxz3hcomz3l+KR+6gr4lHVhlnCCsdWvWxf15WzbkbRuTufx981djCTrVP+UjUAl+Y05lGQo+gReNYstIpbfofjNi2nsIVSYHzoirkP8oFWC+8b9yJo/qoe1Dug46PaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052593; c=relaxed/simple; bh=XHxubh2Ex6f1fNjOHyxSKBBVuRAcupgCiMdiGQQ8YlM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qBT4vlgUCbaGNxXBSGULNvQaDm2cE7bQ5NiQnpDnTPVcE/W+PCN13TErqtI5FsXS6bNULaDvtL8Vbx5kUDpQwmHPZ159YYMmHe8ycbzMlLd7DtHm1k/DXckHlAdg0x82XQ/uPF4O33rIa/6wBC6V2paa/FTKd3khizYvobx13Dk= 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=GYwn5bAV; 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="GYwn5bAV" 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 5ADEA2SR005967; Thu, 13 Nov 2025 16:49:42 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=GYwn5bAVlswGjJJ/lpS0t AidyF14jnXWt/5XkvH7HCYAkv94zYbmDV0HiGYYKAHHKv3o4ogtPhp0cR4bIxOOZ NYptxsJo/bZ2jWUVYed0NwNHgh/mMTpd+dx9WvBF1H3Nlj58wpPwvzn7Wuz/Ikql dJFqFB7B9zTQ2Eqc3B3x1K9vhf69FhxFKGZmAwffH5+Fmm7CClsTfjDHxECmXlWn ztq/VQFWf00FGRBaWFRbnLCXlbMEvLfHo0KEqZU8MsKClR//B8yJ0ESMH1DNO9Ra ykCzsoWQnK9TXzDuj6jDQbqoRayDzujihTVoSe8jjlbox5LSRFKySa3OeyfM+JnR g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyraa67d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:42 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG9gSR039287; Thu, 13 Nov 2025 16:49:41 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3h3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:41 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKA9008288; Thu, 13 Nov 2025 16:49:40 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-13; Thu, 13 Nov 2025 16:49:40 +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 v4 12/28] objtool: Improve register reporting during function validation Date: Thu, 13 Nov 2025 17:49:01 +0100 Message-ID: <20251113164917.2563486-13-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE1MSBTYWx0ZWRfX2wafvWf6kH3z DvUf+Lxr9OyLswUYiMyCj2b/xOLZ5N6rPppCPU5BTconW/tjHp4al4JgaZZBAheuK9NbvKeqwmt 22U5pInus/w/xeaoXZodKAPxJs3adR3xVLRjAJn/QtWdf469KtQgCA3aaoFUrbRmpx8xfkHEDFB 7ICtzwOiGFnVuPVj8nkd4wCv4nDyqIzZhIM72ib+xdocN5k5zH/OzhNLeF1lJ93J+WdCXeGtiJm IJdyDkqnO/uKcuCmHNs77Qa6xNjgMj3myODmA9Q5GTnV6IQ4RVEDkk5nGHBnp2Y5/yRR1Yk8SUH AY9Gc/258xfFRVVwRI5x9IhBVbm0tlroaL/v3KlbitfO3XYzqE/HQIbDNV0XGNKuTuRRLLkNk0d 0pNCpnZ+EjOnQZd6tlKCXgJ7XzRaAA== X-Proofpoint-GUID: TAkL7dfu3G-zxUaGhumdi7brw8-sG2qk X-Authority-Analysis: v=2.4 cv=ILgPywvG c=1 sm=1 tr=0 ts=69160c26 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=SYeOCZSjma0EYi-zULIA:9 X-Proofpoint-ORIG-GUID: TAkL7dfu3G-zxUaGhumdi7brw8-sG2qk 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 06:55:50 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 2A769364059 for ; Thu, 13 Nov 2025 16:49:55 +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=1763052597; cv=none; b=I5UQL2Y8uXNKg7g9y8oDUDS4GKIMRfoFu3oduEaaXufs9j3klwdAM8qhrsBzlmSyjvq3S5grIZ1M6/5eJ49ljCOf+lksCV9xWy53D0uXN2EhzIiOaW7pYVq/KTY6Ka58bg3JIXH0849H12H+EhJ6HJ/JDLce2XlsSwZ8bvWs5Io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052597; c=relaxed/simple; bh=XUAXAF74DOhHMef9jBz0QJoaQApmYe65pyFCdnksUbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZHVv4EAynZH0ZxMORzM/OQ89ejzVlhfHjm6gWX+RjD6IWb4ROrsHPOU4qpe8SaeSSm5SNZlOLrsq1ylZEyr3sEbdEZQyC3mCKr3t+JE/mD49ksYD3VngKuDTZk+9tO3MLyyx1BeLcv9L9XubsTA7C0EN+fnCh2E5l6U9+pL/m4M= 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=AA2dfbQ6; 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="AA2dfbQ6" 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 5ADE9t5w023876; Thu, 13 Nov 2025 16:49:49 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=AA2dfbQ6zflAI0T4v+Dlv mDSAhqolBFgV0fvoliWVIatr4qDARMJ2uVejqfZpcC02vQEHdCKcvCMGu3LqjsoH f4e0fvPRP+jZ6jyxTobwmtHBLgmO2guWXHAuG1Uxm3cRMuukzbzwbprkDGgc+OyX eWYHbJSaFKvrUczSmlIOjWTrOQD8laNNIClPaNZybaVf5HpwzmxKDqAAjSi+OgCy oWTh8eSXjgmmK68x+JELzqWt9W5yYWY6nMI/XgDFKAj6GqwLc8Z76N0zwHoG/CsF Hbu4Ya86g1hYr+EGR+09ThvRdU7rw/xE5Q6dgPMUTAg0T5io+DvqLxGWdUWGoQ6m A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvsstnn3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:49 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG8EKD039173; Thu, 13 Nov 2025 16:49:42 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3jh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:42 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAB008288; Thu, 13 Nov 2025 16:49:42 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-14; Thu, 13 Nov 2025 16:49:42 +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 v4 13/28] objtool: Identify the different types of alternatives Date: Thu, 13 Nov 2025 17:49:02 +0100 Message-ID: <20251113164917.2563486-14-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=69160c2d cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=RDt3PK5YzZswrGw8on0A:9 X-Proofpoint-GUID: H4nV52YDjxQykx9EGhaZo5FQ00X0zRUn X-Proofpoint-ORIG-GUID: H4nV52YDjxQykx9EGhaZo5FQ00X0zRUn X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfXwCsNKWCHoTuL nMqiyNNvBkX3CCLGM0H8dVoptPKtOgdfp15cP/82u3KIgL5yRbp2UboxO2hi7MYDHmfitcFBmrO Ma5gFbIwquxI/DfuABtNjGM9RLmOHURFf1B9QMUNcTqTy9+IJzqUjjeL3GBJDbVPGMjPWSSi/z4 1UbtC2CrybwnjanI5iMgcpUUVM0XwPmr8VVs4FEfYRz0ZRBr2BHrIrkA/OZkyrupuuTgCs/+S/f XqXjgDOcqA9Vx87H86U7qow82oi4TncdFB4bFmkqB6abMA4O5qAo/fXOZ3msMik+d3DOfkmZDnd OdDfVWtODc7jBEJIRaGVgSlliI2YeQ3+gzu/Sv5hzyuGCiC5kuZFUDjPVfT+V1arIDzrnLCyAnV T/kN9KMSDwcgAttNwpymDbe5vRDA1Q== 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 06:55:50 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 BB59532860F for ; Thu, 13 Nov 2025 16:49:51 +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=1763052594; cv=none; b=RdYEngkju7iHDr7JfHLXvXIczDR/aF3aRydACx4Np362YCR2QT3DI+04WcxD+cBMBdoAfkhaZCedrpp7FgFNNNLXgs8lewKXFLj5wyfYx7PE5IFjmNQ6xNCcEsI7RX6xJYneI8Ruv12DiqWldR5G9vwMk08xpq541RbleRtEXcc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052594; c=relaxed/simple; bh=mXFWRFXFQNO0iChwp/u+oruDreLjX2FPr2+NMEMWJmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hxlrJJoxJtw1PT1fYEcPGLjZX1o5rVPrT28bRvarwHSJKx1eAZE5dUsMEub2BzzhKlTmBbol+GGHLo2+TaHBWakQl3gb8q1gZ0S/kuwksW3FCQ8o4o07tu3q4H4du5D0eOK4DsNQmNgorpqOMGQa2q/7jQ+LpmyoFWlNMWSD4HM= 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=c2dkpYZA; 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="c2dkpYZA" 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 5ADE9sIF015500; Thu, 13 Nov 2025 16:49:45 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=Z1VWq fDwg6ImwsQC1s9AlbhuVjRi/s8fZ+2k0DXWi7g=; b=c2dkpYZApjWS2UEjatwab IHB5Qe7C7pY+6fTWij5CTtRV+lxCTZyzrmtufvA9i2SJHU5xBTqGcp+y58bnnL0x YyGMi9j/9aMERHD6XUeCHnzr3hwlVRFq+QAUPEo1l9G/oPDFTbjjMCGgd4IemuZG YvwB1UFmCPliVcgwjKxaetwv+7zV7K8HCu5KT5+HT2bq4lEtWvPRew+SgcUgf0lz McANrCTWqNz9hop34GdOyLhljuIgI2+eyUl9X9IYaoy4ws5M3aeLn2++bbceHJlb CvA3FNXa446SSd96VpFMDPRVGlTtSnlLxP5AkYPnfdudUSh7ACzjYQnTm/ueWf4A w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxfvjakk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:45 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG6di3039063; Thu, 13 Nov 2025 16:49:44 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3ks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:44 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAD008288; Thu, 13 Nov 2025 16:49:44 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-15; Thu, 13 Nov 2025 16:49:43 +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 v4 14/28] objtool: Improve tracing of alternative instructions Date: Thu, 13 Nov 2025 17:49:03 +0100 Message-ID: <20251113164917.2563486-15-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEzOSBTYWx0ZWRfXwy+JmJt55rlY td+lSQXpXYLKS7ZycE6Cxzi6cTZ9Z5cVE6wNiPKIdQxYQANVU34QEV3v8jBICaeIohWQDESBHLy LD2RQG3ChyvSGAk3gtJfHgusNV+itmjmjYGX0ApRONhxBnxPS1L7WKJw/bsmqFlORqZhCxtsF9t Y/HuRHMlhSsAMoQvrIyhSNtTeH9Bbfe9zPW87/KWzS4BB5tCW1zOpA+lKV5Y6PrwCxG4SvtugGY AUadk2jhCI2fQ9C9RU3LR816fLWRYTSu7jYq7e8adWy+GikkfXs4vKz6tnwwqN6hLhcqtG/9cXx 35s+7m0dzDe6xrKOtrW7v70pQSkAxS6ZZap4ysc0dQf40RMs/yZp+0BuMDZX4HI5Q+6BWWT0t8i nhNuN4Jyp6/lK++J9rLjfk+ZbRkTLQ== X-Proofpoint-ORIG-GUID: SerbLu4S2QDl6FQyhyAzdISmSDuaOAST X-Proofpoint-GUID: SerbLu4S2QDl6FQyhyAzdISmSDuaOAST X-Authority-Analysis: v=2.4 cv=FKYWBuos c=1 sm=1 tr=0 ts=69160c29 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=_QAB5SvoetJT-gxAC74A: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 | 18 +++----- tools/objtool/disas.c | 34 +++++++++++++++ tools/objtool/include/objtool/disas.h | 6 +++ tools/objtool/include/objtool/trace.h | 61 +++++++++++++++++++++++++++ tools/objtool/trace.c | 55 ++++++++++++++++++++++++ 5 files changed, 162 insertions(+), 12 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 93268b7c015e3..9321486e6265e 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 @@ -3561,8 +3561,9 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, struct instruction *prev_insn, struct instruction *next_insn, bool *dead_end) { - /* prev_state is not used if there is no disassembly support */ + /* prev_state and alt_name are not used if there is no disassembly suppor= t */ struct insn_state prev_state __maybe_unused; + char *alt_name __maybe_unused =3D NULL; struct alternative *alt; u8 visited; int ret; @@ -3649,24 +3650,17 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, return 1; =20 if (insn->alts) { - int i, num_alts; - - num_alts =3D 0; - for (alt =3D insn->alts; alt; alt =3D alt->next) - num_alts++; - - i =3D 1; for (alt =3D insn->alts; alt; alt =3D alt->next) { - TRACE_INSN(insn, "alternative %d/%d", i, num_alts); + TRACE_ALT_BEGIN(insn, alt, alt_name); ret =3D validate_branch(file, func, alt->insn, *statep); + TRACE_ALT_END(insn, alt, alt_name); if (ret) { BT_INSN(insn, "(alt)"); return ret; } - i++; } =20 - TRACE_INSN(insn, "alternative orig"); + TRACE_ALT_INFO_NOADDR(insn, "/ ", "DEFAULT"); } =20 if (skip_alt_group(insn)) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 181e4ce975d36..058e2053c31a7 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -3,6 +3,8 @@ * Copyright (C) 2015-2017 Josh Poimboeuf */ =20 +#define _GNU_SOURCE + #include #include #include @@ -427,6 +429,38 @@ size_t disas_insn(struct disas_context *dctx, struct i= nstruction *insn) return disasm(insn->offset, &dctx->info); } =20 +/* + * Provide a name for an alternative. + */ +char *disas_alt_name(struct alternative *alt) +{ + char *str =3D NULL; + + switch (alt->type) { + + case ALT_TYPE_EX_TABLE: + str =3D strdup("EXCEPTION"); + break; + + case ALT_TYPE_JUMP_TABLE: + str =3D strdup("JUMP"); + break; + + case ALT_TYPE_INSTRUCTIONS: + /* + * This is a non-default group alternative. Create a unique + * name using the offset of the first original and alternative + * instructions. + */ + asprintf(&str, "ALTERNATIVE %lx.%lx", + alt->insn->alt_group->orig_group->first_insn->offset, + alt->insn->alt_group->first_insn->offset); + break; + } + + return str; +} + /* * Disassemble a function. */ diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 5db75d06f2197..f1bef2a6003e8 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -6,6 +6,7 @@ #ifndef _DISAS_H #define _DISAS_H =20 +struct alternative; struct disas_context; struct disassemble_info; =20 @@ -24,6 +25,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 @@ -61,6 +63,10 @@ static inline void disas_print_info(FILE *stream, struct= instruction *insn, static inline void disas_print_insn(FILE *stream, struct disas_context *dc= tx, struct instruction *insn, int depth, const char *format, ...) {} +static inline char *disas_alt_name(struct alternative *alt) +{ + return NULL; +} =20 #endif /* DISAS */ =20 diff --git a/tools/objtool/include/objtool/trace.h b/tools/objtool/include/= objtool/trace.h index 5b8abdb9b09fb..9a608523b6b08 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,36 @@ 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__) + +#define TRACE_ALT_BEGIN(insn, alt, alt_name) \ +({ \ + if (trace) { \ + alt_name =3D disas_alt_name(alt); \ + trace_alt_begin(insn, alt, alt_name); \ + } \ +}) + +#define TRACE_ALT_END(insn, alt, alt_name) \ +({ \ + if (trace) { \ + trace_alt_end(insn, alt, alt_name); \ + free(alt_name); \ + } \ +}) + static inline void trace_enable(void) { trace =3D true; @@ -61,17 +106,33 @@ static inline void trace_depth_dec(void) =20 void trace_insn_state(struct instruction *insn, struct insn_state *sprev, struct insn_state *snext); +void trace_alt_begin(struct instruction *orig_insn, struct alternative *al= t, + char *alt_name); +void trace_alt_end(struct instruction *orig_insn, struct alternative *alt, + char *alt_name); =20 #else /* DISAS */ =20 #define TRACE(fmt, ...) +#define TRACE_ADDR(insn, fmt, ...) #define TRACE_INSN(insn, fmt, ...) #define TRACE_INSN_STATE(insn, sprev, snext) +#define TRACE_ALT(insn, fmt, ...) +#define TRACE_ALT_INFO(insn, fmt, ...) +#define TRACE_ALT_INFO_NOADDR(insn, fmt, ...) +#define TRACE_ALT_BEGIN(insn, alt, alt_name) +#define TRACE_ALT_END(insn, alt, alt_name) =20 static inline void trace_enable(void) {} static inline void trace_disable(void) {} static inline void trace_depth_inc(void) {} static inline void trace_depth_dec(void) {} +static inline void trace_alt_begin(struct instruction *orig_insn, + struct alternative *alt, + char *alt_name) {}; +static inline void trace_alt_end(struct instruction *orig_insn, + struct alternative *alt, + char *alt_name) {}; =20 #endif =20 diff --git a/tools/objtool/trace.c b/tools/objtool/trace.c index 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 06:55:50 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 06AE9368271 for ; Thu, 13 Nov 2025 16:49:58 +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=1763052600; cv=none; b=K8b1WVecDmWkDFssvYO1HxMz4Mb5CEJGMmeK/+byStYaBDFJAxKx1Unm/rBUBlPetwpyjYRx8F45rbrctQ+KfbMvzEdzqppHBpumXPw316l+pekT5nDjZZCnjrUCAtRvpKnXGvZEOG6C93r4V30vxrEktZhOBIi/h0R2XGKJAJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052600; c=relaxed/simple; bh=8hK/J3eagHLSJX7FGwqPu/wqoJQoWFec06nic7DyRPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gxurFSH5YO40Yb4ZPNADlsX3KjodHy6fmVCj9dHBu4PEhM+C2MRJqN6PgUFx6eoxXltnOJQyTBNtdVK+HhQIAg/tr4BZyAyyqHYEF5KgcPAJEz+s0wqf21MGJ6BzQ/C7U0jiWOFBAgAkXcsts0kWjqAX8tzmcuk2zR9RlnqgEK8= 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=UmO6xd/Y; 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="UmO6xd/Y" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADE9wLm024388; Thu, 13 Nov 2025 16:49:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=+bERS 0LC/NsnljbQk/9xyULPRD1sZXy5xfjhB435WzY=; b=UmO6xd/YLc8AKSEmP/19y ISlZqift+Qbr9BmKFxJF996qJpk1g4HgTQQPBUTKrSI00tGtQoY30L5133Oqs7hz 3GK0W9jeZZtT74CHp9dzL9gGAKP0JC2dZtNkFGeU/TWWcWpMlegnq0Leva1WllvW 9d1+I+MRDQOWxM+o6o5sZ1jWmMfeqrWZRpeq+Szhbu+Aul7Nk5qFZ33cQSRK8fMN PlmOL1dOKd9LKgN6ovdR/zNRkHA1ez+rcL/G53zLJMr7NMb+QWestWYKC3PsaL7r k0wRaxaLh4cPWoZMB7h1VgugRnXaM2iqcvjvKfG5jxOAKb3hVlNRUws6PeeeSply A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyjta47g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:52 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG6di4039063; Thu, 13 Nov 2025 16:49:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3n4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:46 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAF008288; Thu, 13 Nov 2025 16:49:45 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-16; Thu, 13 Nov 2025 16:49:45 +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 v4 15/28] objtool: Do not validate IBT for .return_sites and .call_sites Date: Thu, 13 Nov 2025 17:49:04 +0100 Message-ID: <20251113164917.2563486-16-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0OSBTYWx0ZWRfXxiqyTwA/9qNY P4pS50PjaeUG79QvTJb43sO7p9UnP4SyRuNSkf49KdVrlKaU80ewOcJC9LuYfMAx8i7fVwh5Adu qXkTPESmUIz64Bi96/hCPSSniz2Y6qo4NZQX3QqkVkTHgD+xSJJ8xr6FgBWPVsEccUtKuPgUHNw nVoTK1s4K7v9KPIJWU9DauKILWi5L4kWbT2zSEjlHXdWMamUS+hyObf1SUBmPqKvxR+Ks5FaoNs NUdVQdEroAoG6pzpJBnJBHY9FU063Cs4YV/Wbskde3olfGEhq1dHE5setwZwLa44YmM/UyKGX68 HCz0+I6LUZmcOQzwlU0XtZqgOrnjS5BNMOp30uM9vBCwGBZQu1bZWjmyW1FdkgBzUMk/5ECruvC BI31ji+UJ48rjaZ036q4YVbPLyPuYg== X-Authority-Analysis: v=2.4 cv=S6/UAYsP c=1 sm=1 tr=0 ts=69160c31 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=yvIqsss6GtJD96b7xZoA:9 X-Proofpoint-ORIG-GUID: 6LRi8_U2YbdDpL75F3rZhigS2nK9uwD_ X-Proofpoint-GUID: 6LRi8_U2YbdDpL75F3rZhigS2nK9uwD_ 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 9321486e6265e..646cb7fe61b02 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4627,6 +4627,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 06:55:50 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 F34B135292F for ; Thu, 13 Nov 2025 16:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052598; cv=none; b=k6r7yE4gxgurQZMEdrb2GP41iiYoRsiImI+hNXUzXiJpQzGo2zegt4Pv1aBGQ8sGK80CVvCRDlkmcGLtWIRzY3rS0uXw6QJcE8676LyBOpF4f4keJFE4fA0BK0co4NyyxrRtQB+OI8WGuYMJPSlMfpL3uJI2eaQkbGsVi4CWAgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052598; c=relaxed/simple; bh=mDJm++wM5GxELzNLJ6G7scMX1MRzAMycFy+sdevP8+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mDn0IpOfcpKfNL1h5zfLibE7oJvHRRbZKRy0JGja5iBz2xgAbOBeuZafe5Dwm/XYIT42CNmJyaqWyZZ8/C543zdR57RZSeH95Op5AgRHXsO59E8iKLoszoAWSLCDhJ+G6/DFbLQEUvSqw48HBoE8uJAA5xVKb7+5orNGorjtav4= 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=SOuDJnxy; 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="SOuDJnxy" 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 5ADE9tMB015519; Thu, 13 Nov 2025 16:49:49 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=j/2Ey pPAlF5Zh+YyDHr+VZy/4XUs9JZKLIYh2ZToZf4=; b=SOuDJnxyLYd9YZqyz6e4a gMRGW20PA7kiqjAxTOR9iRnktV9wQo+4DSTyPvueI5icq8xJcZe8K2sFRd3y76Ck QQvXgYG8QnhLRTn4pII2WKkEaK3j2N6NOB7tDgw3nAkjY6xhP3e7dZ5RXtU2qLAR HptVmefzl/RGvtvj3r936O6B+hSfT1dOvRhtGfek4NfnprWs6GQ6RabbU+msJO93 gOfYOg/NhS86aIqWGBHtH1QcWT7jKAcyTsYfQEx890MTll75my5sO+eSkEHsKMQp GP18qsgyI+iryqDGlyLTfcA5oL46T69yfDFJRFKOQrm88dVN7VPJ4VMJAkYW9SqK Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxfvjaks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:48 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGGxtO038510; Thu, 13 Nov 2025 16:49:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3q0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:48 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAH008288; Thu, 13 Nov 2025 16:49:47 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-17; Thu, 13 Nov 2025 16:49:47 +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 v4 16/28] objtool: Add the --disas= action Date: Thu, 13 Nov 2025 17:49:05 +0100 Message-ID: <20251113164917.2563486-17-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEzOSBTYWx0ZWRfX63rH6NtkBvXF w97RZr0KlfltA2Ht9AoKzJHoOLrHWPX4VspOs7FHFRkpywEx/kVGe0tMdPXqA9VSb+ZDEyjUBEK B8rTtMwjqyvjqYP/89uWPd0ia66Cg0nYPTM81zAkqCBjYZFqFMfrezduyxykdcuIizjlM/fJvVY yc3oPM3y/BCZORft3f0yTt2r+GFdVYaIG6kK7OaeCX849Ni/ytmMTih6ineyVcnAJcMvgvTiHhz 2yDjH9WOvOWxcclbqV+C1qR3dW1AyKbo84AUjCh+6ptwfWaBxUd6IOplYsmbKVhoDiN9KpjcVi4 sSi3twWw5tJ3V9Wx+f3ubvdudg8OjAF7U2aF+S//ZZGL0eARbQZQnhT7iLew5aHytx7LWXLMmQn qqKUAr06j2iSq470SP6eT1zgeSeblA== X-Proofpoint-ORIG-GUID: xwvaa3faij0q82modmpCaVJE4mrN8OZz X-Proofpoint-GUID: xwvaa3faij0q82modmpCaVJE4mrN8OZz X-Authority-Analysis: v=2.4 cv=FKYWBuos c=1 sm=1 tr=0 ts=69160c2c cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=LcGi4TWirBIM2so6JHsA: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 | 27 +++++++++++++++++++ tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/disas.h | 2 ++ 5 files changed, 52 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 646cb7fe61b02..25c1c7185d4f6 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; @@ -4789,14 +4789,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 @@ -4918,19 +4919,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 058e2053c31a7..9b5d9075ab2d3 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -4,6 +4,7 @@ */ =20 #define _GNU_SOURCE +#include =20 #include #include @@ -495,3 +496,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 f1bef2a6003e8..15fd1237f03fc 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -15,6 +15,7 @@ struct disassemble_info; struct disas_context *disas_context_create(struct objtool_file *file); void disas_context_destroy(struct disas_context *dctx); void disas_warned_funcs(struct disas_context *dctx); +void disas_funcs(struct disas_context *dctx); int disas_info_init(struct disassemble_info *dinfo, int arch, int mach32, int mach64, const char *options); @@ -39,6 +40,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 06:55:50 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 A2F93364E9C for ; Thu, 13 Nov 2025 16:49:56 +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=1763052599; cv=none; b=SLxHj9JqJ6VlQdbE07PKIM17dWUEO7m8SSHpfjg0lOmte9sxrvW359sT4sCjYMxwjZP6KLqiLlSWckx1tc6JpGCYcY1MlNrwH5NAyw7Wo5dm01hN+GmMpGpDmOXzZ2aJk/ZItmto60f/OtuKytVfdt27FhL0Y00fORCNYbNCtKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052599; c=relaxed/simple; bh=FMSGnbKxEL01sZ20PRImDAVPUOXXYS4m+KlLsw2RokU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eN0OPpimjwsmzFA8qKEeNJzxM2BWjMfm4RgbhFaT017tmA/WJlBygIDwCC4Q1zxZvtsUfglDMyOcG+7/2W+WlgkFLBnYc6a8/XaIl93bKwbq4Fqb5DlfK32G/J8DmQ9craHoNuuGKXFA8EYKEVXN41jLYtCcPOdfXRCLvttC6Oo= 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=X/4RHLy4; 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="X/4RHLy4" 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 5ADEA1pu024816; Thu, 13 Nov 2025 16:49:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=R0M5o 8fzPyLjmmNK4LXPsrcKOj2yQvDlaQDE9alZKVc=; b=X/4RHLy4ek6Oc+EBfvu4j OL7xj8RKwJo4P039eQn76mRyf53q8+wxf8Oqsab9zN/hGYHyHKGeiU9gU7ZU/zIV oDDGDr7Xqn9UdTM6WQ/6upwADwwrSGm253+r9aBxLhpXOQarosYdldLJ9rqgqTfY p0QZ5ipoMKlOWt3QD1G95xbU5q9WKEKQ9fz+9+rx9xz9+LAhyEc7i8WOFvV27fZP z1Wjy8cYq00C5Wc9fRbBcTMJJC9Xh4D1zUAMcGOpuvM8qV9smQYwCk3BFOq0JRif YqrLVsvENCItgNedXglTs9zRXCMVCLE6AjtkHhG6ob7Uy4AILSfLnhPm+rA7v8cy g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvsstnn9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:50 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG8EKI039173; Thu, 13 Nov 2025 16:49:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3rs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:49 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAJ008288; Thu, 13 Nov 2025 16:49:49 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-18; Thu, 13 Nov 2025 16:49:49 +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 v4 17/28] objtool: Print headers for alternatives Date: Thu, 13 Nov 2025 17:49:06 +0100 Message-ID: <20251113164917.2563486-18-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=69160c2e cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=8cgdJ23b6Str3pk9HK8A:9 X-Proofpoint-GUID: ataKvWXpqmRw75CQDu6xxOMeyZvWw-UV X-Proofpoint-ORIG-GUID: ataKvWXpqmRw75CQDu6xxOMeyZvWw-UV X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfX/xBUqXWP/UhU PykA6N/HsQl5V9HKohv+taU+qaZF54+FGdRKmVt0rp40OFWmzz1H/Z3RSrXc07WHdRkI7eeCpnD nH+quctRaTmR7+etogy1HkKY5GJV40SOBjl/+PSjPLoJnewYXqeFly44x/c+mdbvfJbCu2rRw8o T+aNOOpGcn4rrBhORk5HR+0/ZKjPmgNu2bT2povZ0AKiYx8kOIUrK2+PY6XZmVG2ac1wH8uweTh MhvpNOrN7ulGlO378lbGCC2QXSuRD3veC8uXW4/I81G3wLGF9dl37lJto01sL7Fln4uWHdO/ima gjvv7mDT5ZOYvdtFdKzsrQkjmLxGT68LOlgKP1vQVfnLoJD7LRod0Pq2FyK6/D7N9/xaBhutnOS vi2Oo4Ak65x31SC8mAKzUd59OKJ+lg== 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 | 154 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 148 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 9b5d9075ab2d3..57a13da5e1b39 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -29,6 +29,43 @@ struct disas_context { struct disassemble_info info; }; =20 +/* + * Maximum number of alternatives + */ +#define DISAS_ALT_MAX 5 + +/* + * Maximum number of instructions per alternative + */ +#define DISAS_ALT_INSN_MAX 50 + +/* + * Information to disassemble an alternative + */ +struct disas_alt { + struct instruction *orig_insn; /* original instruction */ + struct alternative *alt; /* alternative or NULL if default code */ + char *name; /* name for this alternative */ + int width; /* formatting width */ +}; + +/* + * Wrapper around asprintf() to allocate and format a string. + * Return the allocated string or NULL on error. + */ +static char *strfmt(const char *fmt, ...) +{ + va_list ap; + char *str; + int rv; + + va_start(ap, fmt); + rv =3D vasprintf(&str, fmt, ap); + va_end(ap); + + return rv =3D=3D -1 ? NULL : str; +} + static int sprint_name(char *str, const char *name, unsigned long offset) { int len; @@ -317,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, @@ -462,21 +502,123 @@ char *disas_alt_name(struct alternative *alt) return str; } =20 +/* + * Initialize an alternative. The default alternative should be initialized + * with alt=3DNULL. + */ +static int disas_alt_init(struct disas_alt *dalt, + struct instruction *orig_insn, + struct alternative *alt, + 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 06:55:50 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 2612E366578 for ; Thu, 13 Nov 2025 16:49:57 +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=1763052600; cv=none; b=OkvN7YAON+YvEWvDNi3ugxke+XjaIRRX0WJhFJH+q1TqOuFUxTHTBNYLJWxSqtQ/nllUjmE0mRrZqJfv1M6yTkkRSvJk24xRtw8HiObwRDXqD4hQ6sCH7rwy4/1IGWBT1bV6jOZn8rJIm2QrXMgDU2S7JFuMqEI7LRYIYpE/tAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052600; c=relaxed/simple; bh=xkPHbeEa/fyoEXZ+IfoRNpBXeQZNyTaLsImOKbE6Tjk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u/nn7W1x0MRAN93uMVk/yFD2VmO6UdSbjXZxcI9LwdHPhV4MU/b8jOCXVDI3aT92f6A35YCi2B/gmdNfbLgg4FSsWS9QM7GYfYWYnBnTyVAdtOgXvEwlBainazZybN7yvh/15/RWqmuFdjaWQIQC+/6PDX+NxLl3IADRMo9UFeI= 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=IWBVV6pG; 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="IWBVV6pG" 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 5ADE9tSv023882; Thu, 13 Nov 2025 16:49:52 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=ynjPT RHYEswaRnW1oTgJz838cGYP3Pd020uwtpiU0WE=; b=IWBVV6pGtqLVzOdaC2C5H AoszfNOc842Xe2BBAARjVmSXs8KUWRi2cyXywx4fDWU9LX83TUuQ6Td4x15Fn7e1 Cz+L0iQ6l/1zF+PViHgiT5jCUKDOaEOhnONuSq8YYgeq3rLZ9n+3RBGwM765y2DA bEqbfJZvkOLSF4144l9nzd4qnnjHEq2UMkPFtAAFYRao3KFIAWSK0Ym776o9VDzI Q5Lm1U0/TawPIeLbQ1QOupF/3SYc3qF6gQLE/XuHSl909iFDnaslhGnLdIDk27VA 01IeCQGSPZtUcCSKuAwdEKYeLPWpQHC9bVEwN0Sh7pznQ4eTYmgAH8PTRpLeL/DQ g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acvsstnnb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:52 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG207b038612; Thu, 13 Nov 2025 16:49:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3tx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:51 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAL008288; Thu, 13 Nov 2025 16:49:51 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-19; Thu, 13 Nov 2025 16:49:50 +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 v4 18/28] objtool: Disassemble group alternatives Date: Thu, 13 Nov 2025 17:49:07 +0100 Message-ID: <20251113164917.2563486-19-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=bJUb4f+Z c=1 sm=1 tr=0 ts=69160c30 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=BZlt5mrdIDfIrSVFCwQA:9 X-Proofpoint-GUID: W10CRdUWyr9DuYn6gj6w95RFTZIHa6_P X-Proofpoint-ORIG-GUID: W10CRdUWyr9DuYn6gj6w95RFTZIHa6_P X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDEyMyBTYWx0ZWRfX7GfEcU5xL09+ x0Vbpfvlnglzr0yE9xA+8JJuZhG6WjDbifO7UGTNU2KYbB6utCkK69A7ZPJWifKK2glhFnNtu9X YII1c7mtgqwDXop8NR1aOh+4F+T6P1zvBuzQymegiq8FQI/Y320Np9dRmhLLEOenKrZpm5rll6w anlebfQRk/EBR8HSmBQwJP/iqqpIhiOA+9I8MmjB6qnz2S53jVlnCX6cG3QsnU1d6jLwSxpOQ2U jz0lum+SXOcQ/X+bAUbS1hIU42s+th6SZZMjZ7fxuEPCRMXE9BseJeBLqjlxhDPrGBAjW20EgN4 JYtMT5slg28tNJsZnXYDDBoQcDR8/QY8HzDuf3AMdXFzrK2y7Y1PxksAfLFEAz1TasKE9809K7U HFlptihlGGYezELzwO4fIjTSVKtMnw== 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 57a13da5e1b39..321256f746425 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)) + /* * Provide a name for an alternative. */ @@ -522,6 +543,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. * @@ -534,22 +632,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) { @@ -558,10 +664,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; @@ -577,11 +698,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 06:55:50 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 804C536999A for ; Thu, 13 Nov 2025 16:50:01 +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=1763052603; cv=none; b=CD3EaIdoqbrlDLBmMwvfo/2eoV/BcmkRAq7OQfeQnDrFO9dzuuJ0P9wuSO0wzeTHIlBSSz1aU+FILa87UKHw0IBbfL7eeznoAT5UlgUBtD16nL6Ene3H03/ZkmtjBIWaJj3tiT/dutPs9G1qopGBK1qfF3n+kKyajFocfJ0VeRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052603; c=relaxed/simple; bh=FlVFBT6oZY2IDD6hO+du+x/huN0yXjvoBQfQjVLEu2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gF28Yw2nVMUXG9Q+G+zHbyN8xgmB3YGlBJqkT3FXFd+42rEi7OUPC1VKi6hf36Cln3A7zQ5HcCKCH0gdicvRWNSviUxWtK2cp0CYxNKSj4dTIs8QoJiwtI5BuVcytWUMWoQUjTHEnB2tx7kDrM+1tSpL0AtFs7T455Bc74drVkY= 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=WTvqBvXH; 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="WTvqBvXH" 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 5ADEA6VF028865; Thu, 13 Nov 2025 16:49: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=5H1K8 PxA4tuOMbESqPA3aePI5+UCeoDPy0LIarZYvWA=; b=WTvqBvXHaYrHteEbr+ug8 sZkxjRe4zWmL268c694OqGZjsrvsQuNNiiIg0FYG+4hTfh8yBK1OautShXuDBD52 fNTrN30T68ueHoffKudNVQLgjwRj2lTbE9PJAsqSNw2fwPOPAXZ8yRgZsmEUksE7 eCXLzgldT6pDDI+x6TWIbRIh2Efl7icyLQEI3HesB2nkx36NNVtx3AFpqRWkn3Qg 3nrIPtGBiH0tf50ye3n2qjVTRHkCPUGCeUQL1kXWhjdAshs0IfTJOeHm/Aq1DKSs p4Y8/roiS+X0Rk2y5iRMtX7XpaVwRuVrzIRo0Xo0JPjevtjEruSvu3qtL9Nu0w06 w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxpnjb00-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:54 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGGxtR038510; Thu, 13 Nov 2025 16:49:53 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3vn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:53 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAN008288; Thu, 13 Nov 2025 16:49:52 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-20; Thu, 13 Nov 2025 16:49:52 +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 v4 19/28] objtool: Print addresses with alternative instructions Date: Thu, 13 Nov 2025 17:49:08 +0100 Message-ID: <20251113164917.2563486-20-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=Criys34D c=1 sm=1 tr=0 ts=69160c32 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=WFXfjiaBZm73b8CXPiEA:9 X-Proofpoint-GUID: FK6mA87YbP45O3z-CcxgOt_g57w5XzJx X-Proofpoint-ORIG-GUID: FK6mA87YbP45O3z-CcxgOt_g57w5XzJx X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0MSBTYWx0ZWRfX+fu80ODm5K7S w8pit4v6cQ/OEWbmF+MC9HwZyjFODwmu2R8T7Re+JM1huJx1lqEOvSIQsf6rp3TdyZW+GAoJTXD QQMfj1iyNd1h6/MeF+vmLEDmOe+xyrVAiVzQ03H61XmGnGpDjpvVMGrIm117J0CU9VCdyqnUxpc WmMZQRx+/MWZcVacQNOCIlntFnUu3XqgbyIFosbzuWUzlOQ8GLmX87EbLf7nf2dXMpxZkYPBfEB P9Y1ATfHLj1eNh0bTZvwjOrGNCMm2VpJ6DpthnL1yUdmd26q2LHRKwoLHWos1Y/tgFnJ8c7Kq71 6nKf2arxgeBT6g+iyvDgtK97RKJn7UfaqBnauROxgGhzjVN3DGgJ2bYdCyxltZ2i4PDIXSvgSGU X2v1qEPRHgw/wZw9EzH3t7KEJjuupQ== 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 321256f746425..f4bd802e38474 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 /* @@ -534,6 +569,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) @@ -543,7 +579,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 @@ -554,7 +591,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 @@ -569,12 +607,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 @@ -583,9 +623,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 @@ -613,13 +654,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. * @@ -633,13 +724,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 @@ -700,16 +792,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 06:55:50 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 17F7B36A00B for ; Thu, 13 Nov 2025 16:50:02 +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=1763052604; cv=none; b=pC1rkA6j31eyDXidUDwteB5XV802mquQjw3t71ig7q0YmgSEyCgjJ1nl1oE3GiH9wJcjl3Va7O+kqdVb3XFrCMX0buVwjJA+jD5AORAtH3vQjZETKXuqo6/EyvKyh8Fy1WrE0cFm5fHR7PmGKpzgUy6cESPZq9CUk0mgF9f5sOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052604; c=relaxed/simple; bh=5sEycPMLXD/u82elFmHaNTYEhudgmp6SE5qHqWsdcAM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vDbjidKw0HxNkxEUjBrC7XsvPwAXfq2yOwNPU2c9xBBuk8R2MmJST/ksxLXUTZiWMLjsQu32fHkyMt9T1bjFHmh1m6568fn+99IAmlvqVVFf4ggChtTJqXWWn4JioeWORP4obLTWmP4J3kMk4Dby3ilovcYSnv2aw1M2dqvrOYk= 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=JwzwDNoN; 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="JwzwDNoN" 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 5ADEACBp028898; Thu, 13 Nov 2025 16:49:56 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=kIenK 1Hz7DEw9GF8Hjzf1LEA+DSZpA9RYpgc7Bh7CGg=; b=JwzwDNoN5vUiFhQCkpWA7 LFtpX6mKm0g1KDVvAFoaiteWSkWP0A05qch148tp8PEjYHV7VANinzxEnjDaDSm5 a9XxY+E9kck9gBdB37oIBy41hGqtvbJ6/H39X9T+yik2TZxD2fR50KoV6wdoYP/5 TXeSvtxPvwO7Pfb9+FKPwT5a9I1xu3veGPQBqg49eGVcinTWGjqeO89pFzz3TfB8 GgjRankGqPPCMpkZuHryDF0hGDZPhug//CnPhvix8V5MZbriV+lB6CWMzFEVZGYp mR24/y8e9bdJUCTY3dUPJuQPK/I7MrJWpiHgZ80vxU8verv1pDdiAaAzmQTRR+M+ w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxpnjb02-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:55 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGAeOw038607; Thu, 13 Nov 2025 16:49:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3x7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:54 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAP008288; Thu, 13 Nov 2025 16:49:54 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-21; Thu, 13 Nov 2025 16:49:54 +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 v4 20/28] objtool: Disassemble exception table alternatives Date: Thu, 13 Nov 2025 17:49:09 +0100 Message-ID: <20251113164917.2563486-21-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=Criys34D c=1 sm=1 tr=0 ts=69160c33 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=UEfQvUvM895RRNYFhMwA:9 X-Proofpoint-GUID: K42ZqXq5oyhxawAgD5PUkcNGrr8CcCLN X-Proofpoint-ORIG-GUID: K42ZqXq5oyhxawAgD5PUkcNGrr8CcCLN X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0MSBTYWx0ZWRfX7dnBuvL6aVPE Q6XQNLCpZIcuW1XchHHi3pLdF8uNUZeWl8yAbHk3rOIUkw7ykNg/ldNShH1HPifNP00M05NzHqP wxQlAh30RoJPaA69D4z2epqAS0kGnhp6jT5X4HcZBh1JUIB3njnJ9sOQ7Xzp6GnNV4KQpHuI+T/ igBTNpEQ0pSOl5wol/VH4r854RdmnjnxhJHg68IyEtiIJxyHkzKxaH8Ou71pDIOpCra7ZQFy1Xd 24m+izI12Hlj/IMq+oH+xQ4bGv2ONVy8G3m49ZuNepCgmdqfwU7Co3xWjVLTkZaMpWq9xcz7WxX 5ay1wryp94jg5IGvjUpJWKxocJ0JD0ZKG0+JdF80YUrgwy4hPXuMkud4/xsZM4S+kHGq8tgEQnB BToSJohlgSp8XYKZYxcPRJxpwkPiuQ== 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 f4bd802e38474..670fb8c646282 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -567,13 +567,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; @@ -599,6 +612,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. @@ -762,12 +795,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 06:55:50 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 7CDFE36A03D for ; Thu, 13 Nov 2025 16:50:03 +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=1763052605; cv=none; b=qCLlpctNLhNitegppLU6wuZtNuWFVZhPqrjIsr3dDGyxL2ukyIla8OqF+QAwCSg90gvbFSO9OD8pLsYTQVQsKwEYadL3sTUhiX21O182INt8LfsAnvxdSoWdEOJjYVV1osc0BS7V+qajNLW7xMADqW6wiw+u+rvIFuUUpAiBKOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052605; c=relaxed/simple; bh=60XqvTxYtvBgpKu1JSbAySRnsUputvEtOSWt4LZJSQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cHzFMPCHL1doDYCnFKTeXXT8jVwcL6xX+CbKGqz+/R3X32OWjS1S/86RZqu8i4NCOjNS6AT0PBkc/vm9nzoH2l96ddE3ES2ozpJ3jIF9Tjt7YV4Z5T2hSlnj5u42rIruAYXNUTFIq19TEDzWCp9BGxQ4eRZzTWPAeQ3VMz3kwhA= 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=ML97FX/V; 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="ML97FX/V" 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 5ADEA2KN028782; Thu, 13 Nov 2025 16:49: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=7GTPB 6wGPmwDh9ro0FXo6DAIReHKYJYMHCsHjqDZO+I=; b=ML97FX/VqIrLsGx5LUZH8 hqBkSmnLzDaO/rbxtOG8QXpIN8KSxqaEndtBbWJdDNz+5MUrpiHTp09gifPU1njr wddidtZN/gTBZ8OVbmnYgyEe+O1nvRt4UeuOZAOgKigagLwjsyuC6xnc9I/hnYxC rwRFdxQaNuXbCyd6c6apvdLWZwdPZTjeQMn1zdZPSAX4xqCWBfDY9+70cbZSq1DC UaF4Qul+4bZuyuI6gwn3Npoi7FE+YAdPPKJ3RSVCVaKXiDDRr3YNv+FN9fYaSwIc YerQwq+TcGUZ6zaQavEzwIdFtNiTdBwY91X8NGwaNIT/GBGGmZyrYPnjJ8ECYe/R w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxpnjb05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:57 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGDUdk038611; Thu, 13 Nov 2025 16:49:56 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc3ys-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:56 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAR008288; Thu, 13 Nov 2025 16:49:56 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-22; Thu, 13 Nov 2025 16:49: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 v4 21/28] objtool: Disassemble jump table alternatives Date: Thu, 13 Nov 2025 17:49:10 +0100 Message-ID: <20251113164917.2563486-22-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=Criys34D c=1 sm=1 tr=0 ts=69160c35 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=lcG_xirucoqnFA0wguoA:9 X-Proofpoint-GUID: ORAi2kUt1cTj3BJAPdW08_A6RxHACQZX X-Proofpoint-ORIG-GUID: ORAi2kUt1cTj3BJAPdW08_A6RxHACQZX X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0MSBTYWx0ZWRfX6oJNRdD86h+8 LB9AQmvrIgL8yRuFrJzwxwsZ0DJWi5cqxPZl+tz61UrltbnI99krJ3bndrIWJP4pbsaNIgVAnwd vF0v6C7yiMInDbDUpEIg/UNnZso66c3zznncCsENzDxQDULDQCN/8bveV/m6GGLsQZshj9Z+zpY me6n1EDIo3eJ1k4fztXpat7oQxqc6EabbnNOFHvcrwAd3j2MaJmP04UxMxyXh0SXFJsGklzG7xk qcmw75t7MEOnH8PwQsgVbwOTcCh8NnO3e7ugbQLhiZvO75Bru+YIaNKXv/47El3sLrbID8DT63g y40C/kJ/o2gQ741o8ZEG2IyOHbYcpVBqtH/GEyep8VGfWiE2UAUW2/PC2T57JNPeGrs1f8JD+3S ZxxVRaILJvvaiYAw0889C3+Slaq3Ng== 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 670fb8c646282..6ec241806f5c4 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -579,6 +579,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; @@ -612,6 +615,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. */ @@ -794,10 +825,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); @@ -805,8 +833,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 06:55:50 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 4949F3730E1 for ; Thu, 13 Nov 2025 16:50: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=1763052609; cv=none; b=rhYUQplUa5Zup1JVOCiby63LPnhNySbGDdlMtf17fQHcUgSR1DEuDEYVztZDfB0OXHYxubIDNkHCgcdFf9uwal4bSJT8VbaUm9YaOhwxTsldkLA371CVwqC09ba8Yjm4eREdOFSS+eZ3f30fpr9PEapu5y3o24crsWPnlbaXlio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052609; c=relaxed/simple; bh=nf/9Zejz3i2Q+KfY+3nx5OVKDM0QxG7EpPvQ9AZYdPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TlaSjVL0DmNEdm11xDsk1QjhGGoVhQbE9TYnOy/6BZqVVI8jzdHBp6BlLmkTFpXCBO8TJgI42ktJVVZnZkLdtoVSDKH5T0uF5e3Mhfj7U8OoYqe4aF/rpfBv6+V5EOrZhoZOMKsfQvtPWb5DUXd5ws27f966T45BjKDCrNhRzqE= 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=iV0aSLLO; 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="iV0aSLLO" 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 5ADE9w1u012345; Thu, 13 Nov 2025 16:49:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=+0mPE ge9g1BCmYp0eJDEd8Ck8Nyj5svfwnh08skl2Ak=; b=iV0aSLLOcWbSrWfVF9x0G PurBDY3E37XIVSBmoYL49rB+vIRXGuKhnKf7d9PP+yetCX/DQg5OpBns8yoWbcBI HRl2xOH2kjrK9Q8uoifh7PkGzSxhKQMS7tSAxgq7TnnY3jE/dildxVr5+JUuMvpx EBosmbb9759H7KyrB2n4M2k43OxW76b3wMB+P+bw8hAc28jFoSS/DbnoXKB4WXD/ rgAPtMuVzRK5TM8kLbVGJ13g3lU1+ANLBqrjadRwLCxxxU+/DxeOj6gHKwUxFpx+ kZfgHBLi7L5ydKniJTkW9Hs1AkS2GH2uU52TXx6O1la8OCWpVTVYienJCInL5NyU A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acybqt8n3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:59 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGBlmb039186; Thu, 13 Nov 2025 16:49:58 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc41x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:49:58 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAT008288; Thu, 13 Nov 2025 16:49:58 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-23; Thu, 13 Nov 2025 16:49:57 +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 v4 22/28] objtool: Fix address references in alternatives Date: Thu, 13 Nov 2025 17:49:11 +0100 Message-ID: <20251113164917.2563486-23-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-GUID: HqAM4HLv_j2ONPROs-Al_iiwJXV1FlYh X-Proofpoint-ORIG-GUID: HqAM4HLv_j2ONPROs-Al_iiwJXV1FlYh X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0NyBTYWx0ZWRfX7yWmp5DQpIhM 3926sIaNbhcy65sU+7kRK4PLmtI0po1EkqFSnO6aclOYUQqky84fc+reCqFupEc5NMZXYfL8Aj6 jFony6aG4Lf16J7gRoF9xBoJBKHZpIOSRBIPu1j/LAcdFMyhxpZoQftLh90bLKNl2+GxiGx+rJM PXmBtwLfPbtJ35keUHYiAGleKPjMMihNHC+NbhCxyC+ETQ22CpayvWQZgU2FHtsEyiLdlQ/Y5bx If97O/kwW1GEtF5y3nCkGfc4pkBcfui472Z7jOX51fRqxzbG7j8u0tN2gWBSn0UNfyzxPJ18br5 l1V8uYM45uahM2OwvtMDWS98o0SUEdAhG5cieEs9H5HGWmURXVe4L5z8BcgbWItY9LubJmPgcX6 mViliMGPoInR0PZGPQ/rj69aexgXFw== X-Authority-Analysis: v=2.4 cv=X7hf6WTe c=1 sm=1 tr=0 ts=69160c37 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=YtZ4u2YuLOXz1tegIYEA:9 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 6ec241806f5c4..e506fdda4d897 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) @@ -682,7 +744,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 06:55:50 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 587EB377E82 for ; Thu, 13 Nov 2025 16:50: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=1763052611; cv=none; b=KpVVdooK481TpGeMWiXUUugULst+9OPAqZJdUzTSWBJpNAA+lF/Y46cPePCDxn2sZ2tcwue2aEMaX/28wuQIU1C3K5rnaEzhbyONnv3LmHyGaYKM0mwQEAWrPjEN3UkevMnaoS5lyQYuDDMexsMnvr2F8ePoyGB2tCbNgDingso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052611; c=relaxed/simple; bh=h8dOoKAF+f/m/Sm7jIWqLl5pUPnTSMT6so3kKeyyxKs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j2XszoCZRs3PVIYeUMwGRArU+yugRtYD7v9L+zp0dmtOQZBaGEsJF+Nwkq+k8mCz8emZfdoUPxwpk4lLL3U1gXmkDVzWqvkGzLaLITj0ljOjor/FQC6CkD703XH2aw9eivy2sNyupJF/0hfHL+ssitRsTQhFKyRdQQXikAP7CZE= 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=aWSTcKoy; 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="aWSTcKoy" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADE9v9N028022; Thu, 13 Nov 2025 16:50:01 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=m4Jyb hwVGsijDuSe4c/+hAWgB433wQsPQQhvIoTjetw=; b=aWSTcKoyagLvpK3BE2TwY ILmCJ7dx1A+DxotUPQqfSNWOoL9KrcejVp474xbfa39Xj2rb7nSOwdmYV0XYhuuf AGUxgzoJ2nNxyFOnXWgQX5Ld8JmlD6N7GAucDpFWZqsYD2AkeZwZvEGrLtjhc0TV SIDCV79DDPXl/LmaBTHz0AfSlSFJRg2bekL9RPWtyua8giMTespUZ3cF+3yZEHKc AZTnZH/rxUGZ0YAYCI+Fu+ekD0Z49dB86RQCF+vSAl5HUpDKe0TiHJ5Fw+FRQF56 Ss2q6X2WtgP1rRPm+ECVsNuIGRGMLWm3EpG0OkpnjNsF9yn2tHAJtJB+xyFWLuCe w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyjsa7v3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:01 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG6diH039063; Thu, 13 Nov 2025 16:50:00 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc434-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:00 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAV008288; Thu, 13 Nov 2025 16:49:59 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-24; Thu, 13 Nov 2025 16:49:59 +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 v4 23/28] objtool: Provide access to feature and flags of group alternatives Date: Thu, 13 Nov 2025 17:49:12 +0100 Message-ID: <20251113164917.2563486-24-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-GUID: MwKkRLfGAkfN1_kHCBicZIWwvL6vWZ4j X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0OSBTYWx0ZWRfX0XP3Tqr1mbfD Smwj1F+EBMgDAZYzVo1Bj3GFpENrMIiFv0mXN6LN0F743CGAIxJdwr0NG/S/2vpOMWatUpJrfIe tqUQ3M0fgug4omyDj7tPl3tzbKhFvHJvi5KadYB7x/atBdNNZoCiaUruelG0aReCG6rMLOjimW9 qCmAw3UfRKod4J3ylozQ1R3rr83CZ/C7aqZWh5IkskDsMKyEt5sk3L6Fc5bfl9K7sFNW5I1NUOe vq5SwK6oxUem/LL0Ona8HJqwTG2BGsBTHvhRXqsF3oxQXbYOwJAIIVO8wA2B7hyByqUJl4J7tTv eeMMrwuvvJYDOnnhq0wmFBLYSGkENMgcGu6GWLYgi56YLuuqz99VbsPz9XHW88kW7BM5azcQlNm 98Krjsz0f3BUEo7KodQCMPRu/WVWcw== X-Proofpoint-ORIG-GUID: MwKkRLfGAkfN1_kHCBicZIWwvL6vWZ4j X-Authority-Analysis: v=2.4 cv=HLzO14tv c=1 sm=1 tr=0 ts=69160c39 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=OMdgKRDbd2JaGKt5H5wA:9 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 25c1c7185d4f6..817ac70fed9fa 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 06:55:50 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 37E6E377E8F for ; Thu, 13 Nov 2025 16:50: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=1763052613; cv=none; b=I153zcAF0phY6Z96BGKdoTCNdRl/0k5tMe7o+GHYZP/yrlBhCY2TYgwCeV7bswisr93U2O1IXblUYxoZ/HQzXVGPYPx8TI5zcZOYUdf6WAgTMzmXlU5e56MroQiTL1PA2X7tfw8hljZmQSergmfjNwhs6P3B3piudE5mDUf4es0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052613; c=relaxed/simple; bh=q1IEGmTiexs9Ib6qyK8SgppppMOswulClNlfSmS4lmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LqzZrykoRpzzfVJ4sk8xr2DpZdGyH0OaVhvTvNdMoub2J4Py5wBLInxBJxSB4PbPsciqsZ2/K1FkPtw+nW7kbH46xw+a/O04M7E8XxOpisGXnN5lgzBboDdjdVIt+GcD8Mm1FS0S7e/MF+VXu7RKVa5vlNQg/dRn2VEOn5Sr9fk= 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=cdG0ebQS; 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="cdG0ebQS" 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 5ADEACBt028898; Thu, 13 Nov 2025 16:50:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=l6fvk GqlkRFWHMJjPFKdouisSAMlA/D3Tt8Ck13xsB0=; b=cdG0ebQS58QdeI3aRcMc2 LDF1x/yTFsT7Eyyf8JZ+PvyUl45Sc69GtnFqOGfEwivgWA0qnoqUy6U1pp4dMIR4 3nN95qRYfSrLsdiDGnGQOq/lavZckdjMgBoqge9QlVCsP6rNfauYZfcJuUsetuNK Wvs8Dy0nvNuBmi1LrBj8K9igOlE/ukeoYJV6R4u0yIf8GNZFhkMBGdyO2CZZij0u 6rjhIjoVAoovxOi1Zj1WconPubDylG710zj3NPJhJuqRe0FRcG8WYAzcgm7ECfYB udWtXwbQ58NUwOi2ehCfJ2j1QJIlFKh9CbGj8fP0eVklZiI1GeeMxesmWKhJby5L A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acxpnjb0v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:04 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGE9Wf038600; Thu, 13 Nov 2025 16:50:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc45k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:01 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAX008288; Thu, 13 Nov 2025 16:50:01 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-25; Thu, 13 Nov 2025 16:50:01 +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 v4 24/28] objtool: Function to get the name of a CPU feature Date: Thu, 13 Nov 2025 17:49:13 +0100 Message-ID: <20251113164917.2563486-25-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Authority-Analysis: v=2.4 cv=Criys34D c=1 sm=1 tr=0 ts=69160c3c cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=BmP2q_L__UogPSo-:21 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=pMlTRUUgVTb7_b65wjsA:9 X-Proofpoint-GUID: SPjswcxq57Rd10ts7vH0e9Si_IN5tfrW X-Proofpoint-ORIG-GUID: SPjswcxq57Rd10ts7vH0e9Si_IN5tfrW X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0MSBTYWx0ZWRfX7SH9BYiIxjzo cgSzCgNz9+e1tFr8swHO1WcE+pEM9gE7R1e9sk0gdbzZ7weXpunSzYvgjiLS45NuZGYrC+kiWoK 3LBpBhstNfVyiNQnYSEpbiLCBEDTOXxwADANyU77e30b6BWmGhP3mQx13JEfjMeF9ozPa7JETY+ PAUwMgbataGScOYxzjnknQ4N8d9DDRHwUIy36iIwlsZ1dhBrjo3rmbDH1FERM2Rtg/YEddy+5xN ZSDggAUAzGlXHGPrA/ODarCMpXbxQvyCiIvYb6O0qc3JYM6Rca0fLly7449ppnQwoc+77KT+vSh ZLOiwH8HC0kqo2jmA7zeJ2T4PrRQmWPFIEnuNsihzk1BjQ2tSTWan1PXH0f2CrzaE7m4gHiJsfV mu74EE7KMzCDpmJJovAroRrK9MCPYw== 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 06:55:50 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 37965393DC5 for ; Thu, 13 Nov 2025 16:50: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=1763052617; cv=none; b=luCnb1Wsjsqy939knlvX2eeOyKpGHydpnLwXbv+tnaplWuhAmrcBVDOzAst4aVXvmqptcheT6jLByr69cBIu1oGP28WqRS78m8IRXNJaya/SCpfwZQPhTK7fuqne9HX8vu+rClB9Rtyq44utGSRtmrTYk5A0f27U+KK59+r+eyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052617; c=relaxed/simple; bh=PDid6cqsEMEYl/A2Kyqeifs2qppo5WweKFE0beqV0fA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GjyAqjYcc2RNElMe2TTaEJii93oa/2NW3jz2VV0v8doHkR9I+pwi6bCjpP//WT6whgSgwsEIVbAeS8nEL72tzzn8HSKNPzO0HveNVJtOrrpRhNIMZfyXNTyTIJu0Y283u8giAdhycPFwGV0m6bGGFzLtGuyIdtxrhBwS7yVtri0= 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=kRJN29gu; 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="kRJN29gu" 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 5ADE9w29012345; Thu, 13 Nov 2025 16:50: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=Qa6XG W4jBEuv5YFs5WWAWkLlhe/mXZ5Qjesi69dQmsQ=; b=kRJN29guDip6z3TU1PJz5 U2Wwy5JshPPseiZwwnk87o3/RZtrfT3wW9ijo0gJsFIZVIwAt4mrF7aR3E+r2NHN b7+XY/yk2uvKRxVlwsQZeCx8scPywX4aj4ANUYT5pussm5psw+bilcv0Br88RC9H ySaZ8x0ETDrNwzQTk7erRQZ5Mp+qfRHIgibxYfZEH/Zu+1BJqmV3Oq7qENVbRmJD Asjg1xOlywqOrKO4ncID+rxEV2n2Yw5JzRNeMF2FYcm/NU3zOVsaQOPQWvABFcVV uRk4iVNdz0MhkOxff2tPpwgR/tNkudTz+UdUyZpTZpoGZDu9HGbc76rGIHGsrcJD A== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acybqt8ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:04 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGH8Q0038719; Thu, 13 Nov 2025 16:50:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc491-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:03 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAZ008288; Thu, 13 Nov 2025 16:50:03 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-26; Thu, 13 Nov 2025 16:50:03 +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 v4 25/28] objtool: Improve naming of group alternatives Date: Thu, 13 Nov 2025 17:49:14 +0100 Message-ID: <20251113164917.2563486-26-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-GUID: HbNHYFNgizWkcinWegDQG-R-v9pS2876 X-Proofpoint-ORIG-GUID: HbNHYFNgizWkcinWegDQG-R-v9pS2876 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0NyBTYWx0ZWRfXw8A3hmxMAe3S DfMAY5ShaZRVthdKsc4TSyQXBma4pMmFPkwUsqbXoTyjv98K7oEgGqOmsRxmYWAgz+BybQBd+XV TUmDh2g1Zk5TXaM9OdjFc+TUdFH24qpZi3NqC2zWalDiUKlAXPJccmGkoFtXCv8+ph+ltXiGl2f iozKxR7r5uz4JxmjftjbYQIaMdt9OmsSlzCaSWb7HuTRKcTK/DnjztEaS0pQ7vaJlcXGyh8BLQl sp0hkCpvxNxtFaqZxW7lGIjTG+tmAPJFzG0vDFcwZ764ahW4Opzjym/bilfjWVSzR6rUPdTUDbh qpkwM8uVhBpCJVEqbTM3c/C3c8PVRtqabX+ZhZCt66sVT6S1cBBU65DQCAqXBAu9IU3t9sB88Ap A/rs6v8XojdnbiQqcDWA7E/CPZ0quQ== X-Authority-Analysis: v=2.4 cv=X7hf6WTe c=1 sm=1 tr=0 ts=69160c3c cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=axKxejlUv49_pL_PyZUA:9 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 | 1 - tools/objtool/disas.c | 86 ++++++++++++++++++++++++++++--------------- 2 files changed, 57 insertions(+), 30 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 817ac70fed9fa..43593766e80e0 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3661,7 +3661,6 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, return ret; } } - TRACE_ALT_INFO_NOADDR(insn, "/ ", "DEFAULT"); } =20 diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index e506fdda4d897..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. @@ -593,7 +609,12 @@ static struct instruction *next_insn_same_alt(struct o= bjtool_file *file, */ char *disas_alt_name(struct alternative *alt) { + char pfx[4] =3D { 0 }; char *str =3D NULL; + const char *name; + int feature; + int flags; + int num; =20 switch (alt->type) { =20 @@ -607,13 +628,37 @@ char *disas_alt_name(struct alternative *alt) =20 case ALT_TYPE_INSTRUCTIONS: /* - * This is a non-default group alternative. Create a unique - * name using the offset of the first original and alternative - * instructions. + * This is a non-default group alternative. Create a name + * based on the feature and flags associated with this + * alternative. Use either the feature name (it is available) + * or the feature number. And add a prefix to show the flags + * used. + * + * Prefix flags characters: + * + * '!' alternative used when feature not enabled + * '+' direct call alternative + * '?' unknown flag */ - asprintf(&str, "ALTERNATIVE %lx.%lx", - alt->insn->alt_group->orig_group->first_insn->offset, - alt->insn->alt_group->first_insn->offset); + + feature =3D alt->insn->alt_group->feature; + num =3D alt_feature(feature); + flags =3D alt_flags(feature); + str =3D pfx; + + if (flags & ~(ALT_FLAG_NOT | ALT_FLAG_DIRECT_CALL)) + *str++ =3D '?'; + if (flags & ALT_FLAG_DIRECT_CALL) + *str++ =3D '+'; + if (flags & ALT_FLAG_NOT) + *str++ =3D '!'; + + name =3D arch_cpu_feature_name(num); + if (!name) + str =3D strfmt("%sFEATURE 0x%X", pfx, num); + else + str =3D strfmt("%s%s", pfx, name); + break; } =20 @@ -626,32 +671,15 @@ char *disas_alt_name(struct alternative *alt) */ 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; @@ -864,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 @@ -883,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 --=20 2.43.5 From nobody Sun Feb 8 06:55:50 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 8CA18377E8F for ; Thu, 13 Nov 2025 16:50:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052620; cv=none; b=bxLHgk5X7efUIKdJjAkJTyyAUan97uHsfGJlQAnunFfAPCSAEJRQAjQ2W7/txI9F7csXSanfnQ/LnHnCY3vJPgw5yb2HGbPu31vH2O2vYB9y/FbAg3aTfEXYRV+lMCvEhlZ6h7mQ+BbppLwp9SBxgQ6kh82AUgFHdRDUNBmosUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052620; c=relaxed/simple; bh=K9ZPIwAwps6x2zzeZEZtqHQGfSnNdnBD+f54ZeHNlSs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fdg9pxft1GeaDgVj2bAw7dXBjS+BWclG6BbpIHTJ3qs4q5XrBplSMMhbc9+fnwbKfzu7uJ8UKojHh3SL7m4L4sEvJNavKrwvo9LdmUyEE55niuhFaCLqPo5PrNNSVi0VISW2JCsJYQS0gJ1HfTUFqwehAekSIvpxJfTRI4o1xZo= 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=YJCaoHAs; 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="YJCaoHAs" 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 5ADEA6Zo006315; Thu, 13 Nov 2025 16:50: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=APx8O xL9EzpsNhH4ciInXZQ4fcurnfaq1hVMxxe0nrU=; b=YJCaoHAskxlFDy6nb/aE+ hUkF5Gc2F2LgJ1R84f9ZFKkQiJYFKEStzvM9ryEI0fOskNCTYMAuDARRxR8YGkx+ F6j1rxvVh9o5AtqFnzCLwPpAoJthSPtdEt3HbMtwNcSrsGtvBMjyuR8CyWLVw6yi DWUek3vTr2+ntZVdbqy0psM21sg+VRafSo/wEAoxpe/eRSElMK5WNWbHsy/5SsRM A+J38OEQGbkI9C7dvnPC4UR8inNDinHTIWmzDd+hUhRbgYEZ5zx8EgDSlWNUDvTc gPasLobLfwxwwusvcixBNfMIPJoitkd0c/8mK/esjfP1Jd8Wf2XH7OHk5lPYuUoP Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyraa68u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:06 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGH8Q2038719; Thu, 13 Nov 2025 16:50:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc4ca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:05 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAb008288; Thu, 13 Nov 2025 16:50:05 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-27; Thu, 13 Nov 2025 16:50: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 v4 26/28] objtool: Get the destination name of a PV call Date: Thu, 13 Nov 2025 17:49:15 +0100 Message-ID: <20251113164917.2563486-27-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE1MSBTYWx0ZWRfX7fQ5dWPIyGjF TJpH8DxpPiA5Y74ArHM5vFKU98XkJw+s75J4Y4MRxE38Wo7lIJCr2LfrYYQLMieutnZGRiFXtGQ 8RHh1ROwG91O+4hVlZSUnF5E16eRbZ2rE8rhjiYEcNmv8MzxntC/bHHV8xT+80avkDF0iqDUKjK h+vH8kXk/GY77yBHm1+78Hrf4/ttKgXkaG5Ec/nafcGy9rkWELEJluMtthVrEtLIBhcpdit1aGT /D8z+JzPvUHd5QJ19s9FIPrjxMFMyYb2YaviweZHlMMYyY93y8k3CmsG6Ejt/UxRqdSHFDpUBlr b05tOoX47ojemCZ2cynSQZl39avuhU6NDbZi/64eltdOK4W310m7bRyHcYrvKS6I1pKa4mBN2O5 52eapgCHJRHqDUN4kYu9PeZeO1a8kg== X-Proofpoint-GUID: f_hZ14nA3_0OgdnAjIgZjC71toCdlyCP X-Authority-Analysis: v=2.4 cv=ILgPywvG c=1 sm=1 tr=0 ts=69160c3e cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=JgagiIEfrknqXQomSD8A:9 X-Proofpoint-ORIG-GUID: f_hZ14nA3_0OgdnAjIgZjC71toCdlyCP 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 43593766e80e0..73caebbf8b6de 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 06:55:50 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 DE04235B147 for ; Thu, 13 Nov 2025 16:50:19 +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=1763052621; cv=none; b=aizDs01LZNpKpF3y2LoavG3xHLfLrJOazD1ttYPD6Ko22j/W0g0gtfLj5qcamVusMvB6Hw3GyBifELdadZgZ6ShthielhvFLqltl4trQvsKY14c8PUyUcQaawJhbD2jaxHStkfqMo/Stj0lquyVyXXVjbEdY+4vJLR4g5Ar83GU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052621; c=relaxed/simple; bh=Y3RgpzdLv8DcizmWss8orCI0E+29f4IgMygjmCW0QD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MWixZYAVC7atGukMoZRnd+ri3Z90af000+ARslQSdz2RKKILzVvBlN4JCjYa2vRh9h0l2iSJxDfjWuORiPbh31sepj5Evzsm3jhHpQwv4wCQlVabAOYHAkuvhRNMyG/BTak6x7IjjFM4gmN15CZ5AAdtkipqodpAQFV8+/1D/WI= 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=Xjpl9J6f; 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="Xjpl9J6f" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADE9tXg027949; Thu, 13 Nov 2025 16:50: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=UXRRB xRUvb8DGbk9rGxPY4YhNOEmQqlz8hEYYwTqgyQ=; b=Xjpl9J6fs3ZOdaUY/aYkz NJDSmjt+saSqp6YvPo52Ceo6P7jkYC6B6mrzkLHoZYFwSjNmEaEPTw34DBcRXH58 d4tqRFxJoRJ/FOijwDodifGAgmHqbAANHfEdZ+9iSfx8Tg9FY4I7Ypqr1dtP9wj6 zdwjmVjZTQA1mAW06PMsqDrdUIGGxaJxkg6x5CdoT1sOJ0LC5EsG/3ZtVgEZP3Of MQEBng2Vjtn05UDanWri06WYlqZiALPaY3mKAvJ0pD/hYKyCJMhG5fihZZC3h/bi Jhzxj3CluPRmnal1iJcmRHjSBRI4yhtrQpeu7XxFjw5WzRSMswKP9pdNprCQSOl0 Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyjsa7w3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:08 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADGBbEN038774; Thu, 13 Nov 2025 16:50:08 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc4gu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:07 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAd008288; Thu, 13 Nov 2025 16:50:07 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-28; Thu, 13 Nov 2025 16:50: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 v4 27/28] objtool: Improve the disassembly of the pv_ops call Date: Thu, 13 Nov 2025 17:49:16 +0100 Message-ID: <20251113164917.2563486-28-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-GUID: vXAzYo7mSJY6d_7D5kYPK_rC1fmuRTmQ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0OSBTYWx0ZWRfX0V+ifK6B1fnY Su6TXU/TExrcEaCt9te6JR3fT8MBCPMsI4DO50JZIt4A/0n3m+Z2OYFInP19rQ6x11IWneabkK9 XWn49N8HBwgDBfttDyGUbUkLKGtrUBXg9a1cmrS5hPspE0hKkiCLbYUupUxtH0z+4nqxhJE7G9X f8X9GXd+TYS496/W9RogqXh/fnppzmES3tCBxxi7HlwDI1ATHRN71x6uVv6Gc4JCYoNrY+5FxQq GMOIw/qK0S7whj4ZG9SSPnMiuy0RgdiB4ANEwLlNJ3IDN+nlkHAhfUFmHhk2kT3EeM8l4U7HVlN sjRbrE+OGY7QwQuf51Odq/jRC3EVoZFchrwZPwM/ZNYY4raS9VWo9KIaZEzl0thEqxvL0VnYd+E 6dqYMSVfvT6t+svBKWQtAlryNa1VLg== X-Proofpoint-ORIG-GUID: vXAzYo7mSJY6d_7D5kYPK_rC1fmuRTmQ X-Authority-Analysis: v=2.4 cv=HLzO14tv c=1 sm=1 tr=0 ts=69160c40 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=tMX4VmICG43G860zTSsA:9 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 06:55:50 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 AB6BC393DD2 for ; Thu, 13 Nov 2025 16:50:19 +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=1763052621; cv=none; b=UnZEWWN7a2JFMOF1VSYtiDLr5jISc8IMFIOzQ0K/bdmgToxa3mE0W0e3JpjdpE5Kq+bw2hTSfNv8ttDJGgOW53ldcKVc2pmClRHMXedo+jmdjjBJ71n9WCFhEToLNt42IbGWCkn8xEvNdHcAOBlEg8XskLcy1t1/JlW6SNd0OLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763052621; c=relaxed/simple; bh=MJuS5aI6TBpNEWLOH7jEJKhRGwaG4j0xhrR0PIheg7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OugdPp5NW5/mNYtwSl0oXqeeu4o2vM7Y2VjOdrNdg+21OxOtkoY6GK4MOyCz+OXJXEED6tHd/9daZcLK2gOVDSPjAbBQ7Bzv2WwsxEOCoTi74OcTLaqSV6oOh9NAOJ1knR5wFyA3DMYMXg96e1v47ZFJKGHDXO9fohQV398nrgI= 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=f0qHEweb; 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="f0qHEweb" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADE9t3Q027934; Thu, 13 Nov 2025 16:50: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=4kujL WXKftYa98GKfPFWNDHJWBntxAXJo2f1Yvze3I0=; b=f0qHEwebDfDS+GHy6QB/9 jrlVEYYpuBV7W6ttUn4kuKkyzoz6FdsMtl8jfJZg9R2BDmXwbDhSX9LicC8K/8ZI eKm50qrAU7gQmgs4J9CkEMPkQEX7xDusbtL0VWz4LhKTdK6jGrWUN1p0fSvE743h 7dzafU619EISFN7BOasF8SnFEHyQeA3IZ0AOAn5PXqQxZIKdReMca4shVxv5C499 O9BeyugRMNtYyxWThUI0zCdNXlDEISzW850oMNt2bbFvKT5nZLLw9ErlpEtItnsV +Eys/TKuJYNqPBF8F24xca9M4gp5/BtBXAxR7rE4mhxTy6CxJy9HKsF5/QWyM1nk Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4acyjsa7w9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:11 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5ADG92mv039199; Thu, 13 Nov 2025 16:50:09 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4a9vacc4m5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 13 Nov 2025 16:50:09 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5ADGnKAf008288; Thu, 13 Nov 2025 16:50:09 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-172-143.vpn.oracle.com [10.154.172.143]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4a9vacc38f-29; Thu, 13 Nov 2025 16:50: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 v4 28/28] objtool: Print single line for alternatives with one instruction Date: Thu, 13 Nov 2025 17:49:17 +0100 Message-ID: <20251113164917.2563486-29-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251113164917.2563486-1-alexandre.chartre@oracle.com> References: <20251113164917.2563486-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-13_03,2025-11-13_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511130130 X-Proofpoint-GUID: UlfALYs35uVa7gB6tU82HMrGxFSrgkH_ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTEyMDE0OSBTYWx0ZWRfX8v0S9kRSHzcg IQcM0CgoR67Ho4baMKHfbLzucSbypL5k0T0Um7O7wX6Ku9whG6Av0hXhLSjglqAS/SDJzuDvc55 bE0pglTtz4AfyFhg7bFrzDBwYTh62fSpPbbHNz4rLsxxFJZCEg7Mojkne5DO8qqO1jar3bsFpP5 5e9dM8Z1AhqGI5xKfWBbNK8CNHqlf9guVdaOa7dKWmeQjKIPCjilJR6s1Dve9rIUO7ryU6BC1ne eOol43UfiwIyCfONczeqnxlgJLW9tyxDKuwPcVjYnRfFBzDkVmggwQgfCWhFfYe8nxdI9Yg1ECE k4JmDMekRj6eeHY8NP1FapXZz5sWFO0Mj4FAmMzDGovkkNX4vwVtFVnnXq19T/PrqH4e0b3PgiA Iczlm1fFiqR30kC2NxBagvbQIsquag== X-Proofpoint-ORIG-GUID: UlfALYs35uVa7gB6tU82HMrGxFSrgkH_ X-Authority-Analysis: v=2.4 cv=HLzO14tv c=1 sm=1 tr=0 ts=69160c43 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=C75Ug1cDibOJfFcMQNQA:9 Content-Type: text/plain; charset="utf-8" When disassembling, if an instruction has alternatives which are all made of a single instruction then print 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