Re: [PATCH v5 08/26] perf annotate: Adapt arch__dwarf_regnum() for arm64

From: Namhyung Kim

Date: Wed Sep 09 2026 - 13:21:52 EST


On Tue, Sep 08, 2026 at 01:05:11PM +0000, Tengda Wu wrote:
> Currently, arch__dwarf_regnum() assumes that all architectures use a
> register prefix character (e.g., '%' for x86) defined by
> arch->objdump.register_char, and uses it to match register names in
> objdump output. However, this assumption does not hold for arm64,
> where assembly syntax uses bare register names like 'x0', 'w1'
> without any prefix.
>
> As a result, arm64 builds may fail to correctly recognize register
> names from objdump disassembly, leading to incomplete or incorrect
> annotation output.
>
> To address this:
>
> - Make the register prefix check optional, allowing architectures
> without a prefix character to be parsed correctly.
>
> - Extend the delimiter set in strpbrk() to include the closing square
> bracket ']'. In arm64 assembly, memory operands often use bracketed
> syntax such as '[x1, #16]' or '[x2]'. Adding ']' ensures clean
> extraction of register names like 'x2' without trailing characters.
>
> Signed-off-by: Tengda Wu <wutengda@xxxxxxxxxxxxxxx>

Reviewed-by: Namhyung Kim <namhyung@xxxxxxxxxx>

Thanks,
Namhyung

> ---
> tools/perf/util/annotate.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index a3d48cf88dad..710a67980cea 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -2474,19 +2474,21 @@ int annotate_check_args(void)
>
> int arch__dwarf_regnum(const struct arch *arch, const char *str)
> {
> - const char *p;
> + const char *p = str;
> char *regname, *q;
> int reg;
>
> - p = strchr(str, arch->objdump.register_char);
> - if (p == NULL)
> - return -1;
> + if (arch->objdump.register_char) {
> + p = strchr(str, arch->objdump.register_char);
> + if (p == NULL)
> + return -1;
> + }
>
> regname = strdup(p);
> if (regname == NULL)
> return -1;
>
> - q = strpbrk(regname, ",) ");
> + q = strpbrk(regname, ",)] ");
> if (q)
> *q = '\0';
>
> --
> 2.34.1
>