From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 A27C41F181F for ; Sun, 23 Nov 2025 02:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865153; cv=none; b=WaxCkWPPIcKh/XStbnDsDdUOXJbpns2En1u78Pb7OwlIaMzZHMqvm60w1okcA8hm1GSuFxma+vXT1jFCEIBfqNSPA29CwyrqjqjQyY7CczFijMoGfnOj7FfpU675+ZSjOLOSKioiEX1S8i2xQ8XMaizVWzPAT2gPN0c3cosxFxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865153; c=relaxed/simple; bh=5QMdl7eVBNTewwuuJO3lMgdAqN0GWRRlNGk3e8qasGg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=uO+ze+UMnL+U23vX5P1qy/3qpfwA1D2lb3PPVP0VH5zFypgOUNGqjs79VzbzpUaOU6LUAlVUTQNhpaxCcb3Dvz6eijucz2ZlztKvfSAlWiAK4pqe6TPr33RY3pC6I8+wh8iRBmQmSauMO6a4JxtGvyUVJE+s+EYOpN+wkEWmd8w= 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=XbWtcnNm; arc=none smtp.client-ip=209.85.215.201 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="XbWtcnNm" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b9ceccbd7e8so7956942a12.0 for ; Sat, 22 Nov 2025 18:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865151; x=1764469951; 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=a3m6U2A9WK68emhqbKZBFX3D9dZLpGkE+dA1a3ZMrcY=; b=XbWtcnNmkzhIhdX6y+Ej3cL+bp/42IWw5pCrBUlvOsTifU3NN0dkHo+XwcMMDotLX/ LG2wetlnTiRtJ4/5RlKJbB9OSBfajQLtXZFavmoHxmvTASE3owko64NJXr/SRl+e7596 HAwaRVYQU+1vNUv3s9sWMGG5G7zKIQBId1PVHWGJrKKmLXsS5O3tpkVpydXo87F+PTDV qRT+FVM/Nop03bcoA9yC8fdp3jqK3rQv8EmT2zkvH3emCB5BguVB4bMPuhRZvUq0mRJb KLkhpwGcH5tC+wL9jlllp3Ei/2vlWwjmcprvWi8Ck3C1SEXANJVIa85M5BHp9SlxoQnQ v+og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865151; x=1764469951; 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=a3m6U2A9WK68emhqbKZBFX3D9dZLpGkE+dA1a3ZMrcY=; b=UqwxEHysWxR7oXonYbymgYy42ygbQ3ubYwrdlvJJFshjhB7WrCYBM+qo9DKGolD9oB xkHwzPN0JKwYZW2bL+7hY9h0pTAAfiOly4oPTKKwq8/fK53xDEKKl5eXsf2SDBq270b1 ewWHTVCJawnrQe+pAEAZ/I7DYM2nNbos6PFeLmN+mcdLpf8/3vqy4MsbMQuTH/gtD+YV 15TSWhTKMtGdBHY8cIobaWLZ2uH9TU+/mh7KSg0LI1YK8O9wnPalMq3CuCX8iZv/g/vA 7sCgbE7sZ3A7DUW7JcrSmgKU+5XfjAMHv7miGozi44k8tfLR7Y6mB5s0o2+coqWxknJr nPAg== X-Forwarded-Encrypted: i=1; AJvYcCUA5H80Xwvm0Ru7Fwuqd4m8TnQKXrvoIv1AvOi5hW+ORNvkbi3b+gwd/+Hn3MYjWmZoKMpTlD2mKgz4mW4=@vger.kernel.org X-Gm-Message-State: AOJu0YzRUUjXBGRwHMA05kftxlm9klsFCXNkTL+CbVLlNK7U0Hgfh3rI cvMIPnhRSRlaeb0w/2cXsm1HJ+czoNlb+9lV29PatCY8tEwycfJjGHwFskYtxjR+l0Z9g0eTTwl XRJdvST5WZw== X-Google-Smtp-Source: AGHT+IH3pIkeTqQHy76r4obdhe86Ny6izg2Sh0yksr9YISTMimKKaq+pmHRF86AOvIkaLfNtdVyaVB15Gd7R X-Received: from dybhi45.prod.google.com ([2002:a05:7301:29ad:b0:2a4:75f7:2135]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:4625:b0:2a4:61d1:f451 with SMTP id 5a478bee46e88-2a7190f6638mr3165341eec.16.1763865150882; Sat, 22 Nov 2025 18:32:30 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:17 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-2-irogers@google.com> Subject: [PATCH v1 1/9] perf symbol: Reduce scope of elf__needs_adjust_symbols From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Function is only used by symsrc__init in symbol-elf.c, make static to reduce scope. Switch to not passing the argument by value but as a pointer. Signed-off-by: Ian Rogers --- tools/perf/util/symbol-elf.c | 8 ++++---- tools/perf/util/symbol.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 9e820599bab3..5cd4844f9bb4 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1051,15 +1051,15 @@ void symsrc__destroy(struct symsrc *ss) close(ss->fd); } =20 -bool elf__needs_adjust_symbols(GElf_Ehdr ehdr) +static bool elf__needs_adjust_symbols(const GElf_Ehdr *ehdr) { /* * Usually vmlinux is an ELF file with type ET_EXEC for most * architectures; except Arm64 kernel is linked with option * '-share', so need to check type ET_DYN. */ - return ehdr.e_type =3D=3D ET_EXEC || ehdr.e_type =3D=3D ET_REL || - ehdr.e_type =3D=3D ET_DYN; + return ehdr->e_type =3D=3D ET_EXEC || ehdr->e_type =3D=3D ET_REL || + ehdr->e_type =3D=3D ET_DYN; } =20 static Elf *read_gnu_debugdata(struct dso *dso, Elf *elf, const char *name= , int *fd_ret) @@ -1232,7 +1232,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, = const char *name, if (dso__kernel(dso) =3D=3D DSO_SPACE__USER) ss->adjust_symbols =3D true; else - ss->adjust_symbols =3D elf__needs_adjust_symbols(ehdr); + ss->adjust_symbols =3D elf__needs_adjust_symbols(&ehdr); =20 ss->name =3D strdup(name); if (!ss->name) { diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 347106218799..d91dc89386e2 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -217,7 +217,6 @@ int setup_intlist(struct intlist **list, const char *li= st_str, const char *list_name); =20 #ifdef HAVE_LIBELF_SUPPORT -bool elf__needs_adjust_symbols(GElf_Ehdr ehdr); void arch__sym_update(struct symbol *s, GElf_Sym *sym); #endif =20 --=20 2.52.0.rc2.455.g230fcf2819-goog From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 67D9720E00B for ; Sun, 23 Nov 2025 02:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865155; cv=none; b=EEm/h94lm5zRjhgr0qQ6p3M7+Z2Xhhoe+6b/MQCVtra80F8PiSldB+ZzGzyKcpb+kc3wHA5Jis2+FA/fFvn10w5kwKAomd3GNlXX9RbSq8t4mSCSOnrnbUieQhQarm52Y3/XSCdsOdrGG8Ebs/A/rTmBgBiYA0SrS1mSNlRkMuk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865155; c=relaxed/simple; bh=AIOFFfn1a4wuAIU5AeQadsr3Kz3VlSrCRDahCs/SE08=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=nTDYLUSY/49Zn+tkhGIvilZfRg5jU2+TDQOC3Zq2sNTzXUqjDWpIzRoPK9vzH1tjsSW2TbyjAKDqHPCsfytGizRUw9P/VnVnDVVPFCIT846CHNSRN2zlebV2vak5PQb+MEFAf2AILpQFl845zJ21Y0nlgyCMtDcUgKoYnR+gzSs= 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=XXfDFLZq; arc=none smtp.client-ip=209.85.215.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="XXfDFLZq" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b969f3f5bb1so5662267a12.0 for ; Sat, 22 Nov 2025 18:32:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865153; x=1764469953; 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=ZXAHOA2dBofuW+6TFI6lLyA+tJ+ZKr1M8T35iNKkIls=; b=XXfDFLZqh3krUEJTkvTa1k5sRR5Exi2Ty3SkmnThFi2GRuHQ0Udq78impI+V7Tt+KR GsLm87EoXhu+rMJj56AJjjzKZXNvoP6yeYxJgbu/w6rU+2ba7BnowLJuxgkm2g2xQBCQ Uy2vAc3ReN+9NUkRe2azBRM2YUbojIV3Ktzib2WpJzhEJfr6zO6BXNXUXEx5SjmgPF4S M4Lc3hosIYtFydUmAiKuGLgbeG5FK4rKnl5Y9GzLNiVFdLnoPoMm7RlTw2G/DtALtzio 1raBfuPFMwu0sKRncPAwybZEzuY8UROj3eL6nZXFhmlqbOEi/kmV4ZCRFfi61VQ9cD12 Sr7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865153; x=1764469953; 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=ZXAHOA2dBofuW+6TFI6lLyA+tJ+ZKr1M8T35iNKkIls=; b=vnvCA9TmPNMJ8qVtd9Mgy+2Rzge8W0LvFa41spOHcR/5eFw1EtAvj5DgTn1WsWxmst yAFpkS31yOBLEgi0O13zRB2giSsRajyLmkTspRbFIZGCvJFs4+PWcdM8nk4tuc075CIQ gjOF1rpYB4RvabmsXaEDtXaLiTW3lmWmVwrNC/xy4u1iaIfpMN76AhaUB1WhKoo+9K8d 2rnpPvZOhBBY4ExSmPmqRRENisJ/dfoXTJgVtCV+s+BIh/UBbEc5BD6DvKwxG9JACx0J I/onDne5A40o+IkZFZlehOQqWpfaf3tE0pt7EFBIlJAiuJcfCOY9k2gIXKuAjbqEhqvk tLTg== X-Forwarded-Encrypted: i=1; AJvYcCXxnyfTAz/SSVajYYPXj+ChpSyuSKU4IZY93AYtEJRLCvaNMCFjXu+IdZTaZmWCnSHtuRF6+87GmBI51cI=@vger.kernel.org X-Gm-Message-State: AOJu0YzmX+1rxXXCrTdmieKMiaHE73e4n7Xjcry/XsiaCUAZDUjkJBmk nPRopBNMMJa0n4jjc6Iowxt2fTMKVQJA+KH68OfttNf0tsRT84yeh9RbdhHXzlYxcjjCym7Sqa2 ATL4gMpR1FQ== X-Google-Smtp-Source: AGHT+IG0+th98zEo0nte2Be3vxkhSzkU0BgoA2iKtM/9oG06MZQAnFG14NRSDuqKLCrKOcFqPu/aKHUiUa70 X-Received: from dlbrh6.prod.google.com ([2002:a05:7022:f306:b0:11a:26c7:567d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:7f07:b0:11b:aca4:be1f with SMTP id a92af1059eb24-11c9d712cd4mr2415052c88.17.1763865152648; Sat, 22 Nov 2025 18:32:32 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:18 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-3-irogers@google.com> Subject: [PATCH v1 2/9] perf symbol: Reduce scope of arch__sym_update From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rather than being a weak arch function, use the e_machine from the ELF header to determine whether to update or not. This should make the function work cross-platform, it also reduces the function's scope. Signed-off-by: Ian Rogers --- tools/perf/arch/powerpc/util/sym-handling.c | 7 ------- tools/perf/util/symbol-elf.c | 9 ++++++--- tools/perf/util/symbol.h | 4 ---- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/= powerpc/util/sym-handling.c index 947bfad7aa59..afefa9bd0c93 100644 --- a/tools/perf/arch/powerpc/util/sym-handling.c +++ b/tools/perf/arch/powerpc/util/sym-handling.c @@ -66,13 +66,6 @@ const char *arch__normalize_symbol_name(const char *name) =20 #if defined(_CALL_ELF) && _CALL_ELF =3D=3D 2 =20 -#ifdef HAVE_LIBELF_SUPPORT -void arch__sym_update(struct symbol *s, GElf_Sym *sym) -{ - s->arch_sym =3D sym->st_other; -} -#endif - #define PPC64LE_LEP_OFFSET 8 =20 void arch__fix_tev_from_maps(struct perf_probe_event *pev, diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 5cd4844f9bb4..629b272e0a13 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1337,8 +1337,11 @@ static u64 ref_reloc(struct kmap *kmap) return 0; } =20 -void __weak arch__sym_update(struct symbol *s __maybe_unused, - GElf_Sym *sym __maybe_unused) { } +static void arch__sym_update(int e_machine, const GElf_Sym *sym, struct sy= mbol *s) +{ + if (e_machine =3D=3D EM_PPC64 || e_machine =3D=3D EM_PPC) + s->arch_sym =3D sym->st_other; +} =20 static int dso__process_kernel_symbol(struct dso *dso, struct map *map, GElf_Sym *sym, GElf_Shdr *shdr, @@ -1717,7 +1720,7 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, if (!f) goto out_elf_end; =20 - arch__sym_update(f, &sym); + arch__sym_update(ehdr.e_machine, &sym, f); =20 __symbols__insert(dso__symbols(curr_dso), f, dso__kernel(dso)); nr++; diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index d91dc89386e2..78fb2ba69f65 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -216,10 +216,6 @@ int setup_list(struct strlist **list, const char *list= _str, int setup_intlist(struct intlist **list, const char *list_str, const char *list_name); =20 -#ifdef HAVE_LIBELF_SUPPORT -void arch__sym_update(struct symbol *s, GElf_Sym *sym); -#endif - const char *arch__normalize_symbol_name(const char *name); #define SYMBOL_A 0 #define SYMBOL_B 1 --=20 2.52.0.rc2.455.g230fcf2819-goog From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 594DD20E005 for ; Sun, 23 Nov 2025 02:32:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865157; cv=none; b=tg+KYMZoma7XPiK/cnucgw1J1vB2184KdAKH6zuyvLv6tbjsDbfVyr0KRsBJj6WlTgtHsAd3mCQ5Rndwh46DLfYxpUoze9oWS5EnkHNXGb4RfT3Ey3dR1CBCcnUdRZBiuyhFsAbNyzMw6jMBT8ikT4M3aKaY9CyUy70QzBD3HJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865157; c=relaxed/simple; bh=aurn4Dh28lozFTymzAvSbXMKa1lOTrutbzsMcEL3k5Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=iEdgDD7RykvXixhQ+6BNw+xrTKRrd0IP4rwqfgxyuDbYMRTv0g5Skq2tVRIVesPb8BZl/59c1h2VmXh+yd0xbxrP5OipMXyXKnWkOZXay8VCBhYvP3PLtwxm29CYrCi/T//ETDPkKb87Kw5wRKLec1gbNelSa1UxPsEyQkuB/n4= 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=dAAjaGIf; arc=none smtp.client-ip=209.85.215.201 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="dAAjaGIf" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b99763210e5so7239865a12.3 for ; Sat, 22 Nov 2025 18:32:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865155; x=1764469955; 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=1hyIb3WLSFrI4ZPWpu7Qui5QIECa8CMI86AYGc9NSmg=; b=dAAjaGIf+T5nS4Jt+ARE7KXIXM49ZEoyATmTF4kX9XhQeeKGBRPW0j6weHIbEejJYb Gz+1hs1Y/+FSABNsaGBWdGxToeO6e0yd4xDv9KeFLmaiZ/SfVqOhZS0oN+d/WoA2FPzc gQgYPTZrw9xYXkQMmphN/Xbp8c2Kh47r6+y/RHVMM6KK9S6ggMByBQD1af6tjhQvGy/O IyFCyOtlfM+Ble8IE3ZVGCPT6xEmYH/mVaNdxC4rUR5XW2KVAWrnjlRm6WnOIwPaHuzc dbusNPDt104KNGXgtRppt18mGn7hiUdH+ukAPm3tLmclDwfxUE3sCJPZUkhPvhKl8Ft6 UwiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865155; x=1764469955; 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=1hyIb3WLSFrI4ZPWpu7Qui5QIECa8CMI86AYGc9NSmg=; b=uH3RncUa7a8hcZmN68muQU7rGrQQHnU6JawOLnS09SzjnseTYlMmLLahq8nVWWE4wB qgoqE2OWFcG5gAb9EBmmZTKAcVM7HQEnehRDoCuhH1ACS3bEUdVJHTvW6xRxjJBM2Vi1 Dgn8gCwnb+f2UWZX28lk3S3IJ7RRSvnBlYNVvgRPV9iOJuk0096DskPShoBASaB/U+zB +jfYc9PjhA0xvQhF2W/HnPIm7fT1kvPImyThcNEYnT4o6ph0Qn+XNv64aTwjlSA2dNy0 Mtjg+xrp7jieTa1PMC11F5VA6+Oxi00sOz9MqqqZt2/KCIFUZXnb4f/ewJ9gRpD7yZae 574w== X-Forwarded-Encrypted: i=1; AJvYcCXDLn9Ic14T+qfIJnAU5F6C2NM+3LKDiDzysro6kVNYWOvJY0tGnY7lb/QZPOCfPCusttgjXhdNAspws9M=@vger.kernel.org X-Gm-Message-State: AOJu0YyaEgAasmbtfKSvxs2Dgl5yxMYd78mz+KfrSxrpz9ioKv5QQDJe w/zarkvksQErQDnafLFXCCGxrkXabVoYrYEVkq8IQvsgsNVdba1V0/jWk6lTfrXvTzRop46duqY KH8yl2Zr0DA== X-Google-Smtp-Source: AGHT+IF4v0ISLVNVWR+f517YFzCUNed78JCR/m2OEg5f9W15rzeFtSWlCjrOJ+aDJ2Vi7/mPFC0Rjrw5O4Lz X-Received: from dyz20.prod.google.com ([2002:a05:693c:4094:b0:2a2:9bd7:1a64]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:de01:b0:2a4:41c6:24f with SMTP id 5a478bee46e88-2a7190b3e87mr3276686eec.7.1763865154630; Sat, 22 Nov 2025 18:32:34 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:19 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-4-irogers@google.com> Subject: [PATCH v1 3/9] perf symbol: Move libelf code to its own file/header From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move perf declarations depending on libelf out of symbol.h into perf-libelf.h. Move the corresponding C code into perf-libelf.c. This is motivated by trying to make it clearer the symbol.[ch] is generic code without library dependencies. Signed-off-by: Ian Rogers --- tools/perf/util/Build | 1 + tools/perf/util/perf-libelf.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/perf-libelf.h | 25 +++++++++++++++++++++++++ tools/perf/util/probe-event.c | 1 + tools/perf/util/probe-finder.c | 1 + tools/perf/util/symbol-elf.c | 27 +-------------------------- tools/perf/util/symbol.h | 19 ------------------- 7 files changed, 61 insertions(+), 45 deletions(-) create mode 100644 tools/perf/util/perf-libelf.c create mode 100644 tools/perf/util/perf-libelf.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 1c2a43e1dc68..dcac6f1e1d99 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -193,6 +193,7 @@ ifeq ($(CONFIG_LIBTRACEEVENT),y) perf-util-$(CONFIG_PERF_BPF_SKEL) +=3D bpf_kwork_top.o endif =20 +perf-util-$(CONFIG_LIBELF) +=3D perf-libelf.o perf-util-$(CONFIG_LIBELF) +=3D symbol-elf.o perf-util-$(CONFIG_LIBELF) +=3D probe-file.o perf-util-$(CONFIG_LIBELF) +=3D probe-event.o diff --git a/tools/perf/util/perf-libelf.c b/tools/perf/util/perf-libelf.c new file mode 100644 index 000000000000..abd55bd7f14b --- /dev/null +++ b/tools/perf/util/perf-libelf.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "perf-libelf.h" + +#include +#include + +Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, + GElf_Shdr *shp, const char *name, size_t *idx) +{ + Elf_Scn *sec =3D NULL; + size_t cnt =3D 1; + + /* ELF is corrupted/truncated, avoid calling elf_strptr. */ + if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) + return NULL; + + while ((sec =3D elf_nextscn(elf, sec)) !=3D NULL) { + char *str; + + gelf_getshdr(sec, shp); + str =3D elf_strptr(elf, ep->e_shstrndx, shp->sh_name); + if (str && !strcmp(name, str)) { + if (idx) + *idx =3D cnt; + return sec; + } + ++cnt; + } + + return NULL; +} + diff --git a/tools/perf/util/perf-libelf.h b/tools/perf/util/perf-libelf.h new file mode 100644 index 000000000000..5d7d18daf5ff --- /dev/null +++ b/tools/perf/util/perf-libelf.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_LIBELF_H +#define __PERF_LIBELF_H + +#ifdef HAVE_LIBELF_SUPPORT + +#include +#include + +/* + * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; + * for newer versions we can use mmap to reduce memory usage: + */ +#ifdef ELF_C_READ_MMAP +# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP +#else +# define PERF_ELF_C_READ_MMAP ELF_C_READ +#endif + +Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, cons= t char *name, + size_t *idx); + +#endif // defined(HAVE_LIBELF_SUPPORT) + +#endif /* __PERF_LIBELF_H */ diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index 6ab2eb551b6c..c27ad9121230 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -23,6 +23,7 @@ #include "build-id.h" #include "event.h" #include "namespaces.h" +#include "perf-libelf.h" #include "strlist.h" #include "strfilter.h" #include "debug.h" diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c index 5ffd97ee4898..f94f742a3458 100644 --- a/tools/perf/util/probe-finder.c +++ b/tools/perf/util/probe-finder.c @@ -25,6 +25,7 @@ #include "debug.h" #include "debuginfo.h" #include "intlist.h" +#include "perf-libelf.h" #include "strbuf.h" #include "strlist.h" #include "symbol.h" diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 629b272e0a13..750a30b216d6 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -12,6 +12,7 @@ #include "libbfd.h" #include "map.h" #include "maps.h" +#include "perf-libelf.h" #include "symbol.h" #include "symsrc.h" #include "machine.h" @@ -183,32 +184,6 @@ static size_t elf_addr_to_index(Elf *elf, GElf_Addr ad= dr) return -1; } =20 -Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, - GElf_Shdr *shp, const char *name, size_t *idx) -{ - Elf_Scn *sec =3D NULL; - size_t cnt =3D 1; - - /* ELF is corrupted/truncated, avoid calling elf_strptr. */ - if (!elf_rawdata(elf_getscn(elf, ep->e_shstrndx), NULL)) - return NULL; - - while ((sec =3D elf_nextscn(elf, sec)) !=3D NULL) { - char *str; - - gelf_getshdr(sec, shp); - str =3D elf_strptr(elf, ep->e_shstrndx, shp->sh_name); - if (str && !strcmp(name, str)) { - if (idx) - *idx =3D cnt; - return sec; - } - ++cnt; - } - - return NULL; -} - bool filename__has_section(const char *filename, const char *sec) { int fd; diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 78fb2ba69f65..0aa8680cbd3e 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -14,10 +14,6 @@ #include "symbol_conf.h" #include "spark.h" =20 -#ifdef HAVE_LIBELF_SUPPORT -#include -#include -#endif #include =20 struct dso; @@ -26,21 +22,6 @@ struct maps; struct option; struct build_id; =20 -/* - * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; - * for newer versions we can use mmap to reduce memory usage: - */ -#ifdef ELF_C_READ_MMAP -# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP -#else -# define PERF_ELF_C_READ_MMAP ELF_C_READ -#endif - -#ifdef HAVE_LIBELF_SUPPORT -Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, - GElf_Shdr *shp, const char *name, size_t *idx); -#endif - /** * A symtab entry. When allocated this may be preceded by an annotation (s= ee * symbol__annotation) and/or a browser_index (see symbol__browser_index). --=20 2.52.0.rc2.455.g230fcf2819-goog From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 188DB21FF4D for ; Sun, 23 Nov 2025 02:32:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865160; cv=none; b=eET7x7zQgXjW4w4KjCnfHuP5LcvTDHwUd+2aGr3vqlxgANXTOhCLf/VBLpHMuYA71wlZg69GG3+xXJJRn/iHFUpGmtAqMDfYCVjwE6cbxXPjiir1ugn1NlQXFb8K7ylg68NSEgil8o/LPcsntQUuUOrsWFlX+PFYbabnt5wgVAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865160; c=relaxed/simple; bh=Rp4eda9C1ATKucMQ/QQtWlwQHJR2M//M3Q8qxQeZp3M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=rq/kHu4Y8E7dVIiP9klzOmkxk7YCJvQeADUwWHR4rk4zTVMj+3qegUSYLJkwJjQvGdqMpNQZNOV4c9ht/Jt7+v4ShP44kU3C5XyhkR7CdDmDQyA4K+E/6Wke8FliHrR3VH4ULp8R0eRCnRgY1ArGJwcl+ACfgKiIiFMnBblt37A= 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=g2G+Vo/g; arc=none smtp.client-ip=209.85.215.201 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="g2G+Vo/g" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b6ce1b57b9cso3493885a12.1 for ; Sat, 22 Nov 2025 18:32:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865156; x=1764469956; 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=9MrD8q8jaHTyg2hGjIo8QUfr8DpjjjCwdkXOe4qqozQ=; b=g2G+Vo/g2M4vllf2Go1LwNHWsIKBJocNRGKuTT5HpnSZ0wEwR5dq39bbnQAx7F9VEC NiVDJ/rFNBYa/SE5nkZnXLZO54mVzydUabwRCNpXwQ1P28Kkz32arHb/geB/XcyOPW+P a9EwzNLVqOZdXCOQn0qjj4LGG2/OJ5YEnDhrvKkMusg/61xLoYc3EvWPovbKueAOMQ25 xT3uz1qpxCjF042Nbi/BhYbVq8hFFXPWsI3b/rTmIzr4MBpzpcWg+zbMw1AEoCdgGVGz pMgs9OacFvHb2dsl4TeOnM0baN4kyBQ1yTPuar+sw3eLvf+2IwXLYCi9cLFoieQ/HM0B 5rlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865156; x=1764469956; 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=9MrD8q8jaHTyg2hGjIo8QUfr8DpjjjCwdkXOe4qqozQ=; b=YqcQS3YIiwiYKd0lSreFithHaJ7KK65/tJDIJnx+QVd8iKWWQxpyUbi9UoEi6a/WGb WA0sNwb1OUOaPrIIFZn/+6bYj7l03LVSUV2zvOMHdezggC82vKJNFZ7iovwaJr/DoCtF dIWvz7XWGd4cLYe0zT6fFtrR7JT/eM1xI1ha4MWDOQSp356NTjIxpRuh58ZXPMmBdz0h WYuSdYbGdJcL+eQU7GCcPDDtd0OLx3iCXsRwuJFyEEVNDBqHnM+x+d9N9i2wJJjmaUS4 m8dClfAbjPcS/QuxQVWMTbMDTjm3cah/FVAig574LAQ7TkGTX63LckcKzvtYebp5vqFY 7aNw== X-Forwarded-Encrypted: i=1; AJvYcCUsng+Od+3XpOz7GbHuk1lFar27/+OMS+fA3wB8RzMMhorR1vydfiggh2AuFxQFoy5tewV5tw0Obpxxfbk=@vger.kernel.org X-Gm-Message-State: AOJu0YxoXSDLGsgBSYjMpdYUhr5efjr8EuejBCQyYdHg8GE4JkRjJyHv mSe11iMsXDQ/YLJXtLVfFOnu6r6wDtO2alCDAkYGB+eVtho75L5RWWLnvCYHN8vxo5YyaihNtbU cxBwrGlqEAw== X-Google-Smtp-Source: AGHT+IETSqRzN9vEjQdORcu+j7IZp0HfOtYxM6hxC++danuF6V0LnSIxR+p6RD1h3J6jBwcbKBj2dNpPegV2 X-Received: from dyjw14.prod.google.com ([2002:a05:7300:568e:b0:2a4:738e:9908]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:f148:b0:2a4:3593:ddf5 with SMTP id 5a478bee46e88-2a71a0015ebmr2747816eec.34.1763865156336; Sat, 22 Nov 2025 18:32:36 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:20 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-5-irogers@google.com> Subject: [PATCH v1 4/9] perf symbol: Remove unused includes From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the includes of addr_location.h, spark.h, , and as they're not used in the file. This caused an issue particularly with addr_location.h where there were lots of transitive dependencies. Resolve those by adding the include to the C file. When adding the necessary includes, sort the includes and fix any other transitive dependency issues. Also, fix paths to files in util, erroneously in ../, etc. Signed-off-by: Ian Rogers --- tools/perf/builtin-annotate.c | 47 +++++----- tools/perf/builtin-c2c.c | 58 ++++++------ tools/perf/builtin-diff.c | 22 ++--- tools/perf/builtin-inject.c | 19 ++-- tools/perf/builtin-kmem.c | 41 +++++---- tools/perf/builtin-kwork.c | 9 +- tools/perf/builtin-mem.c | 16 ++-- tools/perf/builtin-report.c | 76 ++++++++-------- tools/perf/builtin-sched.c | 50 +++++------ tools/perf/builtin-script.c | 89 ++++++++++--------- tools/perf/builtin-timechart.c | 34 +++---- tools/perf/builtin-top.c | 85 +++++++++--------- tools/perf/builtin-trace.c | 82 ++++++++--------- .../scripts/python/Perf-Trace-Util/Context.c | 11 +-- tools/perf/tests/code-reading.c | 1 + tools/perf/tests/hists_cumulate.c | 1 + tools/perf/tests/hists_filter.c | 1 + tools/perf/tests/hists_link.c | 1 + tools/perf/tests/hists_output.c | 1 + tools/perf/tests/mmap-thread-lookup.c | 1 + tools/perf/util/annotate-data.c | 7 +- tools/perf/util/auxtrace.h | 1 + tools/perf/util/block-info.c | 11 +-- tools/perf/util/build-id.c | 28 +++--- tools/perf/util/callchain.c | 1 + tools/perf/util/cs-etm.c | 1 + tools/perf/util/data-convert-json.c | 30 ++++--- tools/perf/util/db-export.c | 16 ++-- tools/perf/util/dlfilter.c | 11 +-- tools/perf/util/dlfilter.h | 1 + tools/perf/util/event.c | 41 +++++---- tools/perf/util/evsel_fprintf.c | 14 +-- tools/perf/util/hist.c | 29 +++--- tools/perf/util/intel-pt.c | 35 ++++---- tools/perf/util/kvm-stat.h | 5 +- tools/perf/util/machine.c | 34 +++---- tools/perf/util/print_insn.c | 14 +-- .../util/scripting-engines/trace-event-perl.c | 1 + .../scripting-engines/trace-event-python.c | 1 + tools/perf/util/symbol.h | 14 ++- tools/perf/util/symbol_fprintf.c | 1 + tools/perf/util/thread-stack.c | 12 +-- tools/perf/util/thread.c | 18 ++-- tools/perf/util/unwind-libdw.c | 15 ++-- 44 files changed, 518 insertions(+), 468 deletions(-) diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 9c27bb30b708..2967dd085b82 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -6,45 +6,46 @@ * look up and read DSOs and symbol information and display * a histogram of results, along various sorting keys. */ + +#include +#include +#include + #include "builtin.h" #include "perf.h" =20 -#include "util/color.h" -#include +#include "arch/common.h" +#include "ui/progress.h" +#include "util/addr_location.h" +#include "util/annotate-data.h" +#include "util/annotate.h" +#include "util/block-range.h" +#include "util/branch.h" #include "util/cache.h" -#include -#include -#include "util/symbol.h" - +#include "util/color.h" +#include "util/data.h" #include "util/debug.h" - +#include "util/dso.h" +#include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" -#include "util/annotate.h" -#include "util/annotate-data.h" -#include "util/event.h" -#include -#include "util/parse-events.h" -#include "util/sort.h" #include "util/hist.h" -#include "util/dso.h" #include "util/machine.h" #include "util/map.h" +#include "util/map_symbol.h" +#include "util/parse-events.h" #include "util/session.h" +#include "util/sort.h" +#include "util/symbol.h" #include "util/tool.h" -#include "util/data.h" -#include "arch/common.h" -#include "util/block-range.h" -#include "util/map_symbol.h" -#include "util/branch.h" #include "util/util.h" -#include "ui/progress.h" =20 -#include -#include #include #include -#include +#include +#include +#include +#include =20 struct perf_annotate { struct perf_tool tool; diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 14c3823f8fed..6cc0060cacca 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -12,41 +12,45 @@ */ #include #include +#include + +#include "builtin.h" + +#include "ui/browsers/hists.h" +#include "ui/progress.h" +#include "ui/ui.h" +#include "util/addr_location.h" +#include "util/annotate.h" +#include "util/cacheline.h" +#include "util/data.h" +#include "util/debug.h" +#include "util/event.h" +#include "util/evlist.h" +#include "util/evsel.h" +#include "util/hist.h" +#include "util/map_symbol.h" +#include "util/mem-events.h" +#include "util/mem-info.h" +#include "util/mem2node.h" +#include "util/pmus.h" +#include "util/session.h" +#include "util/sort.h" +#include "util/string2.h" +#include "util/symbol.h" +#include "util/symbol.h" +#include "util/thread.h" +#include "util/tool.h" +#include "util/util.h" + +#include #include #include #include #include #include -#include -#include -#include "debug.h" -#include "builtin.h" #include #include #include -#include "map_symbol.h" -#include "mem-events.h" -#include "session.h" -#include "hist.h" -#include "sort.h" -#include "tool.h" -#include "cacheline.h" -#include "data.h" -#include "event.h" -#include "evlist.h" -#include "evsel.h" -#include "ui/browsers/hists.h" -#include "thread.h" -#include "mem2node.h" -#include "mem-info.h" -#include "symbol.h" -#include "ui/ui.h" -#include "ui/progress.h" -#include "pmus.h" -#include "string2.h" -#include "util/util.h" -#include "util/symbol.h" -#include "util/annotate.h" =20 struct c2c_hists { struct hists hists; diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index 53d5ea4a6a4f..9fc8a18647d1 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -8,25 +8,27 @@ #include "builtin.h" #include "perf.h" =20 +#include "util/addr_location.h" +#include "util/annotate.h" +#include "util/block-info.h" +#include "util/config.h" +#include "util/data.h" #include "util/debug.h" #include "util/event.h" -#include "util/hist.h" -#include "util/evsel.h" #include "util/evlist.h" +#include "util/evsel.h" +#include "util/hist.h" +#include "util/map.h" #include "util/session.h" -#include "util/tool.h" #include "util/sort.h" +#include "util/spark.h" #include "util/srcline.h" +#include "util/stream.h" #include "util/symbol.h" -#include "util/data.h" -#include "util/config.h" #include "util/time-utils.h" -#include "util/annotate.h" -#include "util/map.h" -#include "util/spark.h" -#include "util/block-info.h" -#include "util/stream.h" +#include "util/tool.h" #include "util/util.h" + #include #include #include diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index bd9245d2dd41..4bc9a3303bcb 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -8,26 +8,27 @@ */ #include "builtin.h" =20 +#include "util/addr_location.h" +#include "util/auxtrace.h" +#include "util/build-id.h" #include "util/color.h" +#include "util/data.h" +#include "util/debug.h" #include "util/dso.h" -#include "util/vdso.h" #include "util/evlist.h" #include "util/evsel.h" +#include "util/jit.h" #include "util/map.h" +#include "util/namespaces.h" #include "util/session.h" -#include "util/tool.h" -#include "util/debug.h" -#include "util/build-id.h" -#include "util/data.h" -#include "util/auxtrace.h" -#include "util/jit.h" #include "util/string2.h" #include "util/symbol.h" #include "util/synthetic-events.h" #include "util/thread.h" -#include "util/namespaces.h" -#include "util/util.h" +#include "util/tool.h" #include "util/tsc.h" +#include "util/util.h" +#include "util/vdso.h" =20 #include =20 diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 7929a5fa5f46..e9f5b3ff24e7 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -1,42 +1,41 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + #include "builtin.h" =20 +#include "util/addr_location.h" +#include "util/callchain.h" +#include "util/config.h" +#include "util/cpumap.h" +#include "util/data.h" +#include "util/debug.h" #include "util/dso.h" #include "util/evlist.h" #include "util/evsel.h" -#include "util/config.h" +#include "util/header.h" #include "util/map.h" +#include "util/session.h" +#include "util/string2.h" #include "util/symbol.h" #include "util/thread.h" -#include "util/header.h" -#include "util/session.h" -#include "util/tool.h" -#include "util/callchain.h" #include "util/time-utils.h" -#include - -#include -#include +#include "util/tool.h" #include "util/trace-event.h" -#include "util/data.h" -#include "util/cpumap.h" - -#include "util/debug.h" -#include "util/string2.h" #include "util/util.h" =20 +#include +#include +#include #include #include #include #include #include -#include -#include -#include -#include - -#include -#include +#include +#include =20 static int kmem_slab; static int kmem_page; diff --git a/tools/perf/builtin-kwork.c b/tools/perf/builtin-kwork.c index 7f3068264568..4a274c550cdf 100644 --- a/tools/perf/builtin-kwork.c +++ b/tools/perf/builtin-kwork.c @@ -8,18 +8,19 @@ #include "builtin.h" #include "perf.h" =20 +#include "util/addr_location.h" +#include "util/callchain.h" #include "util/data.h" +#include "util/debug.h" #include "util/evlist.h" #include "util/evsel.h" +#include "util/evsel_fprintf.h" #include "util/header.h" #include "util/kwork.h" -#include "util/debug.h" #include "util/session.h" +#include "util/string2.h" #include "util/symbol.h" #include "util/thread.h" -#include "util/string2.h" -#include "util/callchain.h" -#include "util/evsel_fprintf.h" #include "util/util.h" =20 #include diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c index d43500b92a7b..bad3784bd119 100644 --- a/tools/perf/builtin-mem.c +++ b/tools/perf/builtin-mem.c @@ -7,24 +7,26 @@ #include "builtin.h" #include "perf.h" =20 -#include +#include "util/addr_location.h" #include "util/auxtrace.h" -#include "util/trace-event.h" -#include "util/tool.h" -#include "util/session.h" #include "util/data.h" -#include "util/map_symbol.h" -#include "util/mem-events.h" #include "util/debug.h" #include "util/dso.h" #include "util/map.h" -#include "util/symbol.h" +#include "util/map_symbol.h" +#include "util/mem-events.h" #include "util/pmus.h" #include "util/sample.h" +#include "util/session.h" #include "util/sort.h" #include "util/string2.h" +#include "util/symbol.h" +#include "util/tool.h" +#include "util/trace-event.h" #include "util/util.h" + #include +#include =20 #define MEM_OPERATION_LOAD 0x1 #define MEM_OPERATION_STORE 0x2 diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 2bc269f5fcef..cdc7dd8d6320 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -6,68 +6,66 @@ * look up and read DSOs and symbol information and display * a histogram of results, along various sorting keys. */ -#include "builtin.h" +#include +#include +#include +#include +#include +#include +#include +#include =20 -#include "util/config.h" +#include "builtin.h" +#include "perf.h" =20 +#include "arch/common.h" +#include "ui/progress.h" +#include "ui/ui.h" +#include "util/addr_location.h" #include "util/annotate.h" -#include "util/color.h" -#include "util/dso.h" -#include -#include -#include -#include -#include "util/map.h" -#include "util/symbol.h" -#include "util/map_symbol.h" -#include "util/mem-events.h" +#include "util/auxtrace.h" +#include "util/block-info.h" #include "util/branch.h" #include "util/callchain.h" -#include "util/values.h" - -#include "perf.h" +#include "util/color.h" +#include "util/config.h" +#include "util/data.h" #include "util/debug.h" +#include "util/dso.h" #include "util/evlist.h" #include "util/evsel.h" #include "util/evswitch.h" #include "util/header.h" +#include "util/hist.h" +#include "util/map.h" +#include "util/map_symbol.h" +#include "util/mem-events.h" #include "util/mem-info.h" +#include "util/parse-events.h" #include "util/session.h" +#include "util/sort.h" #include "util/srcline.h" -#include "util/tool.h" - -#include -#include -#include "util/parse-events.h" - +#include "util/symbol.h" #include "util/thread.h" -#include "util/sort.h" -#include "util/hist.h" -#include "util/data.h" -#include "arch/common.h" #include "util/time-utils.h" -#include "util/auxtrace.h" +#include "util/tool.h" #include "util/units.h" #include "util/util.h" // perf_tip() -#include "ui/ui.h" -#include "ui/progress.h" -#include "util/block-info.h" +#include "util/values.h" =20 -#include -#include -#include -#include -#include -#include #include +#include +#include +#include #include +#include +#include #include #include #include -#include -#include -#include -#include +#include +#include +#include =20 #ifdef HAVE_LIBTRACEEVENT #include diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index eca3b1c58c4b..bc9e098642df 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1,51 +1,49 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include + #include "builtin.h" #include "perf.h" #include "perf-sys.h" =20 +#include "util/addr_location.h" +#include "util/callchain.h" +#include "util/cloexec.h" +#include "util/color.h" #include "util/cpumap.h" +#include "util/debug.h" +#include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" #include "util/evsel_fprintf.h" -#include "util/mutex.h" -#include "util/symbol.h" -#include "util/thread.h" #include "util/header.h" +#include "util/mutex.h" #include "util/session.h" -#include "util/tool.h" -#include "util/cloexec.h" -#include "util/thread_map.h" -#include "util/color.h" #include "util/stat.h" #include "util/string2.h" -#include "util/callchain.h" +#include "util/symbol.h" +#include "util/thread.h" +#include "util/thread_map.h" #include "util/time-utils.h" - -#include -#include +#include "util/tool.h" #include "util/trace-event.h" - -#include "util/debug.h" -#include "util/event.h" #include "util/util.h" =20 +#include +#include +#include #include #include +#include #include +#include +#include +#include #include #include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include =20 #define PR_SET_NAME 15 /* Set process name */ #define MAX_CPUS 4096 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 011962e1ee0f..ba363884a79d 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1,73 +1,76 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + #include "builtin.h" +#include "perf.h" =20 +#include "ui/ui.h" +#include "util/addr_location.h" +#include "util/annotate.h" +#include "util/archinsn.h" +#include "util/auxtrace.h" +#include "util/cgroup.h" +#include "util/color.h" #include "util/counts.h" +#include "util/cpumap.h" +#include "util/data.h" #include "util/debug.h" +#include "util/dlfilter.h" #include "util/dso.h" -#include -#include "util/header.h" -#include -#include "util/perf_regs.h" -#include "util/session.h" -#include "util/tool.h" -#include "util/map.h" -#include "util/srcline.h" -#include "util/symbol.h" -#include "util/thread.h" -#include "util/trace-event.h" +#include "util/dump-insn.h" #include "util/env.h" +#include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" #include "util/evsel_fprintf.h" #include "util/evswitch.h" +#include "util/header.h" +#include "util/map.h" +#include "util/mem-events.h" +#include "util/mem-info.h" +#include "util/metricgroup.h" +#include "util/path.h" +#include "util/perf_regs.h" +#include "util/print_binary.h" +#include "util/print_insn.h" +#include "util/record.h" +#include "util/session.h" #include "util/sort.h" -#include "util/data.h" -#include "util/auxtrace.h" -#include "util/cpumap.h" -#include "util/thread_map.h" +#include "util/srcline.h" #include "util/stat.h" -#include "util/color.h" #include "util/string2.h" +#include "util/symbol.h" #include "util/thread-stack.h" +#include "util/thread.h" +#include "util/thread_map.h" #include "util/time-utils.h" -#include "util/path.h" -#include "util/event.h" -#include "util/mem-info.h" -#include "util/metricgroup.h" -#include "ui/ui.h" -#include "print_binary.h" -#include "print_insn.h" -#include "archinsn.h" +#include "util/tool.h" +#include "util/trace-event.h" +#include "util/util.h" + +#include #include #include +#include #include #include #include -#include #include -#include -#include "asm/bug.h" -#include "util/mem-events.h" -#include "util/dump-insn.h" -#include -#include -#include +#include +#include #include #include +#include +#include +#include #include -#include #include -#include +#include +#include #include -#include -#include -#include -#include "util/dlfilter.h" -#include "util/record.h" -#include "util/util.h" -#include "util/cgroup.h" -#include "util/annotate.h" -#include "perf.h" =20 #include #ifdef HAVE_LIBTRACEEVENT diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c index 22050c640dfa..3f464df723d4 100644 --- a/tools/perf/builtin-timechart.c +++ b/tools/perf/builtin-timechart.c @@ -12,33 +12,35 @@ #include =20 #include "builtin.h" + +#include "util/addr_location.h" +#include "util/callchain.h" #include "util/color.h" -#include +#include "util/data.h" +#include "util/debug.h" +#include "util/event.h" #include "util/evlist.h" // for struct evsel_str_handler #include "util/evsel.h" -#include -#include -#include -#include -#include "util/symbol.h" -#include "util/thread.h" -#include "util/callchain.h" - #include "util/header.h" -#include -#include #include "util/parse-events.h" -#include "util/event.h" #include "util/session.h" +#include "util/string2.h" #include "util/svghelper.h" +#include "util/symbol.h" +#include "util/thread.h" #include "util/tool.h" -#include "util/data.h" -#include "util/debug.h" -#include "util/string2.h" #include "util/tracepoint.h" #include "util/util.h" -#include + #include +#include +#include +#include +#include +#include +#include +#include +#include =20 #ifdef LACKS_OPEN_MEMSTREAM_PROTOTYPE FILE *open_memstream(char **ptr, size_t *sizeloc); diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 710604c4f6f6..60cb08783457 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -16,77 +16,72 @@ * Mike Galbraith * Paul Mackerras */ -#include "builtin.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include =20 +#include "builtin.h" #include "perf.h" =20 +#include "arch/common.h" +#include "ui/ui.h" +#include "util/addr_location.h" #include "util/annotate.h" #include "util/bpf-event.h" +#include "util/callchain.h" #include "util/cgroup.h" -#include "util/config.h" #include "util/color.h" +#include "util/config.h" +#include "util/cpumap.h" +#include "util/debug.h" #include "util/dso.h" +#include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" #include "util/evsel_config.h" -#include "util/event.h" +#include "util/intlist.h" #include "util/machine.h" #include "util/map.h" #include "util/mmap.h" +#include "util/ordered-events.h" +#include "util/parse-branch-options.h" +#include "util/parse-events.h" +#include "util/pfm.h" #include "util/session.h" -#include "util/thread.h" +#include "util/sort.h" #include "util/stat.h" +#include "util/string2.h" #include "util/symbol.h" #include "util/synthetic-events.h" +#include "util/term.h" +#include "util/thread.h" #include "util/top.h" #include "util/util.h" -#include -#include -#include "util/parse-events.h" -#include "util/callchain.h" -#include "util/cpumap.h" -#include "util/sort.h" -#include "util/string2.h" -#include "util/term.h" -#include "util/intlist.h" -#include "util/parse-branch-options.h" -#include "arch/common.h" -#include "ui/ui.h" =20 -#include "util/debug.h" -#include "util/ordered-events.h" -#include "util/pfm.h" - -#include #include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - +#include +#include +#include #include #include #include -#include - -#include #include +#include =20 static volatile sig_atomic_t done; static volatile sig_atomic_t resize; diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index a743bda294bd..f4791b9b8b3b 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -13,17 +13,22 @@ * * http://lwn.net/Articles/415728/ ("Announcing a new utility: 'trace'") */ +#include +#include +#include +#include +#include +#include +#include +#include =20 -#include "util/record.h" -#include -#ifdef HAVE_LIBBPF_SUPPORT -#include -#include -#include -#endif -#include "util/bpf_map.h" -#include "util/rlimit.h" #include "builtin.h" +#include "perf.h" + +#include "trace/beauty/beauty.h" +#include "util/addr_location.h" +#include "util/bpf_map.h" +#include "util/callchain.h" #include "util/cgroup.h" #include "util/color.h" #include "util/config.h" @@ -31,47 +36,39 @@ #include "util/dso.h" #include "util/env.h" #include "util/event.h" +#include "util/evlist.h" #include "util/evsel.h" #include "util/evsel_fprintf.h" -#include "util/synthetic-events.h" -#include "util/evlist.h" #include "util/evswitch.h" #include "util/hashmap.h" -#include "util/mmap.h" -#include -#include +#include "util/include/dwarf-regs.h" +#include "util/intlist.h" #include "util/machine.h" #include "util/map.h" -#include "util/symbol.h" +#include "util/mmap.h" +#include "util/parse-events.h" #include "util/path.h" +#include "util/print_binary.h" +#include "util/record.h" +#include "util/rlimit.h" #include "util/session.h" -#include "util/thread.h" -#include +#include "util/stat.h" +#include "util/string2.h" #include "util/strlist.h" -#include "util/intlist.h" +#include "util/symbol.h" +#include "util/synthetic-events.h" +#include "util/syscalltbl.h" +#include "util/thread.h" #include "util/thread_map.h" -#include "util/stat.h" #include "util/tool.h" +#include "util/trace-event.h" #include "util/trace.h" -#include "util/util.h" -#include "trace/beauty/beauty.h" -#include "trace-event.h" -#include "util/parse-events.h" +#include "util/trace_augment.h" #include "util/tracepoint.h" -#include "callchain.h" -#include "print_binary.h" -#include "string2.h" -#include "syscalltbl.h" -#include "../perf.h" -#include "trace_augment.h" -#include "dwarf-regs.h" +#include "util/util.h" =20 -#include -#include -#include -#include -#include -#include +#include +#include #include #include #include @@ -80,13 +77,18 @@ #include #include #include -#include -#include - -#include #include +#include +#include +#include #include =20 +#ifdef HAVE_LIBBPF_SUPPORT +#include +#include +#include +#endif + #ifdef HAVE_LIBTRACEEVENT #include #endif diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/scripts/python/Perf-Trace-Util/Context.c index 60dcfe56d4d9..aeafcc71cb08 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -12,17 +12,18 @@ #define PY_SSIZE_T_CLEAN =20 #include +#include "../../../util/addr_location.h" +#include "../../../util/auxtrace.h" #include "../../../util/config.h" -#include "../../../util/trace-event.h" #include "../../../util/event.h" -#include "../../../util/symbol.h" -#include "../../../util/thread.h" #include "../../../util/map.h" #include "../../../util/maps.h" -#include "../../../util/auxtrace.h" #include "../../../util/session.h" -#include "../../../util/srcline.h" #include "../../../util/srccode.h" +#include "../../../util/srcline.h" +#include "../../../util/symbol.h" +#include "../../../util/thread.h" +#include "../../../util/trace-event.h" =20 #define _PyCapsule_GetPointer(arg1, arg2) \ PyCapsule_GetPointer((arg1), (arg2)) diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-readin= g.c index 5927d1ea20e2..cff0ecb0a805 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -15,6 +15,7 @@ #include #include =20 +#include "addr_location.h" #include "debug.h" #include "dso.h" #include "env.h" diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cum= ulate.c index 3eb9ef8d7ec6..c0931f639fb0 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include "util/addr_location.h" #include "util/debug.h" #include "util/dso.h" #include "util/event.h" diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filte= r.c index 1cebd20cc91c..24f98c874ba6 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include "util/addr_location.h" #include "util/debug.h" #include "util/map.h" #include "util/symbol.h" diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index 996f5f0b3bd1..04197fcdfa9b 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "tests.h" +#include "addr_location.h" #include "debug.h" #include "symbol.h" #include "sort.h" diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_outpu= t.c index ee5ec8bda60e..5e121f2181de 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include "util/addr_location.h" #include "util/debug.h" #include "util/dso.h" #include "util/event.h" diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-= thread-lookup.c index 0c5619c6e6e9..f39dc0b28810 100644 --- a/tools/perf/tests/mmap-thread-lookup.c +++ b/tools/perf/tests/mmap-thread-lookup.c @@ -7,6 +7,7 @@ #include #include #include +#include "addr_location.h" #include "debug.h" #include "env.h" #include "event.h" diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 07cf9c334be0..85ab4330da0b 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -10,14 +10,15 @@ #include #include =20 -#include "annotate.h" +#include "addr_location.h" #include "annotate-data.h" -#include "debuginfo.h" +#include "annotate.h" #include "debug.h" +#include "debuginfo.h" #include "dso.h" #include "dwarf-regs.h" -#include "evsel.h" #include "evlist.h" +#include "evsel.h" #include "map.h" #include "map_symbol.h" #include "sort.h" diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index eee2c11f7666..a07e9b6ab24d 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -8,6 +8,7 @@ #define __PERF_AUXTRACE_H =20 #include // FILE +#include // pid_t #include #include #include diff --git a/tools/perf/util/block-info.c b/tools/perf/util/block-info.c index 649392bee7ed..15e42e9fb2e8 100644 --- a/tools/perf/util/block-info.c +++ b/tools/perf/util/block-info.c @@ -2,15 +2,16 @@ #include #include #include -#include "block-info.h" -#include "sort.h" +#include "addr_location.h" #include "annotate.h" -#include "symbol.h" +#include "block-info.h" #include "dso.h" -#include "map.h" -#include "srcline.h" #include "evlist.h" #include "hist.h" +#include "map.h" +#include "sort.h" +#include "srcline.h" +#include "symbol.h" #include "ui/browsers/hists.h" =20 static struct block_header_column { diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 35505a1ffd11..f1cadf037d46 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -7,38 +7,40 @@ * Copyright (C) 2009, 2010 Red Hat Inc. * Copyright (C) 2009, 2010 Arnaldo Carvalho de Melo */ -#include "util.h" // lsdir(), mkdir_p(), rm_rf() #include #include #include #include #include -#include "util/copyfile.h" -#include "dso.h" + +#include "addr_location.h" #include "build-id.h" +#include "copyfile.h" +#include "debug.h" +#include "dso.h" #include "event.h" -#include "namespaces.h" +#include "header.h" #include "map.h" +#include "namespaces.h" +#include "path.h" +#include "probe-file.h" +#include "session.h" +#include "strlist.h" #include "symbol.h" #include "thread.h" -#include -#include "debug.h" -#include "session.h" #include "tool.h" -#include "header.h" +#include "util.h" // lsdir(), mkdir_p(), rm_rf() #include "vdso.h" -#include "path.h" -#include "probe-file.h" -#include "strlist.h" =20 #ifdef HAVE_DEBUGINFOD_SUPPORT #include #endif =20 +#include #include -#include +#include #include -#include +#include =20 static bool no_buildid_cache; =20 diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index d7b7eef740b9..9c295b38d1e1 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -21,6 +21,7 @@ =20 #include "asm/bug.h" =20 +#include "addr_location.h" #include "debug.h" #include "dso.h" #include "event.h" diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 25d56e0f1c07..cb499a81625a 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -17,6 +17,7 @@ =20 #include =20 +#include "addr_location.h" #include "auxtrace.h" #include "color.h" #include "cs-etm.h" diff --git a/tools/perf/util/data-convert-json.c b/tools/perf/util/data-con= vert-json.c index 9dc1e184cf3c..aec1302e599b 100644 --- a/tools/perf/util/data-convert-json.c +++ b/tools/perf/util/data-convert-json.c @@ -12,20 +12,22 @@ #include #include =20 -#include "linux/compiler.h" -#include "linux/err.h" -#include "util/auxtrace.h" -#include "util/debug.h" -#include "util/dso.h" -#include "util/event.h" -#include "util/evsel.h" -#include "util/evlist.h" -#include "util/header.h" -#include "util/map.h" -#include "util/session.h" -#include "util/symbol.h" -#include "util/thread.h" -#include "util/tool.h" +#include "addr_location.h" +#include "auxtrace.h" +#include "debug.h" +#include "dso.h" +#include "event.h" +#include "evlist.h" +#include "evsel.h" +#include "header.h" +#include "map.h" +#include "session.h" +#include "symbol.h" +#include "thread.h" +#include "tool.h" + +#include +#include =20 #ifdef HAVE_LIBTRACEEVENT #include diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index 8f52e8cefcf3..5c23b1b2eafb 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -7,18 +7,20 @@ #include #include =20 +#include "addr_location.h" +#include "call-path.h" +#include "callchain.h" +#include "comm.h" +#include "db-export.h" #include "dso.h" +#include "event.h" #include "evsel.h" #include "machine.h" -#include "thread.h" -#include "comm.h" -#include "symbol.h" #include "map.h" -#include "event.h" +#include "symbol.h" #include "thread-stack.h" -#include "callchain.h" -#include "call-path.h" -#include "db-export.h" +#include "thread.h" + #include =20 int db_export__init(struct db_export *dbe) diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index c0afcbd954f8..70e322de711f 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -13,17 +13,18 @@ #include #include =20 +#include "../include/perf/perf_dlfilter.h" +#include "addr_location.h" #include "debug.h" +#include "dlfilter.h" +#include "dso.h" #include "event.h" #include "evsel.h" -#include "dso.h" #include "map.h" +#include "srcline.h" +#include "symbol.h" #include "thread.h" #include "trace-event.h" -#include "symbol.h" -#include "srcline.h" -#include "dlfilter.h" -#include "../include/perf/perf_dlfilter.h" =20 static void al_to_d_al(struct addr_location *al, struct perf_dlfilter_al *= d_al) { diff --git a/tools/perf/util/dlfilter.h b/tools/perf/util/dlfilter.h index cc4bb9657d05..522d8e707db0 100644 --- a/tools/perf/util/dlfilter.h +++ b/tools/perf/util/dlfilter.h @@ -13,6 +13,7 @@ struct perf_sample; struct evsel; struct machine; struct addr_location; +struct option; struct perf_dlfilter_fns; struct perf_dlfilter_sample; struct perf_dlfilter_al; diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index fcf44149feb2..f4a3f76edad2 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -1,42 +1,45 @@ #include #include #include -#include -#include -#include -#include -#include #include #include #include #include -#include /* To get things like MAP_HUGETLB even on old= er libc headers */ -#include -#include + +#include "addr_location.h" +#include "bpf-event.h" #include "cpumap.h" +#include "debug.h" #include "dso.h" #include "event.h" -#include "debug.h" #include "hist.h" #include "machine.h" +#include "map.h" +#include "print_binary.h" +#include "session.h" #include "sort.h" +#include "stat.h" #include "string2.h" #include "strlist.h" +#include "symbol.h" +#include "symbol/kallsyms.h" #include "thread.h" #include "thread_map.h" #include "time-utils.h" -#include -#include "map.h" -#include "util/namespaces.h" -#include "symbol.h" -#include "symbol/kallsyms.h" -#include "asm/bug.h" -#include "stat.h" -#include "session.h" -#include "bpf-event.h" -#include "print_binary.h" #include "tool.h" #include "util.h" +#include "namespaces.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* To get things like MAP_HUGETLB even on old= er libc headers */ =20 static const char *perf_event__names[] =3D { [0] =3D "TOTAL", diff --git a/tools/perf/util/evsel_fprintf.c b/tools/perf/util/evsel_fprint= f.c index 103984b29b1e..abdd9985c4e3 100644 --- a/tools/perf/util/evsel_fprintf.c +++ b/tools/perf/util/evsel_fprintf.c @@ -2,16 +2,18 @@ #include #include #include -#include "util/evlist.h" -#include "evsel.h" -#include "util/evsel_fprintf.h" -#include "util/event.h" + +#include "addr_location.h" #include "callchain.h" +#include "dso.h" +#include "event.h" +#include "evlist.h" +#include "evsel.h" +#include "evsel_fprintf.h" #include "map.h" +#include "srcline.h" #include "strlist.h" #include "symbol.h" -#include "srcline.h" -#include "dso.h" =20 #ifdef HAVE_LIBTRACEEVENT #include diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 64ff427040c3..bd71e48c1183 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -1,32 +1,35 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include + +#include "addr_location.h" +#include "annotate.h" +#include "block-info.h" +#include "branch.h" +#include "build-id.h" #include "callchain.h" +#include "cgroup.h" #include "debug.h" #include "dso.h" -#include "build-id.h" +#include "evlist.h" +#include "evsel.h" #include "hist.h" #include "kvm-stat.h" #include "map.h" #include "map_symbol.h" -#include "branch.h" #include "mem-events.h" #include "mem-info.h" -#include "session.h" #include "namespaces.h" -#include "cgroup.h" +#include "session.h" #include "sort.h" -#include "units.h" -#include "evlist.h" -#include "evsel.h" -#include "annotate.h" #include "srcline.h" #include "symbol.h" #include "thread.h" -#include "block-info.h" #include "ui/progress.h" -#include -#include -#include -#include +#include "units.h" + #include #include #include diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index fc9eec8b54b8..244749c89770 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -14,29 +14,30 @@ #include #include =20 -#include "session.h" -#include "machine.h" -#include "memswap.h" -#include "sort.h" -#include "tool.h" +#include "addr_location.h" +#include "auxtrace.h" +#include "callchain.h" +#include "color.h" +#include "config.h" +#include "debug.h" +#include "dso.h" #include "event.h" #include "evlist.h" #include "evsel.h" +#include "intel-pt.h" +#include "machine.h" #include "map.h" -#include "color.h" -#include "thread.h" -#include "thread-stack.h" +#include "memswap.h" +#include "perf_api_probe.h" +#include "session.h" +#include "sort.h" #include "symbol.h" -#include "callchain.h" -#include "dso.h" -#include "debug.h" -#include "auxtrace.h" -#include "tsc.h" -#include "intel-pt.h" -#include "config.h" -#include "util/perf_api_probe.h" -#include "util/synthetic-events.h" +#include "synthetic-events.h" +#include "thread-stack.h" +#include "thread.h" #include "time-utils.h" +#include "tool.h" +#include "tsc.h" =20 #include "../arch/x86/include/uapi/asm/perf_regs.h" =20 diff --git a/tools/perf/util/kvm-stat.h b/tools/perf/util/kvm-stat.h index a356b839c2ee..7b63b1ba1b8a 100644 --- a/tools/perf/util/kvm-stat.h +++ b/tools/perf/util/kvm-stat.h @@ -4,11 +4,12 @@ =20 #ifdef HAVE_KVM_STAT_SUPPORT =20 -#include "tool.h" +#include "addr_location.h" +#include "record.h" #include "sort.h" #include "stat.h" #include "symbol.h" -#include "record.h" +#include "tool.h" =20 #include #include diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index b5dd42588c91..db8052443259 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -3,8 +3,19 @@ #include #include #include +#include #include +#include +#include +#include + +#include "addr_location.h" +#include "arm64-frame-pointer-unwind-support.h" +#include "asm/bug.h" +#include "bpf-event.h" +#include "branch.h" #include "callchain.h" +#include "cgroup.h" #include "debug.h" #include "dso.h" #include "env.h" @@ -14,37 +25,28 @@ #include "machine.h" #include "map.h" #include "map_symbol.h" -#include "branch.h" #include "mem-events.h" #include "mem-info.h" #include "path.h" +#include "sort.h" #include "srcline.h" +#include "strlist.h" #include "symbol.h" #include "synthetic-events.h" -#include "sort.h" -#include "strlist.h" #include "target.h" #include "thread.h" +#include "unwind.h" #include "util.h" #include "vdso.h" -#include -#include -#include -#include -#include "unwind.h" -#include "linux/hash.h" -#include "asm/bug.h" -#include "bpf-event.h" -#include // page_size -#include "cgroup.h" -#include "arm64-frame-pointer-unwind-support.h" -#include =20 +#include +#include // page_size #include -#include +#include #include #include #include +#include =20 static struct dso *machine__kernel_dso(struct machine *machine) { diff --git a/tools/perf/util/print_insn.c b/tools/perf/util/print_insn.c index 02e6fbb8ca04..07f9c9f6e244 100644 --- a/tools/perf/util/print_insn.c +++ b/tools/perf/util/print_insn.c @@ -5,18 +5,20 @@ * Author(s): Changbin Du */ #include -#include #include +#include + +#include "addr_location.h" #include "capstone.h" #include "debug.h" +#include "dso.h" +#include "dump-insn.h" +#include "machine.h" +#include "map.h" +#include "print_insn.h" #include "sample.h" #include "symbol.h" -#include "machine.h" #include "thread.h" -#include "print_insn.h" -#include "dump-insn.h" -#include "map.h" -#include "dso.h" =20 size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp) { diff --git a/tools/perf/util/scripting-engines/trace-event-perl.c b/tools/p= erf/util/scripting-engines/trace-event-perl.c index e261a57b87d4..9116ffa252b4 100644 --- a/tools/perf/util/scripting-engines/trace-event-perl.c +++ b/tools/perf/util/scripting-engines/trace-event-perl.c @@ -35,6 +35,7 @@ #include #include =20 +#include "../addr_location.h" #include "../callchain.h" #include "../dso.h" #include "../machine.h" diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index 6655c0bbe0d8..aacb4dc3cb90 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -34,6 +34,7 @@ #include #endif =20 +#include "../addr_location.h" #include "../build-id.h" #include "../counts.h" #include "../debug.h" diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 0aa8680cbd3e..42d8e3fd1d01 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -2,20 +2,18 @@ #ifndef __PERF_SYMBOL #define __PERF_SYMBOL 1 =20 -#include -#include #include -#include +#include +#include + +#include #include #include -#include -#include "addr_location.h" + #include "path.h" #include "symbol_conf.h" -#include "spark.h" - -#include =20 +struct addr_location; struct dso; struct map; struct maps; diff --git a/tools/perf/util/symbol_fprintf.c b/tools/perf/util/symbol_fpri= ntf.c index 53e1af4ed9ac..59aa97c0a997 100644 --- a/tools/perf/util/symbol_fprintf.c +++ b/tools/perf/util/symbol_fprintf.c @@ -3,6 +3,7 @@ #include #include =20 +#include "addr_location.h" #include "dso.h" #include "map.h" #include "symbol.h" diff --git a/tools/perf/util/thread-stack.c b/tools/perf/util/thread-stack.c index c6a0a27b12c2..0d0cbc1250e9 100644 --- a/tools/perf/util/thread-stack.c +++ b/tools/perf/util/thread-stack.c @@ -11,15 +11,17 @@ #include #include #include -#include "thread.h" + +#include "addr_location.h" +#include "call-path.h" +#include "comm.h" +#include "debug.h" +#include "env.h" #include "event.h" #include "machine.h" -#include "env.h" -#include "debug.h" #include "symbol.h" -#include "comm.h" -#include "call-path.h" #include "thread-stack.h" +#include "thread.h" =20 #define STACK_GROWTH 2048 =20 diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index aa9c58bbf9d3..bf051074d66c 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -7,18 +7,20 @@ #include #include #include -#include "dso.h" -#include "session.h" -#include "thread.h" -#include "thread-stack.h" -#include "debug.h" -#include "namespaces.h" + +#include "addr_location.h" +#include "callchain.h" #include "comm.h" +#include "debug.h" +#include "dso.h" +#include "dwarf-regs.h" #include "map.h" +#include "namespaces.h" +#include "session.h" #include "symbol.h" +#include "thread-stack.h" +#include "thread.h" #include "unwind.h" -#include "callchain.h" -#include "dwarf-regs.h" =20 #include =20 diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index ae70fb56a057..552cffb4bb92 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -4,20 +4,23 @@ #include #include #include + +#include "addr_location.h" +#include "callchain.h" #include "debug.h" #include "dso.h" -#include "unwind.h" -#include "unwind-libdw.h" +#include "env.h" +#include "event.h" #include "machine.h" #include "map.h" +#include "perf_regs.h" #include "symbol.h" #include "thread.h" +#include "unwind-libdw.h" +#include "unwind.h" + #include #include -#include "event.h" -#include "perf_regs.h" -#include "callchain.h" -#include "util/env.h" =20 static char *debuginfo_path; =20 --=20 2.52.0.rc2.455.g230fcf2819-goog From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 2CE02207A09 for ; Sun, 23 Nov 2025 02:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865160; cv=none; b=GDEQcUrtYQszieL+8Q4Sq5ji+1j7AEMLZfne9+Q+T+vHNgkcpzIWx0FP7X9+fMPv4Mvif0uHP1AhrooQSWN8vUA3ibZ/aIYDdxn4Xdtu79F5aB74o1rE8657IPdqOzEqqoXEaf83HWZXOG3hWTTkDREP5+ZQ7Y9cjjlAAfP0eDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865160; c=relaxed/simple; bh=7PuQ+2QfZxjWPqMiWzFq8W4TadqStCpGBbZ5HXyMZoo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=G6spaqdWlriYYWGWh9DLK8U6RIR/yjLHaBKJXR4QFq3EFTO5sBeSiONWzpfzn76y8IL54DXRUP/noEIM2cszZeBmb1hf3SbpW14i5Um+3yZ4NW4I13WnejRbNb08oGW7ZkOZvpq8Wr14lkNe0WalsWvZodzGtdCv6QExTe8lVK0= 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=auI7rHlj; arc=none smtp.client-ip=209.85.215.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="auI7rHlj" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b9b9e8b0812so6182573a12.0 for ; Sat, 22 Nov 2025 18:32:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865158; x=1764469958; 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=O3SPglcuk3Z0Bx6JNwPMJEe2HFAseXrWXU/S0ehemlo=; b=auI7rHlj9Ia0YI223PoAV9SeqRbbXD4GhubKScfpPGfe97CKB+iESLzoCaFWV4gzV/ k58ocy/VMDHTF9aruYIyA+o5L/0kjOuvCEGH1u1/JEFhNGUP0etIVNi50jC8jzKl++UI gUjtC/0f/TllrnwDxNbqw97niCD2/9r+9Jze4Qg+LkFt4TkMqcopempnR/IRrxsD493E sHZA4h5OPd7epJvcgPrSPZ0S8xq/ScENFtxQAIUcKMB5YdLg0SR/R1mbBqMHU1/AujjS I9cnyipF1NqSwGYYkgBjRIxaNiOQEdyx6XQnptk3IT8CbacCoLtX9Dl+jly7lcm6kpfG nzBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865158; x=1764469958; 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=O3SPglcuk3Z0Bx6JNwPMJEe2HFAseXrWXU/S0ehemlo=; b=prziMjKlCxcIYcMjVFZDKqkojdbsoG8HDQ6OQ3fL+VhUr85bLvfNzk6Btyws5FEr4c OXKoft0nNMtpGy5+2zdUumfWRCUjo9l6xkhFZSo0NI4Jz/gaNP0/qqZil81qVp4O6KeH cxG6qSiS/tpr4wnQwQX/dqfwnFOPBMGuwQX8SqpKgOL45k6AC995ob51PM/iMGj1LWfN gE+u7FS8A+Pps5psEz2igRDHQwNx8ZJxQ1ioL0cuP3VIbimWSRMGsQhjmSdHBOX32q+v yTS4ug1Aom4Yu+PZXaDuZwPd7LmLYC2dZIUWhnBpmvUltHWdsrYvT413Iun5mfWG4o76 3Ugw== X-Forwarded-Encrypted: i=1; AJvYcCX26idVjOjd0wzzC48kNBL6bSI9Q4o4RuDKMC+2HRKTzAgeqaH5QBujpwzTYialE9YuovnyHX6oeGDH8s0=@vger.kernel.org X-Gm-Message-State: AOJu0Yww/wvZ28VKyroaDc5WnRNlw6OzwIyNjnvsCPpe3mCDoT4+NkX8 b12qOFHp62ZO41+T94oKxeWSrf7RsaffwBLB2WonU0qL2fj3yGdBZ4LbWdkyV5gHS/Nwc0+Irkv bq3HKyKmRmw== X-Google-Smtp-Source: AGHT+IHpnscFt0RbrixTCI6wfRaiIvfhemxe2TZOMx4yN/HHuYTJZo/qUbwepJRnIOjTYXKPTGPuVzfgMBsW X-Received: from dlnn37.prod.google.com ([2002:a05:7022:61a5:b0:11a:2020:acaf]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7023:c085:b0:119:e56c:18b3 with SMTP id a92af1059eb24-11c9d8480b1mr3697387c88.27.1763865158103; Sat, 22 Nov 2025 18:32:38 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:21 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-6-irogers@google.com> Subject: [PATCH v1 5/9] perf symbol: Move dso__load_bfd_symbols out of symbol.h From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move into libbfd.h where the code is and to make it clear that symbol.h and symbol.c are generic code. Add libbfd.h to symbol.c includes and organize the includes. Signed-off-by: Ian Rogers --- tools/perf/tests/pe-file-parsing.c | 5 ++-- tools/perf/util/libbfd.h | 7 ++++++ tools/perf/util/symbol.c | 38 +++++++++++++++++------------- tools/perf/util/symbol.h | 4 ---- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/tools/perf/tests/pe-file-parsing.c b/tools/perf/tests/pe-file-= parsing.c index 8b31d1d05f90..2459656b01ac 100644 --- a/tools/perf/tests/pe-file-parsing.c +++ b/tools/perf/tests/pe-file-parsing.c @@ -11,10 +11,11 @@ #include #include =20 -#include "debug.h" #include "util/build-id.h" -#include "util/symbol.h" +#include "util/debug.h" #include "util/dso.h" +#include "util/libbfd.h" +#include "util/symbol.h" =20 #include "tests.h" =20 diff --git a/tools/perf/util/libbfd.h b/tools/perf/util/libbfd.h index e300f171d1bd..5b5149516f1a 100644 --- a/tools/perf/util/libbfd.h +++ b/tools/perf/util/libbfd.h @@ -21,6 +21,7 @@ int libbfd__addr2line(const char *dso_name, u64 addr, =20 =20 void dso__free_a2l_libbfd(struct dso *dso); +int dso__load_bfd_symbols(struct dso *dso, const char *debugfile); =20 int symbol__disassemble_libbfd(const char *filename, struct symbol *sym, struct annotate_args *args); @@ -51,6 +52,12 @@ static inline void dso__free_a2l_libbfd(struct dso *dso = __always_unused) { } =20 +static inline int dso__load_bfd_symbols(struct dso *dso __always_unused, + const char *debugfile __always_unused) +{ + return -1; +} + static inline int symbol__disassemble_libbfd(const char *filename __always= _unused, struct symbol *sym __always_unused, struct annotate_args *args __always_unused) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index cc26b7bf302b..638015651547 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -1,47 +1,51 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -#include +#include +#include #include +#include #include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include +#include #include -#include + #include "annotate.h" #include "build-id.h" #include "cap.h" #include "cpumap.h" #include "debug.h" +#include "debug.h" #include "demangle-cxx.h" #include "demangle-java.h" #include "demangle-ocaml.h" #include "demangle-rust-v0.h" #include "dso.h" -#include "util.h" // lsdir() -#include "debug.h" #include "event.h" +#include "header.h" +#include "intlist.h" +#include "libbfd.h" #include "machine.h" #include "map.h" -#include "symbol.h" #include "map_symbol.h" #include "mem-events.h" #include "mem-info.h" -#include "symsrc.h" -#include "strlist.h" -#include "intlist.h" #include "namespaces.h" -#include "header.h" #include "path.h" +#include "perf-libelf.h" +#include "strlist.h" +#include "symbol.h" +#include "symsrc.h" +#include "util.h" // lsdir() + +#include #include +#include #include +#include +#include +#include #include =20 #include diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 42d8e3fd1d01..d37d5a97bc6f 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -153,10 +153,6 @@ int symbol__config_symfs(const struct option *opt __ma= ybe_unused, =20 struct symsrc; =20 -#ifdef HAVE_LIBBFD_SUPPORT -int dso__load_bfd_symbols(struct dso *dso, const char *debugfile); -#endif - int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, struct symsrc *runtime_ss, int kmodule); int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss); --=20 2.52.0.rc2.455.g230fcf2819-goog From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 06BAD224B14 for ; Sun, 23 Nov 2025 02:32:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865162; cv=none; b=MGVeDMdmXY+K7KS8IOm+FTcrIyUi9FVM/Ix3swDi7Tz1r/dhmx+oaKiWR7u4v+Jc/M/N55rHZJPWMkjlWJm0FSWqqmd0W91YvG9FYGFHRIOdl9zhkHxhl4OGcJRJO+o97HeAKOWCT3b3EDVJ4eRrT7MDHU7SqdIsKwy4DthRxLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865162; c=relaxed/simple; bh=lR4XJex+YhLGvlJNmOkyF66H8cbin8etsWj49bkyRGY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=EvxUHsuKo5l+Pr0QU0TPo/3eFYAxRp0UGKSwK1rcIAhEYOKPXGNRhizlXXKcaeuNHeS9oAU8+kurZ+13z5xpmxPzQZyjIAFHh7N96aBVJ3gBH/tX4ervPqoUBxN6WvB2kmBrmjMFmNO3NyOdOFza93xcMhKTLS1Wh3oZPIpgtvI= 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=Kj4/xV7/; arc=none smtp.client-ip=209.85.216.74 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="Kj4/xV7/" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3437863d0easo5849814a91.0 for ; Sat, 22 Nov 2025 18:32:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865160; x=1764469960; 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=tyZ/CCFSnZu+HsL8ZbXhwTe/1CPGu9zLNC6RL/LGjsc=; b=Kj4/xV7/+jSs89V3D3mnbGWIyXGnxV5GZJFB1LgsrnlscpldNUMbW8YKKPe5/tbrKU CHb0f5Fiw1saCZql+KxB+Bdaii6TbRZUMtKyGMGVEhokDQgntcfEn+piEao720uU2K+8 sZTKmLBt4Iy5l7rB+HLGqeuJEOQ1o+GhyJQnPwoESzmWscf3Hn3OtGXDFXfXyG4T+JF6 9s9fHbtrkUbxgm54C+DCF51dDs1FuD3PrE463ZQy97tj6zJYwSM6eZ29z9tYCCv16JXt ADI4EpnihNnBhB3ADNrMjMps7RosxIiAGbdpSh3Ds60EvNuIK7vpGHJf3p5c8xLlH6c8 +dfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865160; x=1764469960; 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=tyZ/CCFSnZu+HsL8ZbXhwTe/1CPGu9zLNC6RL/LGjsc=; b=Mk4s4/MqbHsXc5RfdDiY8KRoKCZIp4QvWwQt442s97UI4fOUSxHyur38Gqr/1/IrIm 6XqIr3pjP+1sUt57U6fQH2/MaxEINIK7aSLMFvfIfEDujHXArVte6LwDYAHxNEUxjgir oUVQTkguLWxuGlKUI5VTdGOdmUOj3fQ7Z+quaw/ltNdzc6L0sJcMndS+hf49PuluqvRV /rq7nYxR1jOQY/t1Mb+4QQYXTixzbhTEYDmcDdkno3evxGx9PljnDYRpu/ksTeIoHGBY X4zXH+1S4Ks9TSZcmKXJ5kOYEAONQBAKs6b2JKR5D9q5K8d4sEqzEQmEwRboEfv43ZiO 52wQ== X-Forwarded-Encrypted: i=1; AJvYcCVbbnVbhFxRs2niGIiqxrqGYGvgrvD7FrhKwpd2/nGW8gGlsVRnG6UBx/4iNwGzxPF9Xm6OnWLQWKJCt04=@vger.kernel.org X-Gm-Message-State: AOJu0YxCuz1pKqw5QdPLZlZU7cB3hC6O1gLOW4RU5yiW5x/qrZspaeCI o8pRm5Zuz3CreJq7tWr15sV5/R/k9jg5gGc9w7u2lYgyufBvrTCOfvVEf503qDoIEKSzFo1YXyg IRdrTiEhnhF19omVSfAdGVl1tc7fgfQDDwExwBsomh9XGqmTpb0EInozxcJLnWwY3Dy6zoyIJZu k= X-Google-Smtp-Source: AGHT+IFC3vf6O88V6VSVadTfGoCXlyrt97nwA9qA3Uv2+6kOqVnoS/yKs4LzVYCyizDC30uVoYAmsUNS+hjF X-Received: from dlbps2.prod.google.com ([2002:a05:7023:882:b0:11b:9777:3bd6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4288:b0:11b:8161:5cfc with SMTP id a92af1059eb24-11c9d863815mr5019072c88.36.1763865160232; Sat, 22 Nov 2025 18:32:40 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:22 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-7-irogers@google.com> Subject: [PATCH v1 6/9] perf symbol: Use fallbacks with filename__read_build_id From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org X-ccpol: medium Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Try libbfd, libelf and then symbol-minimal when trying to read a build ID. Always compile in symbol-minimal so that it is the fallback of last resort. Rename libelf reading code. Move the decompression code into symbol.c and allow its use with the symbol-minimal version. Signed-off-by: Ian Rogers --- tools/perf/util/Build | 5 +- tools/perf/util/libbfd.c | 4 +- tools/perf/util/libbfd.h | 8 +- tools/perf/util/perf-libelf.c | 113 +++++++++++++++++++++++ tools/perf/util/perf-libelf.h | 20 ++++ tools/perf/util/symbol-elf.c | 154 +------------------------------ tools/perf/util/symbol-minimal.c | 12 ++- tools/perf/util/symbol-minimal.h | 9 ++ tools/perf/util/symbol.c | 50 ++++++++++ 9 files changed, 210 insertions(+), 165 deletions(-) create mode 100644 tools/perf/util/symbol-minimal.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index dcac6f1e1d99..c40053db2212 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -54,6 +54,7 @@ perf-util-y +=3D usage.o perf-util-y +=3D dso.o perf-util-y +=3D dsos.o perf-util-y +=3D symbol.o +perf-util-y +=3D symbol-minimal.o perf-util-y +=3D symbol_fprintf.o perf-util-y +=3D map_symbol.o perf-util-y +=3D color.o @@ -209,10 +210,6 @@ ifdef hashmap perf-util-y +=3D hashmap.o endif =20 -ifndef CONFIG_LIBELF -perf-util-y +=3D symbol-minimal.o -endif - ifndef CONFIG_SETNS perf-util-y +=3D setns.o endif diff --git a/tools/perf/util/libbfd.c b/tools/perf/util/libbfd.c index 6434c2dccd4a..c438fbd03b24 100644 --- a/tools/perf/util/libbfd.c +++ b/tools/perf/util/libbfd.c @@ -418,13 +418,13 @@ int dso__load_bfd_symbols(struct dso *dso, const char= *debugfile) return err; } =20 -int libbfd__read_build_id(const char *filename, struct build_id *bid, bool= block) +int libbfd__read_build_id(int _fd, const char *filename, struct build_id *= bid) { size_t size =3D sizeof(bid->data); int err =3D -1, fd; bfd *abfd; =20 - fd =3D open(filename, block ? O_RDONLY : (O_RDONLY | O_NONBLOCK)); + fd =3D dup(_fd); if (fd < 0) return -1; =20 diff --git a/tools/perf/util/libbfd.h b/tools/perf/util/libbfd.h index 5b5149516f1a..72f1ad9a7578 100644 --- a/tools/perf/util/libbfd.h +++ b/tools/perf/util/libbfd.h @@ -26,7 +26,7 @@ int dso__load_bfd_symbols(struct dso *dso, const char *de= bugfile); int symbol__disassemble_libbfd(const char *filename, struct symbol *sym, struct annotate_args *args); =20 -int libbfd__read_build_id(const char *filename, struct build_id *bid, bool= block); +int libbfd__read_build_id(int fd, const char *filename, struct build_id *b= id); =20 int libbfd_filename__read_debuglink(const char *filename, char *debuglink,= size_t size); =20 @@ -65,9 +65,9 @@ static inline int symbol__disassemble_libbfd(const char *= filename __always_unuse return -1; } =20 -static inline int libbfd__read_build_id(const char *filename __always_unus= ed, - struct build_id *bid __always_unused, - bool block __always_unused) +static inline int libbfd__read_build_id(int fd __always_unused, + const char *filename __always_unused, + struct build_id *bid __always_unused) { return -1; } diff --git a/tools/perf/util/perf-libelf.c b/tools/perf/util/perf-libelf.c index abd55bd7f14b..c7fa08a177d0 100644 --- a/tools/perf/util/perf-libelf.c +++ b/tools/perf/util/perf-libelf.c @@ -3,6 +3,10 @@ =20 #include #include +#include + +#include "build-id.h" +#include "debug.h" =20 Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, const char *name, size_t *idx) @@ -30,3 +34,112 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, return NULL; } =20 +int __libelf__read_build_id(Elf *elf, void *bf, size_t size) +{ + int err =3D -1; + GElf_Ehdr ehdr; + GElf_Shdr shdr; + Elf_Data *data; + Elf_Scn *sec; + Elf_Kind ek; + void *ptr; + + if (size < BUILD_ID_SIZE) + goto out; + + ek =3D elf_kind(elf); + if (ek !=3D ELF_K_ELF) + goto out; + + if (gelf_getehdr(elf, &ehdr) =3D=3D NULL) { + pr_err("%s: cannot get elf header.\n", __func__); + goto out; + } + + /* + * Check following sections for notes: + * '.note.gnu.build-id' + * '.notes' + * '.note' (VDSO specific) + */ + do { + sec =3D elf_section_by_name(elf, &ehdr, &shdr, + ".note.gnu.build-id", NULL); + if (sec) + break; + + sec =3D elf_section_by_name(elf, &ehdr, &shdr, + ".notes", NULL); + if (sec) + break; + + sec =3D elf_section_by_name(elf, &ehdr, &shdr, + ".note", NULL); + if (sec) + break; + + return err; + + } while (0); + + data =3D elf_getdata(sec, NULL); + if (data =3D=3D NULL) + goto out; + + ptr =3D data->d_buf; + while (ptr < (data->d_buf + data->d_size)) { + GElf_Nhdr *nhdr =3D ptr; + size_t namesz =3D NOTE_ALIGN(nhdr->n_namesz), + descsz =3D NOTE_ALIGN(nhdr->n_descsz); + const char *name; + + ptr +=3D sizeof(*nhdr); + name =3D ptr; + ptr +=3D namesz; + if (nhdr->n_type =3D=3D NT_GNU_BUILD_ID && + nhdr->n_namesz =3D=3D sizeof("GNU")) { + if (memcmp(name, "GNU", sizeof("GNU")) =3D=3D 0) { + size_t sz =3D min(size, descsz); + + memcpy(bf, ptr, sz); + memset(bf + sz, 0, size - sz); + err =3D sz; + break; + } + } + ptr +=3D descsz; + } + +out: + return err; +} + +int libelf__read_build_id(int _fd, const char *filename, struct build_id *= bid) +{ + size_t size =3D sizeof(bid->data); + int fd, err =3D -1; + Elf *elf; + + if (size < BUILD_ID_SIZE) + goto out; + + fd =3D dup(_fd); + if (fd < 0) + goto out; + + elf =3D elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); + if (elf =3D=3D NULL) { + pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); + goto out_close; + } + + err =3D __libelf__read_build_id(elf, bid->data, size); + if (err > 0) + bid->size =3D err; + + elf_end(elf); +out_close: + close(fd); +out: + return err; +} diff --git a/tools/perf/util/perf-libelf.h b/tools/perf/util/perf-libelf.h index 5d7d18daf5ff..931597493b1f 100644 --- a/tools/perf/util/perf-libelf.h +++ b/tools/perf/util/perf-libelf.h @@ -2,6 +2,8 @@ #ifndef __PERF_LIBELF_H #define __PERF_LIBELF_H =20 +struct build_id; + #ifdef HAVE_LIBELF_SUPPORT =20 #include @@ -17,9 +19,27 @@ # define PERF_ELF_C_READ_MMAP ELF_C_READ #endif =20 +/* + * Align offset to 4 bytes as needed for note name and descriptor data. + */ +#define NOTE_ALIGN(n) (((n) + 3) & -4U) + Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, cons= t char *name, size_t *idx); =20 +int __libelf__read_build_id(Elf *elf, void *bf, size_t size); + +int libelf__read_build_id(int _fd, const char *filename, struct build_id *= bid); + +#else // !defined(HAVE_LIBELF_SUPPORT) + +static inline int libelf__read_build_id(int fd __always_unused, + const char *filename __always_unused, + struct build_id *bid __always_unused) +{ + return -1; +} + #endif // defined(HAVE_LIBELF_SUPPORT) =20 #endif /* __PERF_LIBELF_H */ diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 750a30b216d6..b301f1263ecc 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -751,158 +751,6 @@ int dso__synthesize_plt_symbols(struct dso *dso, stru= ct symsrc *ss) return 0; } =20 -/* - * Align offset to 4 bytes as needed for note name and descriptor data. - */ -#define NOTE_ALIGN(n) (((n) + 3) & -4U) - -static int elf_read_build_id(Elf *elf, void *bf, size_t size) -{ - int err =3D -1; - GElf_Ehdr ehdr; - GElf_Shdr shdr; - Elf_Data *data; - Elf_Scn *sec; - Elf_Kind ek; - void *ptr; - - if (size < BUILD_ID_SIZE) - goto out; - - ek =3D elf_kind(elf); - if (ek !=3D ELF_K_ELF) - goto out; - - if (gelf_getehdr(elf, &ehdr) =3D=3D NULL) { - pr_err("%s: cannot get elf header.\n", __func__); - goto out; - } - - /* - * Check following sections for notes: - * '.note.gnu.build-id' - * '.notes' - * '.note' (VDSO specific) - */ - do { - sec =3D elf_section_by_name(elf, &ehdr, &shdr, - ".note.gnu.build-id", NULL); - if (sec) - break; - - sec =3D elf_section_by_name(elf, &ehdr, &shdr, - ".notes", NULL); - if (sec) - break; - - sec =3D elf_section_by_name(elf, &ehdr, &shdr, - ".note", NULL); - if (sec) - break; - - return err; - - } while (0); - - data =3D elf_getdata(sec, NULL); - if (data =3D=3D NULL) - goto out; - - ptr =3D data->d_buf; - while (ptr < (data->d_buf + data->d_size)) { - GElf_Nhdr *nhdr =3D ptr; - size_t namesz =3D NOTE_ALIGN(nhdr->n_namesz), - descsz =3D NOTE_ALIGN(nhdr->n_descsz); - const char *name; - - ptr +=3D sizeof(*nhdr); - name =3D ptr; - ptr +=3D namesz; - if (nhdr->n_type =3D=3D NT_GNU_BUILD_ID && - nhdr->n_namesz =3D=3D sizeof("GNU")) { - if (memcmp(name, "GNU", sizeof("GNU")) =3D=3D 0) { - size_t sz =3D min(size, descsz); - memcpy(bf, ptr, sz); - memset(bf + sz, 0, size - sz); - err =3D sz; - break; - } - } - ptr +=3D descsz; - } - -out: - return err; -} - -static int read_build_id(const char *filename, struct build_id *bid, bool = block) -{ - size_t size =3D sizeof(bid->data); - int fd, err; - Elf *elf; - - err =3D libbfd__read_build_id(filename, bid, block); - if (err >=3D 0) - goto out; - - if (size < BUILD_ID_SIZE) - goto out; - - fd =3D open(filename, block ? O_RDONLY : (O_RDONLY | O_NONBLOCK)); - if (fd < 0) - goto out; - - elf =3D elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); - if (elf =3D=3D NULL) { - pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); - goto out_close; - } - - err =3D elf_read_build_id(elf, bid->data, size); - if (err > 0) - bid->size =3D err; - - elf_end(elf); -out_close: - close(fd); -out: - return err; -} - -int filename__read_build_id(const char *filename, struct build_id *bid, bo= ol block) -{ - struct kmod_path m =3D { .name =3D NULL, }; - char path[PATH_MAX]; - int err; - - if (!filename) - return -EFAULT; - - err =3D kmod_path__parse(&m, filename); - if (err) - return -1; - - if (m.comp) { - int error =3D 0, fd; - - fd =3D filename__decompress(filename, path, sizeof(path), m.comp, &error= ); - if (fd < 0) { - pr_debug("Failed to decompress (error %d) %s\n", - error, filename); - return -1; - } - close(fd); - filename =3D path; - block =3D true; - } - - err =3D read_build_id(filename, bid, block); - - if (m.comp) - unlink(filename); - return err; -} - int sysfs__read_build_id(const char *filename, struct build_id *bid) { size_t size =3D sizeof(bid->data); @@ -1170,7 +1018,7 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, = const char *name, struct build_id bid; int size; =20 - size =3D elf_read_build_id(elf, build_id, BUILD_ID_SIZE); + size =3D __libelf__read_build_id(elf, build_id, BUILD_ID_SIZE); if (size <=3D 0) { *dso__load_errno(dso) =3D DSO_LOAD_ERRNO__CANNOT_READ_BUILDID; goto out_elf_end; diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-mini= mal.c index aeb253248895..f9adeb09ef00 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -1,5 +1,7 @@ +#include "debug.h" #include "dso.h" #include "symbol.h" +#include "symbol-minimal.h" #include "symsrc.h" =20 #include @@ -75,17 +77,19 @@ static int read_build_id(void *note_data, size_t note_l= en, struct build_id *bid, return -1; } =20 +#ifndef HAVE_LIBELF_SUPPORT int filename__read_debuglink(const char *filename __maybe_unused, char *debuglink __maybe_unused, size_t size __maybe_unused) { return -1; } +#endif =20 /* * Just try PT_NOTE header otherwise fails */ -int filename__read_build_id(const char *filename, struct build_id *bid, bo= ol block) +int sym_min__read_build_id(int _fd, const char *filename, struct build_id = *bid) { int fd, ret =3D -1; bool need_swap =3D false, elf32; @@ -102,7 +106,7 @@ int filename__read_build_id(const char *filename, struc= t build_id *bid, bool blo void *phdr, *buf =3D NULL; ssize_t phdr_size, ehdr_size, buf_size =3D 0; =20 - fd =3D open(filename, block ? O_RDONLY : (O_RDONLY | O_NONBLOCK)); + fd =3D dup(_fd); if (fd < 0) return -1; =20 @@ -194,9 +198,12 @@ int filename__read_build_id(const char *filename, stru= ct build_id *bid, bool blo free(phdr); out: close(fd); + if (ret) + pr_debug("Error reading build-id from %s\n", filename); return ret; } =20 +#ifndef HAVE_LIBELF_SUPPORT int sysfs__read_build_id(const char *filename, struct build_id *bid) { int fd; @@ -358,3 +365,4 @@ bool filename__has_section(const char *filename __maybe= _unused, const char *sec { return false; } +#endif // HAVE_LIBELF_SUPPORT diff --git a/tools/perf/util/symbol-minimal.h b/tools/perf/util/symbol-mini= mal.h new file mode 100644 index 000000000000..185d98968212 --- /dev/null +++ b/tools/perf/util/symbol-minimal.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PERF_SYMBOL_MINIMAL_H +#define __PERF_SYMBOL_MINIMAL_H + +struct build_id; + +int sym_min__read_build_id(int _fd, const char *filename, struct build_id = *bid); + +#endif /* __PERF_SYMBOL_MINIMAL_H */ diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 638015651547..c8795e1da2df 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -35,6 +35,7 @@ #include "path.h" #include "perf-libelf.h" #include "strlist.h" +#include "symbol-minimal.h" #include "symbol.h" #include "symsrc.h" #include "util.h" // lsdir() @@ -1999,6 +2000,55 @@ static bool filename__readable(const char *file) return true; } =20 +int filename__read_build_id(const char *filename, struct build_id *bid, bo= ol block) +{ + struct kmod_path m =3D { .name =3D NULL, }; + char path[PATH_MAX]; + int err, fd; + + if (!filename) + return -EFAULT; + + err =3D kmod_path__parse(&m, filename); + if (err) + return -1; + + if (m.comp) { + int error =3D 0; + + fd =3D filename__decompress(filename, path, sizeof(path), m.comp, &error= ); + if (fd < 0) { + pr_debug("Failed to decompress (error %d) %s\n", + error, filename); + return -1; + } + lseek(fd, 0, SEEK_SET); + filename =3D path; + block =3D true; + } else { + fd =3D open(filename, block ? O_RDONLY : (O_RDONLY | O_NONBLOCK)); + if (fd < 0) { + pr_debug("Failed to open %s\n", filename); + return -1; + } + } + + err =3D libbfd__read_build_id(fd, filename, bid); + if (err =3D=3D 0) + goto out; + + err =3D libelf__read_build_id(fd, filename, bid); + if (err =3D=3D 0) + goto out; + + err =3D sym_min__read_build_id(fd, filename, bid); +out: + close(fd); + if (m.comp) + unlink(filename); + return err; +} + static char *dso__find_kallsyms(struct dso *dso, struct map *map) { struct build_id bid =3D { .size =3D 0, }; --=20 2.52.0.rc2.455.g230fcf2819-goog From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 0BDA222A4FE for ; Sun, 23 Nov 2025 02:32:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865164; cv=none; b=DD8b5YuhPZyKj5A2wnK9aD+As5H2Jk4PLK4qpm2cG3sZDt+TpfxF+eXwxYRBa2YM94Z+AgPkDMD38pKQBgy7Zdy5hy+8WBrwsXK+iZ3xZB9hTJ19WCLyltqhtgvItcDgz8LTwIKua0v0CzeaCiwbD0Y2cDLP8wmOfmsmoOQE3BM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865164; c=relaxed/simple; bh=/m4nFY58ooW3j4EVV44rHempiLtSr3soyPpOz7+8zMw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=m2sCgHCFywDq4r2H9tC7R2fLOXL2WvqRw22xFqIChYwJ2MK91mfNlJlPeXxO5t3fjoUlthgIF1stPAuPjch/ybJz3A4+oOY5WfgDQiFKwqyGhqfvrlDxsPMtWO+2cgRzsBU6pMp/2WVlkmkXqk4NuFERorZSEbHlLlPdwlbEDp0= 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=iNFfS4ud; arc=none smtp.client-ip=209.85.215.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="iNFfS4ud" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b98e6ff908aso9327552a12.2 for ; Sat, 22 Nov 2025 18:32:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865162; x=1764469962; 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=216g4UGP++NTukOPT8kADTLlrUxIj1uULiiBz8Jq85U=; b=iNFfS4udZdML+ra6Rav6nnRvB3wCjrh5Hko+RWF4Bu5PUXxiVhtqV/b4Xcp+wh1D9P ykZwhXiM+vdrCyD9u8fDaIkunm8lthODq9bzwAAAMSDwv4D/TAcc/a1NdwIS/IHfdbzI amI3mlNPe/aoFoz8XyMtYjsB4zHAo7E9zq09Dreul/wHCyW36L88izWMKdcayz4vHOuN gXA85Y2dAR/S2i48pO4alZn4SJVJCgl33T+oMRxzedzKpjy8fboD5XoY1pdR7s4BkPXs pAwLI/YNsQNwWkxiLz89Gy9/48hK+henZ0sSwUhUmIDjx+pEZviTFeVUYvWk6u0hIWfu NiZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865162; x=1764469962; 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=216g4UGP++NTukOPT8kADTLlrUxIj1uULiiBz8Jq85U=; b=BG4ePgOQjgssWueYXhDbulpKk0zZhgTYsjhMp4CnSGeO+tqOHDocO0FtEmUAAiobOx GCiglzxxnewgdpN2EDaDPZ3AhojjkTXYQoHAyYlnOrMDa2/RDqPAcQmBxYDumhBzOrKR 0SMPdTKvrUKB6WUfN94CccX2AIfYV9/5GU1s+z1JuGFfL3zcVHfVIepQnoMUUwOaRwLE /3zMh5fKpYrFqPCYW3MOU9Rl10vZU7fEkpOa5Za4r6Nfq97YmcbBw4q6m6FEutxY/niy jxDCOpJ7lP5KTyOywW7w2KJvw11qZwdbdzqS6QqNtobKcHm5MbnHynXJsceQ7EzLDqkZ 2rDg== X-Forwarded-Encrypted: i=1; AJvYcCXQyzPcU7BnnOnnmnXqB/JGxGHDprDT7p0XoCifALfC1p35bQx5AsCsKwiyuGtWrCzXWTCrMFWwMZmIf0o=@vger.kernel.org X-Gm-Message-State: AOJu0YyoezQQhBiPNTeJn/nSD1UFacxVf9+deu+knu/meLbaceyCfJKz mkMJzRo1Mgd+zQ/1LJ2DOqoEnSOD9gaABDeJniNwM8SjjMkhB+GqxdRoeeT/Zeyc4FZ/5upYaz0 +mygYU7MFKA== X-Google-Smtp-Source: AGHT+IGGs1lL6zRYCul6ahXzZCqjt8nz/UVOMvKplJnd7VbGxuyghTPmQmQgkb8WrlEkl2RA5LNvOK7xeE4H X-Received: from dydx8.prod.google.com ([2002:a05:7300:2288:b0:2a4:4bd0:6ed8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:168e:b0:2a4:5154:b346 with SMTP id 5a478bee46e88-2a7192e071cmr4743854eec.35.1763865162232; Sat, 22 Nov 2025 18:32:42 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:23 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-8-irogers@google.com> Subject: [PATCH v1 7/9] perf symbol: Use fallbacks for filename__read_debuglink From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Try libbfd and then libelf in symbol.c. Remove the non-existent symbol-minimal version. Signed-off-by: Ian Rogers --- tools/perf/util/perf-libelf.c | 52 +++++++++++++++++++++++++++++ tools/perf/util/perf-libelf.h | 10 ++++++ tools/perf/util/symbol-elf.c | 56 -------------------------------- tools/perf/util/symbol-minimal.c | 9 ----- tools/perf/util/symbol.c | 10 ++++++ 5 files changed, 72 insertions(+), 65 deletions(-) diff --git a/tools/perf/util/perf-libelf.c b/tools/perf/util/perf-libelf.c index c7fa08a177d0..a8a8c39056da 100644 --- a/tools/perf/util/perf-libelf.c +++ b/tools/perf/util/perf-libelf.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include "perf-libelf.h" =20 +#include #include #include #include @@ -143,3 +144,54 @@ int libelf__read_build_id(int _fd, const char *filenam= e, struct build_id *bid) out: return err; } + +int libelf_filename__read_debuglink(const char *filename, char *debuglink,= size_t size) +{ + int fd, err =3D -1; + Elf *elf; + GElf_Ehdr ehdr; + GElf_Shdr shdr; + Elf_Data *data; + Elf_Scn *sec; + Elf_Kind ek; + + fd =3D open(filename, O_RDONLY); + if (fd < 0) + goto out; + + elf =3D elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); + if (elf =3D=3D NULL) { + pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); + goto out_close; + } + + ek =3D elf_kind(elf); + if (ek !=3D ELF_K_ELF) + goto out_elf_end; + + if (gelf_getehdr(elf, &ehdr) =3D=3D NULL) { + pr_err("%s: cannot get elf header.\n", __func__); + goto out_elf_end; + } + + sec =3D elf_section_by_name(elf, &ehdr, &shdr, + ".gnu_debuglink", NULL); + if (sec =3D=3D NULL) + goto out_elf_end; + + data =3D elf_getdata(sec, NULL); + if (data =3D=3D NULL) + goto out_elf_end; + + /* the start of this section is a zero-terminated string */ + strncpy(debuglink, data->d_buf, size); + + err =3D 0; + +out_elf_end: + elf_end(elf); +out_close: + close(fd); +out: + return err; +} diff --git a/tools/perf/util/perf-libelf.h b/tools/perf/util/perf-libelf.h index 931597493b1f..167679f9fc9b 100644 --- a/tools/perf/util/perf-libelf.h +++ b/tools/perf/util/perf-libelf.h @@ -2,6 +2,8 @@ #ifndef __PERF_LIBELF_H #define __PERF_LIBELF_H =20 +#include + struct build_id; =20 #ifdef HAVE_LIBELF_SUPPORT @@ -30,6 +32,7 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GEl= f_Shdr *shp, const char int __libelf__read_build_id(Elf *elf, void *bf, size_t size); =20 int libelf__read_build_id(int _fd, const char *filename, struct build_id *= bid); +int libelf_filename__read_debuglink(const char *filename, char *debuglink,= size_t size); =20 #else // !defined(HAVE_LIBELF_SUPPORT) =20 @@ -40,6 +43,13 @@ static inline int libelf__read_build_id(int fd __always_= unused, return -1; } =20 +static inline int libelf_filename__read_debuglink(const char *filename __a= lways_unused, + char *debuglink __always_unused, + size_t size __always_unused) +{ + return -1; +} + #endif // defined(HAVE_LIBELF_SUPPORT) =20 #endif /* __PERF_LIBELF_H */ diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index b301f1263ecc..d4a1b01010c1 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -801,62 +801,6 @@ int sysfs__read_build_id(const char *filename, struct = build_id *bid) return err; } =20 -int filename__read_debuglink(const char *filename, char *debuglink, - size_t size) -{ - int fd, err =3D -1; - Elf *elf; - GElf_Ehdr ehdr; - GElf_Shdr shdr; - Elf_Data *data; - Elf_Scn *sec; - Elf_Kind ek; - - err =3D libbfd_filename__read_debuglink(filename, debuglink, size); - if (err >=3D 0) - goto out; - - fd =3D open(filename, O_RDONLY); - if (fd < 0) - goto out; - - elf =3D elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); - if (elf =3D=3D NULL) { - pr_debug2("%s: cannot read %s ELF file.\n", __func__, filename); - goto out_close; - } - - ek =3D elf_kind(elf); - if (ek !=3D ELF_K_ELF) - goto out_elf_end; - - if (gelf_getehdr(elf, &ehdr) =3D=3D NULL) { - pr_err("%s: cannot get elf header.\n", __func__); - goto out_elf_end; - } - - sec =3D elf_section_by_name(elf, &ehdr, &shdr, - ".gnu_debuglink", NULL); - if (sec =3D=3D NULL) - goto out_elf_end; - - data =3D elf_getdata(sec, NULL); - if (data =3D=3D NULL) - goto out_elf_end; - - /* the start of this section is a zero-terminated string */ - strncpy(debuglink, data->d_buf, size); - - err =3D 0; - -out_elf_end: - elf_end(elf); -out_close: - close(fd); -out: - return err; -} - bool symsrc__possibly_runtime(struct symsrc *ss) { return ss->dynsym || ss->opdsec; diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-mini= mal.c index f9adeb09ef00..8700c0628437 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -77,15 +77,6 @@ static int read_build_id(void *note_data, size_t note_le= n, struct build_id *bid, return -1; } =20 -#ifndef HAVE_LIBELF_SUPPORT -int filename__read_debuglink(const char *filename __maybe_unused, - char *debuglink __maybe_unused, - size_t size __maybe_unused) -{ - return -1; -} -#endif - /* * Just try PT_NOTE header otherwise fails */ diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index c8795e1da2df..1152d11a0366 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -2049,6 +2049,16 @@ int filename__read_build_id(const char *filename, st= ruct build_id *bid, bool blo return err; } =20 +int filename__read_debuglink(const char *filename, char *debuglink, size_t= size) +{ + int err =3D libbfd_filename__read_debuglink(filename, debuglink, size); + + if (err =3D=3D 0) + return 0; + + return libelf_filename__read_debuglink(filename, debuglink, size); +} + static char *dso__find_kallsyms(struct dso *dso, struct map *map) { struct build_id bid =3D { .size =3D 0, }; --=20 2.52.0.rc2.455.g230fcf2819-goog From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 E16872356BE for ; Sun, 23 Nov 2025 02:32:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865166; cv=none; b=B9093f3lq55yotmUc5pZYmHt2ZqiK8jbeqBSCMVRvqmetamvXA/nkbhvcrPDR2t2GlgyY2pTculPYhO5ocTH/MwkLH7JD78oEgx4eYnryBOlXnvq2/PFqkO0aNmzKo896RSHlLcSOEA1dv+99MB3GaB02uOP7GVUN165d1n+ePE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865166; c=relaxed/simple; bh=8PCV8gXQ8V6nDsf7afO/nL/dMr2vpBmrTqN18/8lUVc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Rh7relBiBZE6R7cgNqGvI6OZPQfnE4i6qbCydbDwSJkmZKB7T1Ea+Auh8fpJoxGPXTFi3KXZZURXpgr/OWj3cmQXZt5KoBL6xqBlp87sGrKAwKxXRM/LHyg3o9Ais+zVG4iiGA0ryltHNyKu4gPFsm7yPZ3lL0cetctltov0GcY= 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=RjJ8cQJa; arc=none smtp.client-ip=209.85.215.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="RjJ8cQJa" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b993eb2701bso3161943a12.0 for ; Sat, 22 Nov 2025 18:32:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865164; x=1764469964; 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=M2kO6YXL2sAgHQwAq8vIr/1t6R+Qh+dvjHWTyxEb3ww=; b=RjJ8cQJai0XXftLkLIBOv7MU6Qjx22v/2als+4Roa4j/l5NAHqC3OLugYiZBpI3gXb zPAHofdnD6VbRu4QWtffaf1KJy9gGnChIREspdy+ElbONikAf1cJDSlaxtW72VfLbPOm Pt89kyY6f0G3XkTSwcAF0YrG0YTwrT89EGhuvL7RaqT6T0e2JzoBJDR4fir+TBt02fJ8 2o79fXyOO1EAn2sWNIPUC+2SDDbzemwxPzsVRGjOGOV98Aud2Yfdlb1TxC9IiR0FD1D1 oz/O4qM/nEROblZDQV6I+U9chiOgUQ84clFJgOo0NNTcIq6ankINzT2RdW36P51ljGlI /PdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865164; x=1764469964; 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=M2kO6YXL2sAgHQwAq8vIr/1t6R+Qh+dvjHWTyxEb3ww=; b=JoQR3HOyVdaE0PCP6CBNpbe8b3HvFGlPnfuvViY8TwAg/FTSxCA1NIAeqS9brARYBK fFl3NjTLgtb436NC/D2Q8T41N5ehZy2bWJtplISj1oiEXObODzo0pItTtLgz4FP7n7Rl 71B0C1gwlxX68jrR2wfIDFVyceej65ZfiUHMhV2IEZPvhBkV1ve/Xqz735KYBFYTZlzj esVA7xblQFdXFB/JnuLVmhrRHJjIxcNzw9kr1ttt/ktinNkZFt+asKyeTRwA00mfyLVY Y9uIH6kW+w4q3GqMXiPyNHEPuJmNNbI1dg6L263q39pJfo23R++gUxMUkpXQ2olGL9L8 2RHA== X-Forwarded-Encrypted: i=1; AJvYcCXWCfQSEwQpQhbJTfM9W0+V8vE56EKP9mbToQIBuAe9+Lkl1qJisQkb9kZeuDKjLU77cvsU7SePZ0oUDIk=@vger.kernel.org X-Gm-Message-State: AOJu0YwMc3cqAnEailgmQRjyI0G2AG5CFXVYsZsPQx7gsrQgsDChRjt6 lIAXiNe1f7N8yfM8668tEL/sSgeFqad+3wxRoioE12jjvkoV7dCykacwpcMMBXxWkXzksDiiF+C KluxKSkRCeQ== X-Google-Smtp-Source: AGHT+IFJk2oPW4r6McQs/nWZKohHl26TK542JQ9qyywVf6xez5/Uz4mzhA1OszwKINIzeSyPsG1Wz/ZjsSLx X-Received: from dlbvp8.prod.google.com ([2002:a05:7022:ff48:b0:11b:b1cd:e328]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ea46:10b0:11b:9386:826d with SMTP id a92af1059eb24-11c9d8707d7mr4146724c88.42.1763865164339; Sat, 22 Nov 2025 18:32:44 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:24 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-9-irogers@google.com> Subject: [PATCH v1 8/9] perf symbol: Use fallbacks for sysfs__read_build_id From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Try libelf then symbol-minimal version in symbol.c. Reduce scope of NOTE_ALIGN macro. Signed-off-by: Ian Rogers --- tools/perf/util/perf-libelf.c | 56 ++++++++++++++++++++++++++++++++ tools/perf/util/perf-libelf.h | 12 ++++--- tools/perf/util/symbol-elf.c | 50 ---------------------------- tools/perf/util/symbol-minimal.c | 4 +-- tools/perf/util/symbol-minimal.h | 1 + tools/perf/util/symbol.c | 10 ++++++ 6 files changed, 76 insertions(+), 57 deletions(-) diff --git a/tools/perf/util/perf-libelf.c b/tools/perf/util/perf-libelf.c index a8a8c39056da..861cb7ae9b45 100644 --- a/tools/perf/util/perf-libelf.c +++ b/tools/perf/util/perf-libelf.c @@ -9,6 +9,11 @@ #include "build-id.h" #include "debug.h" =20 +/* + * Align offset to 4 bytes as needed for note name and descriptor data. + */ +#define NOTE_ALIGN(n) (((n) + 3) & -4U) + Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, const char *name, size_t *idx) { @@ -145,6 +150,57 @@ int libelf__read_build_id(int _fd, const char *filenam= e, struct build_id *bid) return err; } =20 +int libelf_sysfs__read_build_id(const char *filename, struct build_id *bid) +{ + size_t size =3D sizeof(bid->data); + int fd, err =3D -1; + + fd =3D open(filename, O_RDONLY); + if (fd < 0) + goto out; + + while (1) { + char bf[BUFSIZ]; + GElf_Nhdr nhdr; + size_t namesz, descsz; + + if (read(fd, &nhdr, sizeof(nhdr)) !=3D sizeof(nhdr)) + break; + + namesz =3D NOTE_ALIGN(nhdr.n_namesz); + descsz =3D NOTE_ALIGN(nhdr.n_descsz); + if (nhdr.n_type =3D=3D NT_GNU_BUILD_ID && + nhdr.n_namesz =3D=3D sizeof("GNU")) { + if (read(fd, bf, namesz) !=3D (ssize_t)namesz) + break; + if (memcmp(bf, "GNU", sizeof("GNU")) =3D=3D 0) { + size_t sz =3D min(descsz, size); + + if (read(fd, bid->data, sz) =3D=3D (ssize_t)sz) { + memset(bid->data + sz, 0, size - sz); + bid->size =3D sz; + err =3D 0; + break; + } + } else if (read(fd, bf, descsz) !=3D (ssize_t)descsz) + break; + } else { + int n =3D namesz + descsz; + + if (n > (int)sizeof(bf)) { + n =3D sizeof(bf); + pr_debug("%s: truncating reading of build id in sysfs file %s: n_names= z=3D%u, n_descsz=3D%u.\n", + __func__, filename, nhdr.n_namesz, nhdr.n_descsz); + } + if (read(fd, bf, n) !=3D n) + break; + } + } + close(fd); +out: + return err; +} + int libelf_filename__read_debuglink(const char *filename, char *debuglink,= size_t size) { int fd, err =3D -1; diff --git a/tools/perf/util/perf-libelf.h b/tools/perf/util/perf-libelf.h index 167679f9fc9b..95fe8805aa41 100644 --- a/tools/perf/util/perf-libelf.h +++ b/tools/perf/util/perf-libelf.h @@ -21,17 +21,13 @@ struct build_id; # define PERF_ELF_C_READ_MMAP ELF_C_READ #endif =20 -/* - * Align offset to 4 bytes as needed for note name and descriptor data. - */ -#define NOTE_ALIGN(n) (((n) + 3) & -4U) - Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, cons= t char *name, size_t *idx); =20 int __libelf__read_build_id(Elf *elf, void *bf, size_t size); =20 int libelf__read_build_id(int _fd, const char *filename, struct build_id *= bid); +int libelf_sysfs__read_build_id(const char *filename, struct build_id *bid= ); int libelf_filename__read_debuglink(const char *filename, char *debuglink,= size_t size); =20 #else // !defined(HAVE_LIBELF_SUPPORT) @@ -43,6 +39,12 @@ static inline int libelf__read_build_id(int fd __always_= unused, return -1; } =20 +static inline int libelf_sysfs__read_build_id(const char *filename __alway= s_unused, + struct build_id *bid __always_unused) +{ + return -1; +} + static inline int libelf_filename__read_debuglink(const char *filename __a= lways_unused, char *debuglink __always_unused, size_t size __always_unused) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index d4a1b01010c1..5ddf8353e01b 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -751,56 +751,6 @@ int dso__synthesize_plt_symbols(struct dso *dso, struc= t symsrc *ss) return 0; } =20 -int sysfs__read_build_id(const char *filename, struct build_id *bid) -{ - size_t size =3D sizeof(bid->data); - int fd, err =3D -1; - - fd =3D open(filename, O_RDONLY); - if (fd < 0) - goto out; - - while (1) { - char bf[BUFSIZ]; - GElf_Nhdr nhdr; - size_t namesz, descsz; - - if (read(fd, &nhdr, sizeof(nhdr)) !=3D sizeof(nhdr)) - break; - - namesz =3D NOTE_ALIGN(nhdr.n_namesz); - descsz =3D NOTE_ALIGN(nhdr.n_descsz); - if (nhdr.n_type =3D=3D NT_GNU_BUILD_ID && - nhdr.n_namesz =3D=3D sizeof("GNU")) { - if (read(fd, bf, namesz) !=3D (ssize_t)namesz) - break; - if (memcmp(bf, "GNU", sizeof("GNU")) =3D=3D 0) { - size_t sz =3D min(descsz, size); - if (read(fd, bid->data, sz) =3D=3D (ssize_t)sz) { - memset(bid->data + sz, 0, size - sz); - bid->size =3D sz; - err =3D 0; - break; - } - } else if (read(fd, bf, descsz) !=3D (ssize_t)descsz) - break; - } else { - int n =3D namesz + descsz; - - if (n > (int)sizeof(bf)) { - n =3D sizeof(bf); - pr_debug("%s: truncating reading of build id in sysfs file %s: n_names= z=3D%u, n_descsz=3D%u.\n", - __func__, filename, nhdr.n_namesz, nhdr.n_descsz); - } - if (read(fd, bf, n) !=3D n) - break; - } - } - close(fd); -out: - return err; -} - bool symsrc__possibly_runtime(struct symsrc *ss) { return ss->dynsym || ss->opdsec; diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-mini= mal.c index 8700c0628437..cc9055ba2f2a 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -194,8 +194,7 @@ int sym_min__read_build_id(int _fd, const char *filenam= e, struct build_id *bid) return ret; } =20 -#ifndef HAVE_LIBELF_SUPPORT -int sysfs__read_build_id(const char *filename, struct build_id *bid) +int sym_min_sysfs__read_build_id(const char *filename, struct build_id *bi= d) { int fd; int ret =3D -1; @@ -226,6 +225,7 @@ int sysfs__read_build_id(const char *filename, struct b= uild_id *bid) return ret; } =20 +#ifndef HAVE_LIBELF_SUPPORT int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, enum dso_binary_type type) { diff --git a/tools/perf/util/symbol-minimal.h b/tools/perf/util/symbol-mini= mal.h index 185d98968212..5cce1f1f0f16 100644 --- a/tools/perf/util/symbol-minimal.h +++ b/tools/perf/util/symbol-minimal.h @@ -5,5 +5,6 @@ struct build_id; =20 int sym_min__read_build_id(int _fd, const char *filename, struct build_id = *bid); +int sym_min_sysfs__read_build_id(const char *filename, struct build_id *bi= d); =20 #endif /* __PERF_SYMBOL_MINIMAL_H */ diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 1152d11a0366..81f4428f7bed 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -2049,6 +2049,16 @@ int filename__read_build_id(const char *filename, st= ruct build_id *bid, bool blo return err; } =20 +int sysfs__read_build_id(const char *filename, struct build_id *bid) +{ + int err =3D libelf_sysfs__read_build_id(filename, bid); + + if (err =3D=3D 0) + return 0; + + return sym_min_sysfs__read_build_id(filename, bid); +} + int filename__read_debuglink(const char *filename, char *debuglink, size_t= size) { int err =3D libbfd_filename__read_debuglink(filename, debuglink, size); --=20 2.52.0.rc2.455.g230fcf2819-goog From nobody Tue Dec 2 01:06:06 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 B224C213E9C for ; Sun, 23 Nov 2025 02:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865168; cv=none; b=Uy+zZNQ6etzIi5/LLyFnMr08n/UkgbE2KNkz2dcLhHQuxhSs5sreeO+0Ed71Csu36rkvJ+BIFaj5fc4HGFaHlV3YQqoYXsyHpAIbx/VeTwQLpyzwW1fADmwkkcInWtaBlxXStBU+pQQee+J42MmF3rvWaiBLNcy78iD+baEdXZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763865168; c=relaxed/simple; bh=gmLo+tgn4IZIr717BNDUYeGmMI7UzWO3Pd0YWYVvZ0s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=WI6G6JVq1AXJ6+cq7pQK5qn/bYPZjWB9ArU8X5R4DWlQJGtT2zKwACEvaagdy8phpNzhrP4eeaN7XHlM6PuRcoeruP3x42xk9FAGWxZtxbbEYsuq7OH1sWeWS2KLqvdx2CENm2F3eAONYZ6VKYImm2PImENGgokjMsPqhSHsTj8= 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=rOXcy/dl; arc=none smtp.client-ip=209.85.215.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="rOXcy/dl" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b630753cc38so6036111a12.1 for ; Sat, 22 Nov 2025 18:32:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763865166; x=1764469966; 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=PJWi9LJoNL3FYJ5G98IXAS+1MZDxRsbBpxNCWiuvz3Y=; b=rOXcy/dliwqxm0O0CMdF/7SSgwPjy8bmhvMwPfHBndZZ1J3ry0i+PCMmRwmU8prfTA BGywM3lMP5ruW3VckQ2VO37w9DdfuhxdZQ4iW8PH8aghz2FcKRN6jBaCMGv39mQE6Osq n9zfqi7vjnPVoZFP+bUPnyELIGkNTiBXcjj8SEriUh4aXBcE0xSmeEhGDVSUfgqHsaPi LnZ8KsKU5xMWxnBroiOzEFZOK5TYQEbMWRbaXYYrXmqowP0jdFpsdekYJdM7VLzyNAAa 5SXp9TIk7RMJFUjgBbQQxGE2DpALxMvOrEi6ZVEdiywWHFa8FoXHP0mYd6QSoTe94QEu 04OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763865166; x=1764469966; 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=PJWi9LJoNL3FYJ5G98IXAS+1MZDxRsbBpxNCWiuvz3Y=; b=EYyrKJ/X3kXWUgZYd0sYU75uNeMJOsqdVt04J3uWjx+K3lo74ij0IpLUvwACHlzRgB ayrvEXnzn7SuxJ6ZA3jEj13e0YjNFwne2AL5dLy8VSRAEJ4oeD9s/TvEMlaVOE9inpWz zVFfwpXn6R9tNWmK4pF6Jc/U+yuuSoKgWxRzVkNoZmKEsshjF5JZz29TjdTE58yzt5ro U+sgQhuTcXuGBXUHuFgS9rJfgUlvpge9qho9DQBGM3WF6cxdBHVX/LDQDdLk2Y1Y7dtk 8QyGpYOTkijW3vfbxOx6rhHfgoTBDdoSUeNjk6JU4/5Yw4MBXQ7ZVJhwmPBnkkoVQzxx G1Lw== X-Forwarded-Encrypted: i=1; AJvYcCWcRAlrzPnhaZIxe/4N8NYpNoKMTPVSxPI5o7pEHtDYFPSVAsW5HafaHUA1cLL7PrKJe7gO1DxTysKgduo=@vger.kernel.org X-Gm-Message-State: AOJu0Yww6zOLu9i47BdUYNunRxMiUVNEAK1zAPA6V/9w787rVaFhzyht bElheNhPprPAaClg30pWtJqNn3U3O4jwGpAVH80F7dcktttelHp2UU+eioDAbk6d+u2UNkx0arn zgKHYTkixGA== X-Google-Smtp-Source: AGHT+IGlLjcaAxzInDuxNrjd4MICP4gAlip8m1PZOAGVSGoEQnG3ECgO4g4ensv3j1w62Z5aRC/CWmyas1X5 X-Received: from dlbrh6.prod.google.com ([2002:a05:7022:f306:b0:11a:26c7:567d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f909:b0:11b:9386:a380 with SMTP id a92af1059eb24-11c9d8720c3mr2820469c88.47.1763865165987; Sat, 22 Nov 2025 18:32:45 -0800 (PST) Date: Sat, 22 Nov 2025 18:32:25 -0800 In-Reply-To: <20251123023225.8069-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: <20251123023225.8069-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251123023225.8069-10-irogers@google.com> Subject: [PATCH v1 9/9] perf dso: Move type helpers out of symbol and use fallbacks From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Athira Rajeev , tanze , Aditya Bodkhe , Stephen Brennan , Andi Kleen , Chun-Tse Shao , Thomas Falcon , Dapeng Mi , "Dr. David Alan Gilbert" , Christophe Leroy , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Masami Hiramatsu (Google)" , Alexandre Ghiti , Haibo Xu , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fallback between libelf and symbol-minimal versions. Remove the symbol.c code and just directly inline into the only caller in dso.c. Signed-off-by: Ian Rogers --- tools/perf/util/dso.c | 57 ++++++++++++++---------- tools/perf/util/perf-libelf.c | 33 ++++++++++++++ tools/perf/util/perf-libelf.h | 8 ++++ tools/perf/util/symbol-elf.c | 33 -------------- tools/perf/util/symbol-minimal.c | 76 ++++++++++++++++---------------- tools/perf/util/symbol-minimal.h | 3 ++ tools/perf/util/symbol.h | 2 - 7 files changed, 115 insertions(+), 97 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 344e689567ee..421fa4d27d2a 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1,37 +1,42 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include -#ifdef HAVE_LIBBPF_SUPPORT -#include -#include "bpf-event.h" -#include "bpf-utils.h" -#endif +#include +#include +#include +#include +#include + +#include "annotate-data.h" +#include "auxtrace.h" #include "compress.h" +#include "debug.h" +#include "dso.h" +#include "dsos.h" #include "env.h" +#include "machine.h" +#include "map.h" #include "namespaces.h" #include "path.h" -#include "map.h" -#include "symbol.h" +#include "perf-libelf.h" #include "srcline.h" -#include "dso.h" -#include "dsos.h" -#include "machine.h" -#include "auxtrace.h" -#include "util.h" /* O_CLOEXEC for older systems */ -#include "debug.h" #include "string2.h" +#include "symbol-minimal.h" +#include "symbol.h" +#include "util.h" /* O_CLOEXEC for older systems */ #include "vdso.h" -#include "annotate-data.h" + +#include +#include +#include +#include + +#ifdef HAVE_LIBBPF_SUPPORT +#include +#include "bpf-event.h" +#include "bpf-utils.h" +#endif =20 static const char * const debuglink_paths[] =3D { "%.0s%s", @@ -1747,7 +1752,11 @@ enum dso_type dso__type(struct dso *dso, struct mach= ine *machine) enum dso_type type =3D DSO__TYPE_UNKNOWN; =20 if (dso__data_get_fd(dso, machine, &fd)) { - type =3D dso__type_fd(fd); + type =3D libelf_dso__type_fd(fd); + + if (type =3D=3D DSO__TYPE_UNKNOWN) + type =3D sym_min_dso__type_fd(fd); + dso__data_put_fd(dso); } =20 diff --git a/tools/perf/util/perf-libelf.c b/tools/perf/util/perf-libelf.c index 861cb7ae9b45..d36b69ccccda 100644 --- a/tools/perf/util/perf-libelf.c +++ b/tools/perf/util/perf-libelf.c @@ -251,3 +251,36 @@ int libelf_filename__read_debuglink(const char *filena= me, char *debuglink, size_ out: return err; } + +enum dso_type libelf_dso__type_fd(int fd) +{ + enum dso_type dso_type =3D DSO__TYPE_UNKNOWN; + GElf_Ehdr ehdr; + Elf_Kind ek; + Elf *elf; + + elf =3D elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); + if (elf =3D=3D NULL) + goto out; + + ek =3D elf_kind(elf); + if (ek !=3D ELF_K_ELF) + goto out_end; + + if (gelf_getclass(elf) =3D=3D ELFCLASS64) { + dso_type =3D DSO__TYPE_64BIT; + goto out_end; + } + + if (gelf_getehdr(elf, &ehdr) =3D=3D NULL) + goto out_end; + + if (ehdr.e_machine =3D=3D EM_X86_64) + dso_type =3D DSO__TYPE_X32BIT; + else + dso_type =3D DSO__TYPE_32BIT; +out_end: + elf_end(elf); +out: + return dso_type; +} diff --git a/tools/perf/util/perf-libelf.h b/tools/perf/util/perf-libelf.h index 95fe8805aa41..976fe3fb5cd8 100644 --- a/tools/perf/util/perf-libelf.h +++ b/tools/perf/util/perf-libelf.h @@ -4,6 +4,8 @@ =20 #include =20 +#include "dso.h" + struct build_id; =20 #ifdef HAVE_LIBELF_SUPPORT @@ -29,6 +31,7 @@ int __libelf__read_build_id(Elf *elf, void *bf, size_t si= ze); int libelf__read_build_id(int _fd, const char *filename, struct build_id *= bid); int libelf_sysfs__read_build_id(const char *filename, struct build_id *bid= ); int libelf_filename__read_debuglink(const char *filename, char *debuglink,= size_t size); +enum dso_type libelf_dso__type_fd(int fd); =20 #else // !defined(HAVE_LIBELF_SUPPORT) =20 @@ -52,6 +55,11 @@ static inline int libelf_filename__read_debuglink(const = char *filename __always_ return -1; } =20 +enum dso_type libelf_dso__type_fd(int fd __always_unused) +{ + return DSO__TYPE_UNKNOWN; +} + #endif // defined(HAVE_LIBELF_SUPPORT) =20 #endif /* __PERF_LIBELF_H */ diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 5ddf8353e01b..3d385d749c53 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1572,39 +1572,6 @@ int file__read_maps(int fd, bool exe, mapfn_t mapfn,= void *data, return err; } =20 -enum dso_type dso__type_fd(int fd) -{ - enum dso_type dso_type =3D DSO__TYPE_UNKNOWN; - GElf_Ehdr ehdr; - Elf_Kind ek; - Elf *elf; - - elf =3D elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL); - if (elf =3D=3D NULL) - goto out; - - ek =3D elf_kind(elf); - if (ek !=3D ELF_K_ELF) - goto out_end; - - if (gelf_getclass(elf) =3D=3D ELFCLASS64) { - dso_type =3D DSO__TYPE_64BIT; - goto out_end; - } - - if (gelf_getehdr(elf, &ehdr) =3D=3D NULL) - goto out_end; - - if (ehdr.e_machine =3D=3D EM_X86_64) - dso_type =3D DSO__TYPE_X32BIT; - else - dso_type =3D DSO__TYPE_32BIT; -out_end: - elf_end(elf); -out: - return dso_type; -} - static int copy_bytes(int from, off_t from_offs, int to, off_t to_offs, u6= 4 len) { ssize_t r; diff --git a/tools/perf/util/symbol-minimal.c b/tools/perf/util/symbol-mini= mal.c index cc9055ba2f2a..336886c2b1ff 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -225,6 +225,44 @@ int sym_min_sysfs__read_build_id(const char *filename,= struct build_id *bid) return ret; } =20 +static int fd__is_64_bit(int fd) +{ + u8 e_ident[EI_NIDENT]; + + if (lseek(fd, 0, SEEK_SET)) + return -1; + + if (readn(fd, e_ident, sizeof(e_ident)) !=3D sizeof(e_ident)) + return -1; + + if (memcmp(e_ident, ELFMAG, SELFMAG) || + e_ident[EI_VERSION] !=3D EV_CURRENT) + return -1; + + return e_ident[EI_CLASS] =3D=3D ELFCLASS64; +} + +enum dso_type sym_min_dso__type_fd(int fd) +{ + Elf64_Ehdr ehdr; + int ret; + + ret =3D fd__is_64_bit(fd); + if (ret < 0) + return DSO__TYPE_UNKNOWN; + + if (ret) + return DSO__TYPE_64BIT; + + if (readn(fd, &ehdr, sizeof(ehdr)) !=3D sizeof(ehdr)) + return DSO__TYPE_UNKNOWN; + + if (ehdr.e_machine =3D=3D EM_X86_64) + return DSO__TYPE_X32BIT; + + return DSO__TYPE_32BIT; +} + #ifndef HAVE_LIBELF_SUPPORT int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, enum dso_binary_type type) @@ -271,44 +309,6 @@ int dso__synthesize_plt_symbols(struct dso *dso __mayb= e_unused, return 0; } =20 -static int fd__is_64_bit(int fd) -{ - u8 e_ident[EI_NIDENT]; - - if (lseek(fd, 0, SEEK_SET)) - return -1; - - if (readn(fd, e_ident, sizeof(e_ident)) !=3D sizeof(e_ident)) - return -1; - - if (memcmp(e_ident, ELFMAG, SELFMAG) || - e_ident[EI_VERSION] !=3D EV_CURRENT) - return -1; - - return e_ident[EI_CLASS] =3D=3D ELFCLASS64; -} - -enum dso_type dso__type_fd(int fd) -{ - Elf64_Ehdr ehdr; - int ret; - - ret =3D fd__is_64_bit(fd); - if (ret < 0) - return DSO__TYPE_UNKNOWN; - - if (ret) - return DSO__TYPE_64BIT; - - if (readn(fd, &ehdr, sizeof(ehdr)) !=3D sizeof(ehdr)) - return DSO__TYPE_UNKNOWN; - - if (ehdr.e_machine =3D=3D EM_X86_64) - return DSO__TYPE_X32BIT; - - return DSO__TYPE_32BIT; -} - int dso__load_sym(struct dso *dso, struct map *map __maybe_unused, struct symsrc *ss, struct symsrc *runtime_ss __maybe_unused, diff --git a/tools/perf/util/symbol-minimal.h b/tools/perf/util/symbol-mini= mal.h index 5cce1f1f0f16..282466aca7d9 100644 --- a/tools/perf/util/symbol-minimal.h +++ b/tools/perf/util/symbol-minimal.h @@ -2,9 +2,12 @@ #ifndef __PERF_SYMBOL_MINIMAL_H #define __PERF_SYMBOL_MINIMAL_H =20 +#include "dso.h" + struct build_id; =20 int sym_min__read_build_id(int _fd, const char *filename, struct build_id = *bid); int sym_min_sysfs__read_build_id(const char *filename, struct build_id *bi= d); +enum dso_type sym_min_dso__type_fd(int fd); =20 #endif /* __PERF_SYMBOL_MINIMAL_H */ diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index d37d5a97bc6f..25484b2e7fa4 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -117,8 +117,6 @@ struct symbol *dso__first_symbol(struct dso *dso); struct symbol *dso__last_symbol(struct dso *dso); struct symbol *dso__next_symbol(struct symbol *sym); =20 -enum dso_type dso__type_fd(int fd); - int filename__read_build_id(const char *filename, struct build_id *id, boo= l block); int sysfs__read_build_id(const char *filename, struct build_id *bid); int modules__parse(const char *filename, void *arg, --=20 2.52.0.rc2.455.g230fcf2819-goog