From mboxrd@z Thu Jan 1 00:00:00 1970 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 C9D2D246788 for ; Mon, 29 Sep 2025 19:08:28 +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=1759172910; cv=none; b=G7tlP8C5b1hUoklwSCt2fztaD8lo0ThCmJcOG9AWx36qhg7qqJvYNiEBkfue2HoHe8w0k5aPaBhN6Kl0PPCDsHUscwy7ZLlDkA3Jv3niwqzIOAbbrPWPUEzThua0fZdpsA/DxIWoR5NKeLDwWDZ4SUxsFYBlxxfPE5yw7/oM9DE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759172910; c=relaxed/simple; bh=jts437rB1GIJacBrxxx4epa/L3BnkDASSEk1qV6a9yg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=kUfYoTPeI4LmxvKyCLNzqnEz9FZwcv8In1zhOzbTDoCfPdPmko9FDP7c3Wabg9PJyrWByNxadB2qZmE/JXOcOdOLvEPBjfBq4Lc6fLNUQ1dgE46KYnTV/4P9RTppncT0iksK4US3RbnM2HVO/YhOZH7kvUGdJHnWQQZfoSFQMk4= 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=s3M4Ftag; 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="s3M4Ftag" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2699ebc0319so50679655ad.3 for ; Mon, 29 Sep 2025 12:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1759172908; x=1759777708; darn=lists.linux.dev; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=cCPSZa95CLjIX1ekaMXSBPwEqC8hhuYwGZNsoeQYOdI=; b=s3M4Ftagi23ofpN7F7mYpXuo8N1hxBT+ajV2nySp9RJLawIzYsPfbx/5NkOZcSUOG6 Lp9BBXe50QtcJTpNSWlHUQD6KeUS1NEPiY9BS2sB9Qk2IONO4YvqMgSJovHavGyTpOi0 Jy24OTbuH82I6H2UTmtOrIuJWVAs578Yy/N++DEyA9v8UCk7c5iKj3qlY+YHjXumJXVw RLNwpVIJTk12gviu3qQRF4Ou/cqhR314jzTXsnuQl9xeWld9BWPzVCkhVr/md8AwoV51 R10D2MToILib7iiphNHFNjlJ8a5kq2McaHIAe4s4c15owVbROEP3Ybda3z9T4dDRE9wO xj5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759172908; x=1759777708; 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=cCPSZa95CLjIX1ekaMXSBPwEqC8hhuYwGZNsoeQYOdI=; b=spmYerGP8By3fG//CqwoLWB8sh7Uk1voWySUXayY7yqjU5e92xngKf9WGZ8Q57KBfd Vl5ang174W6Ni5kDNZm3Cc+vGQA9Qr7HaJHY8a0SXvs5KAjB0gXk2IcgVHHLTkn+j7sv LfDmTgB5oozjQOkJ38GDRf2saZ5rUAN2bJTZgNB3kGNvnPDHQPcn7PAQZ8VTvXWu9qPY 0fpgazdCgkg2pkkBCHXh7chKt02xSul9kGAEinMOHrj5GZW5FP/JIhwRoQc73ib1DupL vQuzirrYP9OO9zepo+v1K7uw5RQIfJ7CWOsFN0q1COP1VaDHkpOyAcBfzMI4FvXK3cVe y75Q== X-Forwarded-Encrypted: i=1; AJvYcCXwPvCfLZ9XG+eEYXmZDjkvikr3NZJ6X7ZDzTdnxU9hEkO17iHmaBsURU+3b1nC/gEz/pmM@lists.linux.dev X-Gm-Message-State: AOJu0Ywa8XAGlCLawRlyoCZfwizux77Nf304QihGxaZOuVJMVNZhC7Uk NNWP/Gx/U8OxmUDHMFCtpEfkQXisxjTjaMyOxtYHyuTdE9/GMdzdWFjzlTUJKiGfnxZy2FD9kkL IGQTRdmydNQ== X-Google-Smtp-Source: AGHT+IHRqf99uJlVCyIDD61PqSw9guLbG8f2axDFVLPxmfvJQ46Ggtr9CTWOji6+cSZrHK7d8OcAI0/g0sj4 X-Received: from pjbfh12.prod.google.com ([2002:a17:90b:34c:b0:32f:46d:993b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ecca:b0:269:8d16:42d1 with SMTP id d9443c01a7336-27ed4aac32cmr171706855ad.50.1759172908198; Mon, 29 Sep 2025 12:08:28 -0700 (PDT) Date: Mon, 29 Sep 2025 12:07:51 -0700 In-Reply-To: <20250929190805.201446-1-irogers@google.com> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250929190805.201446-1-irogers@google.com> X-Mailer: git-send-email 2.51.0.570.gb178f27e6d-goog Message-ID: <20250929190805.201446-2-irogers@google.com> Subject: [PATCH v6 01/15] perf map: Constify objdump offset/address conversion APIs From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Charlie Jenkins , Eric Biggers , "Masami Hiramatsu (Google)" , James Clark , Collin Funk , "Dr. David Alan Gilbert" , Li Huafei , Athira Rajeev , Stephen Brennan , Dmitry Vyukov , Alexandre Ghiti , Haibo Xu , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev, Song Liu Content-Type: text/plain; charset="UTF-8" Make the map argument const as the conversion act won't modify the map and this allows other callers to use a const struct map. Signed-off-by: Ian Rogers --- tools/perf/util/map.c | 19 +++++++++++++++---- tools/perf/util/map.h | 6 +++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index b46c68c24d1c..41cdddc987ee 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -513,6 +513,8 @@ void srccode_state_free(struct srccode_state *state) state->line = 0; } +static const struct kmap *__map__const_kmap(const struct map *map); + /** * map__rip_2objdump - convert symbol start address to objdump address. * @map: memory map @@ -524,9 +526,9 @@ void srccode_state_free(struct srccode_state *state) * * Return: Address suitable for passing to "objdump --start-address=" */ -u64 map__rip_2objdump(struct map *map, u64 rip) +u64 map__rip_2objdump(const struct map *map, u64 rip) { - struct kmap *kmap = __map__kmap(map); + const struct kmap *kmap = __map__const_kmap(map); const struct dso *dso = map__dso(map); /* @@ -569,7 +571,7 @@ u64 map__rip_2objdump(struct map *map, u64 rip) * * Return: Memory address. */ -u64 map__objdump_2mem(struct map *map, u64 ip) +u64 map__objdump_2mem(const struct map *map, u64 ip) { const struct dso *dso = map__dso(map); @@ -586,7 +588,7 @@ u64 map__objdump_2mem(struct map *map, u64 ip) } /* convert objdump address to relative address. (To be removed) */ -u64 map__objdump_2rip(struct map *map, u64 ip) +u64 map__objdump_2rip(const struct map *map, u64 ip) { const struct dso *dso = map__dso(map); @@ -618,6 +620,15 @@ struct kmap *__map__kmap(struct map *map) return (struct kmap *)(&RC_CHK_ACCESS(map)[1]); } +static const struct kmap *__map__const_kmap(const struct map *map) +{ + const struct dso *dso = map__dso(map); + + if (!dso || !dso__kernel(dso)) + return NULL; + return (struct kmap *)(&RC_CHK_ACCESS(map)[1]); +} + struct kmap *map__kmap(struct map *map) { struct kmap *kmap = __map__kmap(map); diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 9cadf533a561..979b3e11b9bc 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -133,13 +133,13 @@ static inline u64 map__unmap_ip(const struct map *map, u64 ip_or_rip) } /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */ -u64 map__rip_2objdump(struct map *map, u64 rip); +u64 map__rip_2objdump(const struct map *map, u64 rip); /* objdump address -> memory address */ -u64 map__objdump_2mem(struct map *map, u64 ip); +u64 map__objdump_2mem(const struct map *map, u64 ip); /* objdump address -> rip */ -u64 map__objdump_2rip(struct map *map, u64 ip); +u64 map__objdump_2rip(const struct map *map, u64 ip); struct symbol; struct thread; -- 2.51.0.570.gb178f27e6d-goog