From mboxrd@z Thu Jan 1 00:00:00 1970 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 53555130A58 for ; Wed, 8 May 2024 21:00:59 +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=1715202059; cv=none; b=s+GSR2h6Siyn4a7WUkO0lyrr4J7eWnohgjgrhbxpu+/1QlnMyI35DtPXOJoY89Nx6QEeikXALutNu2bf5gyrU80aoRBMpmLREqEolgMRkKtj9tDwh2S+X1XtLKlmLnNJaI5lZLfMnU2/DO6b3MnWv4C0FE5UmqCa/EnRs7H1128= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715202059; c=relaxed/simple; bh=6BEz+LFSSLx1fz3oO0i0k8ch+IZPgjsp+IeHgBtJzGQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WtDTmsAQv06PgNCMm6WP8STtiqU8OK1WDcYENWauAWUvSQuOS0cYs5G5DWeZrirGQfSRyKAvbs3cGSM/W4Yf9gILl1P8wOfmDtqKUE3ZVlAG2LsTittSXExf+ilJuMMpvCCFBn+En3yHJS82g5wNzuZWO4Pal9MX5r2fsje/fNU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PzgbAWcs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PzgbAWcs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A6DBC4AF08; Wed, 8 May 2024 21:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715202058; bh=6BEz+LFSSLx1fz3oO0i0k8ch+IZPgjsp+IeHgBtJzGQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PzgbAWcs86YWLGw3GdV0BKAcBHAknEgVRYD4rpEH/N9sgpBKU+JiM6epmELQB0rvV wDbAJOPfp9ty/wCUEGgFV/033llu8S55Kw+FGRMYfdbQOtY7G9qf+2WcD6gawZGMM/ W6x6UjWJEiPuXi66ElV1w/xk85v7IShpST2/VOxwYhT5PhfSqY4tt1njzphrLgPnzh z7NJ8hp9on63tCkVrQXDKSrP6U70pzaCXIft6oyzecXxaY5N6OTzkm4aJMr1q7iZig 4H1YdZGqeZ5tSYYFeo0gu/j4GrdpOIG4SPzNYsT3SrTyLXn0PLN6toiodAVoUO1sU8 z8HR5e9c5oPdQ== From: Namhyung Kim To: stable@kernel.org, Sasha Levin , Greg Kroah-Hartman Cc: Arnaldo Carvalho de Melo , Namhyung Kim , Pablo Galindo Salgado , stable@vger.kernel.org, Adrian Hunter , Fangrui Song , Ian Rogers , Ingo Molnar , Jiri Olsa , Milian Wolff , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH for-v6.1 2/2] perf unwind-libdw: Handle JIT-generated DSOs properly Date: Wed, 8 May 2024 14:00:56 -0700 Message-ID: <20240508210056.2253626-2-namhyung@kernel.org> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240508210056.2253626-1-namhyung@kernel.org> References: <20240508210056.2253626-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit [ Upstream commit c966d23a351a33f8a977fd7efbb6f467132f7383 ] 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: 1fe627da30331024 ("perf unwind: Take pgoff into account when reporting elf to libdwfl") Signed-off-by: Namhyung Kim Cc: Adrian Hunter Cc: Fangrui Song Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: Milian Wolff Cc: Pablo Galindo Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20231212070547.612536-3-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- 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 94aa40f6e348..9a7bdc0e14cc 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -45,6 +45,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. @@ -57,24 +58,36 @@ 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 info + * 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 = al->map->start; + else + base = al->map->start - al->map->pgoff; + mod = dwfl_addrmodule(ui->dwfl, ip); if (mod) { Dwarf_Addr s; dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, NULL); - if (s != al->map->start - al->map->pgoff) - mod = 0; + if (s != base) + mod = NULL; } if (!mod) mod = dwfl_report_elf(ui->dwfl, dso->short_name, dso->long_name, -1, - al->map->start - al->map->pgoff, 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, - al->map->start - al->map->pgoff, false); + base, false); } if (mod) { -- 2.45.0.rc1.225.g2a3ae87e7f-goog