From nobody Fri Dec 19 20:21:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F779C433FE for ; Tue, 24 May 2022 00:17:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232009AbiEXARo (ORCPT ); Mon, 23 May 2022 20:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231866AbiEXARG (ORCPT ); Mon, 23 May 2022 20:17:06 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7BA0F7356E; Mon, 23 May 2022 17:16:57 -0700 (PDT) Received: from x64host.home (unknown [47.189.24.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 840BF20B8961; Mon, 23 May 2022 17:16:56 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 840BF20B8961 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1653351417; bh=R+hlXlIgmzD2z81ekWg5REk7Zg6/92uCUr3rLRNg/rg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QAAfP8w12GLVb9uPNNedsIVKNCQj6aLqSkeHejW1GXkuc4iLXRtACFewvA5oBKo+/ d/uWxOfrtdguU0ytD3rjVxdOpumo2FbWjhfnqCwQLdqUaBe1mPIBbH42pQ5uVK0CGL rmuUO+gvuvU2BmRtg5gtEOMec8dRs6SzyF7EwiuM= From: madvenka@linux.microsoft.com To: jpoimboe@redhat.com, peterz@infradead.org, chenzhongjin@huawei.com, mark.rutland@arm.com, broonie@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jamorris@linux.microsoft.com, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [RFC PATCH v2 10/20] objtool: arm64: Compute destinations for call and jump instructions Date: Mon, 23 May 2022 19:16:27 -0500 Message-Id: <20220524001637.1707472-11-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220524001637.1707472-1-madvenka@linux.microsoft.com> References: <20220524001637.1707472-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: "Madhavan T. Venkataraman" Compute the destination address of each call and jump instruction after decoding all the instructions. Signed-off-by: Madhavan T. Venkataraman --- tools/objtool/arch/arm64/decode.c | 12 ++++++++ tools/objtool/fpv.c | 47 ++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/arm64/decode.c b/tools/objtool/arch/arm64/d= ecode.c index 8a9ff030085d..f9df8b321659 100644 --- a/tools/objtool/arch/arm64/decode.c +++ b/tools/objtool/arch/arm64/decode.c @@ -33,6 +33,18 @@ struct decode { s64 *imm, struct list_head *stack_ops); }; =20 +/* --------------------- arch support functions ------------------------- = */ + +unsigned long arch_dest_reloc_offset(int addend) +{ + return addend; +} + +unsigned long arch_jump_destination(struct instruction *insn) +{ + return insn->offset + insn->immediate; +} + /* --------------------- miscellaneous functions -------------------------= -- */ =20 static void reg_check(unsigned int sp_check, unsigned int fp_check, diff --git a/tools/objtool/fpv.c b/tools/objtool/fpv.c index 76f0f2e611a8..92ad0d0aac8e 100644 --- a/tools/objtool/fpv.c +++ b/tools/objtool/fpv.c @@ -13,7 +13,52 @@ #include #include =20 +/* + * Find the destination instructions for all jumps. + */ +static void add_jump_destinations(struct objtool_file *file) +{ + struct instruction *insn; + struct reloc *reloc; + struct section *dest_sec; + unsigned long dest_off; + + for_each_insn(file, insn) { + if (insn->type !=3D INSN_CALL && + insn->type !=3D INSN_JUMP_CONDITIONAL && + insn->type !=3D INSN_JUMP_UNCONDITIONAL) { + continue; + } + + reloc =3D insn_reloc(file, insn); + if (!reloc) { + dest_sec =3D insn->sec; + dest_off =3D arch_jump_destination(insn); + } else if (reloc->sym->type =3D=3D STT_SECTION) { + dest_sec =3D reloc->sym->sec; + dest_off =3D arch_dest_reloc_offset(reloc->addend); + } else if (reloc->sym->sec->idx) { + dest_sec =3D reloc->sym->sec; + dest_off =3D reloc->sym->sym.st_value + + arch_dest_reloc_offset(reloc->addend); + } else { + /* non-func asm code jumping to another file */ + continue; + } + + insn->jump_dest =3D find_insn(file, dest_sec, dest_off); + } +} + int fpv_decode(struct objtool_file *file) { - return decode_instructions(file); + int ret; + + ret =3D decode_instructions(file); + if (ret) + return ret; + + add_jump_destinations(file); + + return 0; } --=20 2.25.1