Message ID | 20240202220459.527138-5-namhyung@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp723904dyc; Fri, 2 Feb 2024 14:06:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8So8M8id+zdltAraZkJvZgj4qNgFQTIbs77OZrxcqD4BTi/wt0QSBnInG0jtwPIwKzb3q X-Received: by 2002:a17:90a:c684:b0:28e:20d5:a047 with SMTP id n4-20020a17090ac68400b0028e20d5a047mr6689470pjt.27.1706911603117; Fri, 02 Feb 2024 14:06:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706911603; cv=pass; d=google.com; s=arc-20160816; b=ypdJy50MkAiX3ZNHjQHeg3DBqLscy8CswGzsjsQ2LA+xmz7VaURrfVPSidrtY3QTvM TolAXyc3O2pE9uvqbn0HlTCs86BbpiqSimZG9FkJlcNoc+Tg4kDN80X/KW+2PeFGlRzs 2f+JA7Iq1zdWIL0Y4z+qcSOgldDrJd2s7/LpdcZTFfDUe+ezCeROIJzOy6JbrTFJDOl3 k4LMdE30F5rTXRIon/OHhV1dEeIBmA+UcYXeXfsHlEv78oP5RLRVUieGAyOr8q40Twv+ Xp48nmoTWzSXsvoFO/rASx2IJ0J7ITKS68mS1aomvoRrPWkyT34LMJ7gXefqZmREHDi7 2nuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vOc2Z8JyMWK1Cos1JZ+vw5yBKHBtj+bfr6QqbvgGh24=; fh=hciVlrIpZng8ZH56LuNKBzZCwMRhTxchalCyg/wl3HA=; b=T7xYqTzCdg6VEv4fMFwZWuGwAbkZ+a9TwEVHydFhfNDW8qs8zn4HrUZAp//gQ+dy7+ PDYm2r6XQYQhx7Qhsr4AIIzU9Gf+YrqoO4CQUbffHaQ5ccjuPIe5knxkAEQiQ3fm1qF3 +q/YO3yr/Bmp44bb/2zULx0IoxxqKRfH5cgK5iUkhj5FhrQDdXqHi5uiyzk1S5YPZf9Z klHSHvw1oIE4jruiD+H84yaZI1V54vOEvMSLUYElKtTv3DJMFu9NG09FZLpSOMsX8gcN CAys0XCnpk/BgiZr+VbtQ+Snb7LrwWsAGqRo+iDnz3D0JJXTXBDlUmi2LtEP9NARVWAP 93Iw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m77Rje8K; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUwLp48F2Z/9X/b7D317TEJEpmxw1OXmaCyy97p2A7axlzcDda55og94NffrbJvOLUADnvqfvgIEMgxvVxKfGypPyygtQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id mh4-20020a17090b4ac400b00296563fbb75si547016pjb.95.2024.02.02.14.06.42 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 14:06:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m77Rje8K; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DB2EA28AFDF for <ouuuleilei@gmail.com>; Fri, 2 Feb 2024 22:06:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51A9612D76C; Fri, 2 Feb 2024 22:05:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m77Rje8K" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EE19126F05; Fri, 2 Feb 2024 22:05:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706911504; cv=none; b=AEf1MDc50sIOPZOTXzmW/z3RoCEw+3QUJ8XkRoc9RSe8od5lyjc2rBYHFjbWJyjeW57GiFa/Qm8w40VmS0nPYmRicyH/KXVRAJbWWLAG6LNyGPCHtKJ8IkS48RjGXlO8PgpLyXDAiSaGnTehnslUAzyi3AHiy0SA5+wFUqESUww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706911504; c=relaxed/simple; bh=ksRwB6y7Bf3D1VViK194iwXHp5tebaWmPZdpxqK0sY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TnA+i7v3d3liwQtiQbnX2FuNxv3XX+hkxS+AorjE3vfrYxZfFHW614gjn+rw2D7ntfVaHMEOP5QcfjbGVuz2jB9MTV+WsDXUEjwzNc5nUOHadzcA1/rSOS8KWE0HyHb29DsCQsL6RXYibpSXv9yFTLJGLTE5ORCORC41xrwTEzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m77Rje8K; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B86C7C43142; Fri, 2 Feb 2024 22:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706911504; bh=ksRwB6y7Bf3D1VViK194iwXHp5tebaWmPZdpxqK0sY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m77Rje8KR9qi8D7/IwR6G3a4rHlf/J2LNxrkGo9chaQfeUpCtzwJCtvn2yEtaELOR bPS5LmLOZlDx3zlMgBjlypofa0Av7AgggOIMMEYWCI9fEsu7vSpl2r8xY3zcohzotp Jwir98s5VsJsH9Y5CbUem2Ye+RenIHOZDeK+HevXhlTta9PchwxswwTv/w1RAXO4eX QPb0eL+G+aoJ6wQ5xEADdI3PXuLlIn77WFMMCqqgoB1txsrQ3/i+qa4LwzVnV9qzPw jxLWHtmv0kU2eQnID/E4vs9JnoJ1QnmzjGIgA3giByztmpgvXLS46P1QrZGYS3JgND Y9jq+KcezyAmQ== From: Namhyung Kim <namhyung@kernel.org> To: Arnaldo Carvalho de Melo <acme@kernel.org>, Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@kernel.org>, Adrian Hunter <adrian.hunter@intel.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>, LKML <linux-kernel@vger.kernel.org>, linux-perf-users@vger.kernel.org, Linus Torvalds <torvalds@linux-foundation.org>, Stephane Eranian <eranian@google.com>, Masami Hiramatsu <mhiramat@kernel.org>, linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 04/14] perf map: Add map__objdump_2rip() Date: Fri, 2 Feb 2024 14:04:49 -0800 Message-ID: <20240202220459.527138-5-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202220459.527138-1-namhyung@kernel.org> References: <20240202220459.527138-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789826540855746179 X-GMAIL-MSGID: 1789826540855746179 |
Series |
perf tools: Remaining bits of data type profiling (v5)
|
|
Commit Message
Namhyung Kim
Feb. 2, 2024, 10:04 p.m. UTC
Sometimes we want to convert an address in objdump output to
map-relative address to match with a sample data. Let's add
map__objdump_2rip() for that.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/map.c | 20 ++++++++++++++++++++
tools/perf/util/map.h | 3 +++
2 files changed, 23 insertions(+)
Comments
On Fri, Feb 2, 2024 at 2:05 PM Namhyung Kim <namhyung@kernel.org> wrote: > > Sometimes we want to convert an address in objdump output to > map-relative address to match with a sample data. Let's add > map__objdump_2rip() for that. Hi Namhyung, I think the naming can be better here. Aren't the objdump addresses DSO relative offsets? Is the relative IP relative to the map or the DSO? Thanks, Ian > Cc: Adrian Hunter <adrian.hunter@intel.com> > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > --- > tools/perf/util/map.c | 20 ++++++++++++++++++++ > tools/perf/util/map.h | 3 +++ > 2 files changed, 23 insertions(+) > > diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c > index 54c67cb7ecef..66542864b7b5 100644 > --- a/tools/perf/util/map.c > +++ b/tools/perf/util/map.c > @@ -594,6 +594,26 @@ u64 map__objdump_2mem(struct map *map, u64 ip) > return ip + map__reloc(map); > } > > +u64 map__objdump_2rip(struct map *map, u64 ip) > +{ > + const struct dso *dso = map__dso(map); > + > + if (!dso->adjust_symbols) > + return ip; > + > + if (dso->rel) > + return ip + map__pgoff(map); > + > + /* > + * kernel modules also have DSO_TYPE_USER in dso->kernel, > + * but all kernel modules are ET_REL, so won't get here. > + */ > + if (dso->kernel == DSO_SPACE__USER) > + return ip - dso->text_offset; > + > + return map__map_ip(map, ip + map__reloc(map)); > +} > + > bool map__contains_symbol(const struct map *map, const struct symbol *sym) > { > u64 ip = map__unmap_ip(map, sym->start); > diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h > index 49756716cb13..65e2609fa1b1 100644 > --- a/tools/perf/util/map.h > +++ b/tools/perf/util/map.h > @@ -132,6 +132,9 @@ u64 map__rip_2objdump(struct map *map, u64 rip); > /* objdump address -> memory address */ > u64 map__objdump_2mem(struct map *map, u64 ip); > > +/* objdump address -> rip */ > +u64 map__objdump_2rip(struct map *map, u64 ip); > + > struct symbol; > struct thread; > > -- > 2.43.0.594.gd9cf4e227d-goog >
Hi Ian, On Fri, Feb 2, 2024 at 5:42 PM Ian Rogers <irogers@google.com> wrote: > > On Fri, Feb 2, 2024 at 2:05 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > Sometimes we want to convert an address in objdump output to > > map-relative address to match with a sample data. Let's add > > map__objdump_2rip() for that. > > Hi Namhyung, > > I think the naming can be better here. Aren't the objdump addresses > DSO relative offsets? Is the relative IP relative to the map or the > DSO? AFAIK the objdump addresses are DSO-relative and rip is to map. They are mostly the same but sometimes different due to kASLR for the kernel. > > > Cc: Adrian Hunter <adrian.hunter@intel.com> > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > --- > > tools/perf/util/map.c | 20 ++++++++++++++++++++ > > tools/perf/util/map.h | 3 +++ > > 2 files changed, 23 insertions(+) > > > > diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c > > index 54c67cb7ecef..66542864b7b5 100644 > > --- a/tools/perf/util/map.c > > +++ b/tools/perf/util/map.c > > @@ -594,6 +594,26 @@ u64 map__objdump_2mem(struct map *map, u64 ip) > > return ip + map__reloc(map); > > } > > > > +u64 map__objdump_2rip(struct map *map, u64 ip) > > +{ > > + const struct dso *dso = map__dso(map); > > + > > + if (!dso->adjust_symbols) > > + return ip; > > + > > + if (dso->rel) > > + return ip + map__pgoff(map); > > + > > + /* > > + * kernel modules also have DSO_TYPE_USER in dso->kernel, > > + * but all kernel modules are ET_REL, so won't get here. > > + */ Hmm.. This comment is not true anymore. Will remove in other places too. Thanks, Namhyung > > + if (dso->kernel == DSO_SPACE__USER) > > + return ip - dso->text_offset; > > + > > + return map__map_ip(map, ip + map__reloc(map)); > > +} > > + > > bool map__contains_symbol(const struct map *map, const struct symbol *sym) > > { > > u64 ip = map__unmap_ip(map, sym->start); > > diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h > > index 49756716cb13..65e2609fa1b1 100644 > > --- a/tools/perf/util/map.h > > +++ b/tools/perf/util/map.h > > @@ -132,6 +132,9 @@ u64 map__rip_2objdump(struct map *map, u64 rip); > > /* objdump address -> memory address */ > > u64 map__objdump_2mem(struct map *map, u64 ip); > > > > +/* objdump address -> rip */ > > +u64 map__objdump_2rip(struct map *map, u64 ip); > > + > > struct symbol; > > struct thread; > > > > -- > > 2.43.0.594.gd9cf4e227d-goog > >
On Tue, Feb 6, 2024 at 3:04 PM Namhyung Kim <namhyung@kernel.org> wrote: > > Hi Ian, > > On Fri, Feb 2, 2024 at 5:42 PM Ian Rogers <irogers@google.com> wrote: > > > > On Fri, Feb 2, 2024 at 2:05 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > Sometimes we want to convert an address in objdump output to > > > map-relative address to match with a sample data. Let's add > > > map__objdump_2rip() for that. > > > > Hi Namhyung, > > > > I think the naming can be better here. Aren't the objdump addresses > > DSO relative offsets? Is the relative IP relative to the map or the > > DSO? > > AFAIK the objdump addresses are DSO-relative and rip is to map. > They are mostly the same but sometimes different due to kASLR > for the kernel. Perhaps we need to use names like map_rip for mapping relative and dso_rip to clean this up, or to add a different mapping_type to the enum. For non-kernel maps addresses for map are either the whole virtual address space (identity) or relative to a dso: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/map.h?h=perf-tools-next#n115 https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/map.h?h=perf-tools-next#n20 The dso addresses should work for objdump so perhaps the kernel addresses need map__pgoff fixing? Thanks, Ian > > > > > Cc: Adrian Hunter <adrian.hunter@intel.com> > > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > > --- > > > tools/perf/util/map.c | 20 ++++++++++++++++++++ > > > tools/perf/util/map.h | 3 +++ > > > 2 files changed, 23 insertions(+) > > > > > > diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c > > > index 54c67cb7ecef..66542864b7b5 100644 > > > --- a/tools/perf/util/map.c > > > +++ b/tools/perf/util/map.c > > > @@ -594,6 +594,26 @@ u64 map__objdump_2mem(struct map *map, u64 ip) > > > return ip + map__reloc(map); > > > } > > > > > > +u64 map__objdump_2rip(struct map *map, u64 ip) > > > +{ > > > + const struct dso *dso = map__dso(map); > > > + > > > + if (!dso->adjust_symbols) > > > + return ip; > > > + > > > + if (dso->rel) > > > + return ip + map__pgoff(map); > > > + > > > + /* > > > + * kernel modules also have DSO_TYPE_USER in dso->kernel, > > > + * but all kernel modules are ET_REL, so won't get here. > > > + */ > > Hmm.. This comment is not true anymore. Will remove > in other places too. > > Thanks, > Namhyung > > > > > + if (dso->kernel == DSO_SPACE__USER) > > > + return ip - dso->text_offset; > > > + > > > + return map__map_ip(map, ip + map__reloc(map)); > > > +} > > > + > > > bool map__contains_symbol(const struct map *map, const struct symbol *sym) > > > { > > > u64 ip = map__unmap_ip(map, sym->start); > > > diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h > > > index 49756716cb13..65e2609fa1b1 100644 > > > --- a/tools/perf/util/map.h > > > +++ b/tools/perf/util/map.h > > > @@ -132,6 +132,9 @@ u64 map__rip_2objdump(struct map *map, u64 rip); > > > /* objdump address -> memory address */ > > > u64 map__objdump_2mem(struct map *map, u64 ip); > > > > > > +/* objdump address -> rip */ > > > +u64 map__objdump_2rip(struct map *map, u64 ip); > > > + > > > struct symbol; > > > struct thread; > > > > > > -- > > > 2.43.0.594.gd9cf4e227d-goog > > >
On Tue, Feb 6, 2024 at 3:34 PM Ian Rogers <irogers@google.com> wrote: > > On Tue, Feb 6, 2024 at 3:04 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > Hi Ian, > > > > On Fri, Feb 2, 2024 at 5:42 PM Ian Rogers <irogers@google.com> wrote: > > > > > > On Fri, Feb 2, 2024 at 2:05 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > Sometimes we want to convert an address in objdump output to > > > > map-relative address to match with a sample data. Let's add > > > > map__objdump_2rip() for that. > > > > > > Hi Namhyung, > > > > > > I think the naming can be better here. Aren't the objdump addresses > > > DSO relative offsets? Is the relative IP relative to the map or the > > > DSO? > > > > AFAIK the objdump addresses are DSO-relative and rip is to map. > > They are mostly the same but sometimes different due to kASLR > > for the kernel. > > Perhaps we need to use names like map_rip for mapping relative and > dso_rip to clean this up, or to add a different mapping_type to the > enum. For non-kernel maps addresses for map are either the whole > virtual address space (identity) or relative to a dso: > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/map.h?h=perf-tools-next#n115 > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/map.h?h=perf-tools-next#n20 > The dso addresses should work for objdump so perhaps the kernel > addresses need map__pgoff fixing? I'm not sure about the vDSO case. By the way, I need to take a look if we can make this objdump-rip thing simpler as you mentioned. My feeling is that it can be done but I'd like to do it in a separate work and to move this forward. Thanks, Namhyung
On Wed, Feb 7, 2024 at 11:04 AM Namhyung Kim <namhyung@kernel.org> wrote: > > On Tue, Feb 6, 2024 at 3:34 PM Ian Rogers <irogers@google.com> wrote: > > > > On Tue, Feb 6, 2024 at 3:04 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > Hi Ian, > > > > > > On Fri, Feb 2, 2024 at 5:42 PM Ian Rogers <irogers@google.com> wrote: > > > > > > > > On Fri, Feb 2, 2024 at 2:05 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > > > Sometimes we want to convert an address in objdump output to > > > > > map-relative address to match with a sample data. Let's add > > > > > map__objdump_2rip() for that. > > > > > > > > Hi Namhyung, > > > > > > > > I think the naming can be better here. Aren't the objdump addresses > > > > DSO relative offsets? Is the relative IP relative to the map or the > > > > DSO? > > > > > > AFAIK the objdump addresses are DSO-relative and rip is to map. > > > They are mostly the same but sometimes different due to kASLR > > > for the kernel. > > > > Perhaps we need to use names like map_rip for mapping relative and > > dso_rip to clean this up, or to add a different mapping_type to the > > enum. For non-kernel maps addresses for map are either the whole > > virtual address space (identity) or relative to a dso: > > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/map.h?h=perf-tools-next#n115 > > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/map.h?h=perf-tools-next#n20 > > The dso addresses should work for objdump so perhaps the kernel > > addresses need map__pgoff fixing? > > I'm not sure about the vDSO case. > > By the way, I need to take a look if we can make this objdump-rip > thing simpler as you mentioned. My feeling is that it can be done > but I'd like to do it in a separate work and to move this forward. Makes sense. Could we add a comment to the header file definition to capture some of this? Perhaps a "to be removed" to avoid later patches adding dependencies to the function. Thanks, Ian > Thanks, > Namhyung
On Wed, Feb 7, 2024 at 11:56 AM Ian Rogers <irogers@google.com> wrote: > > On Wed, Feb 7, 2024 at 11:04 AM Namhyung Kim <namhyung@kernel.org> wrote: > > > > On Tue, Feb 6, 2024 at 3:34 PM Ian Rogers <irogers@google.com> wrote: > > > > > > On Tue, Feb 6, 2024 at 3:04 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > Hi Ian, > > > > > > > > On Fri, Feb 2, 2024 at 5:42 PM Ian Rogers <irogers@google.com> wrote: > > > > > > > > > > On Fri, Feb 2, 2024 at 2:05 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > > > > > > > > > Sometimes we want to convert an address in objdump output to > > > > > > map-relative address to match with a sample data. Let's add > > > > > > map__objdump_2rip() for that. > > > > > > > > > > Hi Namhyung, > > > > > > > > > > I think the naming can be better here. Aren't the objdump addresses > > > > > DSO relative offsets? Is the relative IP relative to the map or the > > > > > DSO? > > > > > > > > AFAIK the objdump addresses are DSO-relative and rip is to map. > > > > They are mostly the same but sometimes different due to kASLR > > > > for the kernel. > > > > > > Perhaps we need to use names like map_rip for mapping relative and > > > dso_rip to clean this up, or to add a different mapping_type to the > > > enum. For non-kernel maps addresses for map are either the whole > > > virtual address space (identity) or relative to a dso: > > > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/map.h?h=perf-tools-next#n115 > > > https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/map.h?h=perf-tools-next#n20 > > > The dso addresses should work for objdump so perhaps the kernel > > > addresses need map__pgoff fixing? > > > > I'm not sure about the vDSO case. > > > > By the way, I need to take a look if we can make this objdump-rip > > thing simpler as you mentioned. My feeling is that it can be done > > but I'd like to do it in a separate work and to move this forward. > > Makes sense. Could we add a comment to the header file definition to > capture some of this? Perhaps a "to be removed" to avoid later patches > adding dependencies to the function. Sure, will add that in v6. Thanks, Namhyung
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 54c67cb7ecef..66542864b7b5 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -594,6 +594,26 @@ u64 map__objdump_2mem(struct map *map, u64 ip) return ip + map__reloc(map); } +u64 map__objdump_2rip(struct map *map, u64 ip) +{ + const struct dso *dso = map__dso(map); + + if (!dso->adjust_symbols) + return ip; + + if (dso->rel) + return ip + map__pgoff(map); + + /* + * kernel modules also have DSO_TYPE_USER in dso->kernel, + * but all kernel modules are ET_REL, so won't get here. + */ + if (dso->kernel == DSO_SPACE__USER) + return ip - dso->text_offset; + + return map__map_ip(map, ip + map__reloc(map)); +} + bool map__contains_symbol(const struct map *map, const struct symbol *sym) { u64 ip = map__unmap_ip(map, sym->start); diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 49756716cb13..65e2609fa1b1 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -132,6 +132,9 @@ u64 map__rip_2objdump(struct map *map, u64 rip); /* objdump address -> memory address */ u64 map__objdump_2mem(struct map *map, u64 ip); +/* objdump address -> rip */ +u64 map__objdump_2rip(struct map *map, u64 ip); + struct symbol; struct thread;