Re: [PATCH] perf llvm: Clean up after a failed disassembly
From: Ian Rogers
Date: Tue Mar 03 2026 - 18:31:03 EST
On Tue, Mar 3, 2026 at 3:00 PM Peter Collingbourne <pcc@xxxxxxxxxx> wrote:
>
> An error returned from a failed backend will cause perf to call the next
> backend. If the error happens mid-function, e.g. due to an unrecognized
> instruction, we will end up with duplicated instructions in the output
> unless the backend that failed deletes any instructions that it created
> before failing. The capstone backend was already doing this but the LLVM
> backend was not; fix it.
>
> Link: https://linux-review.googlesource.com/id/I377eef3cd662ab98fbcd69e5004a259fa3d7aa06
> Signed-off-by: Peter Collingbourne <pcc@xxxxxxxxxx>
Reviewed-by: Ian Rogers <irogers@xxxxxxxxxx>
Thanks,
Ian
> ---
> tools/perf/util/llvm.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/tools/perf/util/llvm.c b/tools/perf/util/llvm.c
> index 0d126d233c019..87fceae8488a7 100644
> --- a/tools/perf/util/llvm.c
> +++ b/tools/perf/util/llvm.c
> @@ -261,6 +261,15 @@ int symbol__disassemble_llvm(const char *filename, struct symbol *sym,
> ret = 0;
>
> err:
> + if (ret != 0) {
> + struct disasm_line *tmp;
> +
> + list_for_each_entry_safe(dl, tmp, ¬es->src->source,
> + al.node) {
> + list_del(&dl->al.node);
> + disasm_line__free(dl);
> + }
> + }
> LLVMDisasmDispose(disasm);
> free(code_buf);
> free(line_storage);
> --
> 2.53.0.473.g4a7958ca14-goog
>