From nobody Tue Feb 10 19:01:04 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 033282D0C9D for ; Sat, 10 Jan 2026 08:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768033632; cv=none; b=V9G1uxi2USECrlSsLIFJzaKVcKE/QsOep8gTWrYARNQXlf8C+evXUCoKDP5Jf7ypqJcqDjbBV0KLtlEuzRWB9ir8rAdjmYwakkMP4SXbIYcuTcKy8ifDeLKmyMxGhgSsVK+syQrETLNUqzAjUIs4uGSH0icfFvO2kqSPlQP2Ios= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768033632; c=relaxed/simple; bh=pnkoaS3BDyegUiypzuayNhPPwN3jB4XGtFWuYD1ZLdE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ituH9Fn2WLEa6Zql1nYAd8eOI+g84ajaIoE++tgu7R4aClKIHKVYK6Zyk53AvYWxDLiu7Kx4/2GJHdF3ruoEUJb32w/zsnx/0vzqtKxAGjnJOyTrDMiVCNY04ZKq8ov/LBaLYTH7tGybpBXqePyjOXrEk94vWmRsaLxyO6sa1uo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Yd0ebnaQ; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Yd0ebnaQ" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b0751d8de7so6545988eec.1 for ; Sat, 10 Jan 2026 00:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768033628; x=1768638428; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=79Lm5r+aff6tOMggRex7lERHHcu3vz/+dw8OY+TEe/4=; b=Yd0ebnaQSX+GYtdVOfJkteUHQNK6P/KHpYrnTzgwmWvMi4F17cAtrh9/t1vrFGErgW clID8T+Za5Nj6FX91zhbRR1aV94emW995LEL2eqweP0dqLUvHB/UAebYIzYvgEzQfaVz 8Bv5Kag9zZ5r058xuouZfpk55NBYddJ7jFkdMaNL1Gha9zvnMa4gKB1rJ92K1ed0Yz8V DyE+4Mv2Z7Ea7drEpg9ATz8Tnm6H7QVVofqWYN3jmkaOGTwyLU84468+WPAlFQPgoZd8 fiAY+m7Ym42o5VkZqp2p7Z/yRV2Fgh6i1N74gggiX92aD0yivQjWYJfBjg2BWA4a84e9 O3dQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768033628; x=1768638428; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=79Lm5r+aff6tOMggRex7lERHHcu3vz/+dw8OY+TEe/4=; b=GKFdKu1iNOwssDisskk8zGRpMLpQkNE40Sve//H6tV1kh3bnNJ5cSeTqiReaErm78o XKwh4d203OyMxa2reOZNZ/Jf2jz3oYujHuw8MiVEvTy47dp1oetz2L2VUYZgd7knpFQP WHeDVc9eSgIGDE5UcmTrnfST4YQH8pxUdEKVrdhQcccUXZLUDBfIl44N/l7xzHBsXIcL vEtx04od68D4R8k57a+V1kdpYYixYa9F5V3MlqqoLyoh2fA06K6D2nDcEiPNxB01E0J8 br6VMgcxrjyiOBnLXqPv8B+Hs+71erjYzeCRxGEnf0G+g2XLwxmb5YdYptYB9hqj0Cj1 EQGQ== X-Forwarded-Encrypted: i=1; AJvYcCW3aw7Sk7rffycTKAfZPt/3O9kg1z16oueYjUx6xl1/fVrDd/KQaxzR5xLL4fVhHAW/X8+IipOyt1nE8bI=@vger.kernel.org X-Gm-Message-State: AOJu0YyiKJy0DfGcnxsAiGV7GJyOEqCW8O3N4dPIsuPJgcDMuDLSyKjb AlPg11HhMY479399ofF92HwVrYhlTyjov76uPHU9Z6NVjuQfHLygM9hJ8f8may76xEFDybiXbTR PsX2JYkwb6A== X-Google-Smtp-Source: AGHT+IGm21jOzlz78+2UjMxDPLK8wEehACK+/yY7QPmjN+KJZhLWyZGzOZVqvJ/Fkf4vb/EEKX5U3Wycb+pP X-Received: from dlbtk10.prod.google.com ([2002:a05:7022:fb0a:b0:11f:4501:52c4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:e07:b0:119:e56b:98b9 with SMTP id a92af1059eb24-121f8b78f17mr13167388c88.32.1768033627888; Sat, 10 Jan 2026 00:27:07 -0800 (PST) Date: Sat, 10 Jan 2026 00:26:44 -0800 In-Reply-To: <20260110082647.1487574-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260110082647.1487574-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260110082647.1487574-4-irogers@google.com> Subject: [PATCH v2 3/6] perf srcline: Add configuration support for the addr2line style From: Ian Rogers To: Tony Jones , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Howard Chu , Stephen Brennan , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow the addr2line style to be specified on the `perf report` command line or in the .perfconfig file. Signed-off-by: Ian Rogers --- tools/perf/builtin-report.c | 10 ++++ tools/perf/util/config.c | 4 ++ tools/perf/util/srcline.c | 98 +++++++++++++++++++++++++++++++---- tools/perf/util/srcline.h | 2 + tools/perf/util/symbol_conf.h | 10 ++++ 5 files changed, 113 insertions(+), 11 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 6c2b4f93ec78..2e936928e8c0 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -1271,6 +1271,13 @@ parse_percent_limit(const struct option *opt, const = char *str, return 0; } =20 +static int +report_parse_addr2line_config(const struct option *opt __maybe_unused, + const char *arg, int unset __maybe_unused) +{ + return addr2line_configure("addr2line.style", arg, NULL); +} + static int process_attr(const struct perf_tool *tool __maybe_unused, union perf_event *event, struct evlist **pevlist) @@ -1447,6 +1454,9 @@ int cmd_report(int argc, const char **argv) "objdump binary to use for disassembly and annotations"), OPT_STRING(0, "addr2line", &addr2line_path, "path", "addr2line binary to use for line numbers"), + OPT_CALLBACK(0, "addr2line-style", NULL, "addr2line style", + "addr2line styles (libdw,llvm,libbfd,addr2line)", + report_parse_addr2line_config), OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle, "Symbol demangling. Enabled by default, use --no-demangle to disable= ."), OPT_BOOLEAN(0, "demangle-kernel", &symbol_conf.demangle_kernel, diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index e0219bc6330a..0452fbc6c085 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -20,6 +20,7 @@ #include "util/stat.h" /* perf_stat__set_big_num */ #include "util/evsel.h" /* evsel__hw_names, evsel__use_bpf_counters */ #include "util/addr2line.h" /* addr2line_timeout_ms */ +#include "srcline.h" #include "build-id.h" #include "debug.h" #include "config.h" @@ -519,6 +520,9 @@ int perf_default_config(const char *var, const char *va= lue, if (strstarts(var, "stat.")) return perf_stat_config(var, value); =20 + if (strstarts(var, "addr2line.")) + return addr2line_configure(var, value, dummy); + /* Add other config variables here. */ return 0; } diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c index e2d280678b02..28fa1abd1fd3 100644 --- a/tools/perf/util/srcline.c +++ b/tools/perf/util/srcline.c @@ -7,9 +7,11 @@ #include "llvm.h" #include "symbol.h" #include "libdw.h" +#include "debug.h" =20 #include #include +#include =20 bool srcline_full_filename; =20 @@ -138,21 +140,95 @@ static int addr2line(const char *dso_name, u64 addr, = char **file, unsigned int * struct dso *dso, bool unwind_inlines, struct inline_node *node, struct symbol *sym) { - int ret; + int ret =3D 0; + + if (symbol_conf.addr2line_style[0] =3D=3D A2L_STYLE_UNKNOWN) { + int i =3D 0; + + /* Default addr2line fallback order. */ +#ifdef HAVE_LIBDW_SUPPORT + symbol_conf.addr2line_style[i++] =3D A2L_STYLE_LIBDW; +#endif +#ifdef HAVE_LIBLLVM_SUPPORT + symbol_conf.addr2line_style[i++] =3D A2L_STYLE_LLVM; +#endif +#ifdef HAVE_LIBBFD_SUPPORT + symbol_conf.addr2line_style[i++] =3D A2L_STYLE_LIBBFD; +#endif + symbol_conf.addr2line_style[i++] =3D A2L_STYLE_CMD; + } + + for (size_t i =3D 0; i < ARRAY_SIZE(symbol_conf.addr2line_style); i++) { + switch (symbol_conf.addr2line_style[i]) { + case A2L_STYLE_LIBDW: + ret =3D libdw__addr2line(dso_name, addr, file, line_nr, dso, unwind_inl= ines, + node, sym); + break; + case A2L_STYLE_LLVM: + ret =3D llvm__addr2line(dso_name, addr, file, line_nr, dso, unwind_inli= nes, + node, sym); + break; + case A2L_STYLE_LIBBFD: + ret =3D libbfd__addr2line(dso_name, addr, file, line_nr, dso, unwind_in= lines, + node, sym); + break; + case A2L_STYLE_CMD: + ret =3D cmd__addr2line(dso_name, addr, file, line_nr, dso, unwind_inlin= es, + node, sym); + break; + case A2L_STYLE_UNKNOWN: + default: + break; + } + if (ret > 0) + return ret; + } + + return 0; +} + +int addr2line_configure(const char *var, const char *value, void *cb __may= be_unused) +{ + static const char * const a2l_style_names[] =3D { + [A2L_STYLE_LIBDW] =3D "libdw", + [A2L_STYLE_LLVM] =3D "llvm", + [A2L_STYLE_LIBBFD] =3D "libbfd", + [A2L_STYLE_CMD] =3D "addr2line", + NULL + }; + + char *s, *p, *saveptr; + size_t i =3D 0; =20 - ret =3D libdw__addr2line(dso_name, addr, file, line_nr, dso, unwind_inlin= es, node, sym); - if (ret > 0) - return ret; + if (strcmp(var, "addr2line.style")) + return 0; + + if (!value) + return -1; =20 - ret =3D llvm__addr2line(dso_name, addr, file, line_nr, dso, unwind_inline= s, node, sym); - if (ret > 0) - return ret; + s =3D strdup(value); + if (!s) + return -1; =20 - ret =3D libbfd__addr2line(dso_name, addr, file, line_nr, dso, unwind_inli= nes, node, sym); - if (ret > 0) - return ret; + p =3D strtok_r(s, ",", &saveptr); + while (p && i < ARRAY_SIZE(symbol_conf.addr2line_style)) { + bool found =3D false; + char *q =3D strim(p); + + for (size_t j =3D A2L_STYLE_LIBDW; j < MAX_A2L_STYLE; j++) { + if (!strcasecmp(q, a2l_style_names[j])) { + symbol_conf.addr2line_style[i++] =3D j; + found =3D true; + break; + } + } + if (!found) + pr_warning("Unknown addr2line style: %s\n", q); + p =3D strtok_r(NULL, ",", &saveptr); + } =20 - return cmd__addr2line(dso_name, addr, file, line_nr, dso, unwind_inlines,= node, sym); + free(s); + return 0; } =20 static struct inline_node *addr2inlines(const char *dso_name, u64 addr, diff --git a/tools/perf/util/srcline.h b/tools/perf/util/srcline.h index be9f002bf234..7c37b3bf9ce7 100644 --- a/tools/perf/util/srcline.h +++ b/tools/perf/util/srcline.h @@ -63,4 +63,6 @@ struct symbol *new_inline_sym(struct dso *dso, struct symbol *base_sym, const char *funcname); =20 +int addr2line_configure(const char *var, const char *value, void *cb); + #endif /* PERF_SRCLINE_H */ diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h index 7a80d2c14d9b..71bb17372a6c 100644 --- a/tools/perf/util/symbol_conf.h +++ b/tools/perf/util/symbol_conf.h @@ -9,6 +9,15 @@ struct strlist; struct intlist; =20 +enum a2l_style { + A2L_STYLE_UNKNOWN =3D 0, + A2L_STYLE_LIBDW, + A2L_STYLE_LLVM, + A2L_STYLE_LIBBFD, + A2L_STYLE_CMD, +}; +#define MAX_A2L_STYLE (A2L_STYLE_CMD + 1) + struct symbol_conf { bool nanosecs; unsigned short priv_size; @@ -70,6 +79,7 @@ struct symbol_conf { *col_width_list_str, *bt_stop_list_str; const char *addr2line_path; + enum a2l_style addr2line_style[MAX_A2L_STYLE]; unsigned long time_quantum; struct strlist *dso_list, *comm_list, --=20 2.52.0.457.g6b5491de43-goog