Skip to contentSkip to conversation

objtool: fix some objtool warnings

PATCH New Josh Poimboeuf 2 participants 10 messages Jul 27, 2017 – Aug 21, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover objtool: fix some objtool warnings

Some objtool warning fixes, most of which were reported by Arnd.

The first patch fixes an issue which is specific to GCC 7. It has been around a while.

The second patch fixes an issue which has theoretically always existed in objtool, but was only recently uncovered due to some recent function whitelist changes associated with objtool 2.0.

The third and fourth patches are fixes for the recent objtool 2.0 and ORC support.

Josh Poimboeuf (4):
objtool: Assume unannotated 'ud2' instructions are dead ends
objtool: Skip unreachable warnings for 'alt' instructions
objtool: Fix '-mtune=atom' decoding support in objtool 2.0
objtool: Disable GCC '-Wpacked' warnings

 include/linux/compiler-gcc.h    | 16 -----------
 include/linux/compiler.h        | 25 +++++++++++++++-
 tools/objtool/Makefile          |  3 +-
 tools/objtool/arch.h            |  5 ++--
 tools/objtool/arch/x86/decode.c | 43 +++++++++++++++++++++++----
 tools/objtool/check.c           | 64 +++++++++++++++++++++++++++++++++++++++--
 6 files changed, 127 insertions(+), 29 deletions(-)
Signature · 1 line
2.13.3
#1 lore raw

PATCH 1/4 objtool: Assume unannotated 'ud2' instructions are dead ends

Arnd reported some false positive warnings with GCC 7:

drivers/hid/wacom_wac.o: warning: objtool: wacom_bpt3_touch()+0x2a5: stack state mismatch: cfa1=7+8 cfa2=6+16 drivers/iio/adc/vf610_adc.o: warning: objtool: vf610_adc_calculate_rates() falls through to next function vf610_adc_sample_set() drivers/pwm/pwm-hibvt.o: warning: objtool: hibvt_pwm_get_state() falls through to next function hibvt_pwm_remove() drivers/pwm/pwm-mediatek.o: warning: objtool: mtk_pwm_config() falls through to next function mtk_pwm_enable() drivers/spi/spi-bcm2835.o: warning: objtool: .text: unexpected end of section
drivers/spi/spi-bcm2835aux.o: warning: objtool: .text: unexpected end of section drivers/watchdog/digicolor_wdt.o: warning: objtool: dc_wdt_get_timeleft() falls through to next function dc_wdt_restart()

When GCC 7 detects a potential divide-by-zero condition, it sometimes inserts a 'ud2' instruction for the case where the divisor is zero, instead of letting the hardware trap on the divide instruction.

Objtool doesn't consider 'ud2' to be fatal unless it's annotated with unreachable(). So it considers the GCC-generated 'ud2' to be non-fatal, and it tries to follow the control flow past the 'ud2' and gets confused.

Previously, objtool *did* assume 'ud2' was always a dead end. That changed with the following commit:

d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

The motivation behind that change was that Peter was planning on using 'ud2' for __WARN(), which is *not* a dead end. However, it turns out that some emulators rely on 'ud2' being fatal, so he ended up using 'ud0' instead:

9a93848fe787 ("x86/debug: Implement __WARN() using UD0")

For GCC 4.5+, it should be safe to go back to the previous assumption that 'ud2' is fatal, even when it's not annotated with unreachable().

But for pre-4.5 versions of GCC, the unreachable() macro isn't supported, so such cases of 'ud2' need to be explicitly annotated as reachable.

Fixes d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
---
 include/linux/compiler-gcc.h    | 16 ------------
 include/linux/compiler.h        | 25 +++++++++++++++++-
 tools/objtool/arch.h            |  5 ++--
 tools/objtool/arch/x86/decode.c | 17 ++++++++----
 tools/objtool/check.c           | 57 +++++++++++++++++++++++++++++++++++++++--
 5 files changed, 94 insertions(+), 26 deletions(-)
include/linux/compiler-gcc.h +0 -16
index 2a34493e4d04..16d41de92ee3 100644
@@ -128,22 +128,6 @@
 #define __always_unused		__attribute__((unused))
 #define __mode(x)               __attribute__((mode(x)))
 
