From patchwork Tue Jan 31 13:16:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 50847 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2747339wrn; Tue, 31 Jan 2023 05:23:05 -0800 (PST) X-Google-Smtp-Source: AK7set9nn+DFplgPFbI9t+eyCCZgepypOX8G66Y7dPK6SeS5m3ANISQu9Kf5BOH2YHeoXoqbNAWO X-Received: by 2002:a17:90b:3891:b0:22b:ecec:aba6 with SMTP id mu17-20020a17090b389100b0022bececaba6mr29091646pjb.26.1675171385540; Tue, 31 Jan 2023 05:23:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675171385; cv=none; d=google.com; s=arc-20160816; b=Z1+ittYcTg/poNQivQSEm1D1e1Xa7dHpXqfYx/AmBYXy+cPmghGVHtc4wKvEI7G2uW fK1xZF72nyHk10IIFNrcSgOjlPan51tW8NCJHkp4xuq70AyYUZDxTBD3iDVZ1/TYTp20 dB5xPz7gPNMVHUsyQnzRg4IeqJJNXreQR/PpxsBqPsnBGtAHMvZzxz0CyDicQgthp+46 hilGipRZdZzCVA9/o0oHCU3uy4U9LbQd0hrTG66369PJTvlr/8DmN4c1wzl+AGFCCX/P HqiiUh5xQNwXWjYkMXmvftnryfW7aPWZSpLtqBXCQFtk29DWiJIFqGCteKIoo65AGHFN Tmgg== 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=AsL7Nr8/yMHdcVD7i6dH05sudp8BcA9/SlgLgW/fdsw=; b=CUmkfWHSVDS544L/wVpMcHNvU3O8BzEI0AlleVM5h1dKuOu9KC+aMRKb8vV+WL9m6g GN41MQdKK9gjhm+evF/3WCGrolMjyOItwJY/HdPvtQq33eIr1PuGJttnDQvQwKTwzolF Wxa/1nln9jWefhzR3/o/OeZB04uusA326JjZhJaYHZjRA2si/A0YYweLuM+3I8lNCMO3 /uqnnIQBh6n82xStoSDU41bmExdsx+fn+aOb4F90q2zPMESTjVVpEW5MyUXxA+k+eTNj q91V7UlVFBhf61DA+eGr+FfLEEwxebVv4qrtU4dbFhPmvLCfcfRzUJ+kLOxj86z4M30X Ya4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IhcUoNCc; 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 b23-20020a17090aa59700b0022bb87f2dfdsi15534489pjq.129.2023.01.31.05.22.52; Tue, 31 Jan 2023 05:23:05 -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=IhcUoNCc; 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 S231846AbjAaNRG (ORCPT + 99 others); Tue, 31 Jan 2023 08:17:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231705AbjAaNQ4 (ORCPT ); Tue, 31 Jan 2023 08:16:56 -0500 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DF3E367DF; Tue, 31 Jan 2023 05:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675171013; x=1706707013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xv79CpMJX0N54gB4CsU1GJfMgJBj74HpxOAnf609a00=; b=IhcUoNCcvxeTkKYkaetKU6zRIrEZ2kdUNru73cPRsr76mFGWraU7pHVW Sp4/mID7U3oMUcjCId2k8/nBNYoRLtikf9HZA3MNsSRf5HnZc3Ahl2Wsi sCnzmh/f9rjKrUQZNiw9nJyfzjZPwd2/qV0MQZ3Xd/l8/vODLmnulNehn chpLda/0YFBjT/T7hEy+Ai8mZTFh+bMEr3Xj3R4lmIel1PZeyWKZq4lKL Y2bdQsgN0Lg29VvwB0urDYZPOEvQ3x2WNlub0MKE+L7wOELw0Hz0zvuji WKWS9awXRJAHz9jqF5U4jpveeaLIutanZPXXzN7Yj3A3DtkMbaz48rghj A==; X-IronPort-AV: E=McAfee;i="6500,9779,10606"; a="325534189" X-IronPort-AV: E=Sophos;i="5.97,261,1669104000"; d="scan'208";a="325534189" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2023 05:16:52 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10606"; a="657864838" X-IronPort-AV: E=Sophos;i="5.97,261,1669104000"; d="scan'208";a="657864838" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.47.218]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2023 05:16:50 -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 V2 6/9] perf symbols: Allow for .plt without header Date: Tue, 31 Jan 2023 15:16:22 +0200 Message-Id: <20230131131625.6964-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230131131625.6964-1-adrian.hunter@intel.com> References: <20230131131625.6964-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?1756544511046771097?= X-GMAIL-MSGID: =?utf-8?q?1756544511046771097?= A static executable can have a .plt due to the presence of IFUNCs. In that case the .plt does not have a header. Check for whether there is a header by comparing the number of entries to the number of relocation entries. Signed-off-by: Adrian Hunter --- 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 a002fc0bea03..8f7802097c72 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -489,6 +489,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) Elf *elf; int nr = 0, err = -1; struct rel_info ri = { .is_rela = false }; + bool lazy_plt; elf = ss->elf; ehdr = ss->ehdr; @@ -523,8 +524,10 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) plt_sym->end = plt_sym->start + shdr_plt.sh_size; /* Use .plt.sec offset */ plt_offset = plt_sec_shdr.sh_offset; + lazy_plt = false; } else { - plt_offset = shdr_plt.sh_offset + plt_header_size; + plt_offset = shdr_plt.sh_offset; + lazy_plt = true; } scn_dynsym = ss->dynsym; @@ -577,6 +580,17 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) ri.is_rela = shdr_rel_plt.sh_type == SHT_RELA; + if (lazy_plt) { + /* + * Assume a .plt with the same number of entries as the number + * of relocation entries is not lazy and does not have a header. + */ + if (ri.nr_entries * plt_entry_size == shdr_plt.sh_size) + dso__delete_symbol(dso, plt_sym); + else + plt_offset += plt_header_size; + } + /* * x86 doesn't insert IFUNC relocations in .plt order, so sort to get * back in order.