From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2B4AC433E0 for ; Wed, 17 Feb 2021 12:52:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E4A464E45 for ; Wed, 17 Feb 2021 12:52:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232799AbhBQMv5 (ORCPT ); Wed, 17 Feb 2021 07:51:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:55192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230473AbhBQMvx (ORCPT ); Wed, 17 Feb 2021 07:51:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7BB6864D7F; Wed, 17 Feb 2021 12:51:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613566272; bh=3K4qxG5FxziY0VbjYqvHR9bFW2KNVRc8FRhAvzJqfbI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=asLWbWxdyJgKGbMqamq7TNlwn0NaRzjzmz4QYmGVxmq8BmZX9kaZYlkS9iSrWPJcG FfR5G2rfeCADNTpstSq5reFEN1lPj+xjeet+Ic1bSZuSaytPoi/hOqo1pIL9c0EAuo KrAyI+a38OVVtt9csomAb3a9GES5xq4t2xSelCylBeTIveQPLO88cAqkAmfk2ip8Lf 4GzB1qtiZvwIxyrjJy1TzSyLL59mXS80MEm2MH4vUa5H2Zt7eIoaQJgd5NhoQtmt5a ojWZCKx7CU0to9eGvdmHFcCwcYncFzM9QNyMoov5ojQf5ROMn6t/AF11CZ5+A5/Nf3 eLbReNamn+Edg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 6DECF40CD9; Wed, 17 Feb 2021 09:51:10 -0300 (-03) Date: Wed, 17 Feb 2021 09:51:10 -0300 From: Arnaldo Carvalho de Melo To: Jiri Slaby Cc: jolsa@redhat.com, linux-kernel@vger.kernel.org, Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin Subject: Re: [PATCH v2] perf tools: Resolve symbols against debug file first Message-ID: References: <20210217122125.26416-1-jslaby@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210217122125.26416-1-jslaby@suse.cz> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Feb 17, 2021 at 01:21:25PM +0100, Jiri Slaby escreveu: > With LTO, there are symbols like these: > /usr/lib/debug/usr/lib64/libantlr4-runtime.so.4.8-4.8-1.4.x86_64.debug > 10305: 0000000000955fa4 0 NOTYPE LOCAL DEFAULT 29 Predicate.cpp.2bc410e7 > > This comes from a runtime/debug split done by the standard way: > objcopy --only-keep-debug $runtime $debug > objcopy --add-gnu-debuglink=$debugfn -R .comment -R .GCC.command.line --strip-all $runtime > > perf currently cannot resolve such symbols (relicts of LTO), as section > 29 exists only in the debug file (29 is .debug_info). And perf resolves > symbols only against runtime file. This results in all symbols from such > a library being unresolved: > 0.38% main2 libantlr4-runtime.so.4.8 [.] 0x00000000000671e0 > > So try resolving against the debug file first. And only if it fails (the > section has NOBITS set), try runtime file. We can do this, as "objcopy > --only-keep-debug" per documentation preserves all sections, but clears > data of some of them (the runtime ones) and marks them as NOBITS. > > The correct result is now: > 0.38% main2 libantlr4-runtime.so.4.8 [.] antlr4::IntStream::~IntStream > > Note that these LTO symbols are properly skipped anyway as they belong > neither to *text* nor to *data* (is_label && !elf_sec__filter(&shdr, > secstrs) is true). > > Signed-off-by: Jiri Slaby > Acked-by: Namhyung Kim Thanks, applied. - Arnaldo > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Arnaldo Carvalho de Melo > Cc: Mark Rutland > Cc: Alexander Shishkin > Cc: Jiri Olsa > --- > [v2] added a comment > > tools/perf/util/symbol-elf.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c > index f3577f7d72fe..ecc05aa8399d 100644 > --- a/tools/perf/util/symbol-elf.c > +++ b/tools/perf/util/symbol-elf.c > @@ -1226,12 +1226,26 @@ int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, > if (sym.st_shndx == SHN_ABS) > continue; > > - sec = elf_getscn(runtime_ss->elf, sym.st_shndx); > + sec = elf_getscn(syms_ss->elf, sym.st_shndx); > if (!sec) > goto out_elf_end; > > gelf_getshdr(sec, &shdr); > > + /* > + * We have to fallback to runtime when syms' section header has > + * NOBITS set. NOBITS results in file offset (sh_offset) not > + * being incremented. So sh_offset used below has different > + * values for syms (invalid) and runtime (valid). > + */ > + if (shdr.sh_type == SHT_NOBITS) { > + sec = elf_getscn(runtime_ss->elf, sym.st_shndx); > + if (!sec) > + goto out_elf_end; > + > + gelf_getshdr(sec, &shdr); > + } > + > if (is_label && !elf_sec__filter(&shdr, secstrs)) > continue; > > -- > 2.30.1 > -- - Arnaldo