All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Tengda Wu <wutengda@huaweicloud.com>
Cc: sashiko-reviews@lists.linux.dev, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v3 02/21] perf capstone: Fix arm64 jump/adrp disassembly mismatch with objdump
Date: Wed, 8 Jul 2026 23:10:23 -0700	[thread overview]
Message-ID: <ak87T3G5-4EAcKIy@z2> (raw)
In-Reply-To: <70364d4d-e891-45e5-84ed-addf7dcd97d7@huaweicloud.com>

On Wed, Jul 01, 2026 at 02:44:13PM +0800, Tengda Wu wrote:
> 
> 
> On 2026/7/1 12:07, sashiko-bot@kernel.org wrote:
> > Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
> > - [High] Symbol resolution fails for relocated kernels (KASLR) and user-space shared libraries due to mismatched address spaces.
> > - [Low] Build failure due to undeclared `machine` variable and undefined `machine__normalized_is()` function in `capstone_init()`.
> > - [Low] Missing `<stdlib.h>` inclusion causes musl libc build failure.
> > - [Low] Usage of `ARM64_GRP_BRANCH_RELATIVE` causes build failures with Capstone versions prior to 5.0.
> > --
> > 
> > commit 1f9744f04e456b1209677658edb7f30a5b26e56d
> > Author: Tengda Wu <wutengda@huaweicloud.com>
> > 
> > perf capstone: Fix arm64 jump/adrp disassembly mismatch with objdump
> > 
> > The patch implements extended formatting for arm64 jump and adrp instructions
> > during symbol__disassemble_capstone() to match objdump's expected output style.
> > It adds instruction detail resolution in capstone_init() and formats the
> > output with correct symbol and offset mappings.
> > 
> >> diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c
> >> index 9bba78ee0c5a2..a9c0a1d2eb036 100644
> >> --- a/tools/perf/util/capstone.c
> >> +++ b/tools/perf/util/capstone.c
> > 
> > [ ... ]
> > 
> >> @@ -218,6 +218,12 @@ static int capstone_init(uint16_t e_machine, csh *cs_handle, bool is64, bool is_
> >>  		 * on x86 by investigating instruction details.
> >>  		 */
> >>  		perf_cs_option(*cs_handle, CS_OPT_DETAIL, CS_OPT_ON);
> >> +	} else if (machine__normalized_is(machine, "arm64")) {
> > 
> > [Severity: Low]
> > Does this code cause a build failure? The variable machine is not declared
> > in capstone_init(), and the function machine__normalized_is() does not appear
> > to be defined in the codebase.
> > 
> 
> Agreed. This is due to commit 12c4737f55f2 ("perf capstone: Determine architecture from
> e_machine"), which changed the capstone interface. I haven't rebased this part yet.
> The base-commit already fails to build with capstone, so I didn't notice this one.

Yep, it should be 'else if (arch == CS_ARCH_ARM64)' instead.

> 
> >> +		/*
> >> +		 * Same as x86: arm64 needs instruction details to resolve
> >> +		 * symbolic addresses
> >> +		 */
> >> +		perf_cs_option(*cs_handle, CS_OPT_DETAIL, CS_OPT_ON);
> >>  	}
> >>  
> >>  	return 0;
> > 
> > [ ... ]
> > 
> >> +static bool is_pc_relative_insn(struct cs_insn *insn)
> >> +{
> >> +	int i;
> >> +
> >> +	if (insn->id == ARM64_INS_ADR || insn->id == ARM64_INS_ADRP)
> >> +		return true;
> >> +
> >> +	if (insn->detail == NULL)
> >> +		return false;
> >> +
> >> +	for (i = 0; i < insn->detail->groups_count; i++) {
> >> +		if (insn->detail->groups[i] == ARM64_GRP_JUMP ||
> >> +		    insn->detail->groups[i] == ARM64_GRP_CALL ||
> >> +		    insn->detail->groups[i] == ARM64_GRP_BRANCH_RELATIVE)
> > 
> > [Severity: Low]
> > Will this break compilation against Capstone versions prior to 5.0?
> > ARM64_GRP_BRANCH_RELATIVE was introduced in Capstone 5.0. Since the perf
> > tool's build feature detection doesn't mandate a specific Capstone version,
> > relying on this enum might cause build failures on older setups.

I don't think it's added in 5.0.  I can see it in the 4.0 version too.

https://github.com/capstone-engine/capstone/blob/4.0/include/capstone/arm64.h#L1149

> > 
> 
> This enum was added in Capstone 5.0 over two years ago. I think we can
> safely assume most systems are on a newer version now. I'll leave it as-is.

Two years ago is not old enough to ignore them.  In fact, I have a
commit to fix the capstone build issue by adding the missing constants.

https://lore.kernel.org/linux-perf-users/20260706234836.815254-1-namhyung@kernel.org/

> 
> >> +			return true;
> >> +	}
> >> +
> >> +	return false;
> >> +}
> >> +
> >> +static void format_capstone_insn_arm64(struct cs_insn *insn, char *buf,
> >> +				       size_t len, struct annotate_args *args,
> >> +				       u64 addr)
> >> +{
> > 
> > [ ... ]
> > 
> >> +	if (is_pc_relative_insn(insn)) {
> >> +		/* Extract last immediate value as address */
> >> +		last_imm = strrchr(buf, '#');
> >> +		if (!last_imm)
> >> +			return;
> >> +
> >> +		orig_addr = strtoull(last_imm + 1, &endptr, 16);
> > 
> > [Severity: Low]
> > Can this cause a build failure on musl libc? The POSIX standard function
> > strtoull() is used here, but stdlib.h is not explicitly included in the
> > file. Relying on implicit inclusions often works on glibc but breaks on
> > musl libc.
> > 
> 
> I'd say we can ignore this. strtoull() is used all over the perf codebase
> and gets included indirectly. I don't think this is a real issue.

Yep, most of these comments are false alarms.

Thanks,
Namhyung

> 
> >> +		if (endptr == last_imm + 1)
> >> +			return;
> >> +
> >> +		/* Relocate map that contains the address */
> >> +		if (dso__kernel(map__dso(map))) {
> >> +			found_map = maps__find(map__kmaps(map), orig_addr);
> >> +			if (found_map == NULL)
> >> +				return;
> >> +			map = found_map;
> >> +		}
> >> +
> >> +		/* Convert it to map-relative address for search */
> >> +		addr = map__map_ip(map, orig_addr);
> > 
> > [Severity: High]
> > Does this code fail to resolve symbols for relocated kernels (KASLR) or
> > user-space shared libraries (PIE)?
> > 
> > The extracted orig_addr is in the objdump address space. However,
> > maps__find() and map__map_ip() expect absolute memory addresses. By omitting
> > the translation step via map__objdump_2mem(map, orig_addr) (which the x86
> > implementation handles correctly), KASLR relocated kernels will fail in
> > maps__find(), and user-space shared libraries will underflow in
> > map__map_ip().
> > 
> 
> Agreed. I missed map__objdump_2mem() here.
> 
> >> +
> >> +		sym = map__find_symbol(map, addr);
> >> +		if (sym == NULL) {
> >> +			map__put(found_map);
> >> +			return;
> >> +		}
> > 
> 

  reply	other threads:[~2026-07-09  6:10 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  3:53 [PATCH v3 00/21] perf arm64: Support data type profiling Tengda Wu
2026-07-01  3:53 ` [PATCH v3 01/21] perf capstone: Fix kernel map reference count leak Tengda Wu
2026-07-09  5:57   ` Namhyung Kim
2026-07-10 21:49     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 02/21] perf capstone: Fix arm64 jump/adrp disassembly mismatch with objdump Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  6:44     ` Tengda Wu
2026-07-09  6:10       ` Namhyung Kim [this message]
2026-07-01  3:53 ` [PATCH v3 03/21] perf llvm: Fix arm64 adrp instruction " Tengda Wu
2026-07-01  4:05   ` sashiko-bot
2026-07-01  6:45     ` Tengda Wu
2026-07-09  6:18   ` Namhyung Kim
2026-07-09  7:49     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 04/21] perf annotate-arm64: Generalize arm64_mov__parse to support more instructions Tengda Wu
2026-07-01  4:03   ` sashiko-bot
2026-07-01  6:57     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 05/21] perf annotate-arm64: Handle load and store instructions Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  7:03     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 06/21] perf dwarf-regs: Adapt get_dwarf_regnum() for arm64 Tengda Wu
2026-07-01  4:07   ` sashiko-bot
2026-07-01  7:14     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 07/21] perf annotate: Adapt arch__dwarf_regnum() " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 08/21] perf annotate: Introduce extract_op_location callback for arch-specific parsing Tengda Wu
2026-07-01  4:06   ` sashiko-bot
2026-07-01  7:29     ` Tengda Wu
2026-07-09  6:31       ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 09/21] perf annotate-arm64: Implement extract_op_location() callback Tengda Wu
2026-07-01  4:10   ` sashiko-bot
2026-07-01  7:36     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 10/21] perf annotate: Deduplicate overlapping ARM SPE events for data type profiling Tengda Wu
2026-07-01  4:06   ` sashiko-bot
2026-07-09  6:47     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 11/21] perf auxtrace: Set default period to 1 for PERF_ITRACE_PERIOD_INSTRUCTIONS type Tengda Wu
2026-07-01  4:05   ` sashiko-bot
2026-07-01  3:53 ` [PATCH v3 12/21] perf annotate-data: Extract invalidate_reg_state() as a common helper Tengda Wu
2026-07-01  3:53 ` [PATCH v3 13/21] perf annotate-arm64: Enable instruction tracking support Tengda Wu
2026-07-01  4:12   ` sashiko-bot
2026-07-01  7:56     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 14/21] perf annotate-arm64: Support load instruction tracking Tengda Wu
2026-07-01  4:14   ` sashiko-bot
2026-07-01  8:37     ` Tengda Wu
2026-07-09  7:05       ` Namhyung Kim
2026-07-09  7:25         ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 15/21] perf annotate-arm64: Support store " Tengda Wu
2026-07-01  3:53 ` [PATCH v3 16/21] perf annotate-arm64: Support stack variable tracking Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-09  7:11     ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 17/21] perf annotate-arm64: Support 'mov' instruction tracking Tengda Wu
2026-07-01  4:21   ` sashiko-bot
2026-07-01  8:46     ` Tengda Wu
2026-07-09  7:17       ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 18/21] perf annotate-arm64: Support 'add' " Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-01  8:47     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 19/21] perf annotate-arm64: Support 'adrp' instruction to track global variables Tengda Wu
2026-07-01  4:15   ` sashiko-bot
2026-07-01  8:48     ` Tengda Wu
2026-07-09  7:31   ` Namhyung Kim
2026-07-09  7:42     ` Tengda Wu
2026-07-01  3:53 ` [PATCH v3 20/21] perf annotate-arm64: Support per-cpu variable access tracking Tengda Wu
2026-07-01  4:18   ` sashiko-bot
2026-07-09  7:29   ` Namhyung Kim
2026-07-01  3:53 ` [PATCH v3 21/21] perf annotate-arm64: Support 'mrs' instruction to track 'current' pointer Tengda Wu
2026-07-01  4:16   ` sashiko-bot
2026-07-01  8:56     ` Tengda Wu
2026-07-09  7:36       ` Namhyung Kim
2026-07-09  5:54 ` [PATCH v3 00/21] perf arm64: Support data type profiling Namhyung Kim
2026-07-09  8:01   ` Tengda Wu

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=ak87T3G5-4EAcKIy@z2 \
    --to=namhyung@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wutengda@huaweicloud.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.