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

From: Peter Zijlstra
Date: Wed Jul 16 2025 - 05:55:17 EST


On Wed, Jul 16, 2025 at 05:18:30AM +0200, Ard Biesheuvel wrote:
> index d967ac001498..5d1d38404892 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -4643,6 +4643,39 @@ static void disas_warned_funcs(struct objtool_file *file)
> disas_funcs(funcs);
> }
>
> +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 (reloc_type(reloc) == R_ABS64) {

This should probably also check R_ABS32. Yes, your current only user is
x86_64 so R_ABS64 covers things, but we're getting more and more archs
using objtool. No reason this check shouldn't also work on PPC32 for
example.

> + WARN("section %s has absolute relocation at offset 0x%lx",
> + sec->name, reloc_offset(reloc));
> + ret++;
> + }
> + }
> + }
> + return ret;
> +}