Re: [PATCH 17/48] objtool: Fix reloc hash collision in find_reloc_by_dest_range()

From: Peter Zijlstra

Date: Thu Apr 23 2026 - 04:36:58 EST


On Wed, Apr 22, 2026 at 09:03:45PM -0700, Josh Poimboeuf wrote:
> In find_reloc_by_dest_range(), hash collisions can cause a high-offset
> relocation to appear when probing a low-offset hash bucket.
>
> Only return early when the best match found so far genuinely belongs to
> the current bucket (its offset is within the bucket's stride range).
> Otherwise, continue scanning later buckets which may contain
> lower-offset matches.

Maybe mention (and or add a comment to the function) that in case of
multiple matches in the given range, it will return the lowest address
one.

Acked-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>

> Fixes: 74b873e49d92 ("objtool: Optimize find_rela_by_dest_range()")
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> ---
> tools/objtool/elf.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index a5486e172e5c..c4cb371e72b2 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -370,11 +370,11 @@ struct reloc *find_reloc_by_dest_range(const struct elf *elf, struct section *se
> r = reloc;
> }
> }
> - if (r)
> + if (r && (reloc_offset(r) & OFFSET_STRIDE_MASK) == o)
> return r;
> }
>
> - return NULL;
> + return r;
> }
>
> struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, unsigned long offset)
> --
> 2.53.0
>