Skip to content

Commit 7ad7a4a

Browse files
achartrePeter Zijlstra
authored andcommitted
objtool: Preserve alternatives order
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
1 parent 5f326c8 commit 7ad7a4a

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

tools/objtool/check.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,7 @@ static int add_special_section_alts(struct objtool_file *file)
19211921
struct special_alt *special_alt, *tmp;
19221922
enum alternative_type alt_type;
19231923
struct alternative *alt;
1924+
struct alternative *a;
19241925

19251926
if (special_get_alts(file->elf, &special_alts))
19261927
return -1;
@@ -1973,9 +1974,20 @@ static int add_special_section_alts(struct objtool_file *file)
19731974
}
19741975

19751976
alt->insn = new_insn;
1976-
alt->next = orig_insn->alts;
19771977
alt->type = alt_type;
1978-
orig_insn->alts = alt;
1978+
alt->next = NULL;
1979+
1980+
/*
1981+
* Store alternatives in the same order they have been
1982+
* defined.
1983+
*/
1984+
if (!orig_insn->alts) {
1985+
orig_insn->alts = alt;
1986+
} else {
1987+
for (a = orig_insn->alts; a->next; a = a->next)
1988+
;
1989+
a->next = alt;
1990+
}
19791991

19801992
list_del(&special_alt->list);
19811993
free(special_alt);

0 commit comments

Comments
 (0)