Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1421176rdb; Fri, 16 Feb 2024 15:55:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWFHmCvpJ7sIY/7VHZsy7NuG3CF7hyJhvPMYF9AsZg02rSDw4MiKQ72O9nvlGKm7NocAGzw5p0Ke73O//v1XQii/TfRdHlF4C7cuLp/cg== X-Google-Smtp-Source: AGHT+IHbir3epzfNeDKI8lDq6chqkk5IZ4obt3xeJPYAnFOJKHTC24cqQgPCqErQGdstgdD5oAUV X-Received: by 2002:a05:620a:7f1:b0:784:b12:ba1c with SMTP id k17-20020a05620a07f100b007840b12ba1cmr6396431qkk.78.1708127735180; Fri, 16 Feb 2024 15:55:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127735; cv=pass; d=google.com; s=arc-20160816; b=C5V6Rc2qN1YggduZciA2x8/UG343F18aPpIvUeyXdgPp+CNJM+Ai5CbLq+ddXopk2y 4pRGvN1MdaA/U3n3ShJrCCSf9O72YNe7OCWCHBZxXcns7bwqp/iETkiKvxLijp3xh31E /Px1R+Ey6cTzjvLsd7tke2sTdEPmex7uPx8fxT2oMORcs0MsbAENcKuecGDuaMoh8+Ve g1+pysxHB5D8gxCVDhmb4Gm37tpLG2MHYaX87d0lS5caZaGKJ9+BrSw+liUFVqwxldf6 KZ88U2fKeFyVeWCKJaw7MO2l+UXcS7b0vV6A+F+DbMXDTz0/CP+n0YHwIFaV1SgRnQxk XgBg== 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=rbAYfhyZgqMeWRdRJHPU4rQHj2hEJ4EDQLoCK64Uk7E=; fh=44lErbL5kvNUjSV6UDWgBEjJyOJpjjMpxi6K+HFi+Bc=; b=caKr0LaG1MpCkIsOzUMIQQ8kw6dStkd/97uhoHsKWvLEWj2tuFP+im8FGLLksu/7Ve rJ0nNemfG5Nhx0f3CX9z0GTAtJkFVf1Gp6emas65oHa918pbEqrFjKf5C0iPXJ5VPoBt MFnZx9l+Qy8X2AXGFi4oYZ6syCexUJM0aNK5Bk1kOVzGwe3pMXWLdvO+ncmUeKa6X1jH EYzqSJFSDgo54zk9dKV3Eipv1o4K/pqCMl8CG7bZ8PKAEXSYDx02Iwvu8aF5tu8piZR0 mddutwbvwmdzQBe8a6+T6KNp1H8/3edjKwa6p0k7iPy6SJ+JZMju6En0tHk/lz0209NC VfiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Av659Inu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69497-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id oq18-20020a05620a611200b00787167c97cfsi1022992qkn.324.2024.02.16.15.55.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:55:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Av659Inu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69497-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6569B1C2134A for ; Fri, 16 Feb 2024 23:55:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A4CF14A4F1; Fri, 16 Feb 2024 23:54:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Av659Inu" 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 A295014A0B9; Fri, 16 Feb 2024 23:54:27 +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=1708127667; cv=none; b=hzUFPtSK3Bn6Ityx+tunkT8JtlP2jsoDvslFmxJTXcBQfekCiWQhb22mcWtkolJWVjiOaskpNF0pZ87GTo3kHcIqfIQ63HEH8XkgUqH++RF3gT7UpWHT7lrlU32+BU0Y1bMwMVLZYhtFIHcE9p4SdYEkvkPgMbC3TVH/sw4ETUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708127667; c=relaxed/simple; bh=guWfSQhoX6jlJEUVpGGsH55EWxqQ6WRn1lYxZhtk0g8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k73XK9EYw1hXDnbYYKaACthaV50Zdx2n8ZIZoSQE50KHi9NFXdRokJJr6fMsyHzxPpU7EX3WeJmk2fgG1DN7POF4dEUgbS3R/6y/2QccmKXLI+kX/byLKkPeZdW8YgMRCtOItK74Raq5zkAo7Vd9f/ZYjZQPml5pLKdncXbTdGQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Av659Inu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02993C433F1; Fri, 16 Feb 2024 23:54:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708127667; bh=guWfSQhoX6jlJEUVpGGsH55EWxqQ6WRn1lYxZhtk0g8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Av659InuKBIH1peQ3YSR4o7AnooIKjsn5U5brRDHW2BxnmzLmyEYHRjWN/G/R0gqH 4z5eRT5M6R7PRIpVHrUPsdL3S/CBBec1qaDdpWVfFSkLghSe4AVPFhxPwzvAufO9Yk niXrX9ColBgpzW4dR0Y3J7g3OWJaQkMddGl3b2UBfkAMzmVOwxrKGGujeRvtoEXqUS QlbT4dkBiQTMVvkjhShC4wTvMKDiYb+2byX4uyusPIvrxYd+DfzVd1TEDGWRRb3SI5 RB9mD6BzGIZApNhG/7MmMoNikvMPbCq422jevP+EpoCZtsqSxUZqeyMYrUvgTTdeUE DH6+I4D32Rg4Q== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 04/14] perf map: Add map__objdump_2rip() Date: Fri, 16 Feb 2024 15:54:13 -0800 Message-ID: <20240216235423.2343167-5-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240216235423.2343167-1-namhyung@kernel.org> References: <20240216235423.2343167-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Namhyung Kim --- tools/perf/util/map.c | 17 +++++++++++++++++ tools/perf/util/map.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 14a5ea70d81e..a5d57c201a30 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -587,6 +587,23 @@ u64 map__objdump_2mem(struct map *map, u64 ip) return ip + map__reloc(map); } +/* convert objdump address to relative address. (To be removed) */ +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); + + 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.44.0.rc0.258.g7320e95886-goog