aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@redhat.com>2016-10-13 17:22:52 -0400
committerIngo Molnar <mingo@kernel.org>2016-10-16 03:12:35 -0400
commit3732710ff6f2ce2b1b7f044937a422b717d4f953 (patch)
treea7e2d24a7b2537c95c53059979ebf8e27b5de4ac
parent2cc17fda94c5ee8c64c2fdc2ef981fc277e2e958 (diff)
objtool: Improve rare switch jump table pattern detection
GCC 6 added a new switch statement jump table optimization which makes objtool's life harder. It looks like: mov [rodata addr],%reg1 ... some instructions ... jmpq *(%reg1,%reg2,8) The optimization is quite rare, but objtool still needs to be able to identify the pattern so that it can follow all possible control flow paths related to the switch statement. In order to detect the pattern, objtool starts from the indirect jump and scans backwards through the function until it finds the first instruction in the pattern. If it encounters an unconditional jump along the way, it stops and considers the pattern to be not found. As it turns out, unconditional jumps can happen, as long as they are small forward jumps within the range being scanned. This fixes the following warnings: drivers/infiniband/sw/rxe/rxe_comp.o: warning: objtool: rxe_completer()+0x2f4: sibling call from callable instruction with changed frame pointer drivers/infiniband/sw/rxe/rxe_resp.o: warning: objtool: rxe_responder()+0x10f: sibling call from callable instruction with changed frame pointer Reported-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/8a9ed68ae1780e8d3963e4ee13f2f257fe3a3c33.1476393584.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--tools/objtool/builtin-check.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 143b6cdd7f06..a00a05d287e7 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -713,6 +713,7 @@ static struct rela *find_switch_table(struct objtool_file *file,
713 struct instruction *insn) 713 struct instruction *insn)
714{ 714{
715 struct rela *text_rela, *rodata_rela; 715 struct rela *text_rela, *rodata_rela;
716 struct instruction *orig_insn = insn;
716 717
717 text_rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len); 718 text_rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len);
718 if (text_rela && text_rela->sym == file->rodata->sym) { 719 if (text_rela && text_rela->sym == file->rodata->sym) {
@@ -733,10 +734,16 @@ static struct rela *find_switch_table(struct objtool_file *file,
733 734
734 /* case 3 */ 735 /* case 3 */
735 func_for_each_insn_continue_reverse(file, func, insn) { 736 func_for_each_insn_continue_reverse(file, func, insn) {
736 if (insn->type == INSN_JUMP_UNCONDITIONAL || 737 if (insn->type == INSN_JUMP_DYNAMIC)
737 insn->type == INSN_JUMP_DYNAMIC)
738 break; 738 break;
739 739
740 /* allow small jumps within the range */
741 if (insn->type == INSN_JUMP_UNCONDITIONAL &&
742 insn->jump_dest &&
743 (insn->jump_dest->offset <= insn->offset ||
744 insn->jump_dest->offset >= orig_insn->offset))
745 break;
746
740 text_rela = find_rela_by_dest_range(insn->sec, insn->offset, 747 text_rela = find_rela_by_dest_range(insn->sec, insn->offset,
741 insn->len); 748 insn->len);
742 if (text_rela && text_rela->sym == file->rodata->sym) 749 if (text_rela && text_rela->sym == file->rodata->sym)