linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: objtool/core] objtool,x86: Rewrite LEA decode
Date: Wed, 03 Mar 2021 08:45:34 -0000	[thread overview]
Message-ID: <161476113455.20312.5856311735543250667.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20210211173627.143250641@infradead.org>

The following commit has been merged into the objtool/core branch of tip:

Commit-ID:     7ee93978f459ace4e0fe30af582d343d5fb6421a
Gitweb:        https://git.kernel.org/tip/7ee93978f459ace4e0fe30af582d343d5fb6421a
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Tue, 09 Feb 2021 21:29:16 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 03 Mar 2021 09:38:29 +01:00

objtool,x86: Rewrite LEA decode

Current LEA decoding is a bunch of special cases, properly decode the
instruction, with exception of full SIB and RIP-relative modes.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Link: https://lkml.kernel.org/r/20210211173627.143250641@infradead.org
---
 tools/objtool/arch/x86/decode.c | 86 ++++++++++----------------------
 1 file changed, 28 insertions(+), 58 deletions(-)

diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 549813c..d8f0138 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -91,9 +91,10 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 {
 	struct insn insn;
 	int x86_64, sign;
-	unsigned char op1, op2, rex = 0, rex_b = 0, rex_r = 0, rex_w = 0,
-		      rex_x = 0, modrm = 0, modrm_mod = 0, modrm_rm = 0,
-		      modrm_reg = 0, sib = 0;
+	unsigned char op1, op2,
+		      rex = 0, rex_b = 0, rex_r = 0, rex_w = 0, rex_x = 0,
+		      modrm = 0, modrm_mod = 0, modrm_rm = 0, modrm_reg = 0,
+		      sib = 0;
 	struct stack_op *op = NULL;
 	struct symbol *sym;
 
@@ -328,68 +329,37 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec,
 		break;
 
 	case 0x8d:
-		if (sib == 0x24 && rex_w && !rex_b && !rex_x) {
-
-			ADD_OP(op) {
-				if (!insn.displacement.value) {
-					/* lea (%rsp), reg */
-					op->src.type = OP_SRC_REG;
-				} else {
-					/* lea disp(%rsp), reg */
-					op->src.type = OP_SRC_ADD;
-					op->src.offset = insn.displacement.value;
-				}
-				op->src.reg = CFI_SP;
-				op->dest.type = OP_DEST_REG;
-				op->dest.reg = op_to_cfi_reg[modrm_reg][rex_r];
-			}
-
-		} else if (rex == 0x48 && modrm == 0x65) {
-
-			/* lea disp(%rbp), %rsp */
-			ADD_OP(op) {
-				op->src.type = OP_SRC_ADD;
-				op->src.reg = CFI_BP;
-				op->src.offset = insn.displacement.value;
-				op->dest.type = OP_DEST_REG;
-				op->dest.reg = CFI_SP;
-			}
+		if (modrm_mod == 3) {
+			WARN("invalid LEA encoding at %s:0x%lx", sec->name, offset);
+			break;
+		}
 
-		} else if (rex == 0x49 && modrm == 0x62 &&
-			   insn.displacement.value == -8) {
+		/* skip non 64bit ops */
+		if (!rex_w)
+			break;
 
-			/*
-			 * lea -0x8(%r10), %rsp
-			 *
-			 * Restoring rsp back to its original value after a
-			 * stack realignment.
-			 */
-			ADD_OP(op) {
-				op->src.type = OP_SRC_ADD;
-				op->src.reg = CFI_R10;
-				op->src.offset = -8;
-				op->dest.type = OP_DEST_REG;
-				op->dest.reg = CFI_SP;
-			}
+		/* skip nontrivial SIB */
+		if (modrm_rm == 4 && !(sib == 0x24 && rex_b == rex_x))
+			break;
 
-		} else if (rex == 0x49 && modrm == 0x65 &&
-			   insn.displacement.value == -16) {
+		/* skip RIP relative displacement */
+		if (modrm_rm == 5 && modrm_mod == 0)
+			break;
 
-			/*
-			 * lea -0x10(%r13), %rsp
-			 *
-			 * Restoring rsp back to its original value after a
-			 * stack realignment.
-			 */
-			ADD_OP(op) {
+		/* lea disp(%src), %dst */
+		ADD_OP(op) {
+			op->src.offset = insn.displacement.value;
+			if (!op->src.offset) {
+				/* lea (%src), %dst */
+				op->src.type = OP_SRC_REG;
+			} else {
+				/* lea disp(%src), %dst */
 				op->src.type = OP_SRC_ADD;
-				op->src.reg = CFI_R13;
-				op->src.offset = -16;
-				op->dest.type = OP_DEST_REG;
-				op->dest.reg = CFI_SP;
 			}
+			op->src.reg = op_to_cfi_reg[modrm_rm][rex_b];
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = op_to_cfi_reg[modrm_reg][rex_r];
 		}
-
 		break;
 
 	case 0x8f:

  reply	other threads:[~2021-03-03 14:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11 17:30 [RFC][PATCH v2 0/7] objtool x86 decoder fixes Peter Zijlstra
2021-02-11 17:30 ` [RFC][PATCH v2 1/7] objtool: Allow UNWIND_HINT to suppress dodgy stack modifications Peter Zijlstra
2021-03-03  8:45   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-03-06 11:48   ` tip-bot2 for Peter Zijlstra
2021-02-11 17:30 ` [RFC][PATCH v2 2/7] objtool,x86: Renumber CFI_reg Peter Zijlstra
2021-03-03  8:45   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-03-06 11:48   ` tip-bot2 for Peter Zijlstra
2021-02-11 17:30 ` [RFC][PATCH v2 3/7] objtool,x86: Rewrite LEA decode Peter Zijlstra
2021-03-03  8:45   ` tip-bot2 for Peter Zijlstra [this message]
2021-03-06 11:48   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-02-11 17:30 ` [RFC][PATCH v2 4/7] objtool,x86: Rewrite LEAVE Peter Zijlstra
2021-03-03  8:45   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-03-06 11:48   ` tip-bot2 for Peter Zijlstra
2021-02-11 17:30 ` [RFC][PATCH v2 5/7] objtool,x86: Simplify register decode Peter Zijlstra
2021-03-03  8:45   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-03-06 11:48   ` tip-bot2 for Peter Zijlstra
2021-02-11 17:30 ` [RFC][PATCH v2 6/7] objtool,x86: Support %riz encodings Peter Zijlstra
2021-03-03  8:45   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-03-06 11:48   ` tip-bot2 for Peter Zijlstra
2021-02-11 17:30 ` [RFC][PATCH v2 7/7] objtool,x86: Rewrite ADD/SUB/AND Peter Zijlstra
2021-03-03  8:45   ` [tip: objtool/core] " tip-bot2 for Peter Zijlstra
2021-03-06 11:48   ` tip-bot2 for Peter Zijlstra
2021-02-11 18:30 ` [RFC][PATCH v2 0/7] objtool x86 decoder fixes Nick Desaulniers
2021-02-11 20:17 ` Josh Poimboeuf
2021-02-12  8:53 ` [RFC][PATCH v2 8/7] objtool,x86: More ModRM sugar Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=161476113455.20312.5856311735543250667.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).