-#ifdef CONFIG_STACK_VALIDATION
-#define annotate_unreachable() ({					\
-	asm("%c0:\n\t"							\
-	    ".pushsection .discard.unreachable\n\t"			\
-	    ".long %c0b - .\n\t"					\
-	    ".popsection\n\t" : : "i" (__LINE__));			\
-})
-#define ASM_UNREACHABLE							\
-	"999:\n\t"							\
-	".pushsection .discard.unreachable\n\t"				\
-	".long 999b - .\n\t"						\
-	".popsection\n\t"
-#else
-#define annotate_unreachable()
-#endif
-
 /* gcc version specific checks */
 
 #if GCC_VERSION < 30200
include/linux/compiler.h +24 -1
index 2d2721756abf..dfaaeec4a32e 100644
@@ -185,11 +185,34 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 #endif
 
 /* Unreachable code */
+#ifdef CONFIG_STACK_VALIDATION
+#define annotate_reachable() ({						\
+	asm("%c0:\n\t"							\
+	    ".pushsection .discard.reachable\n\t"			\
+	    ".long %c0b - .\n\t"					\
+	    ".popsection\n\t" : : "i" (__LINE__));			\
+})
+#define annotate_unreachable() ({					\
+	asm("%c0:\n\t"							\
+	    ".pushsection .discard.unreachable\n\t"			\
+	    ".long %c0b - .\n\t"					\
+	    ".popsection\n\t" : : "i" (__LINE__));			\
+})
+#define ASM_UNREACHABLE							\
+	"999:\n\t"							\
+	".pushsection .discard.unreachable\n\t"				\
+	".long 999b - .\n\t"						\
+	".popsection\n\t"
+#else
+#define annotate_reachable()
+#define annotate_unreachable()
+#endif
+
 #ifndef ASM_UNREACHABLE
 # define ASM_UNREACHABLE
 #endif
 #ifndef unreachable
-# define unreachable() do { } while (1)
+# define unreachable() do { annotate_reachable(); do { } while (1); } while (0)
 #endif
 
 /*
tools/objtool/arch.h +3 -2
index 21aeca874edb..b0d7dc3d71b5 100644
@@ -31,8 +31,9 @@
 #define INSN_RETURN		6
 #define INSN_CONTEXT_SWITCH	7
 #define INSN_STACK		8
-#define INSN_NOP		9
-#define INSN_OTHER		10
+#define INSN_BUG		9
+#define INSN_NOP		10
+#define INSN_OTHER		11
 #define INSN_LAST		INSN_OTHER
 
 enum op_dest_type {
tools/objtool/arch/x86/decode.c +12 -5
index a36c2eba64e7..e4b400b67e41 100644
@@ -382,20 +382,27 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 
 	case 0x0f:
 
-		if (op2 >= 0x80 && op2 <= 0x8f)
+		if (op2 >= 0x80 && op2 <= 0x8f) {
+
 			*type = INSN_JUMP_CONDITIONAL;
-		else if (op2 == 0x05 || op2 == 0x07 || op2 == 0x34 ||
-			 op2 == 0x35)
+
+		} else if (op2 == 0x05 || op2 == 0x07 || op2 == 0x34 ||
+			   op2 == 0x35) {
 
 			/* sysenter, sysret */
 			*type = INSN_CONTEXT_SWITCH;
 
