[PATCH v3 05/11] objtool: Add --alt-fixup
From: Shivang Upadhyay
Date: Wed Dec 02 2026 - 02:42:26 EST
Add --alt-fixup, an action that reads the alternatives of a linked object
and lets the arch rewrite the replacement code through
arch_support_alt_relocation(), which handle_group_alt() already calls
for each pc-relative relocation in it. Nothing else is validated, so
return from decode_file() once the alternatives have been processed.
Signed-off-by: Shivang Upadhyay <shivangu@xxxxxxxxxxxxx>
---
tools/objtool/builtin-check.c | 4 +++-
tools/objtool/check.c | 5 +++++
tools/objtool/include/objtool/builtin.h | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 75b11dc85010..916ce58bc8b5 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -73,6 +73,7 @@ static int parse_hacks(const struct option *opt, const char *str, int unset)
static const struct option check_options[] = {
OPT_GROUP("Actions:"),
+ OPT_BOOLEAN(0, "alt-fixup", &opts.alt_fixup, "fix up relocations in alternative replacement code"),
OPT_STRING_OPTARG('d', "disas", &opts.disas, "function-pattern", "disassemble functions", "*"),
OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake", "patch toolchain bugs/limitations", parse_hacks),
OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"),
@@ -180,7 +181,8 @@ static bool opts_valid(void)
return false;
}
- if (opts.disas ||
+ if (opts.alt_fixup ||
+ opts.disas ||
opts.hack_jump_label ||
opts.hack_noinstr ||
opts.ibt ||
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 357676135680..6c1bf0aeb3b1 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2603,6 +2603,7 @@ static bool validate_branch_enabled(void)
static bool alts_needed(void)
{
return validate_branch_enabled() ||
+ opts.alt_fixup ||
opts.noinstr ||
opts.hack_jump_label ||
opts.disas ||
@@ -2657,6 +2658,10 @@ int decode_file(struct objtool_file *file)
return -1;
}
+ /* Fixing up the alternatives is all there is to do */
+ if (opts.alt_fixup)
+ return 0;
+
if (add_jump_destinations(file))
return -1;
diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h
index 349690bb1c50..35f94151732e 100644
--- a/tools/objtool/include/objtool/builtin.h
+++ b/tools/objtool/include/objtool/builtin.h
@@ -9,6 +9,7 @@
struct opts {
/* actions: */
+ bool alt_fixup;
bool checksum;
const char *disas;
bool dump_orc;
--
2.56.1