Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp666905lqt; Mon, 18 Mar 2024 22:52:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqEc2zY6Z7SGPpZ/DPJUKNnS5uKeYqO2b3XcdQE7fu91bmhe+cQ2OFol0wI36ha+6KOj3FOY9CysOe2XsuJIA10hEhBVRTXiwAp/ASUw== X-Google-Smtp-Source: AGHT+IG2217YH2kczm6THnp2LR60qdS+3SItZvc7peMODY7P1H89I0Pb1SpVlEA6HXpAHOwRiDzU X-Received: by 2002:ae9:e10f:0:b0:789:dc20:3a4a with SMTP id g15-20020ae9e10f000000b00789dc203a4amr16755620qkm.18.1710827561827; Mon, 18 Mar 2024 22:52:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710827561; cv=pass; d=google.com; s=arc-20160816; b=YJhyXij/mWGbUrVFzeDyPCxO5J+ayj9k0kTAZqW2faZfS7Xkg2Gdb+kncd//HuENNR 77+xkdZisgEbHWKhOvjW9ecOMT6d172c7ZsBYlaLbZB7x6xgeO5trjA6hfg3Fa7RJ5PE N1qj6dLs5lhUGnY8CDhsnHGqU7k9pWqzb4lH+0itQbclnLk7ExgSYGFre/sUSWDSHZhy p8dQD9tURCLSOUCrK47FuYAELS1buBZOhTJzK6B5W4eNNr4gFMmdsGd0VYPalKcsRf6E pUcZyonwg7ZSDKArks+p4C5UrWxcMsMZpRV1xKOMuVKV9ApF87Tvzzf4pKVElC0lmuFH bUQA== 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=/oFtLaxV96/1WifjmDvIU1413I7SNW+3enxhmHoUAHU=; fh=44lErbL5kvNUjSV6UDWgBEjJyOJpjjMpxi6K+HFi+Bc=; b=A22d8smUxHuSfdPmADcFa/Mf3KqH1JFHBqsMh3IctcfzDjT+tdigVuHZlzG+b1bpEc S96hy9SwohtPaeRB/bvnXowL66z6rKXvyswBhyC1/lVtI9oVArqvhnHgPTXqQA2FQ2Lm tf5jWaYTDZ7sm7Yqox2M2cvn2ezOOs8NyOnLUfuNKNw7kuK+iY3N3M6kKapNnleSDA05 G25S58b1M1/VJaVk5saItem5BAOW2hJkXLBnq9rJXHqvJ+SdiZzmrKDmoenknEsMv9tJ DSWxsVAfNZ1sHHdxlDoKMcaodh0AP0fE0lvXTwAN/Ue3r3K2OnRPVyrs1rGzxYZTHUtY WM8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Dl2o4ui5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107031-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s7-20020a05620a080700b00789d2ad4b81si10908346qks.606.2024.03.18.22.52.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 22:52:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Dl2o4ui5; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107031-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 8A25F1C2176D for ; Tue, 19 Mar 2024 05:52:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6EB877D405; Tue, 19 Mar 2024 05:51:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Dl2o4ui5" 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 C00F17CF0F; Tue, 19 Mar 2024 05:51:20 +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=1710827480; cv=none; b=E4n19kSIkQZXEhytjo9YwdDna34WQG2bcT2JeJGRd+ZUEnO9JVtg22+fZ5urwm+/1YVSbqs3e1MUYVMX83CEV5duy6wp8ckwsQLRNV4Srml7GaFq9Vx7MDW0+s3B0oFcIvl2eC+xjFikQSEn9gcQA66onA28pFVodMKLDuyEDYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710827480; c=relaxed/simple; bh=bAEbqgWbLQcfN0MLUSyPEU2jzHHBr14ThaOBDSWbtkE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TWz7TVejQcyRhuYOEUQr9eJbS/A0AlqsBZQ97eQOT9IxSUTtyOq/RLNMI+TlRkZDTpuP0j+E0xEtZ1DolF09KVhjZsq72VxsRDLymTauKlDAaytnhrMWeiqUgqp/lLzspsVaQWGcNxaK4Pm+2WoLSXoaU2TcrIYxNCWWSwNSMRM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dl2o4ui5; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C1ACC43142; Tue, 19 Mar 2024 05:51:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710827480; bh=bAEbqgWbLQcfN0MLUSyPEU2jzHHBr14ThaOBDSWbtkE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dl2o4ui5dqaiRWRM0Z5GOkX7RV6mXREl6wRfu+BD5PuBKCYiJZB8vD1hsD5yVmr5s D1J5wM2qgWjuUFABe32ywmnp8SovoSUpAgBjbIG5/XfxRqE5QGqcr1SjMPd+7D5/jg mbzclIly5Lki1PhigV2HqucZcpx04jUXJAzogdl2ltrW+GDrs/xOM4IbfORppN3Q+z Mkf5AV7xkW/kzTKyuIhv+XCgQr26aGEwqJ6/mSDCBFmBferaNKyvSq+PTXiJDWRbgq MlEmihcKYEaVBDV16EDUPW8eO4U+ED9KwDMzfhUySqfdPmLElOSUp2BYqOnvNz6a9i D7POQN3mWNTuw== 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 05/23] perf map: Add map__objdump_2rip() Date: Mon, 18 Mar 2024 22:50:57 -0700 Message-ID: <20240319055115.4063940-6-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog In-Reply-To: <20240319055115.4063940-1-namhyung@kernel.org> References: <20240319055115.4063940-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.291.gc1ea87d7ee-goog