-		else if (op2 == 0x0d || op2 == 0x1f)
+		} else if (op2 == 0x0b || op2 == 0xb9) {
+
+			/* ud2 */
+			*type = INSN_BUG;
+
+		} else if (op2 == 0x0d || op2 == 0x1f) {
 
 			/* nopl/nopw */
 			*type = INSN_NOP;
 
-		else if (op2 == 0xa0 || op2 == 0xa8) {
+		} else if (op2 == 0xa0 || op2 == 0xa8) {
 
 			/* push fs/gs */
 			*type = INSN_STACK;
tools/objtool/check.c +55 -2

77 lines not on this page · raw message

Signature · 1 line
2.13.3
#2 lore raw

[tip:x86/asm] objtool: Assume unannotated UD2 instructions are dead ends

objtool: Assume unannotated UD2 instructions are dead ends
Commit-ID:  649ea4d5a624f061a111b1f1cb0e47cfdc3ac21b
Gitweb:     http://git.kernel.org/tip/649ea4d5a624f061a111b1f1cb0e47cfdc3ac21b
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 27 Jul 2017 15:56:53 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 28 Jul 2017 08:33:32 +0200

objtool: Assume unannotated UD2 instructions are dead ends

Arnd reported some false positive warnings with GCC 7:

drivers/hid/wacom_wac.o: warning: objtool: wacom_bpt3_touch()+0x2a5: stack state mismatch: cfa1=7+8 cfa2=6+16 drivers/iio/adc/vf610_adc.o: warning: objtool: vf610_adc_calculate_rates() falls through to next function vf610_adc_sample_set() drivers/pwm/pwm-hibvt.o: warning: objtool: hibvt_pwm_get_state() falls through to next function hibvt_pwm_remove() drivers/pwm/pwm-mediatek.o: warning: objtool: mtk_pwm_config() falls through to next function mtk_pwm_enable() drivers/spi/spi-bcm2835.o: warning: objtool: .text: unexpected end of section
drivers/spi/spi-bcm2835aux.o: warning: objtool: .text: unexpected end of section drivers/watchdog/digicolor_wdt.o: warning: objtool: dc_wdt_get_timeleft() falls through to next function dc_wdt_restart()

When GCC 7 detects a potential divide-by-zero condition, it sometimes inserts a UD2 instruction for the case where the divisor is zero, instead of letting the hardware trap on the divide instruction.

Objtool doesn't consider UD2 to be fatal unless it's annotated with unreachable(). So it considers the GCC-generated UD2 to be non-fatal, and it tries to follow the control flow past the UD2 and gets confused.

Previously, objtool *did* assume UD2 was always a dead end. That changed with the following commit:

d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")

The motivation behind that change was that Peter was planning on using UD2 for __WARN(), which is *not* a dead end. However, it turns out that some emulators rely on UD2 being fatal, so he ended up using 'ud0' instead:

9a93848fe787 ("x86/debug: Implement __WARN() using UD0")

For GCC 4.5+, it should be safe to go back to the previous assumption that UD2 is fatal, even when it's not annotated with unreachable().

But for pre-4.5 versions of GCC, the unreachable() macro isn't supported, so such cases of UD2 need to be explicitly annotated as reachable.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes d1091c7fa3d5 ("objtool: Improve detection of BUG() and other dead ends")
---
 include/linux/compiler-gcc.h    | 16 ------------
 include/linux/compiler.h        | 25 +++++++++++++++++-
 tools/objtool/arch.h            |  5 ++--
 tools/objtool/arch/x86/decode.c | 17 ++++++++----
 tools/objtool/check.c           | 57 +++++++++++++++++++++++++++++++++++++++--
 5 files changed, 94 insertions(+), 26 deletions(-)
include/linux/compiler-gcc.h +0 -16
index 17cbe3c..dd4b4c5 100644
@@ -128,22 +128,6 @@
 #define __always_unused		__attribute__((unused))
 #define __mode(x)               __attribute__((mode(x)))
 
-#ifdef CONFIG_STACK_VALIDATION
-#define annotate_unreachable() ({					\
-	asm("%c0:\n\t"							\
-	    ".pushsection .discard.unreachable\n\t"			\
-	    ".long %c0b - .\n\t"					\
-	    ".popsection\n\t" : : "i" (__LINE__));			\
-})
-#define ASM_UNREACHABLE							\
-	"999:\n\t"							\
-	".pushsection .discard.unreachable\n\t"				\
-	".long 999b - .\n\t"						\
-	".popsection\n\t"
-#else
-#define annotate_unreachable()
-#endif
-
 /* gcc version specific checks */
 
 #if GCC_VERSION < 30200
include/linux/compiler.h +24 -1
index 641f591..70f070d 100644
@@ -185,11 +185,34 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 #endif
 
 /* Unreachable code */
