Re: [PATCH v2 46/53] objtool/klp: Rewrite symbol correlation algorithm

From: Song Liu

Date: Fri May 01 2026 - 08:07:31 EST


On Fri, May 1, 2026 at 5:09 AM Josh Poimboeuf <jpoimboe@xxxxxxxxxx> wrote:
>
> Rewrite the symbol correlation code, using a tiered list of
> deterministic strategies in a loop. For duplicately named symbols, each
> tier applies a filter with the goal of finding a 1:1 deterministic
> correlation between the original and patched version of the symbol.
>
> The three matching strategies are:
>
> find_twin(): A funnel of progressively tighter filters. Candidates
> with the same demangled name are counted at four levels: name, scope
> (local-vs-global), file (strict file association), and checksum
> (unchanged functions). The widest level that yields a 1:1 match wins,
> narrower levels are only tried when the wider level is ambiguous.
>
> find_twin_suffixed(): Uses already-correlated LLVM symbol pairs to map
> .llvm.<hash> suffixes from orig to patched. Because all promoted
> symbols from the same TU share the same hash, one correlated pair
> seeds the mapping for the entire TU.
>
> find_twin_positional(): Last resort, matches symbols by position among
> same-named candidates, similar to livepatch sympos. Used for data
> objects like __quirk variables where no deterministic filter can
> distinguish the candidates.
>
> Overall this works much better than the existing algorithm, particularly
> with LTO kernels.
>
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>

Acked-by: Song Liu <song@xxxxxxxxxx>

Thanks for improving the correlation algorithm and adding detailed
comments about all these scenarios!