From nobody Tue Dec 2 02:30:07 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81E72366DD8 for ; Wed, 19 Nov 2025 14:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.165.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562810; cv=none; b=HnmrX8ZHRLE22JOIlRopD1uwrNjwlMULprZfKMo5d0m8basK0jAax/bcNSUC3T5k6Q9JTdc3pHxZi0lddmdWzSOpLukyMLAOKmLnOdKjHoq+caDhAN9WOC2BigM4DbTbCtE4K4yz7DOB+9PsWt7McWUt7yp/EZVQn4pUQKi0wWE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562810; c=relaxed/simple; bh=i3WA1QZmJqbW2yAAB6OrBZDMl1dOFJZ3Ewd690cDo4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mL1U8urRyVhLw0vwfTVlHPUtlCibtx2UGsCvOFKwWH5yIwQJal1ZvuWUxiFqW0YEZJr0Ptq+uy0xx+j3zSRLgBfFbYxKob/9zbTCyDLmPBXzRfiKDNSnGK9Rg9hse9e7suZhs++EdvRmlmOFgrz3UZRIXySm0yAZt5etkHqs8tw= 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=dIJvI9V7; arc=none smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dIJvI9V7" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJER0Bb012005; Wed, 19 Nov 2025 14:33: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=DAOmw fvpy7JkJWn5tQTT+kXs1v6gly525QPLmSGGH+o=; b=dIJvI9V7sikxRFmm0N6Fw eHqE7GUJCkPiZYYvuN/SRaZia95S4HTkjTzgyXaerI2WEcN+lRhwlCCbT+kcTvIJ hs2y9hkqkorraTTWl4GD+o64lMIN8fRjYZJ4rgN5aI7e3SqQI5ILKgx1OtgcAJjj HfVLIe+bUiTZOKNHF7lcNoAtsn328alpTAuGUhlmC09jVP61KtiD9Yb1NYKAbacR yjCRoK44v2TfGQ4PcPnI4JYPQmtimWKJEAuKanjwhUh1vH7/2n1876yP3/gFUfaB B0AoNO6SidsR0gc5pRfinlP/4srTpqcmAyXKXMLMTDLiKpREqbSTI0f2vMeVg2jI A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbpy3ts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:01 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJDAi9l002590; Wed, 19 Nov 2025 14:33:01 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyanrd6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:01 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5AJEWnnG022495; Wed, 19 Nov 2025 14:33:00 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-7; Wed, 19 Nov 2025 14:33:00 +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 06/30] objtool: Store instruction disassembly result Date: Wed, 19 Nov 2025 15:32:23 +0100 Message-ID: <20251119143247.3944213-7-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-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX4pcoG2Ke1oSN yFp9jL7hmYqJ48gqXEbA4DrgndFsEv6GSFFpZoNuM0LYhwLveOD0MReNpTixGHhsY0kgvWXyogj 0D/G4qKjSdiMsfxv7XsVbu1rghKYgM7+ADwmx1u4OBzMgQ4anA8I1kHVf92ykt0RiLheDDW9lII SkIkk3Np5lt0//u7iUuHiskLgDRsZyhA6icVnnfiZSHRylQiKuOu8f/nLBOhZ9uW3sOuKUHLsWv A/Nb6Kj7jU51oemZKc6YhYiAxEextipQd+ZvLFbZKyQ8iq5bO3cY4WC1l+87YsvkW4ZSDBfQUVd A1u99GP4WIiSIW6GOolixlmLIBKqYLXRyeOljN/Su68WPvWesVoPzAgltvG91nH5TzN8tDIsAU7 Au3RLuGwmplNUtqPj+OfnYw+6H+q8A== X-Proofpoint-ORIG-GUID: wr1x5eNkiBV6tOgXsPPw_gmY2LXvhcg_ X-Proofpoint-GUID: wr1x5eNkiBV6tOgXsPPw_gmY2LXvhcg_ X-Authority-Analysis: v=2.4 cv=a+o9NESF c=1 sm=1 tr=0 ts=691dd51e b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=jcmHYjYDc9FjrwFKAggA:9 Content-Type: text/plain; charset="utf-8" When disassembling an instruction store the result instead of directly printing it. Signed-off-by: Alexandre Chartre --- tools/objtool/disas.c | 77 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-) diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c index dee10ab86fa29..89daa121b40b0 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -12,9 +12,16 @@ #include #include =20 +/* + * Size of the buffer for storing the result of disassembling + * a single instruction. + */ +#define DISAS_RESULT_SIZE 1024 + struct disas_context { struct objtool_file *file; struct instruction *insn; + char result[DISAS_RESULT_SIZE]; disassembler_ftype disassembler; struct disassemble_info info; }; @@ -34,6 +41,59 @@ static int sprint_name(char *str, const char *name, unsi= gned long offset) #define DINFO_FPRINTF(dinfo, ...) \ ((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__)) =20 +static int disas_result_fprintf(struct disas_context *dctx, + const char *fmt, va_list ap) +{ + char *buf =3D dctx->result; + int avail, len; + + len =3D strlen(buf); + if (len >=3D DISAS_RESULT_SIZE - 1) { + WARN_FUNC(dctx->insn->sec, dctx->insn->offset, + "disassembly buffer is full"); + return -1; + } + avail =3D DISAS_RESULT_SIZE - len; + + len =3D vsnprintf(buf + len, avail, fmt, ap); + if (len < 0 || len >=3D avail) { + WARN_FUNC(dctx->insn->sec, dctx->insn->offset, + "disassembly buffer is truncated"); + return -1; + } + + return 0; +} + +static int disas_fprintf(void *stream, const char *fmt, ...) +{ + va_list arg; + int rv; + + va_start(arg, fmt); + rv =3D disas_result_fprintf(stream, fmt, arg); + va_end(arg); + + return rv; +} + +/* + * For init_disassemble_info_compat(). + */ +static int disas_fprintf_styled(void *stream, + enum disassembler_style style, + const char *fmt, ...) +{ + va_list arg; + int rv; + + va_start(arg, fmt); + rv =3D disas_result_fprintf(stream, fmt, arg); + va_end(arg); + + return rv; +} + static void disas_print_addr_sym(struct section *sec, struct symbol *sym, bfd_vma addr, struct disassemble_info *dinfo) { @@ -195,9 +255,8 @@ struct disas_context *disas_context_create(struct objto= ol_file *file) dctx->file =3D file; dinfo =3D &dctx->info; =20 - init_disassemble_info_compat(dinfo, stdout, - (fprintf_ftype)fprintf, - fprintf_styled); + init_disassemble_info_compat(dinfo, dctx, + disas_fprintf, disas_fprintf_styled); =20 dinfo->read_memory_func =3D buffer_read_memory; dinfo->print_address_func =3D disas_print_address; @@ -244,6 +303,11 @@ void disas_context_destroy(struct disas_context *dctx) free(dctx); } =20 +static char *disas_result(struct disas_context *dctx) +{ + return dctx->result; +} + /* * Disassemble a single instruction. Return the size of the instruction. */ @@ -254,6 +318,7 @@ static size_t disas_insn(struct disas_context *dctx, struct disassemble_info *dinfo =3D &dctx->info; =20 dctx->insn =3D insn; + dctx->result[0] =3D '\0'; =20 if (insn->type =3D=3D INSN_NOP) { DINFO_FPRINTF(dinfo, "nop%d", insn->len); @@ -282,10 +347,10 @@ static void disas_func(struct disas_context *dctx, st= ruct symbol *func) printf("%s:\n", func->name); sym_for_each_insn(dctx->file, func, insn) { addr =3D insn->offset; - printf(" %6lx: %s+0x%-6lx ", - addr, func->name, addr - func->offset); disas_insn(dctx, insn); - printf("\n"); + printf(" %6lx: %s+0x%-6lx %s\n", + addr, func->name, addr - func->offset, + disas_result(dctx)); } printf("\n"); } --=20 2.43.5