From patchwork Fri Jan 20 12:34:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp172891wrn; Fri, 20 Jan 2023 04:36:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXvmuXiWfZvbOEj1w+8qXSYh19ySyqtiORA2/aC/fpbStGG6ihcdHSXV8j+hDkOKw2GLqFtK X-Received: by 2002:a17:906:7f93:b0:872:cc4:f036 with SMTP id f19-20020a1709067f9300b008720cc4f036mr15593933ejr.57.1674218212754; Fri, 20 Jan 2023 04:36:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218212; cv=none; d=google.com; s=arc-20160816; b=tyY2+wYlyi2dTkuqd+2ySryewPJIPii37TDadptq7EK32hHRWhnoXNC26kMyL5Z0Pz HN9RWke2YN1NlTTQeJCEvRquAolbBIywm7U8gb2sdHxTUjsQ22YTcYEk67M7x/R1Jlgj t7V3HecE1f/3N3/WNbx4SEQ5difx0Ty1qqV8X3kHyTr137rtpSj30NnOCCxqIVSv4soc gc75vNRk+/DrXpY3TJD+N7db3RGqE1aBP7Vhtk461ICso+saWjO3JgY2QY/+R1ZPAV0t TV9YjbYFLE4p2JFLD1ZzOHMP/nmAhpYqtw0QzylZxi7N0KC/MAzHUhcoPkLJHfSEx0Et xmtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KY+TVbjFyqJf2bxVRUpNnotScn8uU8ZkzpQ1HVvCImw=; b=SOm67DQkvGXYCNQ8m7BcT7OWRMIU6rAbcUy/cEvA0d/uzeOWyGDzOJF7J2FuDZJm4C DHo7iAnvcODwRGviHUWnRoLYhQm9PoPxIkIgt1zDKByYb2GZHVvjk+vwg+E+FddTenqT 2Nj6a874GFIN8BenBd7hqcaQ0hW+BrjA3eq3H1WZ1037TAhaZceZh82pxRDNEuL9Ilnp jXou4GWXUyeVuJO2eKkdGa1B20pDTL4jFks+IrPs/YNxWjMlsoFubZXwxkfYCw24iuaf 5xNyvjZeanFGWmQ4lBQxQpphC+83fmnMYnx/j5tDuhXcQ8zblO5gBx68O1leGFpI73eU qM3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kh+4gDkO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ek15-20020a056402370f00b0049e65015797si5818620edb.564.2023.01.20.04.36.28; Fri, 20 Jan 2023 04:36:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kh+4gDkO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230176AbjATMgD (ORCPT + 99 others); Fri, 20 Jan 2023 07:36:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230207AbjATMfy (ORCPT ); Fri, 20 Jan 2023 07:35:54 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38FE5BC883; Fri, 20 Jan 2023 04:35:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218132; x=1705754132; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WY7A8kXmLodxsZZKsPIN5lstuixMq8OdTgkIL+AMf/o=; b=kh+4gDkOrkk+Rz0WY67KcFbHEjP7x253k/J9OZdBTnwG0rkuUAmJ6HB6 Px3FkqIo1Qfua92JCpr31Fs9m5a3o3j+2P6tl6XLcz1gunfvqdOg/eghx pwLatkM2Ori+EJ5Ca2tCxZksfOgeddv+LJZ0Vw2jCs7vPbdAu88cTQwRH XEJqwpyCGuwVicSlJkU0GSHuWNrF5YCg29Y0Ag14Mc0oU7xv0qACpDBK6 iRmCMX8krnHRh37YSK6V6vqBGtwJTXCuLfKb4c+hMT732ieM7hLvGckD1 jpCQoUapvvtPKuk/IBxvRV8zRToDovhle34zqCXN8AWWiNujmqdjhXa+D A==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935260" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935260" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2023 04:35:31 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847446" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847446" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.251.223.163]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jan 2023 04:35:29 -0800 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH 07/10] perf symbols: Add symbol for .plt header Date: Fri, 20 Jan 2023 14:34:53 +0200 Message-Id: <20230120123456.12449-8-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230120123456.12449-1-adrian.hunter@intel.com> References: <20230120123456.12449-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755545036627016384?= X-GMAIL-MSGID: =?utf-8?q?1755545036627016384?= perf expands the _init symbol over .plt because there are no PLT symbols at that point, but then dso__synthesize_plt_symbols() creates them. Fix by truncating the previous symbol and inserting a symbol for .plt header. Example: Before: $ perf test --dso `which uname` -v Symbols 74: Symbols : --- start --- test child forked, pid 191028 Problems creating module maps, continuing anyway... Testing /usr/bin/uname Overlapping symbols: 2000-25f0 g _init 2040-2050 g free@plt test child finished with -1 ---- end ---- Symbols: FAILED! $ perf test --dso `which uname` -vv Symbols 2>/tmp/cmp1.txt After: $ perf test --dso `which uname` -v Symbols 74: Symbols : --- start --- test child forked, pid 194291 Testing /usr/bin/uname test child finished with 0 ---- end ---- Symbols: Ok $ perf test --dso `which uname` -vv Symbols 2>/tmp/cmp2.txt $ diff /tmp/cmp1.txt /tmp/cmp2.txt 4,5c4 < test child forked, pid 191031 < Problems creating module maps, continuing anyway... --- > test child forked, pid 194296 9c8,9 < 2000-25f0 g _init --- > 2000-2030 g _init > 2030-2040 g .plt 100,103c100 < Overlapping symbols: < 2000-25f0 g _init < 2040-2050 g free@plt < test child finished with -1 --- > test child finished with 0 105c102 < Symbols: FAILED! --- > Symbols: Ok $ Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 87b82507c205..a8b7c3860b2d 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -389,6 +389,27 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) elf = ss->elf; ehdr = ss->ehdr; + if (!elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL)) + return 0; + + /* + * A symbol from a previous section (e.g. .init) can have been expanded + * by symbols__fixup_end() to overlap .plt. Truncate it before adding + * a symbol for .plt header. + */ + f = dso__find_symbol_nocache(dso, shdr_plt.sh_offset); + if (f && f->start < shdr_plt.sh_offset && f->end > shdr_plt.sh_offset) + f->end = shdr_plt.sh_offset; + + if (!get_plt_sizes(dso, &ehdr, &shdr_plt, &plt_header_size, &plt_entry_size)) + return 0; + + /* Add a symbol for .plt header */ + f = symbol__new(shdr_plt.sh_offset, plt_header_size, STB_GLOBAL, STT_FUNC, ".plt"); + if (!f) + goto out_elf_end; + symbols__insert(&dso->symbols, f); + scn_dynsym = ss->dynsym; shdr_dynsym = ss->dynshdr; dynsym_idx = ss->dynsym_idx; @@ -408,9 +429,6 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) if (shdr_rel_plt.sh_link != dynsym_idx) goto out_elf_end; - if (elf_section_by_name(elf, &ehdr, &shdr_plt, ".plt", NULL) == NULL) - goto out_elf_end; - /* * Fetch the relocation section to find the idxes to the GOT * and the symbols in the .dynsym they refer to. @@ -436,8 +454,6 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) nr_rel_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize; plt_offset = shdr_plt.sh_offset; - if (!get_plt_sizes(dso, &ehdr, &shdr_plt, &plt_header_size, &plt_entry_size)) - return 0; plt_offset += plt_header_size; if (shdr_rel_plt.sh_type == SHT_RELA) {