objtool: Add is_static_jump() helper
authorJosh Poimboeuf <jpoimboe@redhat.com>
Mon, 10 Feb 2020 18:32:39 +0000 (12:32 -0600)
committerBorislav Petkov <bp@suse.de>
Tue, 11 Feb 2020 12:36:01 +0000 (13:36 +0100)
There are several places where objtool tests for a non-dynamic (aka
direct) jump.  Move the check to a helper function.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Julien Thierry <jthierry@redhat.com>
Link: https://lkml.kernel.org/r/9b8b438df918276315e4765c60d2587f3c7ad698.1581359535.git.jpoimboe@redhat.com
tools/objtool/check.c

index 796f6a172efdbdaf52a98ea02504a55d07c458c4..9016ae1c0c55eb007ceabab7f287299c460d0521 100644 (file)
@@ -97,14 +97,19 @@ static struct instruction *next_insn_same_func(struct objtool_file *file,
        for (insn = next_insn_same_sec(file, insn); insn;               \
             insn = next_insn_same_sec(file, insn))
 
+static bool is_static_jump(struct instruction *insn)
+{
+       return insn->type == INSN_JUMP_CONDITIONAL ||
+              insn->type == INSN_JUMP_UNCONDITIONAL;
+}
+
 static bool is_sibling_call(struct instruction *insn)
 {
        /* An indirect jump is either a sibling call or a jump to a table. */
        if (insn->type == INSN_JUMP_DYNAMIC)
                return list_empty(&insn->alts);
 
-       if (insn->type != INSN_JUMP_CONDITIONAL &&
-           insn->type != INSN_JUMP_UNCONDITIONAL)
+       if (!is_static_jump(insn))
                return false;
 
        /* add_jump_destinations() sets insn->call_dest for sibling calls. */
@@ -553,8 +558,7 @@ static int add_jump_destinations(struct objtool_file *file)
        unsigned long dest_off;
 
        for_each_insn(file, insn) {
-               if (insn->type != INSN_JUMP_CONDITIONAL &&
-                   insn->type != INSN_JUMP_UNCONDITIONAL)
+               if (!is_static_jump(insn))
                        continue;
 
                if (insn->ignore || insn->offset == FAKE_JUMP_OFFSET)
@@ -764,8 +768,7 @@ static int handle_group_alt(struct objtool_file *file,
                insn->ignore = orig_insn->ignore_alts;
                insn->func = orig_insn->func;
 
-               if (insn->type != INSN_JUMP_CONDITIONAL &&
-                   insn->type != INSN_JUMP_UNCONDITIONAL)
+               if (!is_static_jump(insn))
                        continue;
 
                if (!insn->immediate)