From nobody Tue Dec 2 02:30:06 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 49E45369237 for ; Wed, 19 Nov 2025 14:33:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562825; cv=none; b=UtrZIHWUtGQbinMhGI4jLzIE70pA0YDgq7egaW8SsWT3HvH7JURKaG38njl3nX7kofVKUlrXbRBVs0Mp/1UhZ89m9InNeavTpVH5jh1guSMH88MAJd8PDh7P8+VmdinDCn/oR8fWHrRgjJo2xJRBgiCQAvW+QPOqsBoqAEso10E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763562825; c=relaxed/simple; bh=a/tZqH6yoCp0oI+4zMdzIYRX9dEOb7LapX8eE/EOS5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lV7AgmJ+SFJ2FYBP1/O4wDQN94B+lOGQfl/lPbsnJmGcekOxmiIyqn/5/ntnHI2nd0C85HTctv7WmJfpdPz+Sm2K1sU4NA1Sw/pgOqPUM1tTx+Ds7mGZYngRvrgvNjDpMbOdjKq1yPPwhC0bi7T0A4GXAYlmCV+PKCicGtSURFc= 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=OyjqmDkX; 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="OyjqmDkX" 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 5AJER15M032459; Wed, 19 Nov 2025 14:33: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=acGRP E+Gaanopu1vPCh+NsD0MvL71AXjorO3QXC/qQ0=; b=OyjqmDkXeJAlBNBrirYOg YVl0lm/OTSsDU72S2xvA03gkAHPwF1thPMvDSgtqFoDXS6ApLcYym7IcFqbtX8Dp BvKpSenUbEVPlEkEAhs9S5lsV5swUnj9Xv0XeYB2wfQqVfjdK6e6YubdrEkAmRvp nY5CgP91J2WJUwHniZP1wEdftnkUeNM2BYI5A2weEtXSFPlCy8l2vWuYowEcjKbe gQ7DmTgMngBv2yt9R7nB/tLFXuPndKowQhfd6TUEGIpuBVJLpyAhUAmSnPBi/dkU i6DOt7mIoMQAftt/ZD9+n1H34EWEQbQLKqVialh4i1uXlD5ooQHZVuaSctGzMuXd w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbbf9xf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:33:00 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AJENO7l002613; Wed, 19 Nov 2025 14:32:59 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyanrcc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Nov 2025 14:32:59 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5AJEWnnE022495; Wed, 19 Nov 2025 14:32:58 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-6; Wed, 19 Nov 2025 14:32:58 +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 05/30] objtool: Print symbol during disassembly Date: Wed, 19 Nov 2025 15:32:22 +0100 Message-ID: <20251119143247.3944213-6-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=BoqQAIX5 c=1 sm=1 tr=0 ts=691dd51c b=1 cx=c_pps a=WeWmnZmh0fydH62SvGsd2A==:117 a=WeWmnZmh0fydH62SvGsd2A==:17 a=6UeiqGixMTsA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=kcBrYugwK0_vbWm54lEA:9 X-Proofpoint-ORIG-GUID: Qd4LKdLflz5oVhEO4dvuPdoT1d1MxbEy X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX0Rot5e8KwedQ ZEpXNv2J0Q6lengUiuShu4wgBOhB14lHgXF2TETfljp9uSjFAQ/h2aW1D7zVFD1Uokw6MKjGl7u CqvlTs0289glxtKlafHy0n2CFZhiRZOvSB9Y9B6pkuhLUl8Gx5l7wOQvReS4QIUyHE56HrI37O3 GHt44NHQhrWV4BRtLiuv3sHq8pDcINgs+DaOQfcq0d+IfdN8h4rsJnY+5vKBFRjBMDGQteU/fZc TVqqywgK7JlW4n6IqhttXQjc7ugMa5gReoaqAT812NIx0YTSBpWT1fnnIjFLHK+Obkjh24qz2+I mbn5apNPE9GfQ7vLtt/TvmdpVsIx/vpxD2o/eM2adY7VtUdac7a4YMP4sZ5dTMqZTbCnhmgGjKi MkaqSJMFw04wY2ZrG13sdGuTmdBi4g== X-Proofpoint-GUID: Qd4LKdLflz5oVhEO4dvuPdoT1d1MxbEy 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 | 134 ++++++++++++++++++++++++++ tools/objtool/include/objtool/check.h | 9 ++ 3 files changed, 143 insertions(+), 9 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index de156e91ee8b7..8937667f075df 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -134,15 +134,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 11ac2ec04afc1..dee10ab86fa29 100644 --- a/tools/objtool/disas.c +++ b/tools/objtool/disas.c @@ -14,13 +14,144 @@ =20 struct disas_context { struct objtool_file *file; + struct instruction *insn; disassembler_ftype disassembler; struct disassemble_info info; }; =20 +static int sprint_name(char *str, const char *name, unsigned long offset) +{ + int len; + + if (offset) + len =3D sprintf(str, "%s+0x%lx", name, offset); + else + len =3D sprintf(str, "%s", name); + + return len; +} + #define DINFO_FPRINTF(dinfo, ...) \ ((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__)) =20 +static void disas_print_addr_sym(struct section *sec, struct symbol *sym, + bfd_vma addr, struct disassemble_info *dinfo) +{ + char symstr[1024]; + char *str; + + if (sym) { + sprint_name(symstr, sym->name, addr - sym->offset); + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr); + } else { + str =3D offstr(sec, addr); + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str); + free(str); + } +} + +static void disas_print_addr_noreloc(bfd_vma addr, + struct disassemble_info *dinfo) +{ + struct disas_context *dctx =3D dinfo->application_data; + struct instruction *insn =3D dctx->insn; + struct symbol *sym =3D NULL; + + if (insn->sym && addr >=3D insn->sym->offset && + addr < insn->sym->offset + insn->sym->len) { + sym =3D insn->sym; + } + + disas_print_addr_sym(insn->sec, sym, addr, dinfo); +} + +static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *= dinfo) +{ + struct disas_context *dctx =3D dinfo->application_data; + struct instruction *insn =3D dctx->insn; + unsigned long offset; + struct reloc *reloc; + char symstr[1024]; + char *str; + + reloc =3D find_reloc_by_dest_range(dctx->file->elf, insn->sec, + insn->offset, insn->len); + if (!reloc) { + /* + * There is no relocation for this instruction although + * the address to resolve points to the next instruction. + * So this is an effective reference to the next IP, for + * example: "lea 0x0(%rip),%rdi". The kernel can reference + * the next IP with _THIS_IP_ macro. + */ + DINFO_FPRINTF(dinfo, "0x%lx <_THIS_IP_>", addr); + return; + } + + offset =3D arch_insn_adjusted_addend(insn, reloc); + + /* + * If the relocation symbol is a section name (for example ".bss") + * then we try to further resolve the name. + */ + if (reloc->sym->type =3D=3D STT_SECTION) { + str =3D offstr(reloc->sym->sec, reloc->sym->offset + offset); + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str); + free(str); + } else { + sprint_name(symstr, reloc->sym->name, offset); + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr); + } +} + +/* + * Resolve an address into a "+" string. + */ +static void disas_print_address(bfd_vma addr, struct disassemble_info *din= fo) +{ + struct disas_context *dctx =3D dinfo->application_data; + struct instruction *insn =3D dctx->insn; + struct instruction *jump_dest; + struct symbol *sym; + bool is_reloc; + + /* + * If the instruction is a call/jump and it references a + * destination then this is likely the address we are looking + * up. So check it first. + */ + jump_dest =3D insn->jump_dest; + if (jump_dest && jump_dest->sym && jump_dest->offset =3D=3D addr) { + disas_print_addr_sym(jump_dest->sec, jump_dest->sym, + addr, dinfo); + return; + } + + /* + * If the address points to the next instruction then there is + * probably a relocation. It can be a false positive when the + * current instruction is referencing the address of the next + * instruction. This particular case will be handled in + * disas_print_addr_reloc(). + */ + is_reloc =3D (addr =3D=3D insn->offset + insn->len); + + /* + * The call destination offset can be the address we are looking + * up, or 0 if there is a relocation. + */ + sym =3D insn_call_dest(insn); + if (sym && (sym->offset =3D=3D addr || (sym->offset =3D=3D 0 && is_reloc)= )) { + DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, sym->name); + return; + } + + if (!is_reloc) + disas_print_addr_noreloc(addr, dinfo); + else + disas_print_addr_reloc(addr, dinfo); +} + /* * Initialize disassemble info arch, mach (32 or 64-bit) and options. */ @@ -69,6 +200,7 @@ struct disas_context *disas_context_create(struct objtoo= l_file *file) fprintf_styled); =20 dinfo->read_memory_func =3D buffer_read_memory; + dinfo->print_address_func =3D disas_print_address; dinfo->application_data =3D dctx; =20 /* @@ -121,6 +253,8 @@ static size_t disas_insn(struct disas_context *dctx, disassembler_ftype disasm =3D dctx->disassembler; struct disassemble_info *dinfo =3D &dctx->info; =20 + dctx->insn =3D insn; + if (insn->type =3D=3D INSN_NOP) { DINFO_FPRINTF(dinfo, "nop%d", insn->len); return insn->len; diff --git a/tools/objtool/include/objtool/check.h b/tools/objtool/include/= objtool/check.h index 674f57466d125..ad9c73504b120 100644 --- a/tools/objtool/include/objtool/check.h +++ b/tools/objtool/include/objtool/check.h @@ -117,6 +117,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