Commit c0b8a55a authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf map: Constify objdump offset/address conversion APIs



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: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.ibm.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Charlie Jenkins <charlie@rivosinc.com>
Cc: Collin Funk <collin.funk1@gmail.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: Eric Biggers <ebiggers@kernel.org>
Cc: Haibo Xu <haibo1.xu@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Li Huafei <lihuafei1@huawei.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <song@kernel.org>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent cbeb3d47
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -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);
+3 −3
Original line number Diff line number Diff line
@@ -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;