From nobody Sat Feb 7 08:07:06 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 C1DBB2857D2 for ; Fri, 6 Jun 2025 15:34:54 +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=1749224096; cv=none; b=muimDWBA8pVlbhQ3VTtuA/0atS7XI8CntTIJ1JBLos2TD/7TR2B+w/Y4atailUGUYALvCYDQFX6NKjVDa+JEEyL2uedUYjdUucCPy8U8nNxPo/KZd9qgcH3/UIrB9fuB+OLsYxh/KqbfbZiCj6cQ05/psNj5wSW/swHZg0VjCZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224096; c=relaxed/simple; bh=uFli8qripjOIKS+FVhZZomp//yZqATpNXfvNFflsUhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lC2wbbHzAHDs/knMNa/s2vsmlVdIVJFyD51U6PdP6knU2mscchLs52MS5UXhy3zGm4yPN9HNCI2d4W8FyAFKouFQdFahy7Osjf45ToWvHiVBNRp2/IaehvawrRXfIBoM+a5+iMt78PE9/zgli0S/aShxMLr1jryJ6+K0dqSeR80= 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=ALVVZTNv; 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="ALVVZTNv" 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 5565MYQU002138; Fri, 6 Jun 2025 15:34:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=TQjWc pisuoarYkrPpFS4fkXe+RQOPP/UyAZhdCaRaSQ=; b=ALVVZTNvUQHgnoHuoB/lr wQ9+rILCUe41zJLgPAPOIuO3unqWdAKrDUQonV0e3pS0Ui41Rq2/HLaxI2bJc0bG k/Jd1VKeoEsuFAi3c+iYYQ47F287NezTfkQM1TfFd8Px97R3iK+VGOyXkbNayabU ujMde3VJU0h/y3bhFpCJEo0SPNP+OIkq94p0IF2KPJo4VL1tMBy4A6FyZ6BA2Dh5 vTLYDkFMAYn35o55im24CBZ+riDlupq5CILgSo4iWhJZBkXNJKCIVv4RsodCIZHr 6LA74JgIiTbjbDs+ts/p8x4xeWypdXci1/GLTrVewX/9D4kv/HwowD0K+1gJAsEI w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471gahgafe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:47 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556EKfsp039169; Fri, 6 Jun 2025 15:34:46 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7des3q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:46 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3f015517; Fri, 6 Jun 2025 15:34:46 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-2; Fri, 06 Jun 2025 15:34: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: [RFC 01/13] objtool: Move disassembly functions to a separated file Date: Fri, 6 Jun 2025 17:34:28 +0200 Message-ID: <20250606153440.865808-2-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=aqqyCTZV c=1 sm=1 tr=0 ts=68430a97 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=dBVU6wt392Vc8wzyTJAA:9 X-Proofpoint-GUID: afOuQ-x1qthg74Vzxnhh2gywORA-aq3p X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX2myZSbfx0x9q +V6JoFeWGO2E4lB6p1BGpPsfxEidOB0hcwjuf0ageOuLa4Kgp7TTWcaEf2gOK7yG1UsLNAgOf2J LngR4cMCBPuz00KRSGBj07nEjuhUX1th6KIAL6H5a1W8ViCXdqNLxTxTXnPlsSma3xpkR/KLqH9 8RHyTtGbBa7X89pVcltouCJ8kQCRdumfo3c8kiEUSDXhbfKvOCV6gyrz3vM1ef8TDrm0QGmaPGg oenAXUe7OjXNbmiSlRv7tBjXwUt1+bPaP9gAI4qY1Uovm28+9V5L79A0nsgym45iAAJfiClQIeE ShiafMjCWVp84Trjk2q25m3HXxcTMSuJFMH2j2e5sZUojKH16WpmLTq1E4t+QZEC7m9b3XDDjNv 1GA0azkC+XRA4uLKO9y/2KOvn9/E1C8a2kG4bP3M3foR048siuvujn5S/D2CGl6Powj4SNxr X-Proofpoint-ORIG-GUID: afOuQ-x1qthg74Vzxnhh2gywORA-aq3p 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 a3cdf8af6635..677bf9148cba 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 f23bdda737aa..bd1974717fa3 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4561,87 +4561,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); -} - struct insn_chunk { void *addr; struct insn_chunk *next; diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c new file mode 100644 index 000000000000..77de46beb496 --- /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 c0dc86a78ff6..4d3e94b70fd8 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 Sat Feb 7 08:07:06 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 C1CD01C1741 for ; Fri, 6 Jun 2025 15:34:54 +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=1749224096; cv=none; b=T1PgdjM7KK4c1xRf1eW4fvimez4KBB/eEsF6rIP/UiP+/0oZdCqsocj90P2TMNzYjB7pZ3js2LqazPKvUOtz9WVrUw6ie+65/bKPqzaIPmWafRP+e6rLV+C4ArPz7aiaty1pAKWK/2aKtbKl0aN3pHmHZvNTMu7WYfRHPdJ9yDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224096; c=relaxed/simple; bh=4rH/Gc2zIAmQVULcfBWujwFbbIqz8s2kJYv87k077Nk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QL/3KIZnE/2qdPis2AVmT48TfYDNTH6Vyz3/bwGmpAJSFqyMnrwFKgtRRSLAswIOGjS67uVAV1rd23zwPCV9+1XKRIm/cD8WWQXczo4GmsOwcdA12qU8HrY01rjVdLQOSr0IVIxCaH0LkLE9/pvlEX9a7uQFgzucKL/yKqmcHd0= 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=Jov7fJJk; 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="Jov7fJJk" 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 5565Md4K011823; Fri, 6 Jun 2025 15:34: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=fsWbO kl2AGNdbyJ3MQxyQRY4djEzAoU2dzjlX/stUUo=; b=Jov7fJJk6yXySm0iQ8lT+ VP2NqwTU/fAz4QCGRmXqWh4zE8qcUQhJkkNyi/no7eP0WUzqbao/2Qn3woFv7Ela CJm06mh19Tp7YLd5nv2r7fAApI/j3mQOIWgyEZoPT/+ut+y9ivZITv/G4eRmS3Xg mfye1FOhLgwJo3mFonJ97SWsNR0+tqwbMSi4LHRr4ohLn1AsGhZkOSiClempgyX5 v6iSl9q/GTRI5XqcBA3yz/psKbHqdzzQtLTnHqJO35p+bCl3g6cjVxwoLcmIMDF1 GxzzsyYlUJQt63JbVIk5ZGCOEsx6G3Oxto7NEeSSaSFBboXlNJv1STyDEgdnNXMB w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471g8j89ck-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:49 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556E22Oa038561; Fri, 6 Jun 2025 15:34:48 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7des51-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:48 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3h015517; Fri, 6 Jun 2025 15:34:48 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-3; Fri, 06 Jun 2025 15:34: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: [RFC 02/13] objtool: Create disassembly context Date: Fri, 6 Jun 2025 17:34:29 +0200 Message-ID: <20250606153440.865808-3-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=934 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Proofpoint-GUID: 2KpW7A7QWI1djaUkjkBtM-BaPdnmGI2g X-Proofpoint-ORIG-GUID: 2KpW7A7QWI1djaUkjkBtM-BaPdnmGI2g X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX1ZKd6bL/BLPp M7go1xXG1VxXtzkD5TNi8VFfgE9UCp04+/y4KOE5GX9kXrP0dke8YMfdfN3FubKnr5zpFPvfgq/ iz/W7PLWlWlkVj1aMbJ5wmx4vNJbPeg9lsYeGyhr+AyHUuxvLxwGa8nFw+WJMekE2MeRiytG9J8 Gy6CT16uFpcRgzQ6mGvsllYxD+Y7wO/+npEtyNr4KZLaJbNPpIWipKFW55wU6yVBvbTpT0o5L/m M889X0FZdqV4msH5DrCDvInGwltnyYd6P5Y+W7Bd25FcnSOts65Pi0jwU32YhblCvlcmjEl0cJ7 nQUeeMec1uuRZoaIx/VXHsgDLFwoIa0s/U3Yq8+OsVaU3NoZxn0m/qudm6CS4VWSNkul8vOgSvr ZMmxztQ16GseVRX1l9kL9PKHtKKkhe/EmawPSWbn1P7wgWHn/LI/Aftc6Tq6F3NfCvz2pzYu X-Authority-Analysis: v=2.4 cv=QI1oRhLL c=1 sm=1 tr=0 ts=68430a99 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=WrX3ccauloUazzeUkokA:9 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 | 5 +++- tools/objtool/disas.c | 33 +++++++++++++++++++++++-- tools/objtool/include/objtool/objtool.h | 5 +++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index bd1974717fa3..085fcc1b643b 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4591,6 +4591,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); @@ -4720,7 +4721,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 77de46beb496..ed74554bccbf 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -8,6 +8,30 @@ =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 too allocate disassembly context\n"); + 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 +82,17 @@ 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) { + ERROR("disassembly context is not defined"); + 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/objtool.h b/tools/objtool/includ= e/objtool/objtool.h index 4d3e94b70fd8..f5ab71f07f5c 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -47,6 +47,9 @@ 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); +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); =20 #endif /* _OBJTOOL_H */ --=20 2.43.5 From nobody Sat Feb 7 08:07:06 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 39F9528937C for ; Fri, 6 Jun 2025 15:34:56 +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=1749224099; cv=none; b=SotE2hdeRd06EjK4654DrL66DUnofS61uYNdtrDSbTJQKkdKY6n8Zyigri0IpOM6jDvZleui4fMGdymM7bnCpbPwsqWXjNexv9rLDlvkcm1poPDiyVhCyUz22ZPirTkdqpR4krbtpWMn306lFXk0saipKd09pDZp0dnENrC1FGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224099; c=relaxed/simple; bh=3U+y0mvrYcUDNm0lFtJarweNEzMOapJF5DzVUHf/hkI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rkASfTFRZsHG1EWwEx9RPb+71jF2UZE3uOdm3n/1Up3MxwZ4Yc8/fd5v+OWoLDW1Uq0a35R/lC0bLuGpBNMfCJ/n6KE7UXbKd+N0t0DH4ZF6oWOhLSydd+BBkQ5OBKSWe46XdcmDYKyzrgV9TqYT8dqLwXqWYWOtiT+uEJdcSqQ= 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=N5CAAhL6; 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="N5CAAhL6" 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 5565MZlU011741; Fri, 6 Jun 2025 15:34: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=PeI/p k5Il/MGVPlz2adzv5NVdLjN9omB9528dMPld/c=; b=N5CAAhL6bvx03RnB+7uJa DKPYkH7eLAHxLxvnyErWZQ+GOsQlqyBP0jMJKsQbiz1GTRt0QWzVfGjkdrx1ebmU w9V+I/qhiZ6ZzUJYeDKfijQ9G15kAkG1Xm/ubnVYaufu+gf99LFpLjZVOtLPNjad Qf7VLjTm009ygy80+M7RAH/LjXpNvlhagffqe/fMntlOJpK0z9iJLx22HMUeedur Aia7s8GSbD6z5ubdRiPLpMDcsWESifb2NllzWFzj6Sv9OeiCM1G5hbyB5/sB1w5j AN4CTOY4VNXFsGxyRpFfiNfwbH5mxFEmFAD0vP0uA8DPpmrLIHOc+eEY8+NrRggQ g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471g8j89cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:51 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556Eshsk039288; Fri, 6 Jun 2025 15:34:50 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7des69-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:50 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3j015517; Fri, 6 Jun 2025 15:34:50 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-4; Fri, 06 Jun 2025 15:34: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: [RFC 03/13] objtool: Disassemble code with libopcodes instead of running objdump Date: Fri, 6 Jun 2025 17:34:30 +0200 Message-ID: <20250606153440.865808-4-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Proofpoint-GUID: AF7nlqu_3zg58uwv76jnljc7-Sj5ajxD X-Proofpoint-ORIG-GUID: AF7nlqu_3zg58uwv76jnljc7-Sj5ajxD X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX+iqYyXOcqGzH Ysd0gBbvJY8+R7HSK3MrnAx2Birk5Jv/hp4PphWgtlK3MejmQ//+N3nT6pWkHtOBuakj7iMs+sZ KdN9QLwDbXu2KVAHHNuuI1+VQclPA8Y+edJoZ+jSS8jE3tATo7R31GxDMVg6j+FePhuch28cU52 d0G65kU6BhiDj3n3Xj5UiMx235NxVu9ke6RBNCbvKdFA64lEyNvCRR70cw6DZzJ3r6epAVyBOWr j8FKAsp7sSpg3PNLyIZbOW1Z2HDNQgYYxAlGd5HMNo721nYLOjWewnOZ/Z0WFmt7tVBTkGriHpT EgEArh4VU1/kY4h+ZhirstjB5fEAmhOmTAxhf2A1PC9+qlNPEMXX3+hF7h/wTN2/URcUr+Mkn17 eLD46CD4KuobMma047DRukE86UeJng9F5oP4HqM9QPaLbt/gUrWvxwOyI/RVvfxe9SJ+bHbL X-Authority-Analysis: v=2.4 cv=QI1oRhLL c=1 sm=1 tr=0 ts=68430a9b cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=OvpEF-eQTjwjmUvlGM4A:9 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. Signed-off-by: Alexandre Chartre --- tools/objtool/Makefile | 2 +- tools/objtool/arch/loongarch/decode.c | 6 + tools/objtool/arch/powerpc/decode.c | 6 + tools/objtool/arch/x86/decode.c | 7 + tools/objtool/check.c | 4 +- tools/objtool/disas.c | 186 +++++++++++++++--------- tools/objtool/include/objtool/arch.h | 5 + tools/objtool/include/objtool/check.h | 5 + tools/objtool/include/objtool/objtool.h | 4 + 9 files changed, 154 insertions(+), 71 deletions(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 8c20361dd100..00350fc7c662 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -34,7 +34,7 @@ INCLUDES :=3D -I$(srctree)/tools/include \ # is passed here to match a legacy behavior. WARNINGS :=3D $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-= packed -Wno-nested-externs OBJTOOL_CFLAGS :=3D -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES= ) $(LIBELF_FLAGS) -OBJTOOL_LDFLAGS :=3D $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) +OBJTOOL_LDFLAGS :=3D $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) -lo= pcodes =20 # Allow old libelf to be used: elfshdr :=3D $(shell echo '$(pound)include ' | $(HOSTCC) $(OBJTO= OL_CFLAGS) -x c -E - 2>/dev/null | grep elf_getshdr) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index b6fdc68053cc..bf5ac6750512 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -386,4 +386,10 @@ unsigned long arch_jump_table_sym_offset(struct reloc = *reloc, struct reloc *tabl default: return reloc->sym->offset + reloc_addend(reloc); } + +int arch_disas_info_init(struct disassemble_info *dinfo) +{ + return disas_info_init(dinfo, bfd_arch_loongarch, + bfd_mach_loongarch32, bfd_mach_loongarch64, + NULL); } diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/power= pc/decode.c index c851c51d4bd3..c0fcab2d643c 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -127,4 +127,10 @@ unsigned int arch_reloc_size(struct reloc *reloc) default: return 8; } + +int arch_disas_info_init(struct disassemble_info *dinfo) +{ + return disas_info_init(dinfo, bfd_arch_powerpc, + bfd_mach_ppc, bfd_mach_ppc64, + NULL); } diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 98c4713c1b09..6c13c67ed9b9 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -880,3 +880,10 @@ unsigned int arch_reloc_size(struct reloc *reloc) return 8; } } + +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"); +} diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 085fcc1b643b..9cfac23185b8 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4701,8 +4701,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); @@ -4726,5 +4724,7 @@ int check(struct objtool_file *file) disas_context_destroy(disas_ctx); } =20 + free_insns(file); + return ret; } diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index ed74554bccbf..f2eb1050ce11 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -4,17 +4,52 @@ */ =20 #include +#include #include =20 +#include #include +#include =20 struct disas_context { struct objtool_file *file; + disassembler_ftype disassembler; + struct disassemble_info info; }; =20 +/* + * 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) { @@ -23,8 +58,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\n"); + 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\n"); + goto error; + } =20 return dctx; + +error: + free(dctx); + return NULL; } =20 void disas_context_destroy(struct disas_context *dctx) @@ -32,60 +108,54 @@ 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; - } - - cmd =3D malloc(size); + disassembler_ftype disasm =3D dctx->disassembler; + struct disassemble_info *dinfo =3D &dctx->info; + + /* + * 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; + + return disasm(insn->offset, &dctx->info); +} =20 - /* real snprintf() */ - snprintf(cmd, size, objdump_str, cross_compile, objname, funcs); - ret =3D system(cmd); - if (ret) { - WARN("disassembly failed: %d", ret); - return; +/* + * Disassemble a function. + */ +static void disas_func(struct disas_context *dctx, struct symbol *func) +{ + struct instruction *insn; + size_t addr, size; + + 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); + size =3D disas_insn(dctx, insn); + printf("\n"); + if (size !=3D insn->len) + WARN("inconsistent insn size (%ld and %d)\n", size, insn->len); } + 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) { ERROR("disassembly context is not defined"); @@ -93,27 +163,7 @@ void disas_warned_funcs(struct disas_context *dctx) } =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 01ef6f415adf..aecf8fc29571 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -6,6 +6,8 @@ #ifndef _ARCH_H #define _ARCH_H =20 +#include +#include #include #include #include @@ -98,7 +100,10 @@ int arch_rewrite_retpolines(struct objtool_file *file); =20 bool arch_pc_relative_reloc(struct reloc *reloc); =20 + unsigned int arch_reloc_size(struct reloc *reloc); unsigned long arch_jump_table_sym_offset(struct reloc *reloc, struct reloc= *table); =20 +int arch_disas_info_init(struct disassemble_info *dinfo); + #endif /* _ARCH_H */ diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 00fb745e7233..5290ac1ebbc1 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/objtool.h b/tools/objtool/includ= e/objtool/objtool.h index f5ab71f07f5c..0b404cfd81c0 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -48,8 +48,12 @@ int orc_dump(const char *objname); int orc_create(struct objtool_file *file); =20 struct disas_context; +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); +int disas_info_init(struct disassemble_info *dinfo, + int arch, int mach32, int mach64, + const char *options); =20 #endif /* _OBJTOOL_H */ --=20 2.43.5 From nobody Sat Feb 7 08:07:06 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 EA206289E03 for ; Fri, 6 Jun 2025 15:34:58 +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=1749224100; cv=none; b=Ot08UxKCu0S7IuGt17ObFRlMVncM0/1zV85sQGq7QwuoZxTX2SoNFPzf8/J0k1wYIaFA2LkBTER8EmlTLO1ijf4ArGK5apLMoIkZ0jEShKJ9r0tp3fagXEs7DS0xKNpUqFX4Na1c//Io4ePiJJTRQYXq9vul4z1prZZMB97Fndk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224100; c=relaxed/simple; bh=7s1S+tY477XcZ2hoynSKzaGJovL0nWx0gUoFfx5bI9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ELvVGEoDZoM6lhG0veU6hKiX1voJtZVAMXUQgLHO86ulnVeWBSYpymYM1oDlOJUuxxVvvJAKrdgN2LuryduHFLCwFhAv2eiKC1U31r2lU1kVmUlJo6FfxT0A2KIpnFRbHJXhi6dAtaOISBJlrVtBbEtff1zs6axzEaxbO8IB5e4= 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=V2j+fAD6; 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="V2j+fAD6" 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 5565MY8A030076; Fri, 6 Jun 2025 15:34: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=vDQhR jq/WXJAo/D85QYcbbaMFMBUxMy1kZmMNHPiQAU=; b=V2j+fAD66bUGws5IsGJLs g6Z8Ieh3tosA/1LJ5d+gJuU0GhVOfPCrxQUqTr7REUY/9N8H47U+4OtusJSGBDd+ 7y3WaQtd08oiXiY00HQb9Leo/PsmMLSI4dNRkQaWjFUw8YjumfrH5euqri1+dvKK OevwBroX8fwZZQg9XyIBnr1ZXUFDu+Df1h/klFJGOFWv+qPIl0bGEQDaSucZUKKY wjxd4NQQWdljClzc8nkvhtgyixZQo/G80DuAHob8ZvYrnxQ/T8unAF7uxK203l9d cNgmxp75Z1nNGFb+f1tidfZ5aqpC7i0jukl2nuSJfhoOmP5YKxDiH6fNjH6T55EQ w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471g8e086t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:53 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556E22Od038561; Fri, 6 Jun 2025 15:34:52 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7des7t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:52 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3l015517; Fri, 6 Jun 2025 15:34:52 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-5; Fri, 06 Jun 2025 15:34:51 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [RFC 04/13] objtool: Print symbol during disassembly Date: Fri, 6 Jun 2025 17:34:31 +0200 Message-ID: <20250606153440.865808-5-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=Va/3PEp9 c=1 sm=1 tr=0 ts=68430a9d cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=GRtY48bZnyd7kpkPou0A:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX/mVhWij6uIrt g4rFDULjrolbqeI88a9IH/6SXZyUocAutCEo+iRk0O7nYeoVRq9/azBkknM8mRBl47xcFY1HzFC +V1pzuUplWKMuDMHAXFloTBh0ZqjOnlshyZum5/MMNfog7kxTakALRMxMvsvS4JYszmjA7ItOng pOYd462cLruDvooJlJcdC4ACoQmIhRSi7/4ZWI2vQ9biSdvWc4l46o6aDbwuMmGRsm5/6IyEcnp b8NXzUeARVjYxq4xyCFVhW2dhbDVxsuNEuJkVqnXS1BpMdbPOCBx96fTPxDwxetnDh6G+17WKWc fP0/VITR50eKw0e9AiuDurjoqmZIE/BlTKLzreEtTsi7W94BlvE0fSUO+2SvY75jjGOZM7S/QhE 3cyiGyYj8UAM5C6MyWReN9TIMi4rtCPs8/9TBF7lkbgFyLzUdxxaNRxlcNJimbBUCdYQB5nC X-Proofpoint-ORIG-GUID: sKFFsyCCLaCiCk3wJKJ9GCWfOg8gkRDq X-Proofpoint-GUID: sKFFsyCCLaCiCk3wJKJ9GCWfOg8gkRDq Content-Type: text/plain; charset="utf-8" Print symbols referenced during disassembly instead of just printing raw addresses. Also handle address relocation. Signed-off-by: Alexandre Chartre --- tools/objtool/check.c | 9 --- tools/objtool/disas.c | 101 ++++++++++++++++++++++++++ tools/objtool/include/objtool/check.h | 9 +++ 3 files changed, 110 insertions(+), 9 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 9cfac23185b8..ee613f03e57d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -131,15 +131,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 f2eb1050ce11..83fe2c018c4b 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -13,10 +13,108 @@ =20 struct disas_context { struct objtool_file *file; + struct instruction *insn; disassembler_ftype disassembler; struct disassemble_info info; }; =20 +#define DINFO_FPRINTF(dinfo, ...) \ + ((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__)) + +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 objtool_file *file =3D dctx->file; + struct symbol *call_dest, *sym; + struct instruction *jump_dest; + struct section *sec; + struct reloc *reloc; + bool is_reloc; + s64 offset; + + /* + * 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->offset =3D=3D addr) { + DINFO_FPRINTF(dinfo, "%lx <%s+0x%lx>", addr, + jump_dest->sym->name, + jump_dest->offset - jump_dest->sym->offset); + return; + } + + /* + * Assume the address is a relocation if it points to the next + * instruction. + */ + 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. + */ + call_dest =3D insn_call_dest(insn); + if (call_dest) { + if (call_dest->offset =3D=3D addr) { + DINFO_FPRINTF(dinfo, "%lx <%s>", addr, call_dest->name); + return; + } + if (call_dest->offset =3D=3D 0 && is_reloc) { + DINFO_FPRINTF(dinfo, "%s", call_dest->name); + return; + } + } + + if (!is_reloc) { + DINFO_FPRINTF(dinfo, "0x%lx", addr); + return; + } + + /* + * If this is a relocation, check if we have relocation information + * for this instruction. + */ + reloc =3D find_reloc_by_dest_range(file->elf, insn->sec, + insn->offset, insn->len); + if (!reloc) { + DINFO_FPRINTF(dinfo, "0x%lx", addr); + return; + } + + if (reloc_type(reloc) =3D=3D R_X86_64_PC32 || + reloc_type(reloc) =3D=3D R_X86_64_PLT32) + offset =3D arch_dest_reloc_offset(reloc_addend(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. + */ + sec =3D find_section_by_name(file->elf, reloc->sym->name); + if (sec) { + sym =3D find_symbol_containing(sec, offset); + if (sym) { + if (sym->offset =3D=3D offset) + DINFO_FPRINTF(dinfo, "%s+0x%lx =3D %s", + reloc->sym->name, offset, sym->name); + else + DINFO_FPRINTF(dinfo, "%s+0x%lx =3D %s+0x%lx", + reloc->sym->name, offset, + sym->name, offset - sym->offset); + return; + } + } + + if (offset) + DINFO_FPRINTF(dinfo, "%s+0x%lx", reloc->sym->name, offset); + else + DINFO_FPRINTF(dinfo, "%s", reloc->sym->name); +} + /* * Initialize disassemble info arch, mach (32 or 64-bit) and options. */ @@ -65,6 +163,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 /* @@ -117,6 +216,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; + /* * Set the disassembler buffer to read data from the section * containing the instruction to disassemble. diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 5290ac1ebbc1..4adbcd760c6f 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 Sat Feb 7 08:07:06 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 F0175276048 for ; Fri, 6 Jun 2025 15:35:00 +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=1749224102; cv=none; b=BG83fNkS76buN4vbzQBPgb6egVH+LZ2ljtqP51neWR+MpYJSc50nBGlJPEQSIK2XgOnVHtzTEZHDg7jlEn5AQV68qhKkGhHQnZVgouUqMzCUDY2o/2ohEBfb+TIyafBOJFwmUFcAYfSzEeJXIB8nr3i4TtxOrkIObMZzODWP7g8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224102; c=relaxed/simple; bh=kRHpxHGdnDbmGJgSjhss+LvCRQXFlC9CVb2+NgDTQCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=my6Z+TGiIs5VXIU5Wj4NEh/uIinYxqOJlmi//lPU/QB/1XDh3zQMVy/WM1mPPiF55ETvXgsaPvbI0mnu+qXVhGKElsr4zqZaYVdD09HkVgSiONQCC1EUf0n1TXcs9FJfsjCOW8a4cuVR6u2a3Z7IvkGmUFO5EdLlLJJ+DVJFL4c= 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=TS/SflEA; 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="TS/SflEA" 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 5565Nd0U003840; Fri, 6 Jun 2025 15:34: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=5uU22 ZQC8/bZaX1N2l5t1e/8/ilrOtO9X/0/f7od/jw=; b=TS/SflEAZ3b4zjtgYV+Xd AGNmlrcrZvlB7h4mqsD3jo/3c/jfRHIGkH99RsqUz4QeXjKh+ODF9+yT0ng9bYYB EHYo42gafxWFJu03xdtnkyuBBaUxMsWgZMy5QhgcKXBuwv6Xkgcj7R4e8iuLuNiQ T//uYVz9DZoglFDuNo1GRv0VPwxMknVPdb5czEAxP5eFHGgzFLWR+dCrJgfnKg3y cbBPnU+ALdUznh3dELWOM7/qAw6F6v3YkYUPix7kHyrzLj9kvfcDsaKEq2jmfmzg bBOxgMUZUAIqEvox/aWcQDwmWx2xARUfqsPehWEk/jBAk1YArWpon82MFH4cI/Ia w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471gahgafq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:55 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556EJExp038537; Fri, 6 Jun 2025 15:34:54 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7des9e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:54 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3n015517; Fri, 6 Jun 2025 15:34:54 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-6; Fri, 06 Jun 2025 15:34: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: [RFC 05/13] objtool: Store instruction disassembly result Date: Fri, 6 Jun 2025 17:34:32 +0200 Message-ID: <20250606153440.865808-6-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=aqqyCTZV c=1 sm=1 tr=0 ts=68430a9f cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=15-dxsL2gXYqenlZGRYA:9 X-Proofpoint-GUID: Glyc08PLi2wD6WSLjOpAo2H0nxexilx6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX5VbHRAyjQ83/ dZPht+K35Vnc1XDZCC6vgSdsrs4F5MUuh9CadfD53jA4awRE4/4GiswJnmCnpjNB1wDqX9u7sjr PSWVhvQiw6v0ZxF5UaZTyrKpv4uAx58Wzv5AbBgcyq1V1zRsNSkJnTDItHQEp2x8Zd0+Uo7iQiE 7AEdYtN78HjRoFgz4vC7LFEdo3Ra0iMGuT9zirCq4vjucXUCZVcZI8rfxxMJQEEculxB+HkfLC+ A8y4niVqGQbF6hjnl2TsnoMwQh6Xqb4nTfnlv3jDcM9+j0ZbpdERveP1/q7P0ouxndJXWGnqP82 7GR9x2xDYIn8g3rGGKdRy5ohe0W1PeJ8yDh7TalXu7D7meDBvn2qVyTAGbFTwg71stLLkEdssa6 nEZke3WV/0qcZIyZjkwcP3+4Ckbggm76ENKM4SvcaczVBxqOQE/SPqklV6AZQeL0Jzrschk5 X-Proofpoint-ORIG-GUID: Glyc08PLi2wD6WSLjOpAo2H0nxexilx6 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 | 161 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 155 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 83fe2c018c4b..f86b9b04ef97 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -11,9 +11,16 @@ #include #include =20 +struct dbuffer { + char *addr; + size_t size; + size_t used; +}; + struct disas_context { struct objtool_file *file; struct instruction *insn; + struct dbuffer result; disassembler_ftype disassembler; struct disassemble_info info; }; @@ -21,6 +28,129 @@ struct disas_context { #define DINFO_FPRINTF(dinfo, ...) \ ((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__)) =20 + +static int dbuffer_init(struct dbuffer *dbuf, size_t size) +{ + dbuf->used =3D 0; + dbuf->size =3D size; + + if (!size) { + dbuf->addr =3D NULL; + return 0; + } + + dbuf->addr =3D malloc(size); + if (!dbuf->addr) + return -1; + + return 0; +} + +static void dbuffer_fini(struct dbuffer *dbuf) +{ + free(dbuf->addr); + dbuf->size =3D 0; + dbuf->used =3D 0; +} + +static void dbuffer_reset(struct dbuffer *dbuf) +{ + dbuf->used =3D 0; +} + +static char *dbuffer_data(struct dbuffer *dbuf) +{ + return dbuf->addr; +} + +static int dbuffer_expand(struct dbuffer *dbuf, size_t space) +{ + size_t size; + char *addr; + + size =3D dbuf->size + space; + addr =3D realloc(dbuf->addr, size); + if (!addr) + return -1; + + dbuf->addr =3D addr; + dbuf->size =3D size; + + return 0; +} + +static int dbuffer_vappendf_noexpand(struct dbuffer *dbuf, const char *fmt= , va_list ap) +{ + int free, len; + + free =3D dbuf->size - dbuf->used; + + len =3D vsnprintf(dbuf->addr + dbuf->used, free, fmt, ap); + + if (len < 0) + return -1; + + if (len < free) { + dbuf->used +=3D len; + return 0; + } + + return (len - free) + 1; +} + +static int dbuffer_vappendf(struct dbuffer *dbuf, const char *fmt, va_list= ap) +{ + int space_needed, err; + + space_needed =3D dbuffer_vappendf_noexpand(dbuf, fmt, ap); + if (space_needed <=3D 0) + return space_needed; + + /* + * The buffer is not large enough to store all data. Expand + * the buffer and retry. The buffer is expanded with enough + * space to store all data. + */ + err =3D dbuffer_expand(dbuf, space_needed * 2); + if (err) { + WARN("failed to expand buffer\n"); + return -1; + } + + return dbuffer_vappendf_noexpand(dbuf, fmt, ap); +} + +static int disas_fprintf(void *stream, const char *fmt, ...) +{ + va_list arg; + int len; + + va_start(arg, fmt); + len =3D dbuffer_vappendf(stream, fmt, arg); + va_end(arg); + + return len =3D=3D 0 ? 0 : -1; +} + +/* + * For init_disassemble_info_compat(). + */ +static int disas_fprintf_styled(void *stream, + enum disassembler_style style, + const char *fmt, ...) +{ + va_list arg; + int len; + + (void)style; + + va_start(arg, fmt); + len =3D dbuffer_vappendf(stream, fmt, arg); + va_end(arg); + + return len =3D=3D 0 ? 0 : -1; +} + static void disas_print_address(bfd_vma addr, struct disassemble_info *din= fo) { struct disas_context *dctx =3D dinfo->application_data; @@ -147,6 +277,7 @@ struct disas_context *disas_context_create(struct objto= ol_file *file) { struct disas_context *dctx; struct disassemble_info *dinfo; + struct dbuffer *dbuf; int err; =20 dctx =3D malloc(sizeof(*dctx)); @@ -157,10 +288,16 @@ struct disas_context *disas_context_create(struct obj= tool_file *file) =20 dctx->file =3D file; dinfo =3D &dctx->info; + dbuf =3D &dctx->result; + + err =3D dbuffer_init(dbuf, 1024); + if (err) { + WARN("failed to initialize buffer\n"); + return NULL; + } =20 - init_disassemble_info_compat(dinfo, stdout, - (fprintf_ftype)fprintf, - fprintf_styled); + init_disassemble_info_compat(dinfo, dbuf, + disas_fprintf, disas_fprintf_styled); =20 dinfo->read_memory_func =3D buffer_read_memory; dinfo->print_address_func =3D disas_print_address; @@ -204,9 +341,18 @@ struct disas_context *disas_context_create(struct objt= ool_file *file) =20 void disas_context_destroy(struct disas_context *dctx) { + if (!dctx) + return; + + dbuffer_fini(&dctx->result); free(dctx); } =20 +static char *disas_result(struct disas_context *dctx) +{ + return dbuffer_data(&dctx->result); +} + /* * Disassemble a single instruction. Return the size of the instruction. */ @@ -216,6 +362,7 @@ static size_t disas_insn(struct disas_context *dctx, disassembler_ftype disasm =3D dctx->disassembler; struct disassemble_info *dinfo =3D &dctx->info; =20 + dbuffer_reset(&dctx->result); dctx->insn =3D insn; =20 /* @@ -241,10 +388,12 @@ static void disas_func(struct disas_context *dctx, st= ruct symbol *func) sym_for_each_insn(dctx->file, func, insn) { =20 addr =3D insn->offset; - printf(" %6lx: %s+0x%-6lx ", - addr, func->name, addr - func->offset); size =3D disas_insn(dctx, insn); - printf("\n"); + + printf(" %6lx: %s+0x%-6lx %s\n", + addr, func->name, addr - func->offset, + disas_result(dctx)); + if (size !=3D insn->len) WARN("inconsistent insn size (%ld and %d)\n", size, insn->len); } --=20 2.43.5 From nobody Sat Feb 7 08:07:06 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 346E728A1DD for ; Fri, 6 Jun 2025 15:35: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=1749224104; cv=none; b=j6bLt1y/LYMgx1ggy8C9bxd6DB5dayOOR/vmGgLzJAC2YoGdVPwdyoHTovEl/+MvCcGVV2fxzA8O335fgXoj9OiRjQe8nvi/oiIa0W2gDYeEbgF9q0cbjVM5M+v3c7nWWe2RYtw9Ip9g21q+3GZTUpn1uK/9Zb0xSThPrdRHcBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224104; c=relaxed/simple; bh=rh2rppaKF/ghsqA+OyEMxeQOq2p9iJlfrX8v9ArZL3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TXy292uTXggc9nNV+ZSUJTCKhdzdORa/qLUKsbtilKfvxGOQCMa/HkENO9c3xiwbBRp/oXpw37f0aWDq6v679kituxirt8Lwlh1vi9c9VLSQxLbMTLGXiF/77EsLEhj9YUd0w4GF2xsAneBHUZ1bZHjWg9NpQVkKvy3TBXKxgmQ= 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=m98Cz9AF; 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="m98Cz9AF" 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 5565MXVq002110; Fri, 6 Jun 2025 15:34:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=ShrFy nUlxGk8nWVeIgPchPdYzOw/hadrawBr7I8U5Rs=; b=m98Cz9AFnrjZpLdCSlPDb Mo0nLDlA9E/XgsSyG2XQ1KNZHFVR5Duqp5zm3JZKS3uR0rmhckig7a3+Ocz5qm++ ooIaUl4xidiCj+WnoUn/aHu704mooo1fVvRZAMimgmPn8PoPm8jmzbxy8+oETB4D Zw2x8xRzNxsH18of613KuoL7ieltyu8TGXiQ90Gs1o1x2TNr683B+znaoIWm0wbF Eneaw7ypOjMU3vesspaX+n5Tv0vhEC53Z4dGi+1ktSutx63/MkkgyqvBLMpSmG+M lNoBhV3OVWWsPjoNKZ52EeQjifa+iES13mpupX0Cb/UVtpkTfZ/G4VzlSuwKlLMq g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471gahgafv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:57 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556EZ1PY038505; Fri, 6 Jun 2025 15:34:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7desav-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:56 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3p015517; Fri, 6 Jun 2025 15:34:56 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-7; Fri, 06 Jun 2025 15:34: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: [RFC 06/13] objtool: Disassemble instruction on warning or backtrace Date: Fri, 6 Jun 2025 17:34:33 +0200 Message-ID: <20250606153440.865808-7-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=aqqyCTZV c=1 sm=1 tr=0 ts=68430aa2 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=49cdYLv4DVxkACFpF8YA:9 X-Proofpoint-GUID: 8eFwyzk2SNiDdwO87Tl6ExPQVgbfTpQP X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX+PcvDh66Ll5F q/s0sQbFKi/PKr6MZZf6FxM8OG0OOsjxyyTqKxczBb5AnoDX5dA2l6ZobKEqFExVLPYe5LKF9s+ 2WNKDEcW7/77tfjTgZgyfLI5TtxPowgl41kuURhc9yq0aO2SplOY5HfeoXjaeaRAcuR2UvsP1a4 m7ZE/IADqaI7ZY9gtd7KvsqL45V3HWtTak/XFPAVGNbZGmJUjG4oitsIvg3c1H7O2KYxVPZyHec xAulE36toVZm5hTi4LSsJObWd2nzHknroKC6Dk4aPqjgYKcykKIzLTCz3VeMJnDYACfA3MjzJ8g msd9PCcbPrnvE15Amx9QYVOk+k+ahbHWOZiTzM0HqpBH8Ldrk+gCxF4+fLD01yEliY3Mh27k5/U 8MHflJ0qb1vXSEo86RFGznaGsvkPBvHFPgpHl3gc/NXCzJWxV211M2d8jufONegwa6GfPW1a X-Proofpoint-ORIG-GUID: 8eFwyzk2SNiDdwO87Tl6ExPQVgbfTpQP 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 | 30 +++++++++++++++++++++++-- tools/objtool/disas.c | 5 ++--- tools/objtool/include/objtool/check.h | 12 ++++++++++ tools/objtool/include/objtool/objtool.h | 9 -------- tools/objtool/include/objtool/warn.h | 14 ++++++++---- 5 files changed, 52 insertions(+), 18 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index ee613f03e57d..2c73c8d3515d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4580,11 +4580,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); @@ -4710,9 +4733,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); 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 f86b9b04ef97..1e198d5f9205 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -348,7 +348,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 dbuffer_data(&dctx->result); } @@ -356,8 +356,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 4adbcd760c6f..92bfe6b209ad 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -139,4 +139,16 @@ struct instruction *next_insn_same_sec(struct objtool_= file *file, struct instruc insn && insn->offset < sym->offset + sym->len; \ insn =3D next_insn_same_sec(file, insn)) =20 +struct disas_context; +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); +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); +const char *objtool_disas_insn(struct instruction *insn); + #endif /* _CHECK_H */ diff --git a/tools/objtool/include/objtool/objtool.h b/tools/objtool/includ= e/objtool/objtool.h index 0b404cfd81c0..c0dc86a78ff6 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -47,13 +47,4 @@ int check(struct objtool_file *file); int orc_dump(const char *objname); int orc_create(struct objtool_file *file); =20 -struct disas_context; -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); -int disas_info_init(struct disassemble_info *dinfo, - int arch, int mach32, int mach64, - const char *options); - #endif /* _OBJTOOL_H */ diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index cb8fe846d9dd..32a8dd299c87 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,9 +89,13 @@ static inline char *offstr(struct section *sec, unsigned= 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__); \ + 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 2.43.5 From nobody Sat Feb 7 08:07:06 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 5BD8328A3E2 for ; Fri, 6 Jun 2025 15:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224107; cv=none; b=dmy5ceUSPf6MWcAPAq2gON6cQy5IaR1JgCYodF4ek4T/3qjf14nlpJ46PerjtkmMwUX/5jVN8iceglgQmtxy6iFa8Tt1rq/q8irtkANrwYzVV7etT4IWAmiPvd+hHjl/Ai3A2pSYRa6qk3thNhSRKwye5qDwTVZihSiUl/2rWLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224107; c=relaxed/simple; bh=wHEFyBTkm62XrtfmdTIT8TqWz7wYriDq2vcRhdzM6yo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qptNHJjGaa8hD1cNjlHNSG8bnmuUXP5tBnQ8c6+dfN6JiVfhn3weNxUwS02OQbM2MrqAvlSb1XABqGryUeIxmHUb5rMX1zPPUT2OPxejlry2NrMHMopM68Um9Uu4I+7z2ZWq6QlNze8xOsDu+a0RLclrshWm4RI+QpE9SU1z6Yk= 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=i65WNvjv; 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="i65WNvjv" 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 5565McdQ030094; Fri, 6 Jun 2025 15:35:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=SV7xZ kJY28IXuHyUrf/x9Sg5EBI6i480a87R8ab46QA=; b=i65WNvjvvF7Oi0P+UDLq8 G36Xrv+RvgirwnIvZ2EkeIs5qlXGM9Fxphpa30sn953xR8ZI+Gu0BfmvPxJcz8/V f3MVUNIjyda6H5cg3RGhJ8PRfIoxBSVCWI96D6+h6ZEgw7JvyrIkE7slKCkl2z5+ fymmkJfZmaK4wNaA5ehAXXDz1o7oac67WcvXr88ePiWc9iiodIpqYk6h6KvojQJv fglsdaR+4epIbyLwMOncQqdXWQV+b8UT/wzg0ez9k5u8pcYiO4zZlAcIAQ5CFKoY b8O7GdaQuBCrCKBWdTtukbRSgEA3bR7ElT4gO2zrfx0wSmu1FZkGEsa0S88U84r0 A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471g8e0873-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:00 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556ERKdx039260; Fri, 6 Jun 2025 15:34:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7desc8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:34:59 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3r015517; Fri, 6 Jun 2025 15:34:58 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-8; Fri, 06 Jun 2025 15:34:58 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [RFC 07/13] objtool: Extract code to validate instruction from the validate branch loop Date: Fri, 6 Jun 2025 17:34:34 +0200 Message-ID: <20250606153440.865808-8-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=Va/3PEp9 c=1 sm=1 tr=0 ts=68430aa4 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=17Qteg5u5z3jqcDY0jQA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX0DtRWUUTquCu daM2sUul4gY/dAAx1TS5vjChGEb4jesYXr4SRyY+ytyoup57FFgNfeQE88tul4e5oqqfCoiOCv0 f3SYdwZ6uJvI0f/5YLsVOQCFQtJXTC2gePV1a20xboUDJqNKcS/V4IQyX+QHpYs4bZwDh2Q4kbQ BnVhiZNtKZIGNBI6RGjYJNcM1B8MnhkVT6CLT9A1v8bO4UGz+6eT6jX7xs9VvbwcLz2fgUulbGg OBMpFoaQUiYsZciu2xNkYSsUikfj5Zje/62uywnqw14D3CUwCTZFy6VUWujuHhP9X01X0GIuJ/l CiIf4JspYavrQkakWl1moiJAYMn7xMqvjyQMB4nTaKvhnwUGMk79ltLwAArOIB9PiX027C+stua /g+eAoAi2Ev+87maGm58qoVO32jz5yzTGKBGi5ae1Ihxwf1OjaA0G6HNoky8OdRzHZ9IeZrw X-Proofpoint-ORIG-GUID: KUzkORfUHJgnMncUlwMCM2j67GaH3zf3 X-Proofpoint-GUID: KUzkORfUHJgnMncUlwMCM2j67GaH3zf3 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 | 375 +++++++++++++++++++++++------------------- 1 file changed, 208 insertions(+), 167 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 2c73c8d3515d..36ec08b8d654 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3527,6 +3527,11 @@ static bool skip_alt_group(struct instruction *insn) return alt_insn->type =3D=3D INSN_CLAC || alt_insn->type =3D=3D INSN_STAC; } =20 +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 *validate_nextp); + /* * Follow the branch starting at the given instruction, and recursively fo= llow * any other branches (jumps). Meanwhile, track the frame pointer state at @@ -3536,10 +3541,9 @@ static bool skip_alt_group(struct instruction *insn) static int validate_branch(struct objtool_file *file, struct symbol *func, struct instruction *insn, struct insn_state state) { - struct alternative *alt; struct instruction *next_insn, *prev_insn =3D NULL; struct section *sec; - u8 visited; + bool validate_next; int ret; =20 if (func && func->ignore) @@ -3566,232 +3570,269 @@ static int validate_branch(struct objtool_file *f= ile, struct symbol *func, return 1; } =20 - visited =3D VISITED_BRANCH << state.uaccess; - if (insn->visited & VISITED_BRANCH_MASK) { - if (!insn->hint && !insn_cfi_match(insn, &state.cfi)) - return 1; + ret =3D validate_insn(file, func, insn, &state, + prev_insn, next_insn, + &validate_next); + if (!validate_next) + break; =20 - if (insn->visited & visited) + if (!next_insn) { + if (state.cfi.cfa.base =3D=3D CFI_UNDEFINED) return 0; - } else { - nr_insns_visited++; + if (file->ignore_unreachables) + return 0; + + WARN("%s%sunexpected end of section %s", + func ? func->name : "", func ? "(): " : "", + sec->name); + return 1; } =20 - if (state.noinstr) - state.instr +=3D insn->instr; + prev_insn =3D insn; + insn =3D next_insn; + } =20 - if (insn->hint) { - if (insn->restore) { - struct instruction *save_insn, *i; + return ret; +} =20 - i =3D insn; - save_insn =3D NULL; +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 *validate_nextp) +{ + struct alternative *alt; + u8 visited; + int ret; =20 - sym_for_each_insn_continue_reverse(file, func, i) { - if (i->save) { - save_insn =3D i; - break; - } - } + /* + * Indicate that, by default, the calling function should not + * validate the next instruction and validation should be + * stopped. That way this function can stop validation by just + * returning at any point before reaching the end of the function. + * + * If the end of this function is reached then that means that the + * validation should continue and the caller should validate the + * next instruction, so *validate_nextp will be set to true at + * that point. + */ + *validate_nextp =3D false; =20 - if (!save_insn) { - WARN_INSN(insn, "no corresponding CFI save for CFI restore"); - return 1; - } + visited =3D VISITED_BRANCH << statep->uaccess; + if (insn->visited & VISITED_BRANCH_MASK) { + if (!insn->hint && !insn_cfi_match(insn, &statep->cfi)) + return 1; =20 - if (!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 (insn->visited & visited) + return 0; + } else { + nr_insns_visited++; + } =20 - WARN_INSN(insn, "objtool isn't smart enough to handle this CFI save/r= estore combo"); - return 1; - } + if (statep->noinstr) + statep->instr +=3D insn->instr; =20 - insn->cfi =3D save_insn->cfi; - nr_cfi_reused++; - } + if (insn->hint) { + if (insn->restore) { + struct instruction *save_insn, *i; =20 - state.cfi =3D *insn->cfi; - } else { - /* XXX track if we actually changed state.cfi */ + i =3D insn; + save_insn =3D NULL; =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); + sym_for_each_insn_continue_reverse(file, func, i) { + if (i->save) { + save_insn =3D i; + break; + } } - } =20 - insn->visited |=3D visited; + if (!save_insn) { + WARN_INSN(insn, "no corresponding CFI save for CFI restore"); + return 1; + } =20 - if (propagate_alt_cfi(file, insn)) - return 1; + 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; =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; - } + 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 (skip_alt_group(insn)) - return 0; + statep->cfi =3D *insn->cfi; + } else { + /* XXX track if we actually changed statep->cfi */ =20 - if (handle_insn_ops(insn, next_insn, &state)) - return 1; + 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 - switch (insn->type) { + insn->visited |=3D visited; =20 - case INSN_RETURN: - return validate_return(func, insn, &state); + if (propagate_alt_cfi(file, insn)) + return 1; =20 - case INSN_CALL: - case INSN_CALL_DYNAMIC: - ret =3D validate_call(file, insn, &state); - if (ret) + 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; - - if (opts.stackval && func && !is_special_call(insn) && - !has_valid_stack_frame(&state)) { - WARN_INSN(insn, "call without frame pointer save/setup"); - return 1; } + } + } =20 - break; - - 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; - - } else if (insn->jump_dest) { - ret =3D validate_branch(file, func, - insn->jump_dest, state); - if (ret) { - BT_INSN(insn, "(branch)"); - return ret; - } - } + if (skip_alt_group(insn)) + return 0; =20 - if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL) - return 0; + if (handle_insn_ops(insn, next_insn, statep)) + return 1; =20 - break; + switch (insn->type) { =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; - } + case INSN_RETURN: + return validate_return(func, insn, statep); =20 - if (insn->type =3D=3D INSN_JUMP_DYNAMIC) - return 0; + case INSN_CALL: + case INSN_CALL_DYNAMIC: + ret =3D validate_call(file, insn, statep); + if (ret) + return ret; =20 - break; + 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 - case INSN_SYSCALL: - if (func && (!next_insn || !next_insn->hint)) { - WARN_INSN(insn, "unsupported instruction in callable function"); - return 1; - } + break; =20 - break; + 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 - case INSN_SYSRET: - if (func && (!next_insn || !next_insn->hint)) { - WARN_INSN(insn, "unsupported instruction in callable function"); - return 1; + } 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 (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL) return 0; =20 - case INSN_STAC: - if (!opts.uaccess) - break; + break; =20 - if (state.uaccess) { - WARN_INSN(insn, "recursive UACCESS enable"); - return 1; - } + 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 - state.uaccess =3D true; - break; + if (insn->type =3D=3D INSN_JUMP_DYNAMIC) + return 0; =20 - case INSN_CLAC: - if (!opts.uaccess) - break; + break; =20 - if (!state.uaccess && func) { - WARN_INSN(insn, "redundant UACCESS disable"); - return 1; - } + case INSN_SYSCALL: + if (func && (!next_insn || !next_insn->hint)) { + WARN_INSN(insn, "unsupported instruction in callable function"); + return 1; + } =20 - if (func_uaccess_safe(func) && !state.uaccess_stack) { - WARN_INSN(insn, "UACCESS-safe disables UACCESS"); - return 1; - } + break; =20 - state.uaccess =3D false; - break; + case INSN_SYSRET: + if (func && (!next_insn || !next_insn->hint)) { + WARN_INSN(insn, "unsupported instruction in callable function"); + return 1; + } =20 - case INSN_STD: - if (state.df) { - WARN_INSN(insn, "recursive STD"); - return 1; - } + return 0; =20 - state.df =3D true; + case INSN_STAC: + if (!opts.uaccess) break; =20 - case INSN_CLD: - if (!state.df && func) { - WARN_INSN(insn, "redundant CLD"); - return 1; - } + if (statep->uaccess) { + WARN_INSN(insn, "recursive UACCESS enable"); + return 1; + } =20 - state.df =3D false; - break; + statep->uaccess =3D true; + break; =20 - default: + case INSN_CLAC: + if (!opts.uaccess) break; + + if (!statep->uaccess && func) { + WARN_INSN(insn, "redundant UACCESS disable"); + return 1; } =20 - if (insn->dead_end) - return 0; + if (func_uaccess_safe(func) && !statep->uaccess_stack) { + WARN_INSN(insn, "UACCESS-safe disables UACCESS"); + return 1; + } =20 - if (!next_insn) { - if (state.cfi.cfa.base =3D=3D CFI_UNDEFINED) - return 0; - if (file->ignore_unreachables) - return 0; + statep->uaccess =3D false; + break; =20 - WARN("%s%sunexpected end of section %s", - func ? func->name : "", func ? "(): " : "", - sec->name); + case INSN_STD: + if (statep->df) { + WARN_INSN(insn, "recursive STD"); return 1; } =20 - prev_insn =3D insn; - insn =3D next_insn; + statep->df =3D true; + break; + + case INSN_CLD: + if (!statep->df && func) { + WARN_INSN(insn, "redundant CLD"); + return 1; + } + + statep->df =3D false; + break; + + default: + break; } =20 + if (insn->dead_end) + return 0; + + /* + * Indicate that the caller should validate the next + * instruction and continue the validation. + */ + *validate_nextp =3D true; + return 0; } =20 --=20 2.43.5 From nobody Sat Feb 7 08:07:06 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 EE2C928A40C for ; Fri, 6 Jun 2025 15:35: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=1749224108; cv=none; b=Ur34ta/MgVArfJcVl3qZk08ZlxfQzGjfeMj+39YdfBXEnrs+PjzNPKLhifZTgbR/BBVv7WMeI8xgOAibE8EAli+IwWXY2mKsOuaWWanxxQQOY21DBL4ExeH+qVNb2SCNXRi18GLi+VwQQMYB2UBHVcIHi2CZiC3XNRen/7sZX2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224108; c=relaxed/simple; bh=wf45yRpEwq5KiZcDz36ZHOLG9XlM2tWNLMFFlF385kY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UtmER+rwgaOmXDwjN317Kyq7pTci6fb1miOdiwV59R8zfzcT6JuWk36Z9UmXjbNvtluaBuvSO55DY6f1avdWhkx3TQ+R9BboObttpcsLJ1gL92YqrQV3H/FflUbLPpchF3ixFlwEjZuth5Dm6/lwnZXtPf0Pf4DFKw6HcB7XfDs= 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=kszUSr7b; 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="kszUSr7b" 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 5565MWAb002101; Fri, 6 Jun 2025 15:35:02 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=G4+f+ x8WW0xnNhwauAPhEewB+fqNtqeekRCjKKOKkv8=; b=kszUSr7bMRY1tjD/kw/6L FEyttZn5jB/KBErkPqj3XxhWZmyZPDx5wlQIQaj4jLUgY7pJz2hV0vlss1OE379a TgHQeaNJ+THaH97blIEuwoCHX/SDgKFzcdYEH0R1sUln7P5CQ3Wnct8+bRpSaOfw NspDdC/cyQ2ATfNdOrGtqhi3+pfdcGTM+PXifkdPX7jwwcFYC2QH1/J1OGBvvGBS VTqoARwIOCmOn8bVNszQ7Us/6AzKEzBRutmKpVwTG9vDq46dshbO/2Ynoc+017s8 e6CoN7+U1CkScCPcERobjWZn53c5ac87YhIvFhUZTbEPBKWDoyKqS/4jvY+E6zx5 g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471gahgag7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:02 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556EGXHo039442; Fri, 6 Jun 2025 15:35:01 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7desdx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:01 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3t015517; Fri, 6 Jun 2025 15:35:00 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-9; Fri, 06 Jun 2025 15:35:00 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [RFC 08/13] objtool: Record symbol name max length Date: Fri, 6 Jun 2025 17:34:35 +0200 Message-ID: <20250606153440.865808-9-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=aqqyCTZV c=1 sm=1 tr=0 ts=68430aa6 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=xKpiAcmDGk3KfUQPlkUA:9 X-Proofpoint-GUID: e1aT2PFvLXcXI2pJ_4RM6K48iuejL4A3 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX6A6eS7NrWZgb 60CsbyU2+rrEjaUBDPy5cN1GzVJOsciSu9P3vBHYZznFcgcCTcGtJqecppGn+UmB5ym5maIVYhA Tf9RdcAbqecxJvnmwlLofoSFUW58lExHA8uGDMLn6Ess4ssMQHqJidu/Bz/JWJ1KhS8DoqA54eG wn0LyjtJdlblg9mBR5jTmgClhhVoZuvY0wBIiBHRIs12odcaBEbksuWaz1uSYE3ft4MCxN5gbI0 P/CeEoFKeOXtElOrhwowCLHuH73ovwEnbFbT5XacvyLDwxCxRzh9wrBKA3ZeV29knryZFoi2iL2 6Z7OHT/XGhVBNcqGFAbnBndF+1HcpuKIaN0Z7Rxbz1gfR/aDZfRg5SEmHaw6kW9/6fJN3wIEqrN rCnnyECd+t/ritPyFRnCngyUVZBaHok8WrlrIqu1SIeb7C0vdIPz4Z2/sjmoPGU7nmwtnajw X-Proofpoint-ORIG-GUID: e1aT2PFvLXcXI2pJ_4RM6K48iuejL4A3 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 36ec08b8d654..300428cb5c2c 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -34,6 +34,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) { @@ -2458,6 +2460,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")) @@ -2484,6 +2487,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 Sat Feb 7 08:07:06 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 D56E528A712 for ; Fri, 6 Jun 2025 15:35: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=1749224111; cv=none; b=NoQIGCBfZoooJPEXeZlnD+kWebR1CZ89yKf7IIKzoNiMmE5s8kWhp73gkAesf0ENEd2q2tW3Llsnm56vOmWs1joaS/6pELIwPN690CaQ8lBy5Z3+fO5dQbqJ2jyfDVbF4DwK96rs0Bl26zlnaZEEo+tmt49B9hkh7ZpLlWCPpJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224111; c=relaxed/simple; bh=5VRcBlwWdFrzBO1gZwxKYh3RHAZZunOUilG2FYKP2c4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ak5H53mcFD42iU9/ZT01Tuaj56vEao7gge/Z5cKR+RwnI3wrpd+Sjsku/QL3HuhZjDSwItKaQDZMPS8pWtZ50Twu/Q/e9DelfqxOMdMfHZGsRCV4GzyafPuPFy9GQ5639xoVwTJXowSsBr/0JtZsG4q9m3SxORq3in2p4ZN+DGI= 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=i8xOlKOt; 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="i8xOlKOt" 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 5565Nd0Y003840; Fri, 6 Jun 2025 15:35: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=YQ4u7 YKzX0ON4oY/CU35826hOt/DbKIXfUFaOcdRH9g=; b=i8xOlKOtf9J/Rpww/lM5E 3HRmuqahlkgBPdYQE7Yajd+diJN/NVxjR0uAQjgUBmnAM08tt9kYHqzX24dEjVYF OmDkp7uRLUASr8Lkd31WWDknF3sv/4Y9k40sLZmwEwUjMKQ3nH7I+s4sM3xgFSl/ EcVlVnrNumOC25p4idX+yEcs0lHefFozeF/oqCNa+sytUYs/qgce30yvvwsDeLsY gcBjEa8yAzJzJ3WsJahaP6UutMrx1l+SnL510SteP/npVtUb2RfJUqB3WbD0tYAD htKPh4hqljZIkoIqtiHFCOfPMyow2qVdrQLh6yJ1TeubqSMdGm2yFm7AdQ5Y8ZKa A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471gahgaga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:04 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556EHAmA038592; Fri, 6 Jun 2025 15:35:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7desfe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:03 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3v015517; Fri, 6 Jun 2025 15:35:03 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-10; Fri, 06 Jun 2025 15:35:02 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [RFC 09/13] objtool: Add option to trace function validation Date: Fri, 6 Jun 2025 17:34:36 +0200 Message-ID: <20250606153440.865808-10-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=aqqyCTZV c=1 sm=1 tr=0 ts=68430aa8 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=6m_oaggMU0vmvekz6BQA:9 X-Proofpoint-GUID: qjQK7fmGsMVNBOSqSRIFg3gtUi0qjT1L X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX6xXqnDS0xO71 680QuWOVuAck64FUgH1Odil07pCEyxpipkdRC9xd2Jrvp0ApMyUVZCAAUu+qMTI/7+bvpQubUEN BDdHCFOjj+2rw7qiu+EHdHgIjoHFYA0pN0+auX74UyQWBggtwJPdOLx3524r9VRiPZM/sEdhrtD xYzauWMqbab/DMLo2M/I0TVDfuzLKlHLz1aludKJofZmy6Uv05mTBPTb3VYa7xSZrp48tP0jKll T0zTKn/CPVOcdeck7x/lE/JrrwvWC0H+OsKMsMsnJp8ZNhZGjhmD8pagQ7gIAJDLLkul8tACCzk 0NMOaKNn+RoWTF2c8vu/JOz63CSXBB+IS/ZXCNKS79WMJDzHm8m8ehPppWxOGUAWhkHXX5xJq5p RF3t9xpt8JPSDZp+zTWHB+ddwVq5Bg602Y3VonnE6WhtrK9ZmmTz4vKtk45MlYIjMvxrRvrK X-Proofpoint-ORIG-GUID: qjQK7fmGsMVNBOSqSRIFg3gtUi0qjT1L 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/builtin-check.c | 1 + tools/objtool/check.c | 179 ++++++++++++++++++++++-- tools/objtool/include/objtool/builtin.h | 1 + tools/objtool/include/objtool/check.h | 2 + tools/objtool/include/objtool/warn.h | 3 +- 5 files changed, 171 insertions(+), 15 deletions(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 80239843e9f0..ac7baf95f5bf 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -99,6 +99,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 300428cb5c2c..40eaac4b5756 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 @@ -36,6 +37,80 @@ static struct cfi_state force_undefined_cfi; =20 static size_t sym_name_max_len; =20 +static bool vtrace; +static int vtrace_depth; + +/* + * Validation traces are sent to stderr so that they are output + * on the same flow as warnings. + */ +#define VTRACE_PRINTF(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) + +#define VTRACE_INSN(insn, fmt, ...) \ + do { \ + if (vtrace) { \ + vtrace_insn(insn, fmt, ##__VA_ARGS__); \ + VTRACE_PRINTF("\n"); \ + } \ + } while (0) + +#define VTRACE_INSN_OFFSET_SPACE 10 +#define VTRACE_INSN_SPACE 60 + +/* + * Print an instruction address (offset and function), the instruction its= elf + * and an optional message. + */ +static void vtrace_insn(struct instruction *insn, const char *format, ...) +{ + char fake_nop_insn[32]; + const char *addr_str, *insn_str; + bool fake_nop; + va_list args; + int i, len; + + len =3D sym_name_max_len + VTRACE_INSN_OFFSET_SPACE; + + /* + * 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) { + addr_str =3D ""; + snprintf(fake_nop_insn, 32, " (%d bytes)", insn->len); + insn_str =3D fake_nop_insn; + } else { + addr_str =3D offstr(insn->sec, insn->offset); + insn_str =3D objtool_disas_insn(insn); + } + + /* print the instruction address */ + VTRACE_PRINTF("%6lx: %-*s ", insn->offset, len, addr_str); + + /* print vertical bars to show the validation flow */ + for (i =3D 1; i < vtrace_depth; i++) + VTRACE_PRINTF("| "); + + /* print the instruction */ + len =3D vtrace_depth * 2 < VTRACE_INSN_SPACE ? + VTRACE_INSN_SPACE - vtrace_depth * 2 : 1; + VTRACE_PRINTF("%-*s", len, insn_str); + + /* print message if any */ + if (format) { + VTRACE_PRINTF(" - "); + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + } + + insn->vtrace++; + + if (!fake_nop) + free((char *)addr_str); +} + struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset) { @@ -3511,8 +3586,10 @@ static bool skip_alt_group(struct instruction *insn) struct instruction *alt_insn =3D insn->alts ? insn->alts->insn : NULL; =20 /* ANNOTATE_IGNORE_ALTERNATIVE */ - if (insn->alt_group && insn->alt_group->ignore) + if (insn->alt_group && insn->alt_group->ignore) { + VTRACE_INSN(insn, "alt group ignored"); return true; + } =20 /* * For NOP patched with CLAC/STAC, only follow the latter to avoid @@ -3539,14 +3616,17 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, struct instruction *prev_insn, struct instruction *next_insn, bool *validate_nextp); =20 +static int validate_branch(struct objtool_file *file, struct symbol *func, + struct instruction *insn, struct insn_state state); + /* * 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) +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; @@ -3558,7 +3638,10 @@ static int validate_branch(struct objtool_file *file= , struct symbol *func, =20 sec =3D insn->sec; =20 - while (1) { + do { + + insn->vtrace =3D 0; + next_insn =3D next_insn_to_validate(file, insn); =20 if (func && insn_func(insn) && func !=3D insn_func(insn)->pfunc) { @@ -3570,6 +3653,8 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, if (file->ignore_unreachables) return 0; =20 + VTRACE_INSN(insn, "falls through to next function"); + WARN("%s() falls through to next function %s()", func->name, insn_func(insn)->name); func->warned =3D 1; @@ -3580,10 +3665,8 @@ static int validate_branch(struct objtool_file *file= , struct symbol *func, ret =3D validate_insn(file, func, insn, &state, prev_insn, next_insn, &validate_next); - if (!validate_next) - break; =20 - if (!next_insn) { + if (validate_next && !next_insn) { if (state.cfi.cfa.base =3D=3D CFI_UNDEFINED) return 0; if (file->ignore_unreachables) @@ -3595,9 +3678,17 @@ static int validate_branch(struct objtool_file *file= , struct symbol *func, return 1; } =20 + if (!insn->vtrace) { + if (ret) + VTRACE_INSN(insn, "validated (%d)", ret); + else + VTRACE_INSN(insn, NULL); + } + prev_insn =3D insn; insn =3D next_insn; - } + + } while (validate_next); =20 return ret; } @@ -3629,8 +3720,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) { + VTRACE_INSN(insn, "already visited"); return 0; + } } else { nr_insns_visited++; } @@ -3667,8 +3760,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) { + VTRACE_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; @@ -3696,13 +3791,24 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, return 1; =20 if (insn->alts) { + int i, count; + + count =3D 0; + for (alt =3D insn->alts; alt; alt =3D alt->next) + count++; + + i =3D 1; for (alt =3D insn->alts; alt; alt =3D alt->next) { + VTRACE_INSN(insn, "alternative %d/%d", i, count); ret =3D validate_branch(file, func, alt->insn, *statep); if (ret) { BT_INSN(insn, "(alt)"); return ret; } + i++; } + + VTRACE_INSN(insn, "alternative orig"); } =20 if (skip_alt_group(insn)) @@ -3714,10 +3820,12 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, switch (insn->type) { =20 case INSN_RETURN: + VTRACE_INSN(insn, "return"); return validate_return(func, insn, statep); =20 case INSN_CALL: case INSN_CALL_DYNAMIC: + VTRACE_INSN(insn, "call"); ret =3D validate_call(file, insn, statep); if (ret) return ret; @@ -3733,13 +3841,21 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, case INSN_JUMP_CONDITIONAL: case INSN_JUMP_UNCONDITIONAL: if (is_sibling_call(insn)) { + VTRACE_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) { + VTRACE_INSN(insn, "unconditional jump"); + ret =3D do_validate_branch(file, func, + insn->jump_dest, *statep); + } else { + VTRACE_INSN(insn, "jump taken"); + ret =3D validate_branch(file, func, + insn->jump_dest, *statep); + } if (ret) { BT_INSN(insn, "(branch)"); return ret; @@ -3749,10 +3865,12 @@ static int validate_insn(struct objtool_file *file,= struct symbol *func, if (insn->type =3D=3D INSN_JUMP_UNCONDITIONAL) return 0; =20 + VTRACE_INSN(insn, "jump not taken"); break; =20 case INSN_JUMP_DYNAMIC: case INSN_JUMP_DYNAMIC_CONDITIONAL: + VTRACE_INSN(insn, "dynamic jump"); if (is_sibling_call(insn)) { ret =3D validate_sibling_call(file, insn, statep); if (ret) @@ -3765,6 +3883,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_SYSCALL: + VTRACE_INSN(insn, "syscall"); if (func && (!next_insn || !next_insn->hint)) { WARN_INSN(insn, "unsupported instruction in callable function"); return 1; @@ -3773,6 +3892,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_SYSRET: + VTRACE_INSN(insn, "sysret"); if (func && (!next_insn || !next_insn->hint)) { WARN_INSN(insn, "unsupported instruction in callable function"); return 1; @@ -3781,6 +3901,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, return 0; =20 case INSN_STAC: + VTRACE_INSN(insn, "stac"); if (!opts.uaccess) break; =20 @@ -3793,6 +3914,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_CLAC: + VTRACE_INSN(insn, "clac"); if (!opts.uaccess) break; =20 @@ -3810,6 +3932,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_STD: + VTRACE_INSN(insn, "std"); if (statep->df) { WARN_INSN(insn, "recursive STD"); return 1; @@ -3819,6 +3942,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, break; =20 case INSN_CLD: + VTRACE_INSN(insn, "cld"); if (!statep->df && func) { WARN_INSN(insn, "redundant CLD"); return 1; @@ -3831,8 +3955,10 @@ static int validate_insn(struct objtool_file *file, = struct symbol *func, break; } =20 - if (insn->dead_end) + if (insn->dead_end) { + VTRACE_INSN(insn, "dead end"); return 0; + } =20 /* * Indicate that the caller should validate the next @@ -3843,6 +3969,18 @@ static int validate_insn(struct objtool_file *file, = struct symbol *func, return 0; } =20 +static int validate_branch(struct objtool_file *file, struct symbol *func, + struct instruction *insn, struct insn_state state) +{ + int ret; + + vtrace_depth++; + ret =3D do_validate_branch(file, func, insn, state); + vtrace_depth--; + + return ret; +} + static int validate_unwind_hint(struct objtool_file *file, struct instruction *insn, struct insn_state *state) @@ -4253,9 +4391,22 @@ 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) =3D=3D 0) { + vtrace =3D true; + vtrace_depth =3D 0; + VTRACE_PRINTF("%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)"); + + if (vtrace) { + VTRACE_PRINTF("%s: validation %s\n\n", + sym->name, ret ? "failed" : "end"); + vtrace =3D false; + } + return ret; } =20 @@ -4651,7 +4802,7 @@ 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); objtool_disas_ctx =3D disas_ctx; } diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index 6b08666fa69d..b3c84b6fdc5f 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -37,6 +37,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 92bfe6b209ad..1b9b399578ea 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -81,6 +81,8 @@ struct instruction { struct symbol *sym; struct stack_op *stack_ops; struct cfi_state *cfi; + + u32 vtrace; }; =20 static inline struct symbol *insn_func(struct instruction *insn) diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/o= bjtool/warn.h index 32a8dd299c87..0bb94f2d3ae4 100644 --- a/tools/objtool/include/objtool/warn.h +++ b/tools/objtool/include/objtool/warn.h @@ -96,7 +96,8 @@ static inline char *offstr(struct section *sec, unsigned = long offset) 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); \ + free(_str); \ + __insn->vtrace++; \ } \ }) =20 --=20 2.43.5 From nobody Sat Feb 7 08:07:06 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 EF9B028A72F for ; Fri, 6 Jun 2025 15:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224113; cv=none; b=j9nMO8B2qy5NfrDHABEr2XagbseJrYSAv3iU/w16XqO0Vy6Y47D2PgOx1oW2gxEMZz2MEBT6L7c3aAj9Q5D2VeUMWzNUonXJnl6PejCV77kY6CsE+7zGT/2IrXv8H5imsEaRyVKp/ldK4pzwTGMEvRMsWjl6CjDl0c24UnXB/Ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224113; c=relaxed/simple; bh=6Bblu348mo32rRnTruCxD/P6AYHqPJFxK0tzVbRIe7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GHp6UX0pEQY0jkmU9Jlb4kIAvFQUu+hvvFWjy+vo2ZZMMkqkjJH5y94zkuuYXdvOlKtx5M5YNq6qzFCvo2qKkP5VXgRGxbEcj2TVVsQIcqDakDBhe0GQ3MVzjVTNcWEcQ7eVGCwoIX94accslc9TyuOZ9iaQuLv3e+dtLQF1tyI= 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=RYIBqSxz; 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="RYIBqSxz" 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 5565Mteq030195; Fri, 6 Jun 2025 15:35:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=PRLnR 8PU0PfWjOaw1qk46DtX5R6mdIBS8buVTSqwDxU=; b=RYIBqSxzY+j3oar7pl0RC 4lRqM5nBXUk1kAyHl0wQC7JbZMyzmYXETqkmYZI0l3nYaJpdP2WYbiECI+gMNq4t euifI7v0QXs8CbR4gR/1Yli9Q42x9wXIdHx13/CMHvXJgfCgwPOEOsNRcg/UD8gQ DtwvlOdEJSmy1vA5tGa2romPG7D/2tkyrf+nlkVjHRpZlryBq1B5+zhKhv6jjMQi BFWCLv8M0aEoA3/diDMvp2SVwLq+ZjTsk7uO0Y519bLAH4frveCfKNSjAlv3lwZa 409rzqx+UzJEBBtXtvl9TzaAoIgEjitBlKxlK0T2MkIfB1dlCD+tgOqMFEozW5th w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471g8e087e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:06 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556DjJJ7038525; Fri, 6 Jun 2025 15:35:05 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7desgr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:05 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh3x015517; Fri, 6 Jun 2025 15:35:05 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-11; Fri, 06 Jun 2025 15:35:04 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [RFC 10/13] objtool: Trace instruction state changes during function validation Date: Fri, 6 Jun 2025 17:34:37 +0200 Message-ID: <20250606153440.865808-11-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=Va/3PEp9 c=1 sm=1 tr=0 ts=68430aaa cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=drXov0Ccr8RUBnCnCHQA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX0lIbybLshXxO 8K+nYizUUJa+/RXVOuQ+h079xxlHuR/y4Wb2WXS4ymUWaq6MwPPgZFt/Exj9u3PsLDXEyp+azhW CATo102vv713ToX5qYCbl5FSowG2dMpPiIvHz5IW8LCCY9GZj8ncg3ovjdCiL4kBhMdmP20nfm8 j8pWqWUgZt5q5WFerKDxFxJASzGxteY0RQpQBBmmRXCOPizD6kXQBDkM6Z01o2PKEMdYysLXhOt nF5mwB3ETsAXVOS97PbgbPbvltLKrrQ+AUOnkJuZ1gmtzUox8J51Shl7GFu1ZCWf0YmbrmUkwun k9MzLT+aM0zfh2B1hTLaiUHAe0CuYahcdkJ3gZqhQCVX6nJpOF1w9OcOozu4n8fQjmMh+BjkY3s JISQlu5OKdr/tNQFoZ5UNVWtQqVWpj0e3rL5hi+AHmf67RJDe+pbXjdDtLEa++YRJjvdBDNq X-Proofpoint-ORIG-GUID: 8sEli5ux3Vc1FmUomLOlD7wxC05mPr-4 X-Proofpoint-GUID: 8sEli5ux3Vc1FmUomLOlD7wxC05mPr-4 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 | 116 +++++++++++++++++++++++++- tools/objtool/disas.c | 27 ++++++ tools/objtool/include/objtool/check.h | 1 + 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 40eaac4b5756..050d34930372 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -111,6 +111,111 @@ static void vtrace_insn(struct instruction *insn, con= st char *format, ...) free((char *)addr_str); } =20 +/* + * Macros to trace CFI state attributes changes. + */ + +#define VTRACE_CFI_ATTR(attr, prev, next, fmt, ...) \ + do { \ + if ((prev)->attr !=3D (next)->attr) \ + VTRACE_PRINTF("%s=3D" fmt " ", #attr, __VA_ARGS__); \ + } while (0) + +#define VTRACE_CFI_ATTR_BOOL(attr, prev, next) \ + VTRACE_CFI_ATTR(attr, prev, next, \ + "%s", (next)->attr ? "true" : "false") + +#define VTRACE_CFI_ATTR_NUM(attr, prev, next, fmt) \ + VTRACE_CFI_ATTR(attr, prev, next, fmt, (next)->attr) + +/* + * Functions and macros to trace CFI registers changes. + */ + +static void vtrace_cfi_register(const char *prefix, int reg, const char *f= mt, + 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) + VTRACE_PRINTF("%s:", prefix); + + rname =3D register_name(reg); + + if (base_next =3D=3D CFI_UNDEFINED) { + VTRACE_PRINTF("%1$s=3D ", rname); + } else { + VTRACE_PRINTF(fmt, rname, + register_name(base_next), offset_next); + } +} + +static void vtrace_cfi_reg_value(const char *prefix, int reg, + int base_prev, int offset_prev, + int base_next, int offset_next) +{ + vtrace_cfi_register(prefix, reg, "%1$s=3D%2$s%3$+d ", + base_prev, offset_prev, base_next, offset_next); +} + +static void vtrace_cfi_reg_reference(const char *prefix, int reg, + int base_prev, int offset_prev, + int base_next, int offset_next) +{ + vtrace_cfi_register(prefix, reg, "%1$s=3D(%2$s%3$+d) ", + base_prev, offset_prev, base_next, offset_next); +} + +#define VTRACE_CFI_REG_VAL(reg, prev, next) \ + vtrace_cfi_reg_value(NULL, reg, prev.base, prev.offset, \ + next.base, next.offset) + +#define VTRACE_CFI_REG_REF(reg, prev, next) \ + vtrace_cfi_reg_reference(NULL, reg, prev.base, prev.offset, \ + next.base, next.offset) + +static void vtrace_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)) =3D=3D 0) + return; + + cprev =3D &sprev->cfi; + cnext =3D &snext->cfi; + + vtrace_insn(insn, NULL); + VTRACE_PRINTF(" - state: "); + + /* print registers changes */ + VTRACE_CFI_REG_VAL(CFI_CFA, cprev->cfa, cnext->cfa); + for (i =3D 0; i < CFI_NUM_REGS; i++) { + VTRACE_CFI_REG_VAL(i, cprev->vals[i], cnext->vals[i]); + VTRACE_CFI_REG_REF(i, cprev->regs[i], cnext->regs[i]); + } + + /* print attributes changes */ + VTRACE_CFI_ATTR_NUM(stack_size, cprev, cnext, "%d"); + VTRACE_CFI_ATTR_BOOL(drap, cprev, cnext); + if (cnext->drap) { + vtrace_cfi_reg_value("drap", cnext->drap_reg, + cprev->drap_reg, cprev->drap_offset, + cnext->drap_reg, cnext->drap_offset); + } + VTRACE_CFI_ATTR_BOOL(bp_scratch, cprev, cnext); + VTRACE_CFI_ATTR_NUM(instr, sprev, snext, "%d"); + VTRACE_CFI_ATTR_NUM(uaccess_stack, sprev, snext, "%u"); + + VTRACE_PRINTF("\n"); +} + struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset) { @@ -3698,6 +3803,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, struct instruction *prev_insn, struct instruction *next_insn, bool *validate_nextp) { + struct insn_state state_prev; struct alternative *alt; u8 visited; int ret; @@ -3814,7 +3920,15 @@ 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)) + if (vtrace) + state_prev =3D *statep; + + ret =3D handle_insn_ops(insn, next_insn, statep); + + if (vtrace) + vtrace_insn_state(insn, &state_prev, statep); + + if (ret) return 1; =20 switch (insn->type) { diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 1e198d5f9205..4326c608f925 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -29,6 +29,33 @@ struct disas_context { ((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__)) =20 =20 +#define REGISTER_NAME_MAXLEN 16 + +/* + * Return the name of a register. Note that the same static buffer + * is returned if the name is dynamically generated. + */ +const char *register_name(unsigned int reg) +{ + static char rname_buffer[REGISTER_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, REGISTER_NAME_MAXLEN, "r%d", reg) =3D=3D 1) + return NULL; + + return (const char *)rname_buffer; +} + static int dbuffer_init(struct dbuffer *dbuf, size_t size) { dbuf->used =3D 0; diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 1b9b399578ea..137d20963921 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -152,5 +152,6 @@ int disas_info_init(struct disassemble_info *dinfo, size_t disas_insn(struct disas_context *dctx, struct instruction *insn); char *disas_result(struct disas_context *dctx); const char *objtool_disas_insn(struct instruction *insn); +const char *register_name(unsigned int reg); =20 #endif /* _CHECK_H */ --=20 2.43.5 From nobody Sat Feb 7 08:07:06 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 8DE7F28A735 for ; Fri, 6 Jun 2025 15:35:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224115; cv=none; b=fPex5TxCl2P9EleU47yARBu5ycfYMfTaE/BvHYBuKIKA20554i7vhie8yvH/xLE2XA1hG9UizdOMKfnBBR+dzcsbKcPGC87a3vFFyd99MH6r5ojpIlAEW1Nsp1GQ1+HyJSiNj/ZkyDgDFYsGcy8n48dAzet181dnhzEZbZzUgGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224115; c=relaxed/simple; bh=dgMNb7nu3lnJ+1jnVGA/ngCPVqkJTEXfIFpETz3HFyU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IOv7I2WI5bL0kspui8/s6matib0/6lM3YN0Goaoc8Ld38GKkdpFdgwgOSsnJHLAnVdlx0oQXdCKVXxeNM4TxPbnmaEuOHMf2oDZ08CXNpNHH/62Y9DC8TcOzmy6R1OdfIBPjeqq0qOriJI3C4ET7c7JUw3zYwH6V9koDbev4/C4= 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=GFo1JNNt; 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="GFo1JNNt" 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 5565MZft030080; Fri, 6 Jun 2025 15:35: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=wIqqo /7E2WJ8UlpKCwyClHDZQx7NjCfXE9MZI+8M53M=; b=GFo1JNNtU8DtfYiVqw71F GVJs007b+7kddzy9+pF+Igyfd7kHea+kQUpCBTuUjj88mBg3c12FBFucGiNud4Px ywthMtvLnKBvU4/IjvXGUgFP2KBtXFvgfeBkxq6XaUigxWHHa+35FF3hGZMO1P7X 9qlBab6jYvRjsb7/CroZiLn4k7IeAkA3S0ibpWIJ2saK6K3w71CyIlT5UuVrqmPw p8ygOdbmxIdocsKgmay8UhrFPyIySLYVM8qZd7/ARXK1KM07CKKecmgff4Y1cbTM Af6ZQH6AxMdOeZm66u8bKDWxdz34DmnEjCPBK8KvHzgm0TF1LAp1k4eeHolqupgC w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471g8e087g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:08 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556Eshsx039288; Fri, 6 Jun 2025 15:35:07 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7desjb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:07 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh41015517; Fri, 6 Jun 2025 15:35:07 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-12; Fri, 06 Jun 2025 15:35: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: [RFC 11/13] objtool: Improve register reporting during function validation Date: Fri, 6 Jun 2025 17:34:38 +0200 Message-ID: <20250606153440.865808-12-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=Va/3PEp9 c=1 sm=1 tr=0 ts=68430aac cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=CogidulLUEdmuW3A26oA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfXx4CU7yTzBV5J maLSzd0flFMTqFuNXLqsGgkZYy3K/gQnIe4/j4QQFSDiOw0TKRW++6DYa9bsDcWN1ZKsmxKI7uV RF1Y3J/zQj/0JrwN8HFuRa4kyBamXZUNnFTTzIr/Gnoj3i7wcYBniD5xnWItUHZFYL8ORMFe8DW C8moURtp9W9sAdgg7PtbhATnEQ7uyry+cOa44J4zBLdI9Bal+PTNTSx+PpWqRWqi6FZKwpR/4Vt dRJyUaM2NMmgOLIIqSbWykmHb+nGzIK8SRpIFrTtpnE3n1Ij+RF7Mw+v+Ec8oHFaXh0z62WYT1I AwFz0F3VTflDo5iIylzFDz+LYMWLVdqVefplagVRIEY9ntve0bA8elM3FC3o4BBZ/AkB2o4g2sb e2zGsCV95MCoc2DrHd/GGp/JRl9Ru3C0F3aFYKQEoSlnEO6oKrPiuSvJrU5UBV/KxRxqKbxl X-Proofpoint-ORIG-GUID: 3210MFP6L7sjBEL_xe6PHwdRWL07PmeV X-Proofpoint-GUID: 3210MFP6L7sjBEL_xe6PHwdRWL07PmeV 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/disas.c | 7 +++++++ tools/objtool/include/objtool/arch.h | 2 ++ 5 files changed, 40 insertions(+) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loo= ngarch/decode.c index bf5ac6750512..fbad237e54fb 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -7,6 +7,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 c0fcab2d643c..df5bf6476b78 100644 --- a/tools/objtool/arch/powerpc/decode.c +++ b/tools/objtool/arch/powerpc/decode.c @@ -9,6 +9,18 @@ #include #include =20 +const char *arch_reg_name[CFI_NUM_REGS] =3D { + "r0", "sp", "r2", "r3", + "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", + "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", + "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", + "r28", "r29", "r30", "r31", + "ra" +}; + int arch_ftrace_match(char *name) { return !strcmp(name, "_mcount"); diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 6c13c67ed9b9..56e2df35c9ee 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -23,6 +23,14 @@ #include #include =20 +const char *arch_reg_name[CFI_NUM_REGS] =3D { + "rax", "rcx", "rdx", "rbx", + "rsp", "rbp", "rsi", "rdi", + "r8", "r9", "r10", "r11", + "r12", "r13", "r14", "r15", + "ra" +}; + int arch_ftrace_match(char *name) { return !strcmp(name, "__fentry__"); diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 4326c608f925..8265ad7479a3 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -38,6 +38,7 @@ struct disas_context { const char *register_name(unsigned int reg) { static char rname_buffer[REGISTER_NAME_MAXLEN]; + const char *rname; =20 switch (reg) { case CFI_UNDEFINED: @@ -50,6 +51,12 @@ const char *register_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, REGISTER_NAME_MAXLEN, "r%d", reg) =3D=3D 1) return NULL; =20 diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index aecf8fc29571..4736b08805d6 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -106,4 +106,6 @@ unsigned long arch_jump_table_sym_offset(struct reloc *= reloc, struct reloc *tabl =20 int arch_disas_info_init(struct disassemble_info *dinfo); =20 +extern const char *arch_reg_name[CFI_NUM_REGS]; + #endif /* _ARCH_H */ --=20 2.43.5 From nobody Sat Feb 7 08:07:06 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 418C728B407 for ; Fri, 6 Jun 2025 15:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224118; cv=none; b=HbtYCsalU8Jn25U5AfMTxZB9l19YktbFxVUlESZHeEmjVHS/7S7mzDRng3c/rNNdsw5p/fCv3Q35Dqww4t1CAUybtXMcbO5kjv1rWGKwMtAizriMTDQHRpq45wENqem19B1za8ar9Yv4h5vO0qLEDnMc+2HY3imz43HDMAhafbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224118; c=relaxed/simple; bh=pNz8oI4NgRu/uensBbLsGjNJQn6uHB9jVjTVFyCtJ4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BSZaaXyvlZiYlT9x1jxu21P/6R2mQNXucV7CKmcKmtdpjryzbIElLZ6ojHErcnsd/C75Zfn7mhjJOJ7H2zSvX12/P0ZOtHljw1I+152lfGPqT6zouFGVQ1S8emiTT6UNnd/6Fmy9t5jBNcJgXHdfn5ksa+glBeU7VEh3NHLzzvc= 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=mNBcPPCC; 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="mNBcPPCC" 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 5565MZla011741; Fri, 6 Jun 2025 15:35:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=f38ZA 5UozH5ByoH9pR2Me3XWlBHPHaaOZKuA3m4xCvo=; b=mNBcPPCCrNvUL9SWEX+zF wtMfnFD1CxwA9eEKB4G2cQy6D0INZKIN9FFtwspSyzMjdEWKr1WHYYj492TH3yzW FzUzTF03RndBP0E96ioasVIRkHaCM/Fr1k5MuGordPALlFy07ew5FAFgWcCZjQ5l NtsxitRKc2F+SKLHhW3DDgwbfUNiyIz33Rp98MD3p8Uc4d+sY/+1uWijvbL502wy vKQdkL6+wBPGgal7NYUPY5AniLpu5dwsQZgFyjbqcMII06MXqDCreMrEkljxP7Q9 K3i2V3TT4X/DkyJAdegRTWSDuVsrfcfXMRaeUPriv3jeYVPYxaGnSXuH5hi8nwee Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471g8j89dy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:12 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556Ejvkt039147; Fri, 6 Jun 2025 15:35:10 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7desmc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:10 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh43015517; Fri, 6 Jun 2025 15:35:09 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-13; Fri, 06 Jun 2025 15:35: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: [RFC 12/13] objtool: Improve tracing of alternative instructions Date: Fri, 6 Jun 2025 17:34:39 +0200 Message-ID: <20250606153440.865808-13-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Proofpoint-GUID: hhTm_Y8lnZ6qNsoBXw5vdrtJCrxJL3O3 X-Proofpoint-ORIG-GUID: hhTm_Y8lnZ6qNsoBXw5vdrtJCrxJL3O3 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfX1XcM7KO0aCQq Futq2/ZXyc09l51rO2FmdQvHev7IKAL29JbogRGkJG7PMgoCL5HxJevXsgw5BfmRutB8e7nUIlX P6xAnhp0oewvlAqeTsaRwjiYV3HdqjPuEmNQ9vZDHfPJRswKOeET/r52WUi/y3JvwsYxdBrj5Ia QNW+s29Pxrb771+wqHkIVU5JDXJN1vNIrf6yCFJxeD6a/UbUdEMHN1/8ycE27Yt2EQl8dZgS8o3 hq3aQ4VcxKvFuvhEqKQo68ZwsCiN71WR432t61mSdKkPWwfZKyvRPeAjU1sxuc6JUXLkEsBbQqX NxxN4+Lx+CTDL4eXBU4Y/bvr/8V1gdXy+NmAy6M1SYS2gRlVMSAf5O9iPVBeby7yOUcVxK5sRxK H0J3Y6liJ+/X/O1mDxaK3SNm87ktFecUYruB0eZUoNSHwEAYcT+XZgv14kgmbTDJFhjdYX8W X-Authority-Analysis: v=2.4 cv=QI1oRhLL c=1 sm=1 tr=0 ts=68430ab0 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=RxUVdm5A3GcFcKIcQO8A: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 | 59 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 050d34930372..afcb6c67daa9 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -54,9 +54,61 @@ static int vtrace_depth; } \ } while (0) =20 +#define VTRACE_INFO(insn, fmt, ...) \ + do { \ + if (vtrace) \ + vtrace_info(insn, fmt, ##__VA_ARGS__); \ + } while (0) + +#define VTRACE_ALT_FMT(fmt) " alt " fmt + +#define VTRACE_ALT(insn, fmt, ...) \ + VTRACE_INSN(insn, VTRACE_ALT_FMT(fmt), \ + (insn)->offset, ##__VA_ARGS__) + +#define VTRACE_ALT_INFO(insn, fmt, ...) \ + VTRACE_INFO(insn, VTRACE_ALT_FMT(fmt), \ + (insn)->offset, ##__VA_ARGS__) + +#define VTRACE_ALT_INFO_NOADDR(insn, fmt, ...) \ + VTRACE_INFO(NULL, VTRACE_ALT_FMT(fmt), \ + (insn)->offset, ##__VA_ARGS__) + #define VTRACE_INSN_OFFSET_SPACE 10 #define VTRACE_INSN_SPACE 60 =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. + */ +static void vtrace_info(struct instruction *insn, const char *format, ...) +{ + const char *addr_str; + va_list args; + int len; + int i; + + len =3D sym_name_max_len + VTRACE_INSN_OFFSET_SPACE; + if (insn) { + addr_str =3D offstr(insn->sec, insn->offset); + VTRACE_PRINTF("%6lx: %-*s ", insn->offset, len, addr_str); + } else { + len +=3D 11; + VTRACE_PRINTF("%-*s", len, ""); + } + + /* print vertical bars to show the validation flow */ + for (i =3D 1; i < vtrace_depth; i++) + VTRACE_PRINTF("| "); + + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + VTRACE_PRINTF("\n"); +} + /* * Print an instruction address (offset and function), the instruction its= elf * and an optional message. @@ -3692,7 +3744,7 @@ static bool skip_alt_group(struct instruction *insn) =20 /* ANNOTATE_IGNORE_ALTERNATIVE */ if (insn->alt_group && insn->alt_group->ignore) { - VTRACE_INSN(insn, "alt group ignored"); + VTRACE_ALT(insn, "alt group ignored"); return true; } =20 @@ -3905,8 +3957,9 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, =20 i =3D 1; for (alt =3D insn->alts; alt; alt =3D alt->next) { - VTRACE_INSN(insn, "alternative %d/%d", i, count); + VTRACE_ALT_INFO(insn, "%d/%d begin", i, count); ret =3D validate_branch(file, func, alt->insn, *statep); + VTRACE_ALT_INFO_NOADDR(insn, "%d/%d end", i, count); if (ret) { BT_INSN(insn, "(alt)"); return ret; @@ -3914,7 +3967,7 @@ static int validate_insn(struct objtool_file *file, s= truct symbol *func, i++; } =20 - VTRACE_INSN(insn, "alternative orig"); + VTRACE_ALT_INFO(insn, "default"); } =20 if (skip_alt_group(insn)) --=20 2.43.5 From nobody Sat Feb 7 08:07:06 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 0ECD328B41E for ; Fri, 6 Jun 2025 15:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224120; cv=none; b=VeP5ue8FR8xBYwYEUzaeUbQT6S9Ul6MJSrzUGu6cM+jA3HyzqMW1cwQN41sTkQCdZtxtZ0Qbk7f9+/oki8WAa2PFQcFZzxlZeyRPvyan9deOvjlb78AbT1v1oSprYihBWgw353RiBSeU/sXGMhHyyb1fqor1B325puwcovuGxMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749224120; c=relaxed/simple; bh=eapQH9Pu3xNVR8smEr7tNLOEPObMvHtSxQXhpF37H8Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rBAcfxPQApqLgsoh+KgIYyWZnqgbZRYgO59ooKNkcEaXZiilRjcBXWKkABG2okFyklOEvoTKXj8s/+Ur8Z71dmFDq62AiMUOuErS+FF7ySMX/vc4gd9RyUIVU3XT0HY9JF8nxwSSz4AUAkYKOZ6lK1lNqgNIZ9tDthcvH0tu2kU= 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=dp8+meFx; 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="dp8+meFx" 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 5565MWvU002076; Fri, 6 Jun 2025 15:35:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=qKWmo QacCgmw1/3xvcsQO6P0KgtNTrg1orkARsvgoVg=; b=dp8+meFxWEZ3QGs3c/AQg iMz48JYRCBSIlB5Qve0VG0QKceQWd8o8dUg9IxdteqJI8CUw7gzqBwj0VIcJabaR DiAq86tFeLGvfFvv8nbMyvxenK8a6sVNWvuAU6PYMr8qSr8uftw1ef/3iyORGdtF EkFW4uMnlVlMFdMuxtjMDuNMgEsTHbsw/UF9npJz4MGScE6RQ2J0mVmaohNBbcsb 1RQDaLthOq1UjOIscf2ejA8uWJweeL7mJ2uuvdvmtTLp8qWt1ogwCIVG3H45zrbn NvJ5cB2r7XgBagU6r3QVjY3Nn15mpP0V/1iN9LrNnXEuv2KROHWSc+QThc55ObrG A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 471gahgags-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:13 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 556ERKe8039260; Fri, 6 Jun 2025 15:35:12 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 46yr7despk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Jun 2025 15:35:12 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 556FYh45015517; Fri, 6 Jun 2025 15:35:11 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-187-118.vpn.oracle.com [10.154.187.118]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 46yr7des15-14; Fri, 06 Jun 2025 15:35:11 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org Cc: alexandre.chartre@oracle.com Subject: [RFC 13/13] objtool: Do not validate IBT for .return_sites and .call_sites Date: Fri, 6 Jun 2025 17:34:40 +0200 Message-ID: <20250606153440.865808-14-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250606153440.865808-1-alexandre.chartre@oracle.com> References: <20250606153440.865808-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.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-06_05,2025-06-05_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506060136 X-Authority-Analysis: v=2.4 cv=aqqyCTZV c=1 sm=1 tr=0 ts=68430ab1 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6IFa9wvqVegA:10 a=yPCof4ZbAAAA:8 a=yvIqsss6GtJD96b7xZoA:9 X-Proofpoint-GUID: uYYyFBdp_eo6C9GSYKr6E653Ii9VcV2i X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjA2MDEzNyBTYWx0ZWRfXx7WY+3vCKjOe 7+uRcx2V5CuxraB4EJ+1pcW0QBlWxUpxvmritY76Evjyo25bzo2FRilV8f0rP5TN/4SUkUTtlyK VLHwk+X4HceSVbryN/Edlc0b4rsteG4cr4TtdnUbcBA8NOEopKczGk705kXFSKNXnnckfaRoLdn rGGvkydmvesHsRFSyUj+/pmRzIf48OUotwsbLTs2XKcrIf3eq2KHyVSNJsrJos0Z42KyfmhSYgH PAPIff3ipOvPk++fNsND6+J/axx6o2hsFVOhtb8n93v51MCJAAUnu4fXKoPEi7rvrDS5dYJqsSK DSBToVSZowFW3S+uF+SU9Y8WqSgjU+9frgIo1zOn5G04eG5p9SJCgLMw7cSQJF8Jb+0NMmB7s8V R9WvqMjvTj4AcpmrzrB2f6TIRib3IHJTcQIDUojjK0gfcoCTdwMYHqP8PUwYKDz/M23RIQLO X-Proofpoint-ORIG-GUID: uYYyFBdp_eo6C9GSYKr6E653Ii9VcV2i 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 afcb6c67daa9..6d81dabef64e 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4844,6 +4844,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