From nobody Wed Dec 17 06:47:52 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0BD2C4167D for ; Tue, 12 Dec 2023 07:05:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230356AbjLLHFr (ORCPT ); Tue, 12 Dec 2023 02:05:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230266AbjLLHFp (ORCPT ); Tue, 12 Dec 2023 02:05:45 -0500 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8B62D5; Mon, 11 Dec 2023 23:05:51 -0800 (PST) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-20307e91258so11220fac.0; Mon, 11 Dec 2023 23:05:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702364751; x=1702969551; 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=IxQYxpYcrWIqvC1cKCSYLMPQZtsdrNIv93BxHbphWrs=; b=JgTJApR5diAcVXCoDKGxz4igZ2fxk6devxE9l9aWilUpCLVEt5hmDACOGpCpuA1Kd7 O1AutN5f6LoIcQFujNmEGDXvHpMkonwiovwiEdVLC/aYmMnjMJe0FQr7K6pC1qGd79Dp lgx03+MTLgyMI+Q2o8SztL+H4dkKuAIKcFkfZintzgqeMyVYmvqyRwE3p1E8Paljh+w3 GhWb9iaUapjrdswi7RROufbt6WRZoNd2DXNPZwKEMNNM+ZAKmGEqgRJJ1tJ2bGd/xr9+ rV2ocCQslbnjJHJo9hJYXHQg4Xt1grGXJempUkLbUKzIL1ddH+MfPRKRGIvYTj8No8yC uUiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702364751; x=1702969551; 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=IxQYxpYcrWIqvC1cKCSYLMPQZtsdrNIv93BxHbphWrs=; b=m3WwWqyjKreV11kngzPWAvuacOz1oV23+/FcPX09YyBoQCOIuQ6r6eN4Bg360UdPPz sqMMtF7bvM/l6drLA4njJiW/7R+/s7pKD+LsN9kjZ9PUvcrNTw2aGQFoMzr8tN7hf43J pQ/gPIco3ctMAceGJDQbvMfeWmc95Cih/aD6jeD0hY+zuoa/jShRjuIistByJdrUHrFS Pn61a23Bmgo1Tj1wW8Yz31lB/koACLMW4vXPOjdkB0b5LoJXczBA8hbULGA6HTF07Rq2 KXomk/ud3POQahm8PITo/iwzNVSnG1wWoJc08MQT83kziQgPnbTEHCYnPMyZmYOkPWQ/ ofaQ== X-Gm-Message-State: AOJu0YwcRzHYMDojk45mIoQkkjeqa3pgUwcCmQvZkbLQ1VvHreNPFMME QTz6TOyckD9KbcAJ6Q2p5+k= X-Google-Smtp-Source: AGHT+IFIPRwDp5aw1X9LTPnHC7HkFiMRiZ3w/V+YsEOXcNFTStkOgj3TcG3rVDdRoxEiytIyYRjrBg== X-Received: by 2002:a05:6870:61d4:b0:1fb:75a:77c1 with SMTP id b20-20020a05687061d400b001fb075a77c1mr5353980oah.114.1702364750851; Mon, 11 Dec 2023 23:05:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 23:05:50 -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 1/3] perf genelf: Set ELF program header addresses properly Date: Mon, 11 Dec 2023 23:05:44 -0800 Message-ID: <20231212070547.612536-2-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The text section starts after the ELF headers so PHDR.p_vaddr and others should have the correct addresses. Fixes: babd04386b1d ("perf jit: Include program header in ELF files") Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/util/genelf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c index fefc72066c4e..ac17a3cb59dc 100644 --- a/tools/perf/util/genelf.c +++ b/tools/perf/util/genelf.c @@ -293,9 +293,9 @@ jit_write_elf(int fd, uint64_t load_addr, const char *s= ym, */ phdr =3D elf_newphdr(e, 1); phdr[0].p_type =3D PT_LOAD; - phdr[0].p_offset =3D 0; - phdr[0].p_vaddr =3D 0; - phdr[0].p_paddr =3D 0; + phdr[0].p_offset =3D GEN_ELF_TEXT_OFFSET; + phdr[0].p_vaddr =3D GEN_ELF_TEXT_OFFSET; + phdr[0].p_paddr =3D GEN_ELF_TEXT_OFFSET; phdr[0].p_filesz =3D csize; phdr[0].p_memsz =3D csize; phdr[0].p_flags =3D PF_X | PF_R; --=20 2.43.0.472.g3155946c3a-goog From nobody Wed Dec 17 06:47:52 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AE5CC4167B for ; Tue, 12 Dec 2023 07:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbjLLHFx (ORCPT ); Tue, 12 Dec 2023 02:05:53 -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-Google-Smtp-Source: AGHT+IGO1gxqJtPsMRhGhpkniGLOsXPTrca+Ix5rWiE+tExABkSHUl4g9pzL2c1aqd8j6Np2Y4e33A== 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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 e= lf 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 =3D 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, u6= 4 ip, if (!dso) return 0; =20 + /* + * 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 =3D map__start(al->map); + else + base =3D map__start(al->map) - map__pgoff(al->map); + mod =3D dwfl_addrmodule(ui->dwfl, ip); if (mod) { Dwarf_Addr s; =20 dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, NULL); - if (s !=3D map__start(al->map) - map__pgoff(al->map)) - mod =3D 0; + if (s !=3D base) + mod =3D NULL; } =20 if (!mod) { @@ -72,14 +85,14 @@ static int __report_module(struct addr_location *al, u6= 4 ip, =20 __symbol__join_symfs(filename, sizeof(filename), dso->long_name); mod =3D 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]; =20 if (dso__build_id_filename(dso, filename, sizeof(filename), false)) mod =3D dwfl_report_elf(ui->dwfl, dso->short_name, filename, -1, - map__start(al->map) - map__pgoff(al->map), false); + base, false); } =20 if (mod) { --=20 2.43.0.472.g3155946c3a-goog From nobody Wed Dec 17 06:47:52 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C8C1C4332F for ; Tue, 12 Dec 2023 07:06:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230331AbjLLHF4 (ORCPT ); Tue, 12 Dec 2023 02:05:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230360AbjLLHFr (ORCPT ); Tue, 12 Dec 2023 02:05:47 -0500 Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28ADAD0; Mon, 11 Dec 2023 23:05:54 -0800 (PST) Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-590b3337d2bso2037220eaf.2; Mon, 11 Dec 2023 23:05:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702364753; x=1702969553; 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=h7MmpZWXIj03M3uDOilYQIEOcQY8xZL0V5IuLXoT63s=; b=eCK+ZX0PffaP0WcIiHc9Jm86gljP3ACMk8PVUnJTt7QLmLm1iZvRF64/QQwZrhVJcP nKe8+Vwuf813a/zN8l5PyFaA7N0UUiQjJn7QMQMZlEcg3pEmyphLT257V6SGUUNxQQ/k mbN09+shBo2YpUH8LdIFJa3NyBzEAgXtQbEi5b7Ix76x7dHCEXG8A/3qPPeY/iZ1+BQH hfoz9hxKhgBS6bu2Vzet3mt+ZH6Xx13wSGty8ZpuZaiMRhVN3vUgEAiD3N47zNfmrBxv YN8lY61SkrYRWN92zNiJRrumEiPxqsYeB4PdxsKXiM/a4IwaSFrqtGuJ0fomZRy00hHR W20w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702364753; x=1702969553; 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=h7MmpZWXIj03M3uDOilYQIEOcQY8xZL0V5IuLXoT63s=; b=W3HwC3nrbUO+FQbsY9jJa1Q8R4LQIxnv5PuCuUWc8IAYraLJGDMhER4Yw1U2kcCigy IpSJY2BK/+uzve+wD++yfxul86S/uVsYToOVXDz/s5h0LkofSKNW9nXWJgV6Gk2ruHUs tDgxPE+CglonJn26K1uih9hSNV6QpYv71H/SCYU6BWbURBZuGgyY9js9yL0SYw3VdTjK TbPFGCOxY9hGti5vVra609Ue+1oBOwsimRMVmPg+4dLBqovpnhAgX8ofgnK8qSI6WOXz 9o36BdZ4TFeAFe2/1jmIfke0pQI38LtdOmvjIJWm0k9XlWM+KY21schujeGjKlpBEYY1 9NTg== X-Gm-Message-State: AOJu0YzGgHjtgde3pM3ymt/W1UnMOb54TvTjF2CvaQHj25q+FyefthsZ r1e2o0FCd4JebmH0tVzO33w= X-Google-Smtp-Source: AGHT+IEKK1PG3Igx/3v5NKBHwbQVvC92wq1g1r492iiziO6sUZtoxHvt/SdfwNUyWjAgDxKZUvhquw== X-Received: by 2002:a05:6358:6f93:b0:170:f1ab:9612 with SMTP id s19-20020a0563586f9300b00170f1ab9612mr7264rwn.65.1702364753280; Mon, 11 Dec 2023 23:05:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 23:05:53 -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 3/3] perf unwind-libunwind: Fix base address for .eh_frame Date: Mon, 11 Dec 2023 23:05:46 -0800 Message-ID: <20231212070547.612536-4-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: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The base address of a DSO mapping should start at the start of the file. Usually DSOs are mapped from the pgoff 0 so it doesn't matter when it uses the start of the map address. But generated DSOs for JIT codes doesn't start from the 0 so it should subtract the offset to calculate the .eh_frame table offsets correctly. Fixes: dc2cf4ca866f ("perf unwind: Fix segbase for ld.lld linked objects") Signed-off-by: Namhyung Kim Reviewed-by: Ian Rogers --- tools/perf/util/unwind-libunwind-local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unw= ind-libunwind-local.c index c0641882fd2f..5e5c3395a499 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c @@ -327,7 +327,7 @@ static int read_unwind_spec_eh_frame(struct dso *dso, s= truct unwind_info *ui, =20 maps__for_each_entry(thread__maps(ui->thread), map_node) { struct map *map =3D map_node->map; - u64 start =3D map__start(map); + u64 start =3D map__start(map) - map__pgoff(map); =20 if (map__dso(map) =3D=3D dso && start < base_addr) base_addr =3D start; --=20 2.43.0.472.g3155946c3a-goog