Re: [PATCH v2 08/18] perf symbol: Add reference counting and DECLARE_RC_STRUCT(symbol)

From: Alireza Haghdoost

Date: Fri Oct 30 2026 - 09:22:35 EST


On Tue, Oct 27, 2026 at 4:15 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> struct map_symbol ms = {
> .thread = thread__get(list->ms.thread),
> .map = map__get(list->ms.map),
> + .sym = symbol__get(list->ms.sym),
> };

This fixes a real bug and worth it's own patch ahead of the
conversion series so it can go to the LTS independently imo.

Since commit bffb5b0c0976a ("perf map/maps/thread:
Changes to reference counting") the temporary map_symbol in
merge_chain_branch() has had no .sym, so callchains merged during
collapse lose their symbol. With this line, the default
'perf report --children' output changes on recordings with inlined
frames: a line like "|--35.41%--0x55566d988a0f" becomes
"bench_sched_messaging" / "group (inlined)", with different
percentages.

> - frame->sym = NULL;
> - frame->sym_name = pos->sym ? strdup(symbol__name(pos->sym)) : NULL;
> + frame->sym = symbol__get(pos->sym);
[...]
> - if (frame->map)
> - frame->sym = pos->sym;

Before this patch, frame->sym was only set when thread__find_map()
found a map. call_path__init() stores ip = 0 whenever the call path
has a symbol, so for those frames no map is found, and sym_offset now
returns 0 - symbol__start(sym) instead of None. Returning None from
pyrf_callchain_node__get_sym_offset() when there is no map would keep
the old behaviour.

Smaller things related to this patch:
- call__parse() no longer records a call to the same function, so
Enter on a recursive call in TUI annotate says "The called function
was not found".

- builtin-annotate.c now takes a symbol reference for each block_range
entry, but the process-global block_ranges tree has no teardown.
Patch 15/18 retains symbols with a refcount greater than one, so any
symbol still referenced by this tree is permanently ineligible for
shrinking. Could block_range get a cleanup path that puts the symbol
references and frees the tree?

Thanks,
Alireza