From nobody Tue Dec 2 00:46:05 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 9219B26E6E4 for ; Mon, 1 Dec 2025 20:55:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622526; cv=none; b=BZ46XTT2C0+515pdhAu3af/WDYcCUQVHg0GCUk3MaAVrErAabTsWuCqvKMlzgZi+vGdIx1fgBwtim0x1rjqurn9Yq7wDk1WvU3Us0RubcmFiG5Fjsby2LLFKqPbqIlKUH7jTl8ZsYPW+On8aP7vgXNv/lcW3xAvv1a285dMafZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622526; c=relaxed/simple; bh=z6FtVLqdmY2BvHaJao1xCfusHONbHKHJuP9pFmB/d0g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Yl9Rg4WzO4Vqp068aAbOy2399zsLVhyM2+IiP7BEinscl3Oc8JL137jf3z64WIBejA8n3zDcy13ruXQvtKf5QoYUuXkO/RhsNUtx3MeGaGbcmjDSvfi+cRR+2quwZLirne5X+5dnM+X2PqrZdKJvi5UASbRJFUN8+MPKeRu5CSk= 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=BeNIDYFL; arc=none smtp.client-ip=209.85.216.73 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="BeNIDYFL" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3438744f11bso7783301a91.2 for ; Mon, 01 Dec 2025 12:55:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622523; x=1765227323; 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=z77aYCybIIHavayyPQkrG4XKGziZQG4YhRaKisouWww=; b=BeNIDYFLvcrWLpYVaLbdUPxdx2AuDX4AZBdSkedivw9VyUPp+skyrPQGTSYNlwp4W8 zcspHRCrOIXo95lRS449hGEhMfd3JNW3T2c98vw0uJ4BY23HIcBXpxxtJtA0gj02negR aW0E06xshfvUjC7ru0NWPeVFw2X7vYRh3nV6HQ+sPr2qrANqwEMnAn5ZrkBpO/KWt178 CCYUcWDpu9mL8W1v47kXcfcpofFpNl9JlGGAZZFiSIUZVfyt8M3+9R4olqqmUc9j/0lW o/b1+XckYzRUZiU0L8McshodyTPwDTsURYxSMnuzALAbj7Oppo0X0JCOP/EsJ4TUJpBc NKzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622523; x=1765227323; 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=z77aYCybIIHavayyPQkrG4XKGziZQG4YhRaKisouWww=; b=OuD6PL6ecs/3+e2HpbiIDTP4IM+JpX55uZQfYBEo1xFgOFZbCN5GmZM2XQ7HoAoEMM iBgydHS+SC86FaWLByehI5mX7vvMz8j0hU0rWCbezTLD+urpH3jXWjpykwwYfJzd/5WZ +YuYciXCuoKstTaeEPHEQvV2AlAkeelGnOZG8h6ue+iMiCO+ayyxB9DxGkzLgY11lehN PpUYYDAzPftc8ht3LeHZObe1yC7sc31oCNfuF+46UuHb2LSi++nrCpOGl8wAIthpmlko tW0S2mKKCakZ5WHF8kdoqynObUPTvITACN8LogVKrIJ3mGN6QEA8La+NLxfemzjssVZo nueg== X-Forwarded-Encrypted: i=1; AJvYcCVfYIIBlDRT8LH+yP6pNBOZesE9lcRXtseY1CDzxG2zZPnISPForcsXsFKl03Agx17YsZtCGP5jB3LziCk=@vger.kernel.org X-Gm-Message-State: AOJu0Yznal7qy6VjaHcU41LxMBqorU36UbGzW09t0gnjY17kOeVdsXYj vq3r32Dk0fuPZHZUzM4fUoEuk/RoWAer/15tuDEsYeqid95/mdb31aq0J+YswoxahGrVFhGBmW9 yLAv0++LdEw== X-Google-Smtp-Source: AGHT+IEE9W5jzAEEvpyu9+iNLMSoHbvRdj4v9fElI9rpCqSB7ekTOa4+XG6BRiJddwmiLaTozOsN4F8a2pxb X-Received: from dlbvv24.prod.google.com ([2002:a05:7022:5f18:b0:11b:a892:80ac]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:2219:b0:11a:51f9:daf with SMTP id a92af1059eb24-11c9d718ef4mr24872885c88.14.1764622523344; Mon, 01 Dec 2025 12:55:23 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:00 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-2-irogers@google.com> Subject: [PATCH v2 01/10] 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 , 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 c5c382c3409a..f661ea6c8ac2 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1052,15 +1052,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) @@ -1233,7 +1233,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 3fb5d146d9b1..9aa0016937b7 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.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 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 6F6B7269CE7 for ; Mon, 1 Dec 2025 20:55:30 +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=1764622532; cv=none; b=SoLeJD6w8zDUaqv4U9AIlMysP/vq2q5MStRX/x5nw5YZOGf2aXP+U964XGkB9tCXEIyuAqU9GONlST+8n5Gq8rW7wG6FeBjnI8CQbeZBdtgTnwytSLzyeLWgopM6BrCjb5jMjXosXpZ2ShoDAM/mCpYRjQWDSlmORsvRvH2S4hE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622532; c=relaxed/simple; bh=RGdmhyBYFRnGgFw20jM0roDN+95aj0Dmbo2wN7m/qV4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=UnCU9ZebQ680hB+D0CctwoCTyP7GJmxU9r1O9RAK6MuTbGZ5OCYfIqr/iY9OdVUYrgTcbxE3Bo1MCfhH3n20FFvZEklYAsezWR6wc+8bhM0oAoTY7uXaSjhprERKwPf1e9IqmQBIl7uKZvU9wr5t69h61UtMBxUKzhxes9rUYCo= 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=4WJ96559; 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="4WJ96559" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b969f3f5c13so4737077a12.0 for ; Mon, 01 Dec 2025 12:55:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622530; x=1765227330; 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=nuvqYDAGbb4tGYCC6QK3TUQ9PWdRvfqu3GrG0lS3IVQ=; b=4WJ96559VIGAaEALefJFSywyqSKX97vmrU3b8y7AuhfkssiFgamEO0w2V3IZoN04eM FWHhmIywjEca7SpAzKCmC0HZfLtaJF+tL5G5za4dnRd0Vc3ZXhZBYWPG6q6sJbs+ebJ3 jEYHKaJD468Hk4CLGHTyDVCTYeJ1xkde5t6uE1OQnr1UiPdnEP5lMmLjLhAEGT4ZPXUq qxCneXcSHcKkI5iNFJCn2tFOmTadjMQ4k/ZAwsfbpPOK2UpBSAyJIkcTB11XXfoJFOmc IS0H9W5W8pTuHlBMqDBbO9yQRok0c8Haw7potcOadDRRYGu5kcAleWtxL8PhtWv9lg8K 5LLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622530; x=1765227330; 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=nuvqYDAGbb4tGYCC6QK3TUQ9PWdRvfqu3GrG0lS3IVQ=; b=wNF5qIFc/H9k7By8OzGJHtHEXIOwaJTjdx/dP6BywUrZl01C3LhB0sP7SCmQ5Wb/Np gLZXIRDzCvGOuwEoaFDIbNPkOtymm0IHx8bHhJ2yUmXcJgtbchuAOON/cnVHXTor8mMS EOlik0UclPBvTPk5JLLWlvBRbX/0UdkSk3xaKuUVsFbuZ1SaR30shyaXdaII1C6JRvAX lOeQJXWLa4Wp+QiYf/AD0wslXeeot1ThLY5yqq37mbVraoIWufyZ17x6u9FsBwb9qMyb DXhXJ0KlHAWmweNOaXRg5SwgOBCMbMPfSqQNw+nNyetbh+xCGBqmxA9hOdn+jRpgY5u7 fpTg== X-Forwarded-Encrypted: i=1; AJvYcCUTK9TdWlltzp7NJCmT+ERUfVrXW+7ukVxhgdHJrot+O+fQI+8JVkP1/nkOOA35cSNczvpg2LMVo+JZna4=@vger.kernel.org X-Gm-Message-State: AOJu0YzTOQLy7M20UsbxLo/4zKFxrhaxS8+C0xZPsvKrQbD5VFdT3wb/ OgZTIM4m1u9uxAvieKNMNnROa61N0Nwh/BpjgO+BIny2aEUqWHwYQtGWN9J8DlIPMVhIqdK0Hkf RZq1auPQ06w== X-Google-Smtp-Source: AGHT+IFFXPeFIT+moZ3s44tHExWRRKrP5myjYRtAUhgxSg5dgFVxNxqkGlXQGLrK0E1CN+rPJMvc0QOl3Lch X-Received: from dybgu41.prod.google.com ([2002:a05:7301:22a9:b0:2a9:7031:8efc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:fe46:b0:2a4:5028:342d with SMTP id 5a478bee46e88-2a9418914f7mr11875973eec.33.1764622529695; Mon, 01 Dec 2025 12:55:29 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:01 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-3-irogers@google.com> Subject: [PATCH v2 02/10] 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 , 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. Note, the previous PPC code would compile both for 32 and 64-bit and when _CALL_ELF=3D=3D2. Similar testing could be done using the ELF file's e_machine for PPC32 and e_flags for not EF_PPC_EMB. It can also be done on the symbol for a non-zero st_other. Given we're just copying the value, which would otherwise be 0, there's no need to introduce a st_other !=3D 0 test. The value is only used in arch__fix_tev_from_maps on PowerPC in the PPC64_LOCAL_ENTRY_OFFSET macro, where 64-bit is assumed. 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 f661ea6c8ac2..99b1e060acf5 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1338,8 +1338,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) + 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, @@ -1718,7 +1721,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 9aa0016937b7..f12bb3d0e08b 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.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 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 DF3F9269CE7 for ; Mon, 1 Dec 2025 20:55:35 +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=1764622537; cv=none; b=pimencGXWzGJ+Fvmfa2wiIhkEEZ9algQh80JkF6FrFm9+vtGQDuDE9yJD/+jMZ8+UbW/Hf5kiU9NTmVeJkg6JPWQjOb/U7+OTY++wpLjdnNR+Wreck1YRxhFx3z1QTmhh2ZW/V9sQct/2yMPrAVrGBFxh2cTMpAQgtQUBI7I32U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622537; c=relaxed/simple; bh=zUVBgiiZ0gXg2kVcXRXUmDd2ZV1Y5zckGB+gp6QQQ3g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=mMec+GZuYshdhaypYviePBIQJ3Sfo0gT23w19wLpiwReUo2Gu8So1tdm3Y20jP1krXbzcJygzTY/GUPmswEBSG3yKFvKVFtmQmw4Gdy2k63n03/qpkHI5ds2DaRSazlILsw9du2wBn4CTOnH/YuyxowRwq906U7SUgxiJsNg0Ac= 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=0SBZyhNT; 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="0SBZyhNT" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-bc0de474d4eso9537974a12.0 for ; Mon, 01 Dec 2025 12:55:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622535; x=1765227335; 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=XN0PksgfGile0bb+ntHwdR8Wgi7cddiEbQBXMGD33y4=; b=0SBZyhNT1JI1uVh/pxDe7hy13GbP1VqWP884TLe/9r0A+uL1LUYfcGHje10fq/B4c4 bJJPrvz7/0oPVPy1h82p8goahoV6ycRRVIxz7Y/27p6VzJskGWBa5iimrw4le2tr7qO7 AkwVFycjCZjRszXofyfFiDXefT2p1b1DnGwf/GkCS9S+hlFgdOOl20jY5dx2W9BuldVd SHGxpIjpbo7JM5AKvyOmOoZJJFx7IQKTAAJRSY34Rn98BzK3nOdCC9tYAxH/45uykOoW H+26kJRG7UQV8afh+iFGSD70+BzGGZjbgrl2SiFDmPItIm9lQyf5G9lPn7J2G7EYC/Zz Z3tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622535; x=1765227335; 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=XN0PksgfGile0bb+ntHwdR8Wgi7cddiEbQBXMGD33y4=; b=NITGadSe0i/nTpeUZ1M7O9QEOakCDs9VBYr0bzs0RqUVc0jIVpIuZjfSVcWQs8heNd cZ5HRGt3u4+AeRcZy6aY0NKDIrtNxgOT7vepYi+4V48cUT2Xfx53XaxBck6GJpnmWzfC LNcQKLKIJNeNWhvNAYz4X6YguxGu9JwJGU+QbyrdttqAZBcy9iAafhIGi1MJZBUyEQX9 nkKXOnJJx8WmIWe7p6B21qxDisSYYQPMkQ7U/iWkouKVWynHXgbwLty2YYb9jslReN98 BQzGkIxKpsFS5cy2lD9/Rta8vNISBxy0RgO4Y1nYkvvzBalw9jbrL26/x4BPQ1Xh1v4C aOQg== X-Forwarded-Encrypted: i=1; AJvYcCWe8Uef9ve1rryDFC/yFzAh+JHjNoi0lURJtEEaClgWX0WY7rIaHE8ZUtnADrMnjRtWdBaEyvHolwRV3oY=@vger.kernel.org X-Gm-Message-State: AOJu0YzKF1U6v2D6tWxjAju0BSog9j0zviWWCaRLaVKjf/VzjddbLNY4 4X4Ig3jbqLy5BpDR0/UZF9QoFqGfwufJuOrQdNDNRQ6x+nh8wJQ9Ym3NLYkj7cghWjrjEDAMGk9 gnxzapt35dQ== X-Google-Smtp-Source: AGHT+IFHeAOg9/N3Q5WZyX9xvhKVcksBco4IpwEXc2kFEVfynL65kSy79cDzSSZueJGis+MGC5RUjkOviWyf X-Received: from dybph18.prod.google.com ([2002:a05:7301:4192:b0:2a4:7453:cd4e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:2a18:b0:2a4:4bce:309c with SMTP id 5a478bee46e88-2a94186f8f4mr15215437eec.22.1764622534894; Mon, 01 Dec 2025 12:55:34 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:02 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-4-irogers@google.com> Subject: [PATCH v2 03/10] 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 , 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 99b1e060acf5..72632bf9cc30 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 f12bb3d0e08b..393a528326d5 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.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 9731427FB35 for ; Mon, 1 Dec 2025 20:55:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622544; cv=none; b=YDClHuIfMJJfjnVidZdWJ1WRUBRyigBKiNuA1TfLZL9RrYWfNlYU41Py5yfy4oNbbO6RmF5DrHmTB4dSZmJHntBbf3Uai7jQDVI5KjRQkd8+9hAFl5YGXHOpTW4Nk2UhfDdvJlEkuqAsQy2OHFcL5TzF/vqrxaoW4wE816+6pTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622544; c=relaxed/simple; bh=LUgHek8vbiWDOkcjtIU9UCv7EbmsEAOGQ2dFOdHmat4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=JtH3/9pYxV/L6s14TOShHXMMqZetInGEi5BqJrdvWDqyfGxRHMRcB7zct1IETilc3qff2Msry6mds3cxx4QhwB8mqiAXBbdjnsqwzxvqnCWO3oZbceudUChdikYT/tYAxOq+Mw9gw0X2NUS1ExN2d7XS5o49WCys2o7xJs6FGmk= 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=WZQUEoeH; arc=none smtp.client-ip=209.85.210.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="WZQUEoeH" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7ba92341f38so4542603b3a.0 for ; Mon, 01 Dec 2025 12:55:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622539; x=1765227339; 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=2xT8wtJEMfyCmAK5hUMH5sU9s6sTyGN/uGz6ngBwjqc=; b=WZQUEoeHp2Ex9JVwIXXfmzST1niW8P8gWkdb1dbmvxoA58QFYM8V6QJ4UzsNPLydjN SKqk+vLCz1BGb4dfeImfyOINC2FIR9ONOL9uBEop4155LxjdexFf0e+JKLUVqG612PoA 2Z3SYkM0Q9scZSLNB/EW5zPRup7xcp91z1xZp6G7+H1WG37r15QigM4hbhVdqORDjsbi sHlbIQOnd2BpYjbwIwLq67TC+qs9+cMjRz7gpTGomz9sTLaDGHbr9qC572vN7KZNfFhi dEVEbygX2DPc3NGowidqj+w4MMzZn2EemBXqQxBsvBkpvnBfOmZ3FrV8jDca3SAkGya3 6svQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622539; x=1765227339; 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=2xT8wtJEMfyCmAK5hUMH5sU9s6sTyGN/uGz6ngBwjqc=; b=f4k2zNE4E6mlJLd3Mz5WxT01nRjZj7XStHUrHc0VMuxWIC9HUdPm9BQXxbOS0CnTWW 9R9TQNTnw2Fa5cWIoBaURk3mKJiTuQADkVSaaa7l+FNqN0upcSKiYEqVEoK1BN83vYzp Dp18HvIO2rtP9mYYB5r1boENupaGNkh60QxCEHgaA9/RjNt54LJlvfw9FUBan8Gsvoe+ Lb8YgrHexSeepSvZlSrSEKMe8be4opp1dBg5SH1ZFG9QhfyJWdUJWfboEEzGaoiAqGuQ Ab781gUB/IbEPfgMC0/OtCyQvahfEAz8d/hwb0z63ogR/Wea0q3IAR4D+8kY25T+qjhH dzXg== X-Forwarded-Encrypted: i=1; AJvYcCUi38CSMCHUFRpTTh9pk0C3ggwHUCZPEujoQZbZUFGYXDGhTNovbvXfBczJQXIc3bqY72O6WW/pCNdyYq0=@vger.kernel.org X-Gm-Message-State: AOJu0YznQ86keBPCyzbnqMMoAZHDefqk/6/dN3NEEwbYWPp8//SWcVWC ENtrY91Pe+eE/tgHMHx0w5AouLgnizi4vshy8GLiaXhA4BWhxN3T368UUibe81+8z2X4DKEcz+A Srp3LexyP3g== X-Google-Smtp-Source: AGHT+IHXYsxbKhTOiExqvbHu2q8pVlZxS4dN2TT7L+3HHwF5ECvIXkrd5YPNRU7kCSmbr0naZcrGy4shEL2g X-Received: from pfus11.prod.google.com ([2002:a05:6a00:8cb:b0:7bf:76b4:31f8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:124d:b0:777:797b:7318 with SMTP id d2e1a72fcca58-7ca88e8eee2mr29377223b3a.7.1764622539453; Mon, 01 Dec 2025 12:55:39 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:03 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-5-irogers@google.com> Subject: [PATCH v2 04/10] 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 , 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 0e40f2a4bd18..311225944b78 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 fdb35133fde4..9e1f8d5f6d51 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 393a528326d5..2b2bbb5914b9 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.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 8BEBD277C86 for ; Mon, 1 Dec 2025 20:55:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622544; cv=none; b=PX5WQgsz8E0g2q6H0rErJLxFG7LvdA5H63ZzU8UQHnfmKvyd2n5icbgkuZvoQwoxj0qPrM4OXpSOszDXeU/hbd/v9hUxdwNoOn66NdmkYtEBF5uQyMFK/l/KUUoIL7pZAixGWvKkzfFOoWUemWs4kT8sn36iTQOWFNsrUb8Z+Qw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622544; c=relaxed/simple; bh=/HQYxPyULLvORGSXVTG3Vsicqzs81N227w3aDCmJViU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Ure2d3Xwnlz0K9UZX3AttV5jSI8g2kC4DY8Oov9citj+wtE282PdK719QchjR2Uvfq8OIYBnIAdZ+Mf25fjViNC7QvCSJBOyb1Nq5f9YgxJf7UeQL8Oyr8CZB1JEaZBWU9nvftf7sBpZ8HngiZ5ZB+Ej9b1rNxLNc45zOB77q9o= 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=0R8R8Wjt; arc=none smtp.client-ip=209.85.214.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="0R8R8Wjt" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2958a134514so62139765ad.2 for ; Mon, 01 Dec 2025 12:55:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622542; x=1765227342; 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=nqxG4c4Ejh1cwsCwJj6cVtGyxfElTSuoVo6DlnxDj58=; b=0R8R8WjtsORCzY+mx/L8snPNBZubAOhcZA7Xlco9CWtz9piW33s+gUqltKxh5fbpy8 uqbVv4EwZtjx+bROroI339a4zCNQbWn6NZMbc81i1PK62XB4dRPsRyXgN3l/g4Bjcrdp AHVFs1TVutz8YNERrKzRmdFPCBdbnVZ2/tVqmEERrItJqr+VnVniiBYGY40wdSac6Gub EnKcgi7uZk+QKoZcCXX2XGSVR8XOOqq0roqKrAal47yqXXvXkx7/ybXPVVJlMrPwEKiR ZqMUcbbvGl6Fg2qRhss+84rbRpeBNQlPGTQ+48uFJ9TG43nt7Ln4Cp9nLg3zeZ59c2QR okRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622542; x=1765227342; 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=nqxG4c4Ejh1cwsCwJj6cVtGyxfElTSuoVo6DlnxDj58=; b=I9b737rvNY9fwoMvUPtl2ehvRqu01lJL7T+aMx8ohQQFX+3C+egsIEvXEtzToFkeGe ZtqctKJfV+ehBACOLNTcLunml66byIMyAwwkkRRStLB9glAg6kBZHKSLn05KYv1PUGWY x0K1jySpLpSxovYOS/vIjCbhCm9KgZvArON1N1kXTaSD+8VAr+lZI6WCWfgP+sEUia8O uDvpwqRORX+2E50hrRyCwe9KvZDF8YF3+WGrmNU11goKP4vmQZzX2RqgaJcqUrSUJihn XrSh9TebYEBWGC0h0Sacw9M/CyE/7d2+IZvZr31zTZl4LqqwrM5BKNZkTGhNJo0/KDbE 3SlA== X-Forwarded-Encrypted: i=1; AJvYcCVPjdSuRGY6yz3O28oUUgpKmP0rKvxw5+JS2s5EYObbqP0r45oGtZW9OO3OO3NvotV3yoE/p1LoRhdSvl0=@vger.kernel.org X-Gm-Message-State: AOJu0YwZ8QWfJReKgmxx/OH7WLU7SMHo1DzM3Cs7lnVTDLC7ttKu5QNw xQsTE/Zm/io8LpiZlXvQljUu/tAxe/KMzcuK9w/t1R2OQkUSYHvSU6Yom3zVE0AEgYf3Yc+Ac0t fKQRRhykRIA== X-Google-Smtp-Source: AGHT+IHxPPg1nZrMrBc6g6s28MBG/8AEGZ8L7TvRjMLuUaeyN2ppmycAcDPmZoMx3Y71gdUm1zTzeLbZv/AJ X-Received: from dlbqy10.prod.google.com ([2002:a05:7022:ef0a:b0:119:78ff:fe16]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4186:b0:119:e55a:9bf8 with SMTP id a92af1059eb24-11cb3ef2761mr19885364c88.20.1764622541626; Mon, 01 Dec 2025 12:55:41 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:04 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-6-irogers@google.com> Subject: [PATCH v2 05/10] 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 , 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 30c7da79e109..e97c7662664e 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 953886f3d62f..086c5f12cc34 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 d8fc5ea77f84..f8c6a37464ca 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 2b2bbb5914b9..e265e1f028be 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.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 C5928280A56 for ; Mon, 1 Dec 2025 20:55:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622548; cv=none; b=Ai0oyvtarYPKzIlV1hFjW2yR5F4l0Kl98c3PoXZekN1eMwk6CtyOBx4HYDuvVZYHsKgTawHt/UpJ9cKP9XwZALDlqB+KR2eeE8xvfoI7bZuGXdEUYc9BSONnXU9qDMwMYZLJcug5habqleT/7Zr35sR8THyRCBu8JebjmKcYNUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622548; c=relaxed/simple; bh=5iVPidYYfX18F10dAb9vsXKf5nS8G6rYK37eH1zEKGQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=HMAENHl77W2aXQkDISBYGJ7lCmla2Jw1QOYKhspPmApvfKo5M1+diKmGKsLQAdHQlzxghscYU2j9A/mvgJRrwRgz6y6DxwYeUgZUmIFCpRqOG6S0Ax+ZZGx82k4TjS/Gfba1uoDWRfPKAGYCqA/uh0L6I/szAGtymgyslehAzIY= 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=YfbHTJku; arc=none smtp.client-ip=209.85.214.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="YfbHTJku" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2956cdcdc17so44045525ad.3 for ; Mon, 01 Dec 2025 12:55:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622544; x=1765227344; 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=uuHgu2glInZJBEhOxRnUAXjhLc1cXn+KrzwpGruaKLM=; b=YfbHTJkub+KGQ+CMQCeb4R6CnqX/Yq42v4czNpniSjJj8rmsYUU9UttKzdgcCHmRFI IRy7usgHBPg/v3UQmOBbi40x4A3e2A11dfKnp/UxgMz8aAngeQx5viLmTDg6Monl06Yh Fx+YO8WCRlUOh7AEbFa0Ctu9fFx5FkaQ6w3wglShKaZ0ZSYw7R/W4lb03fTDd9FOi73F vFgIMwwnS390KYCz0QBgBnOvouUChyDl8aKnYdyxuO6CSvwKo9Wz3mg4PzF2VEsLF6o8 8n0bC8x/I+MsdbEA5f67wL37dpNIlrgJhejiYhBA5tzRkb+kdWQi5sV0Nozq8S3icg4b 0Npw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622544; x=1765227344; 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=uuHgu2glInZJBEhOxRnUAXjhLc1cXn+KrzwpGruaKLM=; b=QhfkdZCswEGhgsbHv6uVUC/Ad6uzM0Qe6bDRQifORzkDAn1dMWtfOg/x9jq2FY313u VG04RaFgBE6GMoXKj4USBxtxyiDWKYQjm/Z+4bL+Hyj7XUFjwSoL9TETHqdGe1IEIoPh 88tKAQa/5LmbB7UkMmq0X4ssrXQmwfnHny1LAa3iyEcCPToribZZxuXG9CbkjYwP9c1o PrOIq9yY0aT3MxRwITtko5TBfbxp3kAMaGi28xH6tsNeduP+JZhlv4LpzKoqvD431vIR oqZ1w+PRrqBxylCSsy8Fs0PpHFEqrUbSxFEOFFldW4JPiwV3+Da1QCVQhZeS6uk6dXQw iZBA== X-Forwarded-Encrypted: i=1; AJvYcCVd6ND6tmRc0NGwx4WZ0Tn9duWhA1IrFvVKRoaLDxSE1lCL/2oTtbJ/ERkDMv8HD9Q2HvIIrQQq8kDYxEo=@vger.kernel.org X-Gm-Message-State: AOJu0YwFHUVVosGPS8p7JptXzCba8tlch2zponWY92R+DEb80GDJlfhn p+HaCxCYgtMNVM8bKrPIw9wTIMoeQHw42XNYHNwl2CRiZM5BfPcxcfKNlYjbizLBUcFrMJPUbdS GcpD69w6tuA== X-Google-Smtp-Source: AGHT+IFYzbePgFT6fkcTqAR3CyIrUOSa1Z5mZa6Ca/+u8aQp6vZKodje8G+ZFlYCmO5NB1H0Ie4XbKA4XWxI X-Received: from dlzz38.prod.google.com ([2002:a05:7022:4a6:b0:11c:b3ab:7f07]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:ec3:b0:11b:9386:8255 with SMTP id a92af1059eb24-11c9d87a215mr30453528c88.42.1764622543976; Mon, 01 Dec 2025 12:55:43 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:05 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-7-irogers@google.com> Subject: [PATCH v2 06/10] 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 , 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, 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 | 9 +- tools/perf/util/libbfd.h | 5 +- tools/perf/util/perf-libelf.c | 113 ++++++++++++++++++++++ tools/perf/util/perf-libelf.h | 20 ++++ tools/perf/util/symbol-elf.c | 155 +------------------------------ tools/perf/util/symbol-minimal.c | 17 ++-- tools/perf/util/symbol-minimal.h | 9 ++ tools/perf/util/symbol.c | 52 +++++++++++ 9 files changed, 211 insertions(+), 174 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 cc0c474cbfaa..c438fbd03b24 100644 --- a/tools/perf/util/libbfd.c +++ b/tools/perf/util/libbfd.c @@ -418,18 +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) +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 - if (!filename) - return -EFAULT; - if (!is_regular_file(filename)) - return -EWOULDBLOCK; - - fd =3D open(filename, O_RDONLY); + 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 086c5f12cc34..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); +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,7 +65,8 @@ 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, +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 72632bf9cc30..8fb7bf743ca6 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -751,159 +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) -{ - size_t size =3D sizeof(bid->data); - int fd, err; - Elf *elf; - - err =3D libbfd__read_build_id(filename, bid); - if (err >=3D 0) - goto out; - - if (size < BUILD_ID_SIZE) - 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; - } - - 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) -{ - struct kmod_path m =3D { .name =3D NULL, }; - char path[PATH_MAX]; - int err; - - if (!filename) - return -EFAULT; - if (!is_regular_file(filename)) - return -EWOULDBLOCK; - - 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; - } - - err =3D read_build_id(filename, bid); - - 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); @@ -1171,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 c6b17c14a2e9..b71cf8caf282 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) +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,12 +106,7 @@ int filename__read_build_id(const char *filename, stru= ct build_id *bid) void *phdr, *buf =3D NULL; ssize_t phdr_size, ehdr_size, buf_size =3D 0; =20 - if (!filename) - return -EFAULT; - if (!is_regular_file(filename)) - return -EWOULDBLOCK; - - fd =3D open(filename, O_RDONLY); + fd =3D dup(_fd); if (fd < 0) return -1; =20 @@ -199,9 +198,12 @@ int filename__read_build_id(const char *filename, stru= ct build_id *bid) 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; @@ -363,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 f8c6a37464ca..8d461974a69f 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() @@ -1998,6 +1999,57 @@ static bool filename__readable(const char *file) return true; } =20 +int filename__read_build_id(const char *filename, struct build_id *bid) +{ + struct kmod_path m =3D { .name =3D NULL, }; + char path[PATH_MAX]; + int err, fd; + + if (!filename) + return -EFAULT; + + if (!is_regular_file(filename)) + return -EWOULDBLOCK; + + 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; + } else { + fd =3D open(filename, O_RDONLY); + 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.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 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 C485D278E47 for ; Mon, 1 Dec 2025 20:55:46 +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=1764622548; cv=none; b=Fm0CaWDISUSfheTeaw/jBL+MtwQigmdwx6KAbSGTHBeoeRKoNzxwfpvSumeQjpqhjPWOzQrW2+a2Wmt/gdYZIL6SvGF08cQtk/HVJNsry9VCUjJHaTb6VzVpsRsAryh93at5CUequDe5YzzAru/zpkdaV41KW8PjDk9lo4l5qUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622548; c=relaxed/simple; bh=fjLI72kegeSJqfZ6jGUOurYAdTweSGw5ZtcUlLf1AoM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Q2NmhZOmKebP7S9uiOzILLx5SF2OkLn1zc0Udu35ud3bu8tvkL/cE31JMKn0wP839ybnmPmo4A+4nU7EXkJi9H3FmXaus8uO45KSGgtBpQA8q0aJ56C0QCOvLiAJhTroWU4TwLIWPCNG0NQrK063SPX9+cnz74a6tHnscoa1drQ= 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=IYHQy8Pv; 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="IYHQy8Pv" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-bddf9ce4935so3701715a12.1 for ; Mon, 01 Dec 2025 12:55:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622546; x=1765227346; 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=c7HvpJfXVkoUBz8+ZXfXdSN3qFolYiwgdTVJfU/maPo=; b=IYHQy8PvH+rEkVJaR55cp0WNy5u8nfe9lJSRDg4bp0Gr881BEwJwvlZOZqrzp8kOo7 QPsAT5gJoc51bBr31IzBmobLUf936C+quSi8d/z9xem5VcOqUAp+hfmNQBXisvsiUoVX P9hs9MagOHUM7aGfzbjl8/faE1KLLFXz1O/Xxs9PltShAv7ZG6C79a/412kgkW6uBmvH ASG9UJYbjVkYqOiNCkRCeTqfWJlm27y3tZW+6+N9J9lO5FEGTjQMSzwenVdLKl+RivBL hYOlEeJ2ZJmeTSTAyJfrDUKsDs/zcO9Y4++3L2+/hg/emch84nsIxgSzxDUzPQ5uCYCB mvJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622546; x=1765227346; 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=c7HvpJfXVkoUBz8+ZXfXdSN3qFolYiwgdTVJfU/maPo=; b=Zd/ysD4ZEuUDRT25VfqXNwbufZWHEOv/0oJf1AI6L0brsH6uz8JbT3bP5RQPYvNO9q 3ZW4GRiv+PjdxrzMUPFdirox62dIvgtC02bg5cKrtsNn9TfGPq+O5wX/cWE4BtuyQRmY W6E0b5K/ZE1EBO34FAmxxC1FwUDp6dcTopwbHEjU0abUtTEhPNTPLM/RiicXvKAk2gg/ q+CzDxj3XKsQu0Dnxfp8pJesIgiUdFMjoQe/wwc/dVpgq0IqWJfatPixIrxtTjbOgKCB Ydyr9ha8ZAIHtkr4cMUmbRj1iBzuzULZYJFY1FetFrI9p0agO4qIiu4czllkGrpyjvpd CXTg== X-Forwarded-Encrypted: i=1; AJvYcCVXFA4q/UaRo4+jDnbPIZilyWOHFhFmaQSKS9Xm2FS2sgfJP3/i/nx8O/Oqjn2weA2d/E/X2Wy+QeYRxwI=@vger.kernel.org X-Gm-Message-State: AOJu0YxkCUNY0Xuq3kG1JhXiDLA4btCovhs0Yz23DHP+nf1boquir3ZL KaofjtUt1bAwqZGDC79b9lXCgnydfLlZ1PC6gicf+YXAaBhAYcc3QFk/To26Ia3HwKvglSPSw1G MHBGJ6ZBc4Q== X-Google-Smtp-Source: AGHT+IGOxiUBhvMxSqyCELGqzF5enfB5jhNuSSvdzglSimtj4YnpmrdDi5VRYzuCfIRwh+KGF1PB54ol3qFa X-Received: from dybqf13.prod.google.com ([2002:a05:7301:648d:b0:2a4:7cf4:5bc0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:d4cd:b0:2a4:5eaa:a9a7 with SMTP id 5a478bee46e88-2a9415730cemr17893504eec.1.1764622546182; Mon, 01 Dec 2025 12:55:46 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:06 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-8-irogers@google.com> Subject: [PATCH v2 07/10] 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 , 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 8fb7bf743ca6..9ceb746b6c59 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 b71cf8caf282..445307f230af 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 8d461974a69f..da75a1c159f2 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -2050,6 +2050,16 @@ int filename__read_build_id(const char *filename, st= ruct build_id *bid) 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.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 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 0674E280A51 for ; Mon, 1 Dec 2025 20:55:48 +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=1764622552; cv=none; b=YifEYg6jQZ/GTAP/Iy/W8fcxwAqeq3G7lZPSYUTubht3apQPEu89y0XWALxlzIWVLmIbyIV60CcB+GqtnKZIX6eZanTWV5c16/I8EkzJtmdMhZzOBnjzfTB/ywxVa9bd9U1GDFK/QHt6TrOq7r5cwsocT1f03Htr1LlYDKWClzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622552; c=relaxed/simple; bh=2hLfLEdeG6Q9fp6ZEtSs1CidG+0p9Bs8uu4s6+QrX+A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=dgrAH+3tDXDvE2exNQoDhMGU87vCVqnTWOjR65CLlvqAR/cVj8E8hjAPJ4KhDxPdlKe2tgoxWtxv0Av6gJdSu/HkXoknndciICmMaEo7swz8rdsfx9Z5xnGkfvtGYLhVaGObSPR59w9FiyaNC6/GuRKUCwl1JKF0ttp1hfTttdw= 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=lMqJfx/j; 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="lMqJfx/j" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b98e6ff908aso10631592a12.2 for ; Mon, 01 Dec 2025 12:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622548; x=1765227348; 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=HKKNjh5F/DaKk8wuFOjnc86WkhY823H5ekf9jbrPtus=; b=lMqJfx/jvWsyx6G8U5XiToYWLJmjU+5j3mqN9w3TaQr1rxzi5o6IcQYXkpzTwIsweH 1NbQ3gLZS3s7Uv424BNmkwjdzow5IMxu6UrERUVE9z9DFOSGxwappWFbqX4wW5b8tJKF cCmWZ0puYQ+n/OJhjKdEZWFt5jmNUfpEMlNUigbMk4fYAGXKgAW5LGovDXo7w2vTI284 sFNfn+mCR3ADVQO2QXpOrC6xxC0mJvbhMRlcFmxG5unz0M1zgrBKTSsOR79VoIwPRI5E +5E+bdZKe7pKk3gAmFPIO50y011Q516VO1yTGeUPtzCB9xgkkN8FgnNOdRFfwAJNgw/s VS+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622548; x=1765227348; 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=HKKNjh5F/DaKk8wuFOjnc86WkhY823H5ekf9jbrPtus=; b=VvzmaCvCIz/oUMxPREEqvO2fIXAmB3Fknkqa0L9fdT4x+1qWrGCpddpPaphh6RS9/i Gs6GIfRDO2coM8IbgqKufe9kEmEtIarl/LkQxeSOmeJP1dvdfZQgerkUSkwXr6OaROug PrpJ+FaCC28bJZ15FmBoBJTCH2DqraRaq9Y4jtf06cyA+zYMH4tP3Gs8AhvACvgXFBiS MssS1Ulg/oCDb9na3uHGF7CO1mXsrPBaG2+aXFhE3zGzHWQq+jrDKGlkz3U/9xCz9ulr Bu47rQfwDYrcfkBhEJUxLkEZEFKgV5BVvTpsoyG6MD0eqy2LYxd9y81Rz+Lz5raStc0w ZCDw== X-Forwarded-Encrypted: i=1; AJvYcCXW9ZTURl4EYqG1qTpi11JAQ4kMjTjkBnZI3lY9bwwjdnNlzccy15SvX0bOZGseCICtpN1qyriyLBFy030=@vger.kernel.org X-Gm-Message-State: AOJu0YwT/p8gZPJ4IJFkdAI0nTyQhTXi2uLQf9LdcQ/9UsAY5vH3X4MG 8HhOUJGMqliuBHDcDl+KhbLC4Uwp/Bw64ig+oCPyH81H4oOVKel9Q/6R0paMjhHinqF3KN28RCh w12wF7b0bUQ== X-Google-Smtp-Source: AGHT+IFR17AdhrIQVLVcu0xi9Bguk4YjUWqci6Qpnra1PNK40h9hsWE1hc6G1x5ZPC695Q4w+8XCmSkGAurL X-Received: from dygu17.prod.google.com ([2002:a05:7300:5411:b0:2a4:85c9:5e08]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:3943:b0:2a4:3592:cf77 with SMTP id 5a478bee46e88-2a941894852mr19882346eec.27.1764622548105; Mon, 01 Dec 2025 12:55:48 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:07 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-9-irogers@google.com> Subject: [PATCH v2 08/10] perf symbol: Make a common 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 , 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" The libelf version of sysfs__read_build_id would read through the file, the symbol-minimal version would read the whole file and then use regular build-id parsing. Given we prefer the libelf code, make both implementations use the libelf implementation and not require reading the whole file. As the libelf implementation uses libelf structs, move the code to symbol-minimal and use the style/implementation that exists there already in the in memory read_build_id code. Note, this means we could avoid reading phdrs where read_build_id is used and switch to read_build_id_fd to potentially avoid some memory allocation. Clean up how bf was being used as it bound checked bf when a build ID note was found but not when the name wasn't "GNU". Switch to just lseek-ing forward the file to avoid any buffer overrun problems and unnecessary reading. Reduce scope of NOTE_ALIGN macro in perf-libelf.h. Signed-off-by: Ian Rogers --- tools/perf/util/perf-libelf.c | 5 ++ tools/perf/util/perf-libelf.h | 5 -- tools/perf/util/symbol-elf.c | 50 -------------------- tools/perf/util/symbol-minimal.c | 80 +++++++++++++++++++++++--------- tools/perf/util/symbol-minimal.h | 1 + tools/perf/util/symbol.c | 6 +++ 6 files changed, 69 insertions(+), 78 deletions(-) diff --git a/tools/perf/util/perf-libelf.c b/tools/perf/util/perf-libelf.c index a8a8c39056da..4198f4dfad9f 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) { diff --git a/tools/perf/util/perf-libelf.h b/tools/perf/util/perf-libelf.h index 167679f9fc9b..2118325c04e5 100644 --- a/tools/perf/util/perf-libelf.h +++ b/tools/perf/util/perf-libelf.h @@ -21,11 +21,6 @@ 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 diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 9ceb746b6c59..cb890de31044 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 445307f230af..0e3a27dae9d6 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -77,6 +77,58 @@ static int read_build_id(void *note_data, size_t note_le= n, struct build_id *bid, return -1; } =20 +static int read_build_id_fd(int fd, struct build_id *bid, bool need_swap) +{ + size_t size =3D sizeof(bid->data); + struct { + u32 n_namesz; + u32 n_descsz; + u32 n_type; + } nhdr; + + while (true) { + size_t namesz, descsz, n; + ssize_t err; + + err =3D read(fd, &nhdr, sizeof(nhdr)); + if (err !=3D sizeof(nhdr)) + return err =3D=3D -1 ? -errno : -EIO; + + if (need_swap) { + nhdr.n_namesz =3D bswap_32(nhdr.n_namesz); + nhdr.n_descsz =3D bswap_32(nhdr.n_descsz); + nhdr.n_type =3D bswap_32(nhdr.n_type); + } + namesz =3D NOTE_ALIGN(nhdr.n_namesz); + descsz =3D NOTE_ALIGN(nhdr.n_descsz); + n =3D namesz + descsz; /* Remaining bytes of this note. */ + + if (nhdr.n_type =3D=3D NT_GNU_BUILD_ID && nhdr.n_namesz =3D=3D sizeof("G= NU")) { + char name[NOTE_ALIGN(sizeof("GNU"))]; + + err =3D read(fd, name, sizeof(name)); + if (err !=3D sizeof(name)) + return err =3D=3D -1 ? -errno : -EIO; + + n =3D descsz; + if (memcmp(name, "GNU", sizeof("GNU")) =3D=3D 0) { + /* Successfully found build ID. */ + ssize_t sz =3D min(descsz, size); + + err =3D read(fd, bid->data, sz); + if (err !=3D sz) + return err =3D=3D -1 ? -errno : -EIO; + + memset(bid->data + sz, 0, size - sz); + bid->size =3D sz; + return 0; + } + } + if (lseek(fd, n, SEEK_CUR) =3D=3D -1) + return -errno; + } +} + /* * Just try PT_NOTE header otherwise fails */ @@ -194,38 +246,20 @@ int sym_min__read_build_id(int _fd, const char *filen= ame, 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; - struct stat stbuf; - size_t buf_size; - void *buf; + int fd, ret; =20 fd =3D open(filename, O_RDONLY); if (fd < 0) - return -1; - - if (fstat(fd, &stbuf) < 0) - goto out; - - buf_size =3D stbuf.st_size; - buf =3D malloc(buf_size); - if (buf =3D=3D NULL) - goto out; - - if (read(fd, buf, buf_size) !=3D (ssize_t) buf_size) - goto out_free; + return -errno; =20 - ret =3D read_build_id(buf, buf_size, bid, false); -out_free: - free(buf); -out: + ret =3D read_build_id_fd(fd, bid, /*need_swap=3D*/false); close(fd); 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 da75a1c159f2..76dc5b70350a 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -2050,6 +2050,12 @@ int filename__read_build_id(const char *filename, st= ruct build_id *bid) return err; } =20 +int sysfs__read_build_id(const char *filename, struct build_id *bid) +{ + /* Doesn't mmap file into memory. */ + 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.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 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 D496928489E for ; Mon, 1 Dec 2025 20:55:50 +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=1764622552; cv=none; b=ubqlCDDIQv5QUzhRqgXjKPw0xvR9UNGF+Rtr/Au2Z2tXqMj4g+E2kqF+G85UFaYjC96qHYkohlgSO07Ibkv1OKQknVQkEEJK2XxrqtfkOxxjf/+9+PciS4hAgKNACmhAhfMpKaQFsWzVWXqLTIn1TPnuoK0dP2dW6tbSB3C6I+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622552; c=relaxed/simple; bh=jrlJM+/Xgy1nehgeiFknXjuulHnnAtIGNxHD7/IQYEo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=jST4Fh2MHJIAuQLH2JL0alXTPWWVDLkXqWH0KBBW6TL+oV7Ow3cgXYV1/NbZKE5djNNer8O3td/3I4/dkIcpeADPn+9OgnbNDaQ2938EEthVDBt0S3kyYvO/iFfOPibKjgmQKTF8Bowibwpf76aelYzf6y7ObFPLNiTWq6HbmjU= 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=Ev/qTNbN; 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="Ev/qTNbN" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b99d6bd6cc9so7672481a12.1 for ; Mon, 01 Dec 2025 12:55:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622550; x=1765227350; 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=cKo8U+r87/wZow77a+6w5wG9mxBjXhr2B97riOby7IM=; b=Ev/qTNbNmqOZiIL74zrSySwFegdLycWrZ5jj7mvEhMa2A7+GGZrbRJ2QIU+MxX08qr n4J9AvvhQdnICpsWdZtFNtp8SRc3510lhUISDFKZTa69w+64MOaauXkpceAkHHZtnUJZ R1/d2aYOIkSQFaFdkpaAW2rn4v6ap/xIzeemSspJ7jTjEJxagtt8lhZZZvhODXMYhgTU 6G8ss8dKQvEq3ptJRsvsP4eZk4vE/1UqTLB4jxQaD57IWI4/T2O9cq783/sE4a9wFCB6 Nr3pyxhUWtSeSIdvHx9BSgurKG3rTrKZOTdg/56tkTD3/j6tFVZeV7iQGj5JQnE3fnO4 czNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622550; x=1765227350; 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=cKo8U+r87/wZow77a+6w5wG9mxBjXhr2B97riOby7IM=; b=HKZFKGZ3zlX/lGqzfK8FvEwZkXqmrSxp3mDwSrAryy8x0RLkBBe5/VSNIlV0O77lvx nrfXQY5JfjbathZeUMAWrPbH6o3GpCqt/rKKTEnOqARrfw2hKkBouKmYR0tG1fSlhwOe kxoSAkwH2S7U2ajvlyqz981SWXPfcBjLCKkLO87B9N28fYVIoG+NgntLb2SgS+Z1mc3f DzhmK6VwhRxktCL+fRR6E97ON0KbNtfkV2fgGoNnLGtqNZryrXl5xnQAHZQXM0a9SEMN lDExSRjvxvjzdSDahbw4ny5nDmyPOjnpWNXw598k8zAVDKIG6iS70HaI0upyHTAYIl4V EtTw== X-Forwarded-Encrypted: i=1; AJvYcCUZsiXTlOivZBUqnrbuhA47Fa0tSZVH+hSNixxaVPqSQyKumQAqmmAl8xIBp7/kj/A9SJxf4Ny+kr60fA0=@vger.kernel.org X-Gm-Message-State: AOJu0YwnRcQyJiXeyfpT+cm6ioCDxoSI7dizYYyjaEo4u39wmFoybtVT nLEfqXHJDZLXYcXrf7OIcIdm2YkVwp3tJ/s/y5ontp5/RljKna14pohuQSbbgYV6+7uWie6y1ke JIuQ/IKVZ0w== X-Google-Smtp-Source: AGHT+IFwfbvxrTUV97nEqe//dS4hmDl4mUXXnvNvY1GF2WwfaNj5WQeqU7NF6PKqtn2upo6UO60uM+9Q7iaX X-Received: from dybuh25.prod.google.com ([2002:a05:7301:7519:b0:2a4:664f:e91d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:550d:b0:2a4:3594:d552 with SMTP id 5a478bee46e88-2a719f9d8d6mr19884768eec.31.1764622549762; Mon, 01 Dec 2025 12:55:49 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:08 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-10-irogers@google.com> Subject: [PATCH v2 09/10] 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 , 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 4198f4dfad9f..eed5c0317f8b 100644 --- a/tools/perf/util/perf-libelf.c +++ b/tools/perf/util/perf-libelf.c @@ -200,3 +200,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 2118325c04e5..5ca5641b9dc9 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 @@ -28,6 +30,7 @@ int __libelf__read_build_id(Elf *elf, void *bf, size_t si= ze); =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); +enum dso_type libelf_dso__type_fd(int fd); =20 #else // !defined(HAVE_LIBELF_SUPPORT) =20 @@ -45,6 +48,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 cb890de31044..f483aa67f69b 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 0e3a27dae9d6..f9724448fb64 100644 --- a/tools/perf/util/symbol-minimal.c +++ b/tools/perf/util/symbol-minimal.c @@ -259,6 +259,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) @@ -305,44 +343,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 e265e1f028be..4cc557981724 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); int sysfs__read_build_id(const char *filename, struct build_id *bid); int modules__parse(const char *filename, void *arg, --=20 2.52.0.158.g65b55ccf14-goog From nobody Tue Dec 2 00:46:05 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 675A9284880 for ; Mon, 1 Dec 2025 20:55:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622554; cv=none; b=jTT6Si1y19nlSfzTn8fasTp37wbo+yAQnvjbmJ6QKn/d2qDanwDc+ozxnPP7p3Q0zKfvC7+2pLrvI2b7l/JuG7Q//eFniLqVnVxqOs5ZWVJx5h9BJYaoCf9QBKJWu3AQrwmqq1S1+uKj4OsIP4BXgy2f7EskauriEZGL6PZx9Dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764622554; c=relaxed/simple; bh=Ok/xo7eYhBLF4aYLIQP94dASAk5ZaAh8Axv9S/Q7Ark=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Z75kY5prXJptmATY2YUg7VglSlECPco05LGQ33m4HUlCOLEXMv2fD4SE3glh9gT+XRVhw8fvQVtMgeLS1yd9rLu2REyh0Gk4b7MAlANgDa9XzMNcx01Gm3ORxABQCCI+ZjqO7OX04mWZxxNiXqFCKKEUw1rX1ibgi8H0iOkFIfY= 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=SphHWViA; arc=none smtp.client-ip=209.85.214.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="SphHWViA" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2980ef53fc5so105819655ad.1 for ; Mon, 01 Dec 2025 12:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764622551; x=1765227351; 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=5hsbicSz/UZUD8nTk2GV2IFD5/kDi3KGaf2M5SRJ974=; b=SphHWViASlv0bFpGMsuooA4tsc+UHRmd/p/6eLd77O0rdZAJqr6QgiHYenFNy5GJe5 4ls5RmyMM7lS51rEGpZ34kmMnRBbozSa/eQNZceJuypzf7FAJy8oPFFkK/sX4SoAjqIm 6llwMtUcpThtiH72uBmBT7LQir+jCK3Yxf67OINX+3GDCPuw2l7+4OVLO6U6lk44eO0k 45qM+NmR4IXMUJHMGRGA2inElQ4ENTYvTa8WWhj+kVNqqr3NNNCpf8HlahUHtXNTGS07 w0Qj8BjRY/G+J1joh773rv2gFB1C4ewJn310hEKM+5FMrXPAXe1WGUkeTKdHz4VyppIv eQdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764622551; x=1765227351; 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=5hsbicSz/UZUD8nTk2GV2IFD5/kDi3KGaf2M5SRJ974=; b=w7AYbjgLzTIgZm+8PbhKiMcqfYX/rTQNUUl0d4Eg/rqC1w0BZSsbZsd3vjdR83/1n5 dTtaAwvnCrRxWXUTEulWNh8k2zcn0qhq77uB/kIG5st2g694XslDdd8pZqsOLCcTtDWd IcNOQ5cv0X8nmHVeSDbTE/wj/uhUeDq9ywObRPcRxWLcX0T6INC2HD3sbkl0cXKbMNbW iMLVOlkZRjTz9Zp5o0oTkCSYseDp9QRnI7mQhKV1xHcD3sVnkDm1UK8Qlb3SsONsCbMz MZmvVcl0f+tVqavlNxQDeXdWpACHfczhB8TCwaovaWDKFDeZByBLNgKnYzVevkqiU/yB ZrNw== X-Forwarded-Encrypted: i=1; AJvYcCXPC/WbqcMhAS57ctGsZ8P8DCH/cSAcxHFhrNbppTK5vVX6i69oTiPDqfkeBRhkH/bHvx816j4nypAcPNs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy99t8gptpuECiebIqimQdbOtkotyBq+XO1yBR3fAuhgwdOuUpJ KBuqr9IKSpRQYKOLw1J8mKdD7zbg0AjEYMnYHCuAzDMV2/A/e3MF1erHBMzfrGHAmYZsAJosMNd wdI3qH7xAfQ== X-Google-Smtp-Source: AGHT+IHx1ya3ZH1MrXnmPeWa+EXedBYXHbjkOhwpTt6Nn3WfS/q8PIEYjleWe0E0pr+lonU84zZsQJ7Haz0+ X-Received: from dlak23.prod.google.com ([2002:a05:701b:2917:b0:119:49ca:6b90]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:24a2:b0:119:e569:f611 with SMTP id a92af1059eb24-11c9d60e253mr27718362c88.10.1764622551457; Mon, 01 Dec 2025 12:55:51 -0800 (PST) Date: Mon, 1 Dec 2025 12:55:09 -0800 In-Reply-To: <20251201205509.195451-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: <20251201205509.195451-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.158.g65b55ccf14-goog Message-ID: <20251201205509.195451-11-irogers@google.com> Subject: [PATCH v2 10/10] perf symbol: Fix ENOENT case for 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 , 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" Some callers of filename__read_build_id assume the error value must be -1, fix by making them handle all < 0 values. If is_regular_file fails in filename__read_build_id then it could be the file is missing (ENOENT) and it would be wrong to return -EWOULDBLOCK in that case. Fix the logic so -EWOULDBLOCK is only reported if other errors with stat haven't occurred. Fixes: 834ebb5678d7 ("perf tools: Don't read build-ids from non-regular fil= es") Signed-off-by: Ian Rogers --- tools/perf/builtin-buildid-cache.c | 6 ++++-- tools/perf/util/symbol.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildi= d-cache.c index c98104481c8a..539e779e3268 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -276,12 +276,14 @@ static bool dso__missing_buildid_cache(struct dso *ds= o, int parm __maybe_unused) { char filename[PATH_MAX]; struct build_id bid =3D { .size =3D 0, }; + int err; =20 if (!dso__build_id_filename(dso, filename, sizeof(filename), false)) return true; =20 - if (filename__read_build_id(filename, &bid) =3D=3D -1) { - if (errno =3D=3D ENOENT) + err =3D filename__read_build_id(filename, &bid); + if (err < 0) { + if (err =3D=3D -ENOENT) return false; =20 pr_warning("Problems with %s file, consider removing it from the cache\n= ", diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 76dc5b70350a..f43e30019e21 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -2008,8 +2008,9 @@ int filename__read_build_id(const char *filename, str= uct build_id *bid) if (!filename) return -EFAULT; =20 + errno =3D 0; if (!is_regular_file(filename)) - return -EWOULDBLOCK; + return errno =3D=3D 0 ? -EWOULDBLOCK : -errno; =20 err =3D kmod_path__parse(&m, filename); if (err) --=20 2.52.0.158.g65b55ccf14-goog