]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
objtool: Add 'alt_group' struct
authorJosh Poimboeuf <jpoimboe@redhat.com>
Fri, 18 Dec 2020 20:19:32 +0000 (14:19 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Jul 2022 09:26:05 +0000 (11:26 +0200)
commit b23cc71c62747f2e4c3e56138872cf47e1294f8a upstream.

Create a new struct associated with each group of alternatives
instructions.  This will help with the removal of fake jumps, and more
importantly with adding support for stack layout changes in
alternatives.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/objtool/check.c
tools/objtool/check.h

index 8932f41c387ff71f6bc21269f5140509d90a8465..6143a0790aa443998ef7bb97d61bf90a5999a405 100644 (file)
@@ -1012,20 +1012,28 @@ static int handle_group_alt(struct objtool_file *file,
                            struct instruction *orig_insn,
                            struct instruction **new_insn)
 {
-       static unsigned int alt_group_next_index = 1;
        struct instruction *last_orig_insn, *last_new_insn, *insn, *fake_jump = NULL;
-       unsigned int alt_group = alt_group_next_index++;
+       struct alt_group *orig_alt_group, *new_alt_group;
        unsigned long dest_off;
 
+
+       orig_alt_group = malloc(sizeof(*orig_alt_group));
+       if (!orig_alt_group) {
+               WARN("malloc failed");
+               return -1;
+       }
        last_orig_insn = NULL;
        insn = orig_insn;
        sec_for_each_insn_from(file, insn) {
                if (insn->offset >= special_alt->orig_off + special_alt->orig_len)
                        break;
 
-               insn->alt_group = alt_group;
+               insn->alt_group = orig_alt_group;
                last_orig_insn = insn;
        }
+       orig_alt_group->orig_group = NULL;
+       orig_alt_group->first_insn = orig_insn;
+       orig_alt_group->last_insn = last_orig_insn;
 
        if (next_insn_same_sec(file, last_orig_insn)) {
                fake_jump = malloc(sizeof(*fake_jump));
@@ -1056,8 +1064,13 @@ static int handle_group_alt(struct objtool_file *file,
                return 0;
        }
 
+       new_alt_group = malloc(sizeof(*new_alt_group));
+       if (!new_alt_group) {
+               WARN("malloc failed");
+               return -1;
+       }
+
        last_new_insn = NULL;
-       alt_group = alt_group_next_index++;
        insn = *new_insn;
        sec_for_each_insn_from(file, insn) {
                struct reloc *alt_reloc;
@@ -1069,7 +1082,7 @@ static int handle_group_alt(struct objtool_file *file,
 
                insn->ignore = orig_insn->ignore_alts;
                insn->func = orig_insn->func;
-               insn->alt_group = alt_group;
+               insn->alt_group = new_alt_group;
 
                /*
                 * Since alternative replacement code is copy/pasted by the
@@ -1118,6 +1131,10 @@ static int handle_group_alt(struct objtool_file *file,
                return -1;
        }
 
+       new_alt_group->orig_group = orig_alt_group;
+       new_alt_group->first_insn = *new_insn;
+       new_alt_group->last_insn = last_new_insn;
+
        if (fake_jump)
                list_add(&fake_jump->list, &last_new_insn->list);
 
@@ -2440,7 +2457,7 @@ static int validate_return(struct symbol *func, struct instruction *insn, struct
 static void fill_alternative_cfi(struct objtool_file *file, struct instruction *insn)
 {
        struct instruction *first_insn = insn;
-       int alt_group = insn->alt_group;
+       struct alt_group *alt_group = insn->alt_group;
 
        sec_for_each_insn_continue(file, insn) {
                if (insn->alt_group != alt_group)
index c280880f5eb4cb1fc2d7355adf241bf6086b43c4..dbf9f34622e8c78ec2e2cdb27be285567fa13804 100644 (file)
@@ -19,6 +19,17 @@ struct insn_state {
        s8 instr;
 };
 
+struct alt_group {
+       /*
+        * Pointer from a replacement group to the original group.  NULL if it
+        * *is* the original group.
+        */
+       struct alt_group *orig_group;
+
+       /* First and last instructions in the group */
+       struct instruction *first_insn, *last_insn;
+};
+
 struct instruction {
        struct list_head list;
        struct hlist_node hash;
@@ -34,7 +45,7 @@ struct instruction {
        s8 instr;
        u8 visited;
        u8 ret_offset;
-       int alt_group;
+       struct alt_group *alt_group;
        struct symbol *call_dest;
        struct instruction *jump_dest;
        struct instruction *first_jump_src;