From patchwork Thu Feb 2 07:40:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 13125489 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 832C9C05027 for ; Thu, 2 Feb 2023 08:04:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=C/Eu46Wzy22FL4JWG4YUJ+wp32w2Kk1sfMQNYQMZv9E=; b=1PPfxCbH6EWesx Cb9waj9YpPGVO0VxbAaOhzZ0xFAME82GjcZ3Tu3Ex1JP5Cvp5aAO2XWIpEN5e/XnqttzUqeNM+tUV uO34BLbzAWxAFDbtQzAR4uq/EftgqFHf1MHTuyiE8Df10+T+K7jV2Fp8AjuNrszrNt9q7j/zgqq65 ajH5xM4Fbfi/uUvRS5NndqHI1+nt+hZHNmHot5cCWtI/5vkBpX6J+uRj0qVpVRJEhHxtMtbhGsrcv 0xDvMotrOUg8FiW6JyzIby0YvqN+svLse8C9s2A+1CGk9fQBopcHkQmbkwf7zP5hzUHwWBq6Yqz5D 7Rm0cSNOSNye+OGKVaxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNUZB-00ErIi-V4; Thu, 02 Feb 2023 08:03:34 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNUYT-00Eqxv-C2 for linux-arm-kernel@bombadil.infradead.org; Thu, 02 Feb 2023 08:02:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description; bh=4Oz2+1ZYx7D5K7SknLE3Ah83SAKi4AO9HhOoR9/v50Y=; b=V2ACiMqqVOs8/PCvvrDtVAeyTU 3QUWfQdsfmdg+qXKxTiGhvIsgcV/TR+RnsuuqYp9KRLI7uXpRVtvrHT+3np+7cav2Sn6Kjt7VHOXZ uaVMcIHLMFz+Ygnc9/rcl0dWGEm3qVL94J/mTqsfQkAsphOhbdxTnKygnTC0uId6XBKXCWi0+IvBf uX1MU8N2BnqPE6dVP15+y/86KCdZ5rF5Jp1Ds9+BKNZkRATLwBCDdpKjIc7aJGW54OHpcyVPZRBJk ssKHgShRFhVWBFhXg0IDM0u3vuDyxpVNUr3iMAtOU0muhddT6ITS2CDvtYQMqvgKZEwRvBFeJ2vTT a6g8d0Qw==; Received: from linux.microsoft.com ([13.77.154.182]) by desiato.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pNUEP-0054yv-1y for linux-arm-kernel@lists.infradead.org; Thu, 02 Feb 2023 07:42:09 +0000 Received: from x64host.home (unknown [47.187.213.40]) by linux.microsoft.com (Postfix) with ESMTPSA id A6A1320B9D4D; Wed, 1 Feb 2023 23:42:36 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A6A1320B9D4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1675323757; bh=4Oz2+1ZYx7D5K7SknLE3Ah83SAKi4AO9HhOoR9/v50Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ereOmhQVPKXkr6Q/wbie7EuTjecB1QvtMyAGoNimgY3RtObxfhUPlePkFXkuXUT0k 701f0VmYEOI0ApYjBEhQXQ8Mrjmmdfp3fiQZhxf7dlMeg1vqyw7PLO2b/f5ep3pBSx CC3U1QdNyRfpM+E0zs2igZ0BxDGco7KBj6reMcUI= 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 v3 12/22] objtool: arm64: Compute destinations for call and jump instructions Date: Thu, 2 Feb 2023 01:40:26 -0600 Message-Id: <20230202074036.507249-13-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230202074036.507249-1-madvenka@linux.microsoft.com> References: <0337266cf19f4c98388e3f6d09f590d9de258dc7> <20230202074036.507249-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230202_074206_730499_DFFED56D X-CRM114-Status: GOOD ( 14.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/dcheck.c | 47 ++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/arm64/decode.c b/tools/objtool/arch/arm64/decode.c index aaae16791807..81653ed3c323 100644 --- a/tools/objtool/arch/arm64/decode.c +++ b/tools/objtool/arch/arm64/decode.c @@ -20,6 +20,18 @@ /* ARM64 instructions are all 4 bytes wide. */ #define INSN_SIZE 4 +/* --------------------- 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; +} + /* --------------------- instruction decode structs ------------------------ */ struct decode_var { diff --git a/tools/objtool/dcheck.c b/tools/objtool/dcheck.c index cd2700153408..eb806a032a32 100644 --- a/tools/objtool/dcheck.c +++ b/tools/objtool/dcheck.c @@ -12,10 +12,55 @@ #include #include +/* + * 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 != INSN_CALL && + insn->type != INSN_JUMP_CONDITIONAL && + insn->type != INSN_JUMP_UNCONDITIONAL) { + continue; + } + + reloc = insn_reloc(file, insn); + if (!reloc) { + dest_sec = insn->sec; + dest_off = arch_jump_destination(insn); + } else if (reloc->sym->type == STT_SECTION) { + dest_sec = reloc->sym->sec; + dest_off = arch_dest_reloc_offset(reloc->addend); + } else if (reloc->sym->sec->idx) { + dest_sec = reloc->sym->sec; + dest_off = reloc->sym->sym.st_value + + arch_dest_reloc_offset(reloc->addend); + } else { + /* non-func asm code jumping to another file */ + continue; + } + + insn->jump_dest = find_insn(file, dest_sec, dest_off); + } +} + int check(struct objtool_file *file) { + int ret; + if (!opts.stackval) return 1; - return decode_instructions(file); + ret = decode_instructions(file); + if (ret) + return ret; + + add_jump_destinations(file); + + return 0; }