Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5624097ybf; Thu, 5 Mar 2020 04:09:04 -0800 (PST) X-Google-Smtp-Source: ADFU+vvlsCxkcJaxFGXBgJkS1Xp0UBo5zkzAD0ko08Y5gLzPRa5jeb0bOt9VXmDqqcNr3YTEWYao X-Received: by 2002:a05:6830:108d:: with SMTP id y13mr6506556oto.241.1583410144386; Thu, 05 Mar 2020 04:09:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583410144; cv=none; d=google.com; s=arc-20160816; b=q0AptUzfngaDX9Q2AouE6ktuuxuIoRhFdw7BK/L/w/vhNMcQuWC0a4zSpUHxm6tBkr VQHX8YFi8NsLsBTab1bL6buywcU+GqYPt6iFNIhoqUGJH14pyf/q96Bd3MHqXYaKF/0K AUmDSbSQ0hAtGL1ug9a9ZCd5wRSTTQsoAmtFLAAnI3SkQaj7I3qds+a5wVzRd6Ju3kj4 YHwwjeOzR0uLBQd4riexo3gQtYZIyPz4h10QpZczYmtuUX4tUVPnGeMdwZhDV68k8xsp 0mVFadFMTSblGfMgdM3ONsDwA0IXpQ46x61JkaCQR++Zb81Ta3fjt6ccIyKn6DbnbAs+ DyVQ== 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:cc :to:from:date:dkim-signature; bh=UIbbEs41/Nl1YQgpb4EpsfEdoNW0JqlObDtghuhl7Fc=; b=tlltPcngSPJ4/u/eiSlD6WN1KiRGdVKJUKgWsQbvPuyx9UBi6KO8/GrPyIENRntCnn cIK29ts9OGA6UGS2b4DEUPG4+gtStZgx9hV3CGJxrMRhzwVZY90pH9kC8hwOyoi6y1iX kL1OzfjD/LI6ddfRkdpxYLF722uxu+Dglw2cr7EPu6FDQ+BiGsqbLNvdWycYfLK9Hn1L CHYplx5XX+/GohENHCTruBqpK6bXw+irvASry/9NE8qJThX0cJ/g4uFhv4owTqzOnLmd YnBvsb5zL2/+nvsr7wkd00BPSfH36nFYkyIoWuD6GrX+eJo2vz81qPgt73N0fGezK8Yn ZAcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n+VKsdoJ; 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 v81si3442971oia.114.2020.03.05.04.08.51; Thu, 05 Mar 2020 04:09:04 -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=n+VKsdoJ; 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 S1726861AbgCEMH5 (ORCPT + 99 others); Thu, 5 Mar 2020 07:07:57 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44823 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbgCEMH5 (ORCPT ); Thu, 5 Mar 2020 07:07:57 -0500 Received: by mail-pl1-f196.google.com with SMTP id d9so2548708plo.11 for ; Thu, 05 Mar 2020 04:07:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=UIbbEs41/Nl1YQgpb4EpsfEdoNW0JqlObDtghuhl7Fc=; b=n+VKsdoJb3+cZXqIxeIftUjiy1LsU8jHX48aYN4biT6csja2fMfMKMjk4FLUCsCnLB lvTg3ezPMaE+jE0AQBca9yUJzsbNnHnjenD4WJM9za8dejz17kBICftjrk6E/TsWSCe7 ISF4T7ERPKwt2lRAsMkjwJqiWE/+WsRZmYON9XzR/EFevnQI7CsFc5DbORYHX6yxHXWm R+PSF+gHosab4EY+1OgWPKCfuEVAG//aYDqgyneN1ijh4yr+lfs4jXv4/8wtb/c0FeOk Nn/E0RN6/ezG+5JCaTypwvBsymCf4PwkSSCxY+gAc+M21G/uz7l3y6iICDywTJSp+Fhj 6KLA== 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:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=UIbbEs41/Nl1YQgpb4EpsfEdoNW0JqlObDtghuhl7Fc=; b=eZmL3NBEYk/p8ihBBddPF4tDN1n2oX9y9LM4dxOI40I/T8G7Fok5pHOxW6Mshd+c/E h69dPg5n/aii/Kt1pghLJsRL09nBZfoXKXtyrrF0XGsWXhHsyrQJSdSJG7KxqBricpDI 7hw6jJGCwDounVmfUOaKm6UQFgfFOYhZWxdGna5xlDVpSI9yZRyIZtJEMHg5Qkvvv5SJ ta9Wsra8KFR7dtZ2hULcAW7/nYhz3T3kBFL60dW/W1ubFwN+5jIapEUz5qL5XUlJXEbc k/RW++0VI8HPiJn5u2oIC2wy9p6GLsb5clFB9bOXK9kLdCzmxSMj9Ae2f8oCyYZydESj ppzw== X-Gm-Message-State: ANhLgQ24eXk4PabXUpMptogWzWtO8+6jSe2HLmDKOy6y/eiIzH93GkuW JEfzpZVTILJmQnO/baICKRjW2Q== X-Received: by 2002:a17:902:c154:: with SMTP id 20mr7912464plj.112.1583410075977; Thu, 05 Mar 2020 04:07:55 -0800 (PST) Received: from leoy-ThinkPad-X240s ([2400:8902::f03c:91ff:fe3f:ee42]) by smtp.gmail.com with ESMTPSA id y1sm28801517pgs.74.2020.03.05.04.07.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 05 Mar 2020 04:07:55 -0800 (PST) Date: Thu, 5 Mar 2020 20:07:38 +0800 From: Leo Yan To: "Naveen N. Rao" Cc: Arnaldo Carvalho de Melo , Alexander Shishkin , Allison Randal , Hendrik Brueckner , Greg Kroah-Hartman , Enrico Weigelt , John Garry , Jiri Olsa , Kate Stewart , linux-kernel@vger.kernel.org, Mark Rutland , Mathieu Poirier , Mike Leach , Ingo Molnar , Namhyung Kim , Peter Zijlstra , Thomas Gleixner , Thomas Richter Subject: Re: [PATCH v2] perf symbols: Consolidate symbol fixup issue Message-ID: <20200305120738.GA31049@leoy-ThinkPad-X240s> References: <20200303110407.28162-1-leo.yan@linaro.org> <1583405831.eapbxpc3ni.naveen@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1583405831.eapbxpc3ni.naveen@linux.ibm.com> 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 Hi Naveen, On Thu, Mar 05, 2020 at 04:32:30PM +0530, Naveen N. Rao wrote: > 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]) > > > > I am not able to reproduce this since powerpc64 kernels are not being built > as ET_EXEC anymore. Thanks for reviewing! Based on the context, I think you mean powerpc64 kernels are not being built as ET_DYN anymore (and now change to ET_EXEC). > > v2: Fixed Arm64 and powerpc native building. > > > > Reported-by: Mike Leach > > Signed-off-by: Leo Yan > > --- > > tools/perf/arch/arm64/util/Build | 1 - > > tools/perf/arch/arm64/util/sym-handling.c | 19 ------------------- > > tools/perf/arch/powerpc/util/Build | 1 - > > tools/perf/arch/powerpc/util/sym-handling.c | 10 ---------- > > tools/perf/util/symbol-elf.c | 8 +++++++- > > 5 files changed, 7 insertions(+), 32 deletions(-) > > delete mode 100644 tools/perf/arch/arm64/util/sym-handling.c > > > > diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build > > index 0a7782c61209..789956f76d85 100644 > > --- a/tools/perf/arch/arm64/util/Build > > +++ b/tools/perf/arch/arm64/util/Build > > @@ -1,6 +1,5 @@ > > perf-y += header.o > > perf-y += perf_regs.o > > -perf-y += sym-handling.o > > perf-$(CONFIG_DWARF) += dwarf-regs.o > > perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o > > perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o > > 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/Build b/tools/perf/arch/powerpc/util/Build > > index 7cf0b8803097..e5c9504f8586 100644 > > --- a/tools/perf/arch/powerpc/util/Build > > +++ b/tools/perf/arch/powerpc/util/Build > > @@ -1,5 +1,4 @@ > > perf-y += header.o > > -perf-y += sym-handling.o > > perf-y += kvm-stat.o > > perf-y += perf_regs.o > > perf-y += mem-events.o > > 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; > > Patch looks good to me. However: Can I add your review tag? > This is only used for checking kernel, so I wonder if we can simply include > check for ET_DYN across all architectures? This would only matter if there > are architectures building their kernel as ET_DYN that _don't_ want to > adjust symbols. Seems only Arm64 enables the link option '-share' for LDFLAGS_vmlinux; I confirmed with below command: $ find arch -name 'Makefile' -exec grep -n '\-share' {} + | grep vmlinux arch/arm64/Makefile:21:LDFLAGS_vmlinux += -shared -Bsymbolic -z notext -z norelro \ Also reviewed the output for searching '\-share' for all Makefiles under 'arch' folder, many architectures use it for vdso but only Arm64 enables '-share' for vmlinux linkage. If so, your suggestion is valid and we can simply include check for ET_DYN for all archs (and it's better to add comment for this). I'd like to wait a bit for anyone has other ideas, and if no objection will send out new patch for this. Thanks, Leo