Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4462531rdb; Mon, 11 Dec 2023 23:06:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZZb7SBWMLY2jXkxvmp6Ye1BhwfCx5+rNobDm2bKS2kjTUg3t1aP8LXDP8S1hWYN+HOZXB X-Received: by 2002:a05:6808:11c8:b0:3ba:2af:c7da with SMTP id p8-20020a05680811c800b003ba02afc7damr5099789oiv.110.1702364791901; Mon, 11 Dec 2023 23:06:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702364791; cv=none; d=google.com; s=arc-20160816; b=P78o2+KiJxPff/p52cCmVVqk/gonb/8UiD5LxoDuG3t22x6QMJ0PAXsg8NCpmh8dCj 5/NGzZMZyxKAdohF5FsU8jUYEvIsmRUgW7LRnb8pUkN6oRvQPZurAVZaE+1n5O6PjfMz 7kKcJylEdxhyXfE1jxbyLccXxIA4T8XlIwv3ItA0uAkwFx1nKhV0Khrv9cDF1YRuXBsZ aiKM0Fqe4qPnzh7otNlBI9MQPReT7XlPAG5n/x2h1z+ajiXF4NSmCYdcxXh5v7fRIZq+ FSfjZdXLfvc7aF4Hwv1HnKvmt9VsIJD8tjQCdNVFnshkvJ5XuwXCYp1Oe/Pkzz3VDOQX sd6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=m8kfa0OmifAdVx0rewv27+H2zarhfc//r99xaIhf+us=; fh=j7XGxNx2Lg8u7nyGj/Zu18oEzBtLERie2+5jwGMgLi0=; b=LZ4TM9sE3exf3oga5qc+8BR8ZMjJXMXEYuO+3geXqcbA9J/M9dFclMjnqKQowSBLZy +kATs8L7oSoo/k7Zk8r9ONY6EZKWlZEu1ONDbCXIT2y1jnxOM47MM9BOevgWkBmjXY37 OxsAzJWm5b5O5/EqtNYWeXHJiQGurtxyCf4aRDekym/8ppXJEitmIlhBOaC2bOoWZ3ov aMDA+KCuntMMg9KAxG5HGc/Xc5E0FPoXtyMeP8Wa86GgqRzyVmUwKnVuXq5wbZ+bFBHK gAi8GeWSVe/AY6KFE3NMEeXILNU2ZJwpPZwRQtfsuaCVOk5wehuACm/g73Vi7+vxJKUg phQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=apG0nOpa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m12-20020a056a00080c00b006bceac424f7si7450834pfk.102.2023.12.11.23.06.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 23:06:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=apG0nOpa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 5F97080728C2; Mon, 11 Dec 2023 23:06:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230401AbjLLHFu (ORCPT + 99 others); Tue, 12 Dec 2023 02:05:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbjLLHFq (ORCPT ); Tue, 12 Dec 2023 02:05:46 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC981BF; Mon, 11 Dec 2023 23:05:52 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6ceb27ec331so3324591b3a.1; Mon, 11 Dec 2023 23:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702364752; x=1702969552; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=m8kfa0OmifAdVx0rewv27+H2zarhfc//r99xaIhf+us=; b=apG0nOpa1dn6mITvJwGLe1jul4Av8UsZ7gVUhv8VTitOcyDGL30fOj1LbfvcV7bm9m FqBTbcF77KLjzgieYlima95Dtvw81daTuy0QVlwGgUavaOVZGJrA8/TGjB93328Vgwzl PiYDrk5YAFqgLIPiqt51yhPdy+M7jM9BrYijp6198TZJS6J8KxvMlxruIRR9yj+9+mKE CuCSQnnwUT/yyLzLM0bTI4roDPn9scTecQvIoWUnaDryPx3s1iZw+193vpI0tbGUG2rR I+2pM/lxZY4lVXnc6Z9wSHO38VEFCj4zdhEsUw50yc1PsGtyQ61k0MeyWC9CLr71OsNJ CEKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702364752; x=1702969552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=m8kfa0OmifAdVx0rewv27+H2zarhfc//r99xaIhf+us=; b=JUx5BjLRZ0eBeTxsSf6xcrNZtHaD2ovbNzujbU5lNOX2ZqiK2MELqrJKlo6Xf+D402 IzpKdmDubyIK4Gh1OBjHS2bh8F2ip6N9WMnJIk+Kyx2+I02EA7o0aFrpHaGQ+JtqTNhx kjq4j/zlSGv6NiMPdHuVu7+AOCUMX44ZSeCrBKrpSL0wDWoaQgnrhbmw87igUORhipIq 8sygBz1r7VUIC84/gloMdGjTweaLZCu22NNqlQF9e31Z8q9hQA/GCXd2ZJ+Ypn+6gmYr sZUU+SAyP++HF+xznhF4NmWxJmJUvPGocFGf+hKohbd1VvbihOVTK+RG7VgcpabahW4x 0KNg== X-Gm-Message-State: AOJu0YzAlBIQ3niSmlgTAqNhlUT3h4s0hRNu7gdyBjvJ4jOeN3Rr2Cuv xNfb2NPoDDjYYQ/3s+8JxbM= X-Received: by 2002:a05:6a00:4b42:b0:6ce:3e7a:cfad with SMTP id kr2-20020a056a004b4200b006ce3e7acfadmr3328198pfb.0.1702364752135; Mon, 11 Dec 2023 23:05:52 -0800 (PST) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:7da0:5ec4:de63:3cf4]) by smtp.gmail.com with ESMTPSA id g17-20020a056a0023d100b006cb6e83bf7fsm7397491pfc.192.2023.12.11.23.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 23:05:51 -0800 (PST) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Milian Wolff , Pablo Galindo , Fangrui Song Subject: [PATCH 2/3] perf unwind-libdw: Handle JIT-generated DSOs properly Date: Mon, 11 Dec 2023 23:05:45 -0800 Message-ID: <20231212070547.612536-3-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog In-Reply-To: <20231212070547.612536-1-namhyung@kernel.org> References: <20231212070547.612536-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 23:06:06 -0800 (PST) Usually DSOs are mapped from the beginning of the file, so the base address of the DSO can be calculated by map->start - map->pgoff. However, JIT DSOs which are generated by `perf inject -j`, are mapped only the code segment. This makes unwind-libdw code confusing and rejects processing unwinds in the JIT DSOs. It should use the map start address as base for them to fix the confusion. Fixes: 1fe627da3033 ("perf unwind: Take pgoff into account when reporting elf to libdwfl") Signed-off-by: Namhyung Kim --- tools/perf/util/unwind-libdw.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index 8554db3fc0d7..6013335a8dae 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -46,6 +46,7 @@ static int __report_module(struct addr_location *al, u64 ip, { Dwfl_Module *mod; struct dso *dso = NULL; + Dwarf_Addr base; /* * Some callers will use al->sym, so we can't just use the * cheaper thread__find_map() here. @@ -58,13 +59,25 @@ static int __report_module(struct addr_location *al, u64 ip, if (!dso) return 0; + /* + * The generated JIT DSO files only map the code segment without + * ELF headers. Since JIT codes used to be packed in a memory + * segment, calculating the base address using pgoff falls into + * a different code in another DSO. So just use the map->start + * directly to pick the correct one. + */ + if (!strncmp(dso->long_name, "/tmp/jitted-", 12)) + base = map__start(al->map); + else + base = map__start(al->map) - map__pgoff(al->map); + mod = dwfl_addrmodule(ui->dwfl, ip); if (mod) { Dwarf_Addr s; dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, NULL); - if (s != map__start(al->map) - map__pgoff(al->map)) - mod = 0; + if (s != base) + mod = NULL; } if (!mod) { @@ -72,14 +85,14 @@ static int __report_module(struct addr_location *al, u64 ip, __symbol__join_symfs(filename, sizeof(filename), dso->long_name); mod = dwfl_report_elf(ui->dwfl, dso->short_name, filename, -1, - map__start(al->map) - map__pgoff(al->map), false); + base, false); } if (!mod) { char filename[PATH_MAX]; if (dso__build_id_filename(dso, filename, sizeof(filename), false)) mod = dwfl_report_elf(ui->dwfl, dso->short_name, filename, -1, - map__start(al->map) - map__pgoff(al->map), false); + base, false); } if (mod) { -- 2.43.0.472.g3155946c3a-goog