From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v1 6/7] perf annotate: Support BPF JIT disassembly via genelf
Date: Tue, 09 Jun 2026 05:33:03 +0000 [thread overview]
Message-ID: <20260609053304.4A0321F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260609051759.405027-7-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The temporary ELF file for BPF JIT disassembly hardcodes the host architecture, breaking cross-platform analysis of perf.data files.
- [High] The temporary ELF file generated for BPF disassembly has a hardcoded Virtual Memory Address (VMA), causing objdump to output no instructions.
--
commit 13f48f3243b7525d8bdc81d7916d768a5bd50b37
Author: Ian Rogers <irogers@google.com>
perf annotate: Support BPF JIT disassembly via genelf
For in-memory BPF DSOs (DSO_BINARY_TYPE__BPF_PROG_INFO), write the
JITted instruction buffer to a temporary ELF file on disk using the
existing genelf framework (jit_write_elf). Reroute disassembly to
this temporary ELF file, allowing objdump and libasm to disassemble it
natively. Clean up the temporary file afterward.
> diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
> index 42af3603fdffd..8c78ef765787f 100644
> --- a/tools/perf/util/disasm.c
> +++ b/tools/perf/util/disasm.c
[ ... ]
> @@ -1540,6 +1543,41 @@ static int symbol__disassemble_objdump(const char *filename, struct symbol *sym,
> return err;
> }
>
> +#ifdef HAVE_LIBELF_SUPPORT
> +static int symbol__create_bpf_temp_elf(const char *filename, struct symbol *sym,
> + struct annotate_args *args,
> + char *tmp_elf, size_t tmp_elf_sz)
> +{
> + struct map *map = args->ms->map;
> + struct dso *dso = map__dso(map);
> + u8 *code_buf = NULL;
> + const u8 *buf;
> + u64 buf_len;
> + bool is_64bit;
> + int tmp_fd;
> + int err = -1;
> +
> + buf = dso__read_symbol(dso, filename, map, sym, &code_buf, &buf_len, &is_64bit);
> + if (!buf)
> + return -1;
> +
> + snprintf(tmp_elf, tmp_elf_sz, "/tmp/perf-bpf-XXXXXX");
> + tmp_fd = mkstemp(tmp_elf);
> + if (tmp_fd >= 0) {
> + if (jit_write_elf(tmp_fd, map__rip_2objdump(map, sym->start),
> + sym->name, buf, buf_len,
> + NULL, 0, NULL, 0, 0) == 0) {
^^^^^^^^^^^^^
[Severity: High]
Does this break cross-platform analysis of perf.data files?
When analyzing a perf.data file from a different architecture (e.g., recorded
on ARM64 but analyzed on an x86_64 host), jit_write_elf() generates the
temporary ELF file using host compile-time macros (GEN_ELF_ARCH).
Because the ELF header incorrectly claims the host's architecture instead of
the target's, disassemblers like objdump will decode the BPF JIT instructions
using the host's instruction set, producing garbage output.
[Severity: High]
Will objdump fail to output any instructions due to a mismatch in addresses?
Here, the actual symbol start address is passed to jit_write_elf() as
load_addr. However, jit_write_elf() ignores load_addr and hardcodes the
ELF .text section VMA and symbol address to GEN_ELF_TEXT_OFFSET (typically
0x40).
Later, symbol__disassemble_objdump() invokes objdump with --start-address
restricted to the actual symbol start address:
err = asprintf(&command,
"%s %s%s --start-address=0x%016" PRIx64
" --stop-address=0x%016" PRIx64 ...
map__rip_2objdump(map, sym->start),
map__rip_2objdump(map, sym->end), ...)
Because the ELF file's contents reside at 0x40, objdump finds no instructions
within the requested start and stop address bounds, and fails the disassembly
process.
> + err = 0;
> + }
> + close(tmp_fd);
> + if (err)
> + unlink(tmp_elf);
> + }
> + free(code_buf);
> + return err;
> +}
> +#endif
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260609051759.405027-1-irogers@google.com?part=6
next prev parent reply other threads:[~2026-06-09 5:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-09 5:17 [PATCH v1 0/7] perf annotate: Add elfutils libasm disassembler backend Ian Rogers
2026-06-09 5:17 ` [PATCH v1 1/7] tools build: Add feature check for elfutils libasm Ian Rogers
2026-06-09 5:28 ` sashiko-bot
2026-06-09 5:17 ` [PATCH v1 2/7] perf build: Add build support and capability " Ian Rogers
2026-06-09 5:28 ` sashiko-bot
2026-06-09 5:17 ` [PATCH v1 3/7] perf annotate: Implement elfutils libasm disassembler backend Ian Rogers
2026-06-09 5:30 ` sashiko-bot
2026-06-09 5:17 ` [PATCH v1 4/7] perf annotate: Add --disassembler command-line option Ian Rogers
2026-06-09 5:17 ` [PATCH v1 5/7] perf test: Enhance annotate test coverage and isolate config Ian Rogers
2026-06-09 5:28 ` sashiko-bot
2026-06-09 5:17 ` [PATCH v1 6/7] perf annotate: Support BPF JIT disassembly via genelf Ian Rogers
2026-06-09 5:33 ` sashiko-bot [this message]
2026-06-09 5:17 ` [PATCH v1 7/7] perf test: Add BPF JIT annotation test coverage for all disassemblers Ian Rogers
2026-06-09 5:36 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260609053304.4A0321F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox