]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
objtool: Preserve alternatives order
authorAlexandre Chartre <alexandre.chartre@oracle.com>
Fri, 21 Nov 2025 09:53:28 +0000 (10:53 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 21 Nov 2025 14:30:12 +0000 (15:30 +0100)
Preserve the order in which alternatives are defined. Currently
objtool stores alternatives in a list in reverse order.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://patch.msgid.link/20251121095340.464045-19-alexandre.chartre@oracle.com
tools/objtool/check.c

index 9cd9f9d4f65650caed72d954f0ca57882f512039..f75364f20bf1425e9c3375dbc58e14cf81f5e606 100644 (file)
@@ -1921,6 +1921,7 @@ static int add_special_section_alts(struct objtool_file *file)
        struct special_alt *special_alt, *tmp;
        enum alternative_type alt_type;
        struct alternative *alt;
+       struct alternative *a;
 
        if (special_get_alts(file->elf, &special_alts))
                return -1;
@@ -1973,9 +1974,20 @@ static int add_special_section_alts(struct objtool_file *file)
                }
 
                alt->insn = new_insn;
-               alt->next = orig_insn->alts;
                alt->type = alt_type;
-               orig_insn->alts = alt;
+               alt->next = NULL;
+
+               /*
+                * Store alternatives in the same order they have been
+                * defined.
+                */
+               if (!orig_insn->alts) {
+                       orig_insn->alts = alt;
+               } else {
+                       for (a = orig_insn->alts; a->next; a = a->next)
+                               ;
+                       a->next = alt;
+               }
 
                list_del(&special_alt->list);
                free(special_alt);