Skip to contentSkip to conversation

objtool fix bytes check

PATCH New Jiri Slaby 2 participants 4 messages Dec 5, 2016 – Dec 14, 2016 objtool

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 objtool fix bytes check

---
Feel free to stash both of them into your objtool-dwarf branch. They are on the top of the upstream fix I have sent earlier today.

 tools/objtool/arch/x86/decode.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/objtool/arch/x86/decode.c +5 -5
index 98eac1bb106f..ca4ede5ddd8c 100644
@@ -206,7 +206,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 		break;
 
 	case 0x89:
-		if (insn.rex_prefix.nbytes && insn.modrm.bytes &&
+		if (insn.rex_prefix.nbytes && insn.modrm.nbytes &&
 		    insn.rex_prefix.bytes[0] == 0x48 &&
 		    insn.modrm.bytes[0] == 0xe5) {
 
@@ -277,7 +277,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 		break;
 
 	case 0x8d:
-		if (insn.rex_prefix.nbytes && insn.modrm.bytes &&
+		if (insn.rex_prefix.nbytes && insn.modrm.nbytes &&
 		    insn.rex_prefix.bytes[0] == 0x48 &&
 		    insn.modrm.bytes[0] == 0x65) {
 
@@ -291,8 +291,8 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			break;
 		}
 
-		if (insn.rex_prefix.bytes && insn.modrm.bytes &&
-		    insn.sib.bytes && insn.rex_prefix.bytes[0] == 0x4c &&
+		if (insn.rex_prefix.nbytes && insn.modrm.nbytes &&
+		    insn.sib.nbytes && insn.rex_prefix.bytes[0] == 0x4c &&
 		    insn.modrm.bytes[0] == 0x54 && insn.sib.bytes[0] == 0x24 &&
 		    insn.displacement.value == 8) {
 
@@ -312,7 +312,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			break;
 		}
 
-		if (drap && insn.rex_prefix.bytes && insn.modrm.bytes &&
+		if (drap && insn.rex_prefix.nbytes && insn.modrm.nbytes &&
 		    insn.rex_prefix.bytes[0] == 0x49 &&
 		    insn.modrm.bytes[0] == 0x62 &&
 		    insn.displacement.value == -8) {
Signature · 1 line
2.11.0
author
#1 lore raw

PATCH 1/1 objtool: fix build

0x8d opcode was handled twice. Fixed.

---
 tools/objtool/arch/x86/decode.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
tools/objtool/arch/x86/decode.c +14 -9
index ca4ede5ddd8c..6011ccbf9384 100644
@@ -291,6 +291,20 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			break;
 		}
 
+		if (insn.rex_prefix.nbytes &&
+		    insn.rex_prefix.bytes[0] == 0x48 &&
+		    insn.modrm.nbytes && insn.modrm.bytes[0] == 0x2c &&
+		    insn.sib.nbytes && insn.sib.bytes[0] == 0x24) {
+			/* lea %(rsp), %rbp */
+			*type = INSN_STACK;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_BP;
+			op->src.type = OP_SRC_ADD;
+			op->src.reg = CFI_SP;
+			op->src.offset = 0;
+			break;
+		}
+
 		if (insn.rex_prefix.nbytes && insn.modrm.nbytes &&
 		    insn.sib.nbytes && insn.rex_prefix.bytes[0] == 0x4c &&
 		    insn.modrm.bytes[0] == 0x54 && insn.sib.bytes[0] == 0x24 &&
@@ -342,15 +356,6 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 		op->src.type = OP_SRC_POP;
 		break;
 
-	case 0x8d:
-		if (insn.rex_prefix.nbytes &&
-		    insn.rex_prefix.bytes[0] == 0x48 &&
-		    insn.modrm.nbytes && insn.modrm.bytes[0] == 0x2c &&
-		    insn.sib.nbytes && insn.sib.bytes[0] == 0x24)
-			/* lea %(rsp), %rbp */
-			*type = INSN_FP_SETUP;
-		break;
-
 	case 0x90:
 		*type = INSN_NOP;
 		break;
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH] objtool: fix build

Quoted 3 lines · Jiri Slaby

0x8d opcode was handled twice. Fixed.

I applied the other patch to the objtool-dwarf branch, but this one doesn't apply (the branch already has the changes this patch is trying to make).

Quoted 48 lines
---
 tools/objtool/arch/x86/decode.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
tools/objtool/arch/x86/decode.c +14 -9
index ca4ede5ddd8c..6011ccbf9384 100644
@@ -291,6 +291,20 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			break;
 		}
 
+		if (insn.rex_prefix.nbytes &&
+		    insn.rex_prefix.bytes[0] == 0x48 &&
+		    insn.modrm.nbytes && insn.modrm.bytes[0] == 0x2c &&
+		    insn.sib.nbytes && insn.sib.bytes[0] == 0x24) {
+			/* lea %(rsp), %rbp */
+			*type = INSN_STACK;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_BP;
+			op->src.type = OP_SRC_ADD;
+			op->src.reg = CFI_SP;
+			op->src.offset = 0;
+			break;
+		}
+
 		if (insn.rex_prefix.nbytes && insn.modrm.nbytes &&
 		    insn.sib.nbytes && insn.rex_prefix.bytes[0] == 0x4c &&
 		    insn.modrm.bytes[0] == 0x54 && insn.sib.bytes[0] == 0x24 &&
@@ -342,15 +356,6 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 		op->src.type = OP_SRC_POP;
 		break;
 
-	case 0x8d:
-		if (insn.rex_prefix.nbytes &&
-		    insn.rex_prefix.bytes[0] == 0x48 &&
-		    insn.modrm.nbytes && insn.modrm.bytes[0] == 0x2c &&
-		    insn.sib.nbytes && insn.sib.bytes[0] == 0x24)
-			/* lea %(rsp), %rbp */
-			*type = INSN_FP_SETUP;
-		break;
-
 	case 0x90:
 		*type = INSN_NOP;
 		break;
Signature · 1 line
2.11.0
Signature · 1 line
Josh
author
#3 lore raw

Re: [PATCH] objtool: fix build

Quoted 8 lines · Josh Poimboeuf
Quoted 3 lines · Jiri Slaby

0x8d opcode was handled twice. Fixed.

I applied the other patch to the objtool-dwarf branch, but this one doesn't apply (the branch already has the changes this patch is trying to make).

You must have the fix from upstream first to have this applied:
commit 69042bf2001b44e81cd86ab11a4637b9d9a14c5a

Author: Jiri Slaby <[email protected]>
Date:   Mon Dec 5 11:55:51 2016 +0100

objtool: Fix bytes check of lea's rex_prefix

Thanks.

Quoted 49 lines
Quoted 48 lines
---
 tools/objtool/arch/x86/decode.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
tools/objtool/arch/x86/decode.c +14 -9
index ca4ede5ddd8c..6011ccbf9384 100644
@@ -291,6 +291,20 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			break;
 		}
 
+		if (insn.rex_prefix.nbytes &&
+		    insn.rex_prefix.bytes[0] == 0x48 &&
+		    insn.modrm.nbytes && insn.modrm.bytes[0] == 0x2c &&
+		    insn.sib.nbytes && insn.sib.bytes[0] == 0x24) {
+			/* lea %(rsp), %rbp */
+			*type = INSN_STACK;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_BP;
+			op->src.type = OP_SRC_ADD;
+			op->src.reg = CFI_SP;
+			op->src.offset = 0;
+			break;
+		}
+
 		if (insn.rex_prefix.nbytes && insn.modrm.nbytes &&
 		    insn.sib.nbytes && insn.rex_prefix.bytes[0] == 0x4c &&
 		    insn.modrm.bytes[0] == 0x54 && insn.sib.bytes[0] == 0x24 &&
@@ -342,15 +356,6 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 		op->src.type = OP_SRC_POP;
 		break;
 
-	case 0x8d:
-		if (insn.rex_prefix.nbytes &&
-		    insn.rex_prefix.bytes[0] == 0x48 &&
-		    insn.modrm.nbytes && insn.modrm.bytes[0] == 0x2c &&
-		    insn.sib.nbytes && insn.sib.bytes[0] == 0x24)
-			/* lea %(rsp), %rbp */
-			*type = INSN_FP_SETUP;
-		break;
-
 	case 0x90:
 		*type = INSN_NOP;
 		break;
Signature · 1 line
2.11.0
Signature · 2 lines
js
suse labs