+#ifdef CONFIG_STACK_VALIDATION
+#define annotate_reachable() ({						\
+	asm("%c0:\n\t"							\
+	    ".pushsection .discard.reachable\n\t"			\
+	    ".long %c0b - .\n\t"					\
+	    ".popsection\n\t" : : "i" (__LINE__));			\
+})
+#define annotate_unreachable() ({					\
+	asm("%c0:\n\t"							\
+	    ".pushsection .discard.unreachable\n\t"			\
+	    ".long %c0b - .\n\t"					\
+	    ".popsection\n\t" : : "i" (__LINE__));			\
+})
+#define ASM_UNREACHABLE							\
+	"999:\n\t"							\
+	".pushsection .discard.unreachable\n\t"				\
+	".long 999b - .\n\t"						\
+	".popsection\n\t"
+#else
+#define annotate_reachable()
+#define annotate_unreachable()
+#endif
+
 #ifndef ASM_UNREACHABLE
 # define ASM_UNREACHABLE
 #endif
 #ifndef unreachable
-# define unreachable() do { } while (1)
+# define unreachable() do { annotate_reachable(); do { } while (1); } while (0)
 #endif
 
 /*
tools/objtool/arch.h +3 -2
index 21aeca8..b0d7dc3 100644
@@ -31,8 +31,9 @@
 #define INSN_RETURN		6
 #define INSN_CONTEXT_SWITCH	7
 #define INSN_STACK		8
-#define INSN_NOP		9
-#define INSN_OTHER		10
+#define INSN_BUG		9
+#define INSN_NOP		10
+#define INSN_OTHER		11
 #define INSN_LAST		INSN_OTHER
 
 enum op_dest_type {
tools/objtool/arch/x86/decode.c +12 -5
index a36c2eb..e4b400b 100644
@@ -382,20 +382,27 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 
 	case 0x0f:
 
-		if (op2 >= 0x80 && op2 <= 0x8f)
+		if (op2 >= 0x80 && op2 <= 0x8f) {
+
 			*type = INSN_JUMP_CONDITIONAL;
-		else if (op2 == 0x05 || op2 == 0x07 || op2 == 0x34 ||
-			 op2 == 0x35)
+
+		} else if (op2 == 0x05 || op2 == 0x07 || op2 == 0x34 ||
+			   op2 == 0x35) {
 
 			/* sysenter, sysret */
 			*type = INSN_CONTEXT_SWITCH;
 
