Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4820577rdb; Tue, 12 Dec 2023 10:07:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZaH5meAM82jndzbm4X0dnunn6m5pUr7I0Q2K+9FbNh/He3dNby7IjB+pxQ8XU+9oqbgHG X-Received: by 2002:a17:90b:110a:b0:285:8a2a:1744 with SMTP id gi10-20020a17090b110a00b002858a2a1744mr3125480pjb.0.1702404452125; Tue, 12 Dec 2023 10:07:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702404452; cv=none; d=google.com; s=arc-20160816; b=IaWoVHXmf/RFq8dJgSjlMp2wDtDi87zAUZCmFR/DeJ1WLGJY8eN+AK6Taw5hXzyq8a nl4KLVZpkA1GbotK8y4B96ilhgt8qUwFNpcKNx/4EGAEd5g1qwYoN22hSBYUxuip+aLt RS0ue3NCRkksTPeCdJ8DMcQw7OF+J2U5FRNi1HNtC73UvBiM6w++bIyegDwlkFxSQfHV GGxTYgWAUILALfBK5FF1mWdL8j2SRwqAwyyV39lus6xwK7wgxq+gJgAdhrWweZohBl+O wRT/HwHpOx3DKtqKFAe6MhDXtbkR/6qzWqiB8Ntl0Ytt/CM86EcFEDwVQEy3x8aZzShZ G1BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=14KyAFs5GhfjaUdeyaHsNjUFEO7kE0hEjwmeNGQaN4E=; fh=gbRfs4Y5vnVImbARvTpg01BxMh7cDiEnWtMIRe61H1s=; b=RV/tLz5Blha0oAu+Bq4sFQ+kD1fFTbKD/XVu4/SqjyOMs+ywXxUB8p3zhrTds4KnJa ucnR5CR47i1SlHW0tOjtcSjHhFBWrlNka3eqg+vIqPe4iLiKWDexHRHgukoeR+VOwmO4 w+B+D066nViPkVodEtGv7V0j276dv02WnM1FDmzfeBqcVwVb2IhKt0u/TOv+aB6N4Eq8 sH0ztO+hQh+FJWDcHpEoCYb79pJUHzOnGf8tj9EF42LDRt/RlbGg6N0y7ZnHd1DhlAQW NLzIganILQdWD9ki1pep1z3uDEq7fbDM1IdSptQD6BWNSdQU0Aj76GB8zV1rHkmI31TY STGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="4ypYS/NC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id nn8-20020a17090b38c800b00274df6d4c38si8188972pjb.89.2023.12.12.10.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 10:07:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="4ypYS/NC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D111B8051B40; Tue, 12 Dec 2023 10:07:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377029AbjLLSHL (ORCPT + 99 others); Tue, 12 Dec 2023 13:07:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230181AbjLLSHK (ORCPT ); Tue, 12 Dec 2023 13:07:10 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADD16AB for ; Tue, 12 Dec 2023 10:07:15 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-50bf09be81bso142e87.1 for ; Tue, 12 Dec 2023 10:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702404434; x=1703009234; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=14KyAFs5GhfjaUdeyaHsNjUFEO7kE0hEjwmeNGQaN4E=; b=4ypYS/NCw76YAGeK4JyfqNS7lxtJyErCDQBQZKyi2yGwh4Hw/8tWk6xi64OzPlEuIU 3ieAB6Oa/5LLwhZGN4ZDIeIvI4z5yJW2Nr0RIWhkmnWYZcImfrCYJ3m0stxqADgEPW/C zTF88rUYPL+VpyFMtGICDNUaWU/Q0/RapNdpjpojjDTCbHjttvyuMx8KF0MaAsWsshyC wArqvrRu3QWKtyYi2CstFtoY++df5+wteb4t5nnuJtP/PsooVKwFgTxLQWzBMk6agKJT lDXPTeiKh2hmfT1rmm0nwBnDTtXGkSiCoEI2Td1uXyZE1XxlUELgXNElrS9/6nJ92gC2 7q/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702404434; x=1703009234; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=14KyAFs5GhfjaUdeyaHsNjUFEO7kE0hEjwmeNGQaN4E=; b=Vp49cDtqOYYq9B7Dgm+YHo9LEp+A16gqU4PfrK61KXwJzZIV2VuuV+RYcjaIS/7scO a8Tp/k75S/yvmV4OG4kfg1OHCyhRCpCcRv0trYpukiv3JnXWSeXCGvXAvLtSCSyEycfv zfqecjX70uO7Aei5lnCRwXqYVm2JMD9rvfJQmADD3dRPKjQvnJ4BGs3ec+zGQkbUI/x/ 4/rPtZWFl6ItR8G4tHT0SSsGc8wLgtwAgZNaqIQCQ+nVnO7PByXnAaSckQY1RGkVMadF GyjGnh6KerSXhJjiagmIjFETlWYRpGlQSuQtKHq8V6Rw/Wuied8+gUl4x2g6oEkMSLiw nvGQ== X-Gm-Message-State: AOJu0YyIvzzYL3Rw3ianC0W6ykCYYRGhjlvz5+dVgy/DTNm2hJllx4A1 nJPYSjVk/392VqT8keQxhSkNiqSSOpphIxkl+L1uQg== X-Received: by 2002:a19:5e41:0:b0:50a:519d:5a8a with SMTP id z1-20020a195e41000000b0050a519d5a8amr278545lfi.5.1702404433671; Tue, 12 Dec 2023 10:07:13 -0800 (PST) MIME-Version: 1.0 References: <20231212070547.612536-1-namhyung@kernel.org> <20231212070547.612536-3-namhyung@kernel.org> In-Reply-To: <20231212070547.612536-3-namhyung@kernel.org> From: Ian Rogers Date: Tue, 12 Dec 2023 10:07:02 -0800 Message-ID: Subject: Re: [PATCH 2/3] perf unwind-libdw: Handle JIT-generated DSOs properly To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Milian Wolff , Pablo Galindo , Fangrui Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 10:07:30 -0800 (PST) On Mon, Dec 11, 2023 at 11:05=E2=80=AFPM Namhyung Kim = wrote: > > 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-libd= w.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, u6= 4 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, = 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)) Perhaps it would be better to test: dso->symtab_type =3D=3D DSO_BINARY_TYPE__JAVA_JIT Thanks, Ian > + 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; > > dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, N= ULL); > - if (s !=3D map__start(al->map) - map__pgoff(al->map)) > - mod =3D 0; > + if (s !=3D base) > + mod =3D NULL; > } > > if (!mod) { > @@ -72,14 +85,14 @@ static int __report_module(struct addr_location *al, = u64 ip, > > __symbol__join_symfs(filename, sizeof(filename), dso->lon= g_name); > mod =3D dwfl_report_elf(ui->dwfl, dso->short_name, filena= me, -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 =3D 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 >