Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2023054ybv; Fri, 21 Feb 2020 07:30:21 -0800 (PST) X-Google-Smtp-Source: APXvYqxAbj8X2CAOBytEMoX9C+vRMAHhurYLppAaTrPbW6XI6qthZyqi0fwcHm7UqH6404zhn8lx X-Received: by 2002:a05:6830:15a:: with SMTP id j26mr27483350otp.137.1582299020624; Fri, 21 Feb 2020 07:30:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582299020; cv=none; d=google.com; s=arc-20160816; b=IpYAexL7SY11JKulmA5/7wwWjGDrbLa0qp/fraT/8DYUMPunqT+WVOs8Fj/1OU3rBf 7S3FFrvG0Y4YFV0Zs6y891aDAd4ld6UULTEcpvvqw1RAnL+GAPPmNIt1TYDMcdcHjt5A 8m7BiawPl4hKpKA7SptSST6iq5UKcMO2Lp+Rr7D0jWGKKoa5UQPS4naStfh8WY8Wls82 y4XUHfWqj3Emz5uwwtSrC12dgXEthB/O0y50iqy9rN9AANFBMJOBWQ7sFOyuh7SysqEA TBx49naDmbyG2/8i4FZ4ytD0MTl1gFuq3PPlK42T8OtXkv7VS22fps9XW6Uvq7O9ll6j 0LSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:dkim-signature; bh=nbVYkFoN0sJ+I2FUooWO9pwNnNtgPmlbc857RSYkSMI=; b=JHZfGrUBgb21JYogxnLOxpgmJHRzPBSgWI7UNc9xQU2ddLXAaIXexPyvTAWAlwCrU8 QhMQ5YYLUsj3eHLRkEjhCWbLncnYKICjffZ9UTkYY4waV/6WfrMJONUbZfVF8PUxFosN KVKmcT6tiZevbmEhdK3eSCK3Bu7edUczBiK+WIuuC+Kd/ZAMiOg8OPIWNgcwQwMNNl2m Eh4m8wtBcRPVH3an+iaN79TEqhYDVnpq16kVVcoXbdqccQ6ngdzW4+D4I9t0gP8dL8Yl lMirgZddzhLHO1nrmDYpt5sPr95sohIJixIh/NkKZLbSwSOSDvDRNVbmsUxlmYXhE9tO LppQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zmpq/G2G"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t22si1545605otc.167.2020.02.21.07.30.07; Fri, 21 Feb 2020 07:30:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zmpq/G2G"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728895AbgBUP3p (ORCPT + 99 others); Fri, 21 Feb 2020 10:29:45 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35542 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbgBUP3p (ORCPT ); Fri, 21 Feb 2020 10:29:45 -0500 Received: by mail-pf1-f193.google.com with SMTP id i19so1397467pfa.2 for ; Fri, 21 Feb 2020 07:29:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=nbVYkFoN0sJ+I2FUooWO9pwNnNtgPmlbc857RSYkSMI=; b=zmpq/G2G/WSdTO0fePtw0amnGiJEca4m6R1dOf1ra3oij697B523LEWAZe6svpwAth CsDDMMxF9k9ZET+mRNiltGGBZOtghgXXJAu0QXpTE+PeoC9ImVVGly5b03XxAU8JoTUT GUyevVFuEClNTvCoSQyUFWjWJPRttR6d2TqF94m2/WY2+FhKEud3hVNfLMBNeomchr5i Fx3jrQRzhQXNtORvn14K9oNKXncUl+l9aCM65choH7LPuBpQzBnjGXM4XruwM28Fr8Sx 6fg1VDdCgihMz2kDDTvcg/RThu6pjpW0Q42BudAtQXQYfnCikRI2B9f219LyB5wf30SX AHqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=nbVYkFoN0sJ+I2FUooWO9pwNnNtgPmlbc857RSYkSMI=; b=T/P2/5iT1OyVyTUbYzVXR6aGGkf59wdxyxATPsFziYkp2H/CluMt53xeVjKFh5sj5i S2axCSidb6HohaqPo4zIsUCs6g8KiQvyBIbk6gkYigPvKrmoZKnPvYQbF2vI3d4CUl9t j4Z/uhBxyjrqyvGklyM1vtZGDqU+B/lZfr4viT8aqSBXJDk7d1/kAlpwMKVSNfcaSilw yHU50IhPn9rejVm+8NC0OBRpYsTTqCX1pwEowuDfGj1lrYDGW8FRgrpGpLpNgtbsOyWL Aqx4OjxZk4SP4Tlr8fXsMwP/PB7/9YF2VHTWFYKhSa1atDC8jFyoPIlc5262Pf7oTq0/ TCMA== X-Gm-Message-State: APjAAAWfpbN5iq36yUKmaFQhtIUgmoK6RXorDwz99tYNvEysgEe2PmPD zHMB+AWwXLqRGuwAEchT/YSFmcK1x5ee6i+C X-Received: by 2002:aa7:8101:: with SMTP id b1mr38558716pfi.105.1582298984615; Fri, 21 Feb 2020 07:29:44 -0800 (PST) Received: from leoy-ThinkPad-X240s ([2400:8904::f03c:91ff:fe8a:bbb8]) by smtp.gmail.com with ESMTPSA id t8sm2910258pjy.20.2020.02.21.07.29.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Feb 2020 07:29:44 -0800 (PST) Date: Fri, 21 Feb 2020 23:29:22 +0800 From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Kate Stewart , Greg Kroah-Hartman , Allison Randal , John Garry , Enrico Weigelt , linux-kernel@vger.kernel.org, Mike Leach , Mathieu Poirier , "Naveen N. Rao" , Hendrik Brueckner , Thomas Richter Subject: Re: [PATCH] perf symbols: Consolidate symbol fixup issue Message-ID: <20200221152922.GA23282@leoy-ThinkPad-X240s> References: <20200221152324.22018-1-leo.yan@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200221152324.22018-1-leo.yan@linaro.org> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Looping PowerPC developers. On Fri, Feb 21, 2020 at 11:23:24PM +0800, Leo Yan wrote: > After copying Arm64's perf archive with object files and perf.data file > to x86 laptop, the x86's perf kernel symbol resolution fails. It > outputs 'unknown' for all symbols parsing. > > This issue is root caused by the function elf__needs_adjust_symbols(), > x86 perf tool uses one weak version, Arm64 (and powerpc) has rewritten > their own version. elf__needs_adjust_symbols() decides if need to parse > symbols with the relative offset address; but x86 building uses the weak > function which misses to check for the elf type 'ET_DYN', so that it > cannot parse symbols in Arm DSOs due to the wrong result from > elf__needs_adjust_symbols(). > > The DSO parsing should not depend on any specific architecture perf > building; e.g. x86 perf tool can parse Arm and Arm64 DSOs, vice versa. > So this patch changes elf__needs_adjust_symbols() as a common function > and removes the arch specific functions for Arm64 and powerpc. > > In the common elf__needs_adjust_symbols(), it checks elf header and if > the machine type is one of Arm64/ppc/ppc64, it checks extra condition > for 'ET_DYN'. Finally, the Arm64 DSO can be parsed properly with x86's > perf tool. > > Before: > > # perf script > main 3258 1 branches: 0 [unknown] ([unknown]) => ffff800010c4665c [unknown] ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c46670 [unknown] ([kernel.kallsyms]) => ffff800010c4eaec [unknown] ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c4eaec [unknown] ([kernel.kallsyms]) => ffff800010c4eb00 [unknown] ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c4eb08 [unknown] ([kernel.kallsyms]) => ffff800010c4e780 [unknown] ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c4e7a0 [unknown] ([kernel.kallsyms]) => ffff800010c4eeac [unknown] ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c4eebc [unknown] ([kernel.kallsyms]) => ffff800010c4ed80 [unknown] ([kernel.kallsyms]) > > After: > > # perf script > main 3258 1 branches: 0 [unknown] ([unknown]) => ffff800010c4665c coresight_timeout+0x54 ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c46670 coresight_timeout+0x68 ([kernel.kallsyms]) => ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms]) => ffff800010c4eb00 etm4_enable_hw+0x3e0 ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c4eb08 etm4_enable_hw+0x3e8 ([kernel.kallsyms]) => ffff800010c4e780 etm4_enable_hw+0x60 ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c4e7a0 etm4_enable_hw+0x80 ([kernel.kallsyms]) => ffff800010c4eeac etm4_enable+0x2d4 ([kernel.kallsyms]) > main 3258 1 branches: ffff800010c4eebc etm4_enable+0x2e4 ([kernel.kallsyms]) => ffff800010c4ed80 etm4_enable+0x1a8 ([kernel.kallsyms]) > > Reported-by: Mike Leach > Signed-off-by: Leo Yan > --- > tools/perf/arch/arm64/util/sym-handling.c | 19 ------------------- > tools/perf/arch/powerpc/util/sym-handling.c | 10 ---------- > tools/perf/util/symbol-elf.c | 8 +++++++- > 3 files changed, 7 insertions(+), 30 deletions(-) > delete mode 100644 tools/perf/arch/arm64/util/sym-handling.c > > diff --git a/tools/perf/arch/arm64/util/sym-handling.c b/tools/perf/arch/arm64/util/sym-handling.c > deleted file mode 100644 > index 8dfa3e5229f1..000000000000 > --- a/tools/perf/arch/arm64/util/sym-handling.c > +++ /dev/null > @@ -1,19 +0,0 @@ > -// SPDX-License-Identifier: GPL-2.0-only > -/* > - * > - * Copyright (C) 2015 Naveen N. Rao, IBM Corporation > - */ > - > -#include "symbol.h" // for the elf__needs_adjust_symbols() prototype > -#include > - > -#ifdef HAVE_LIBELF_SUPPORT > -#include > - > -bool elf__needs_adjust_symbols(GElf_Ehdr ehdr) > -{ > - return ehdr.e_type == ET_EXEC || > - ehdr.e_type == ET_REL || > - ehdr.e_type == ET_DYN; > -} > -#endif > diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c > index abb7a12d8f93..0856b32f9e08 100644 > --- a/tools/perf/arch/powerpc/util/sym-handling.c > +++ b/tools/perf/arch/powerpc/util/sym-handling.c > @@ -10,16 +10,6 @@ > #include "probe-event.h" > #include "probe-file.h" > > -#ifdef HAVE_LIBELF_SUPPORT > -bool elf__needs_adjust_symbols(GElf_Ehdr ehdr) > -{ > - return ehdr.e_type == ET_EXEC || > - ehdr.e_type == ET_REL || > - ehdr.e_type == ET_DYN; > -} > - > -#endif > - > int arch__choose_best_symbol(struct symbol *syma, > struct symbol *symb __maybe_unused) > { > diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c > index 1965aefccb02..ee788ac67415 100644 > --- a/tools/perf/util/symbol-elf.c > +++ b/tools/perf/util/symbol-elf.c > @@ -704,8 +704,14 @@ void symsrc__destroy(struct symsrc *ss) > close(ss->fd); > } > > -bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr) > +bool elf__needs_adjust_symbols(GElf_Ehdr ehdr) > { > + if (ehdr.e_machine == EM_AARCH64 || > + ehdr.e_machine == EM_PPC || > + ehdr.e_machine == EM_PPC64) > + return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL || > + ehdr.e_type == ET_DYN; > + > return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL; > } > > -- > 2.17.1 >