-		else if (op2 == 0x0d || op2 == 0x1f)
+		} else if (op2 == 0x0b || op2 == 0xb9) {
+
+			/* ud2 */
+			*type = INSN_BUG;
+
+		} else if (op2 == 0x0d || op2 == 0x1f) {
 
 			/* nopl/nopw */
 			*type = INSN_NOP;
 
-		else if (op2 == 0xa0 || op2 == 0xa8) {
+		} else if (op2 == 0xa0 || op2 == 0xa8) {
 
 			/* push fs/gs */
 			*type = INSN_STACK;
tools/objtool/check.c +55 -2

77 lines not on this page · raw message

#3 lore raw

PATCH 2/4 objtool: Skip unreachable warnings for 'alt' instructions

In reply to Josh Poimboeuf

When a whitelisted function uses one of the ALTERNATIVE macros, it produces false positive warnings like:

arch/x86/kvm/vmx.o: warning: objtool: .altinstr_replacement+0x0: unreachable instruction arch/x86/kvm/svm.o: warning: objtool: .altinstr_replacement+0x6e: unreachable instruction

There's no easy way to whitelist alternative instructions, so instead just skip any 'unreachable' warnings associated with them.

---
 tools/objtool/check.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/objtool/check.c +6 -1
index d07bf4a62b45..4f0c4aea8f6f 100644
@@ -1746,8 +1746,13 @@ static bool ignore_unreachable_insn(struct instruction *insn)
 	/*
 	 * Ignore any unused exceptions.  This can happen when a whitelisted
 	 * function has an exception table entry.
+	 *
+	 * Also ignore alternative replacement instructions.  This can happen
+	 * when a whitelisted function uses one of the ALTERNATIVE macros.
 	 */
-	if (!strcmp(insn->sec->name, ".fixup"))
+	if (!strcmp(insn->sec->name, ".fixup") ||
+	    !strcmp(insn->sec->name, ".altinstr_replacement") ||
+	    !strcmp(insn->sec->name, ".altinstr_aux"))
 		return true;
 
 	/*
Signature · 1 line
2.13.3
#4 lore raw

[tip:x86/asm] objtool: Skip unreachable warnings for 'alt' instructions

objtool: Skip unreachable warnings for 'alt' instructions
Commit-ID:  0e2bb2bc14b3df754b0a86e87cd8923df0701a1b
Gitweb:     http://git.kernel.org/tip/0e2bb2bc14b3df754b0a86e87cd8923df0701a1b
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 27 Jul 2017 15:56:54 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 28 Jul 2017 08:33:32 +0200

objtool: Skip unreachable warnings for 'alt' instructions

When a whitelisted function uses one of the ALTERNATIVE macros, it produces false positive warnings like:

arch/x86/kvm/vmx.o: warning: objtool: .altinstr_replacement+0x0: unreachable instruction arch/x86/kvm/svm.o: warning: objtool: .altinstr_replacement+0x6e: unreachable instruction

There's no easy way to whitelist alternative instructions, so instead just skip any 'unreachable' warnings associated with them.

---
 tools/objtool/check.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/objtool/check.c +6 -1
index d07bf4a..4f0c4ae 100644
@@ -1746,8 +1746,13 @@ static bool ignore_unreachable_insn(struct instruction *insn)
 	/*
 	 * Ignore any unused exceptions.  This can happen when a whitelisted
 	 * function has an exception table entry.
+	 *
+	 * Also ignore alternative replacement instructions.  This can happen
+	 * when a whitelisted function uses one of the ALTERNATIVE macros.
 	 */
-	if (!strcmp(insn->sec->name, ".fixup"))
+	if (!strcmp(insn->sec->name, ".fixup") ||
+	    !strcmp(insn->sec->name, ".altinstr_replacement") ||
+	    !strcmp(insn->sec->name, ".altinstr_aux"))
 		return true;
 
 	/*
#5 lore raw

PATCH 3/4 objtool: Fix '-mtune=atom' decoding support in objtool 2.0

In reply to Josh Poimboeuf

With '-mtune=atom', which is enabled with CONFIG_MATOM=y, GCC uses some unusual instructions for setting up the stack.

Instead of:

mov %rsp, %rbp

it does:

lea (%rsp), %rbp

And instead of:

add imm, %rsp

it does:

lea disp(%rsp), %rsp

Add support for these instructions to the objtool decoder.

Fixes baa41469a7b9 ("objtool: Implement stack validation 2.0")
---
 tools/objtool/arch/x86/decode.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
tools/objtool/arch/x86/decode.c +25 -1
index e4b400b67e41..7841e5d31973 100644
@@ -271,7 +271,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 	case 0x8d:
 		if (rex == 0x48 && modrm == 0x65) {
 
-			/* lea -disp(%rbp), %rsp */
+			/* lea disp(%rbp), %rsp */
 			*type = INSN_STACK;
 			op->src.type = OP_SRC_ADD;
 			op->src.reg = CFI_BP;
@@ -281,6 +281,30 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			break;
 		}
 
+		if (rex == 0x48 && (modrm == 0xa4 || modrm == 0x64) &&
+		    sib == 0x24) {
+
+			/* lea disp(%rsp), %rsp */
+			*type = INSN_STACK;
+			op->src.type = OP_SRC_ADD;
+			op->src.reg = CFI_SP;
+			op->src.offset = insn.displacement.value;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_SP;
+			break;
+		}
+
+		if (rex == 0x48 && modrm == 0x2c && sib == 0x24) {
+
+			/* lea (%rsp), %rbp */
+			*type = INSN_STACK;
+			op->src.type = OP_SRC_REG;
+			op->src.reg = CFI_SP;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_BP;
+			break;
+		}
+
 		if (rex == 0x4c && modrm == 0x54 && sib == 0x24 &&
 		    insn.displacement.value == 8) {
 
Signature · 1 line
2.13.3
#6 lore raw

[tip:x86/asm] objtool: Fix '-mtune=atom' decoding support in objtool 2.0

objtool: Fix '-mtune=atom' decoding support in objtool 2.0
Commit-ID:  5b8de48e82ba322483c925ce33f193e28e59a5fd
Gitweb:     http://git.kernel.org/tip/5b8de48e82ba322483c925ce33f193e28e59a5fd
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 27 Jul 2017 15:56:55 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 28 Jul 2017 08:33:32 +0200

objtool: Fix '-mtune=atom' decoding support in objtool 2.0

With '-mtune=atom', which is enabled with CONFIG_MATOM=y, GCC uses some unusual instructions for setting up the stack.

Instead of:

mov %rsp, %rbp

it does:

lea (%rsp), %rbp

And instead of:

add imm, %rsp

it does:

lea disp(%rsp), %rsp

Add support for these instructions to the objtool decoder.

---
 tools/objtool/arch/x86/decode.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
tools/objtool/arch/x86/decode.c +25 -1
index e4b400b..7841e5d 100644
@@ -271,7 +271,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 	case 0x8d:
 		if (rex == 0x48 && modrm == 0x65) {
 
-			/* lea -disp(%rbp), %rsp */
+			/* lea disp(%rbp), %rsp */
 			*type = INSN_STACK;
 			op->src.type = OP_SRC_ADD;
 			op->src.reg = CFI_BP;
@@ -281,6 +281,30 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			break;
 		}
 
+		if (rex == 0x48 && (modrm == 0xa4 || modrm == 0x64) &&
+		    sib == 0x24) {
+
+			/* lea disp(%rsp), %rsp */
+			*type = INSN_STACK;
+			op->src.type = OP_SRC_ADD;
+			op->src.reg = CFI_SP;
+			op->src.offset = insn.displacement.value;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_SP;
+			break;
+		}
+
+		if (rex == 0x48 && modrm == 0x2c && sib == 0x24) {
+
+			/* lea (%rsp), %rbp */
+			*type = INSN_STACK;
+			op->src.type = OP_SRC_REG;
+			op->src.reg = CFI_SP;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_BP;
+			break;
+		}
+
 		if (rex == 0x4c && modrm == 0x54 && sib == 0x24 &&
 		    insn.displacement.value == 8) {
 
#7 lore raw

[tip:x86/urgent] objtool: Fix '-mtune=atom' decoding support in objtool 2.0

In reply to Josh Poimboeuf
objtool: Fix '-mtune=atom' decoding support in objtool 2.0
Commit-ID:  deecd4d71b12626db48544faa66bb897e2cafd07
Gitweb:     http://git.kernel.org/tip/deecd4d71b12626db48544faa66bb897e2cafd07
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 27 Jul 2017 15:56:55 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 21 Aug 2017 16:07:27 +0200

objtool: Fix '-mtune=atom' decoding support in objtool 2.0

With '-mtune=atom', which is enabled with CONFIG_MATOM=y, GCC uses some unusual instructions for setting up the stack.

Instead of:

mov %rsp, %rbp

it does:

lea (%rsp), %rbp

And instead of:

add imm, %rsp

it does:

lea disp(%rsp), %rsp

Add support for these instructions to the objtool decoder.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes baa41469a7b9 ("objtool: Implement stack validation 2.0")
[ This is a cherry-picked version of upcoming commit 5b8de48e82ba. ]
---
 tools/objtool/arch/x86/decode.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
tools/objtool/arch/x86/decode.c +25 -1
index a36c2eb..4559a21a 100644
@@ -271,7 +271,7 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 	case 0x8d:
 		if (rex == 0x48 && modrm == 0x65) {
 
-			/* lea -disp(%rbp), %rsp */
+			/* lea disp(%rbp), %rsp */
 			*type = INSN_STACK;
 			op->src.type = OP_SRC_ADD;
 			op->src.reg = CFI_BP;
@@ -281,6 +281,30 @@ int arch_decode_instruction(struct elf *elf, struct section *sec,
 			break;
 		}
 
+		if (rex == 0x48 && (modrm == 0xa4 || modrm == 0x64) &&
+		    sib == 0x24) {
+
+			/* lea disp(%rsp), %rsp */
+			*type = INSN_STACK;
+			op->src.type = OP_SRC_ADD;
+			op->src.reg = CFI_SP;
+			op->src.offset = insn.displacement.value;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_SP;
+			break;
+		}
+
+		if (rex == 0x48 && modrm == 0x2c && sib == 0x24) {
+
+			/* lea (%rsp), %rbp */
+			*type = INSN_STACK;
+			op->src.type = OP_SRC_REG;
+			op->src.reg = CFI_SP;
+			op->dest.type = OP_DEST_REG;
+			op->dest.reg = CFI_BP;
+			break;
+		}
+
 		if (rex == 0x4c && modrm == 0x54 && sib == 0x24 &&
 		    insn.displacement.value == 8) {
 
#8 lore raw

PATCH 4/4 objtool: Disable GCC '-Wpacked' warnings

In reply to Josh Poimboeuf

Objtool is failing to build with GCC 4.4.7 due to the following warnings:

cc1: warnings being treated as errors
In file included from orc.h:21,

                   from orc_gen.c:21:

orc_types.h:86: error: packed attribute is unnecessary for ‘sp_offset’ orc_types.h:87: error: packed attribute is unnecessary for ‘bp_offset’ orc_types.h:88: error: packed attribute is unnecessary for ‘sp_reg’

I suspect those warnings are a GCC bug. But -Wpacked isn't very useful anyway, so just disable it.

Fixes 627fce14809b ("objtool: Add ORC unwind table generation")
---
 tools/objtool/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/objtool/Makefile +2 -1
index 3a6425fefc43..6976c73e60c4 100644
@@ -25,7 +25,8 @@ OBJTOOL_IN := $(OBJTOOL)-in.o
 all: $(OBJTOOL)
 
 INCLUDES := -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi
-CFLAGS   += -Wall -Werror $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -fomit-frame-pointer -O2 -g $(INCLUDES)
+WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
+CFLAGS   += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
 LDFLAGS  += -lelf $(LIBSUBCMD)
 
 # Allow old libelf to be used:
Signature · 1 line
2.13.3
#9 lore raw

[tip:x86/asm] objtool: Disable GCC '-Wpacked' warnings

objtool: Disable GCC '-Wpacked' warnings
Commit-ID:  21ec3bf6aeb4033210747837421e63286ba32646
Gitweb:     http://git.kernel.org/tip/21ec3bf6aeb4033210747837421e63286ba32646
Author:     Josh Poimboeuf <[email protected]>
AuthorDate: Thu, 27 Jul 2017 15:56:56 -0500
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 28 Jul 2017 08:33:32 +0200

objtool: Disable GCC '-Wpacked' warnings

Objtool is failing to build with GCC 4.4.7 due to the following warnings:

cc1: warnings being treated as errors
In file included from orc.h:21,

                   from orc_gen.c:21:

orc_types.h:86: error: packed attribute is unnecessary for ‘sp_offset’ orc_types.h:87: error: packed attribute is unnecessary for ‘bp_offset’ orc_types.h:88: error: packed attribute is unnecessary for ‘sp_reg’

I suspect those warnings are a GCC bug. But -Wpacked isn't very useful anyway, so just disable it.

Cc Arnd Bergmann <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 627fce14809b ("objtool: Add ORC unwind table generation")
---
 tools/objtool/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/objtool/Makefile +2 -1
index 3a6425f..6976c73 100644
@@ -25,7 +25,8 @@ OBJTOOL_IN := $(OBJTOOL)-in.o
 all: $(OBJTOOL)
 
 INCLUDES := -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi
-CFLAGS   += -Wall -Werror $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -fomit-frame-pointer -O2 -g $(INCLUDES)
+WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed
+CFLAGS   += -Wall -Werror $(WARNINGS) -fomit-frame-pointer -O2 -g $(INCLUDES)
 LDFLAGS  += -lelf $(LIBSUBCMD)
 
 # Allow old libelf to be used: