From nobody Tue Dec 2 02:30:05 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD9AF2848A4 for ; Wed, 19 Nov 2025 14:33:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562835; cv=none; b=Z+GF0jtRLleBo0exQnZxLEhFTkCVIEdhpTaS+qFczFdNfuiFo0JwBUb21V3KJ/PZK7OKyMKMtVuEIE2JjF6Isg84oRZxUk7miDxAwvPCbmS2IgeNviHUCaoKALYw5Vp3hWQYPgUBxSVLncaefnicChcPecqDiid93MU5/JQO/U4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562835; c=relaxed/simple; bh=4r2fnDbYLsWGf8TBITmoF2L6L72mfBIVJdl15PRCAQg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IAk0CERvTNmco8Xr4ii8LyPhwsL+CfUkpEmHvmUQ+L9a5d95P0Y2efkdRqdNZGvk+tSZaMskbyX+oY0M/HMmFvw7RM3zz5x77pWC9e9nVRASrns3f9dYHtaxlBhM93tuUWLBnd+r62GJKEh6FrkRdhNYDOpZxceN+VJxgSt5EHw= 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=XLBVv/2Q; 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="XLBVv/2Q" 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 5AJEREUH014375; Wed, 19 Nov 2025 14:33:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=corp-2025-04-25; bh=WAU7Y N4+oqekL6Xpra6xul3Ker5oQk+wV5NYbPpSYfs=; b=XLBVv/2QGFagxu7IGogZf 1laZyKYqUO/f55w3WTOiOG9nK5k5f4j7LrFaNL18ro3Yz3ssmep/Qc9UqJMbJaDD R+xRs5y6Y9qt1VdlpbIG8mSWpM1xfqnFrl+xU/z5+cQChfY8fVi5qaDXkE+mkEkR GebdCKOlaKL4aAgp2ojr0hEfbHyvh1VUWYhn38Dnnd7rga2v2LeAjm3jdWzXveFX 1+p6bmDULZ3njRxhDBkCFP0CE4LxICgZuHmk8R7jADFBhZvm/z//qT9wjIf70ouN MqznpBg/LHeMvZrPHHXRdGQ0Gli7UOIiR3VqgGbkyGi996eF6nO36HSQFE82ljF7 Q== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej9077bw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:17 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJCs2JV002711; Wed, 19 Nov 2025 14:33:16 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyanrp8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:16 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5AJEWnnW022495; Wed, 19 Nov 2025 14:33:16 GMT Received: from laptop-dell-latitude7430.nl.oracle.com (dhcp-10-154-160-110.vpn.oracle.com [10.154.160.110]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4aefyanr5p-15; Wed, 19 Nov 2025 14:33:16 +0000 From: Alexandre Chartre To: linux-kernel@vger.kernel.org, mingo@kernel.org, jpoimboe@kernel.org, peterz@infradead.org, david.laight.linux@gmail.com Cc: alexandre.chartre@oracle.com Subject: [PATCH v5 14/30] objtool: Add functions to better name alternatives Date: Wed, 19 Nov 2025 15:32:31 +0100 Message-ID: <20251119143247.3944213-15-alexandre.chartre@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20251119143247.3944213-1-alexandre.chartre@oracle.com> References: <20251119143247.3944213-1-alexandre.chartre@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-19_04,2025-11-18_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511190116 X-Authority-Analysis: v=2.4 cv=OMAqHCaB c=1 sm=1 tr=0 ts=691dd52d b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=20KFwNOVAAAA:8 a=ejOSxiM7Qr7sFksKtvQA:9 X-Proofpoint-ORIG-GUID: rRhGPZSzZgj2f1Z-1lG9083Ut-zEdjRq X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX98p3AXG+BdXg UmV7kJvs7wrSHV4w05ojqNXyvwlxpKG3nDk5W5CVzfWu5nawR+jj/tANOieQkaIZiH9DP1k5aRt FoZeJro87okbyE50dQJqLRF9WEkAWeljFwgOYzJ3jsOMtvXm+sZVra+bq20xQjITITfyyb6KwJO WD9RVj12vrAxDkGArNxNPtoyBRuCoJvpX7ih+8wBb8cqRiOtFabrTkDAic51ZsWEyV6eNw19FVf 8RUGM/yZXjM8cclhg/BZd+Yo+ehTqEAjdIH0D8uU9LUbNQPsZmsrKzZGDokORSq6kthjLUEMHPD /vvZo2TkTdGV4CIcBA6ZOq3scFxulqiXxD8M4LdliZr2KQPU4pw11YV8Xn4GFD5gwSlhIk0GyST wr3/USSB4a1iTxC5ubk1YINTrgH6YQ== X-Proofpoint-GUID: rRhGPZSzZgj2f1Z-1lG9083Ut-zEdjRq Content-Type: text/plain; charset="utf-8" Add the disas_alt_name() and disas_alt_type_name() to provide a name and a type name for an alternative. This will be used to better name alternatives when tracing their execution. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 72 +++++++++++++++++++++++++++ tools/objtool/include/objtool/disas.h | 12 +++++ 2 files changed, 84 insertions(+) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index 0ca6e6c8559fd..b53be240825da 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -3,6 +3,8 @@ * Copyright (C) 2015-2017 Josh Poimboeuf */ =20 +#define _GNU_SOURCE + #include #include #include @@ -450,6 +452,76 @@ size_t disas_insn(struct disas_context *dctx, struct i= nstruction *insn) return disasm(insn->offset, &dctx->info); } =20 +/* + * Provide a name for the type of alternatives present at the + * specified instruction. + * + * An instruction can have alternatives with different types, for + * example alternative instructions and an exception table. In that + * case the name for the alternative instructions type is used. + * + * Return NULL if the instruction as no alternative. + */ +const char *disas_alt_type_name(struct instruction *insn) +{ + struct alternative *alt; + const char *name; + + name =3D NULL; + for (alt =3D insn->alts; alt; alt =3D alt->next) { + if (alt->type =3D=3D ALT_TYPE_INSTRUCTIONS) { + name =3D "alternative"; + break; + } + + switch (alt->type) { + case ALT_TYPE_EX_TABLE: + name =3D "ex_table"; + break; + case ALT_TYPE_JUMP_TABLE: + name =3D "jump_table"; + break; + default: + name =3D "unknown"; + break; + } + } + + return name; +} + +/* + * Provide a name for an alternative. + */ +char *disas_alt_name(struct alternative *alt) +{ + char *str =3D NULL; + + switch (alt->type) { + + case ALT_TYPE_EX_TABLE: + str =3D strdup("EXCEPTION"); + break; + + case ALT_TYPE_JUMP_TABLE: + str =3D strdup("JUMP"); + break; + + case ALT_TYPE_INSTRUCTIONS: + /* + * This is a non-default group alternative. Create a unique + * name using the offset of the first original and alternative + * instructions. + */ + asprintf(&str, "ALTERNATIVE %lx.%lx", + alt->insn->alt_group->orig_group->first_insn->offset, + alt->insn->alt_group->first_insn->offset); + break; + } + + return str; +} + /* * Disassemble a function. */ diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/= objtool/disas.h index 5db75d06f2197..8959d4c455622 100644 --- a/tools/objtool/include/objtool/disas.h +++ b/tools/objtool/include/objtool/disas.h @@ -6,6 +6,7 @@ #ifndef _DISAS_H #define _DISAS_H =20 +struct alternative; struct disas_context; struct disassemble_info; =20 @@ -24,6 +25,8 @@ void disas_print_info(FILE *stream, struct instruction *i= nsn, int depth, void disas_print_insn(FILE *stream, struct disas_context *dctx, struct instruction *insn, int depth, const char *format, ...); +char *disas_alt_name(struct alternative *alt); +const char *disas_alt_type_name(struct instruction *insn); =20 #else /* DISAS */ =20 @@ -61,6 +64,15 @@ static inline void disas_print_info(FILE *stream, struct= instruction *insn, static inline void disas_print_insn(FILE *stream, struct disas_context *dc= tx, struct instruction *insn, int depth, const char *format, ...) {} +static inline char *disas_alt_name(struct alternative *alt) +{ + return NULL; +} + +static inline const char *disas_alt_type_name(struct instruction *insn) +{ + return NULL; +} =20 #endif /* DISAS */ =20 --=20 2.43.5