Re: [PATCH v7 15/22] objtool: Add action to check for absence of absolute relocations

From: Andreas Schwab

Date: Mon Oct 13 2025 - 05:46:20 EST


On Aug 28 2025, Ard Biesheuvel wrote:

> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 79eab61cd944..aeefc749e237 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -4686,6 +4686,47 @@ static void disas_warned_funcs(struct objtool_file *file)
> disas_funcs(funcs);
> }
>
> +__weak bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc)
> +{
> + unsigned int type = reloc_type(reloc);
> + size_t sz = elf_addr_size(elf);
> +
> + return (sz == 8) ? (type == R_ABS64) : (type == R_ABS32);
> +}
> +
> +static int check_abs_references(struct objtool_file *file)
> +{
> + struct section *sec;
> + struct reloc *reloc;
> + int ret = 0;
> +
> + for_each_sec(file, sec) {
> + /* absolute references in non-loadable sections are fine */
> + if (!(sec->sh.sh_flags & SHF_ALLOC))
> + continue;
> +
> + /* section must have an associated .rela section */
> + if (!sec->rsec)
> + continue;
> +
> + /*
> + * Special case for compiler generated metadata that is not
> + * consumed until after boot.
> + */
> + if (!strcmp(sec->name, "__patchable_function_entries"))
> + continue;
> +
> + for_each_reloc(sec->rsec, reloc) {
> + if (arch_absolute_reloc(file->elf, reloc)) {
> + WARN("section %s has absolute relocation at offset 0x%lx",
> + sec->name, reloc_offset(reloc));

This is wrong for a 32-bit host:

In file included from check.c:16:
check.c: In function ‘check_abs_references’:
/home/andreas/src/linux/linux-6.18-rc1/tools/objtool/include/objtool/warn.h:47:3: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 7 has type ‘u64’ {aka ‘long long unsigned int’} [-Werror=format=]
47 | "%s%s%s: objtool" extra ": " format "\n", \
| ^~~~~~~~~~~~~~~~~
/home/andreas/src/linux/linux-6.18-rc1/tools/objtool/include/objtool/warn.h:54:2: note: in expansion of macro ‘___WARN’
54 | ___WARN(severity, "", format, ##__VA_ARGS__)
| ^~~~~~~
/home/andreas/src/linux/linux-6.18-rc1/tools/objtool/include/objtool/warn.h:74:27: note: in expansion of macro ‘__WARN’
74 | #define WARN(format, ...) __WARN(WARN_STR, format, ##__VA_ARGS__)
| ^~~~~~
check.c:4713:5: note: in expansion of macro ‘WARN’
4713 | WARN("section %s has absolute relocation at offset 0x%lx",
| ^~~~
cc1: all warnings being treated as errors

--
Andreas Schwab, schwab@xxxxxxxxxxxxxx
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."