Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1111893rdb; Fri, 2 Feb 2024 14:14:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0KslXxRpj9Oai8IbF2dZE1kL3gfNW5ynK5hBlIwh/D932NwJ+aB/o/dXks+tSZbTZBx2C X-Received: by 2002:a17:90b:2356:b0:296:1624:5a65 with SMTP id ms22-20020a17090b235600b0029616245a65mr6444926pjb.2.1706912058827; Fri, 02 Feb 2024 14:14:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706912058; cv=pass; d=google.com; s=arc-20160816; b=mhF5CinG4yAu5D/oZjJnY9ZqvZFhSzMWyZ9ka9pVD7l3JWmpVC4W2vDGeAgskVw6eY rxtIfYJfYkgy47AIsDaBVFk+iMrDZKM8H9zjVQHd6RQZn1picIjn13v/XhLno0Vn+YZ9 2I12iSd5WW5vx5E3XBL7rtoyE3paVD3jF6JAjWevUVZyH+YaSZ2xXOMLoe2MpMYOhwkr 4cYNfEWkyNIxRy4ukbm3pYTGd4PAF+9eT4wyIJ+iNdTkkKb57HpWyjiEKB/dPB03O5qH An+4in4nzjyFLXE1MPjZQJy0m8ccWps5Sl1fqDJ6twk51b/+gtNOv5tSs21rMcGLk95t OV3g== 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=1d5Ov7mnVyJMDgvieK16b0fPlA5TesSRKk/ShcwKk+g=; b=Vvg9nz+uW8mraDInaKp8F+7o3Hhd0JpO0or9MuBqHYl2BjPTsfZnMar0dYpIBgf5Un yhEMqcLDWxwI+N0QsqHMCiuAgW6zpk4LwhlSn9jw+Ol5pM5oMa5IMhCMnRxj+N60v4mc wkPUlXLc/Fwi+0eJOLSjt32IHt00yK9tvOSC70C/YimJGjG5WjX4Wed3w30kCfeL+fKv wFREiT7YietIJQ84svlCz7TFaqh+y7lqMlBPMjjh8G1UvctvGrM9IeYffXysBl/n7NIc /82IqCn0SfOIejoc+MJipNAGVuF63LoF7DejgBUPd6ugJBd2qBfFNPOsFePPHMaFi7NN wRvw==; 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50637-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWzoFrz9kuJicR2FOv9LLANDLBlEVBZyZH9fD6CyYboZ4cmBHFAka/w6vvT/oBeuW8TPOTiMyetmwKdeiPGZi0g3t2ZCEtKFi8MUpNwEg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t5-20020a17090aba8500b00290f94a9fbdsi543374pjr.10.2024.02.02.14.14.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 14:14:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50637-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50637-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 3F9E2B26177 for ; Fri, 2 Feb 2024 22:05:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48054126F35; Fri, 2 Feb 2024 22:05:05 +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 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, 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: 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 | 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