From patchwork Fri Feb 16 23:54:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 202436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp59521dyc; Fri, 16 Feb 2024 15:55:51 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU7Cd3UUZEx0UchSb+Die+TDgjVyt3KZIBM/MjtWnKt+RVgQEd2VIujNkJ3J5Wp4PtqkqPjuz1e+36JtLa371hhnBFZZQ== X-Google-Smtp-Source: AGHT+IFh96KW/HMci9ht6XOrYXMoifMnRKwcRlbLZTTXYm2amJBFY61RDLZ2z/Jv3x1O5rdRsOps X-Received: by 2002:a17:903:32c7:b0:1db:8c27:c24d with SMTP id i7-20020a17090332c700b001db8c27c24dmr7199191plr.50.1708127751426; Fri, 16 Feb 2024 15:55:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708127751; cv=pass; d=google.com; s=arc-20160816; b=lfgNBlXYVvgKZ+1tdveVaJ1+HLSxczs1p7wMVRLCD5rs1VqMS3qTN0NttFWRt0/y5B anFDf2vBPcVboOvU3CHC/HXlrpbAShC8wcenjwtW5k87mWfcbH8E4WIKzhk/cyoIeDt+ eCvvQoBzbCpKqhBbO3nm0WCLK5vfF9Ffs2JU8L0lA79TkBeZyyuVJSCrtih0lAqNAcYh 5nGIqCqZ/PHC15i6/aDrGCLk++OMH1EOlNWGouvygktfHQ20iLdzL3uDB3vpjoXMKNg2 nIbDC5Prj2fIDb+MOMZsN4pXfRFjhvdXLnG6ZvANPisEVv6SwxDXKvUn4FKnjmwV2bRk g8RA== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69497-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id kd6-20020a17090313c600b001da1d3d7971si590251plb.447.2024.02.16.15.55.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:55:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69497-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=Av659Inu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69497-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69497-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 41BE4289981 for ; Fri, 16 Feb 2024 23:55:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5508814D42D; Fri, 16 Feb 2024 23:54:30 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791101765180262608 X-GMAIL-MSGID: 1791101765180262608 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;