From patchwork Fri Jan 27 17:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 49519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp940476wrn; Fri, 27 Jan 2023 09:05:45 -0800 (PST) X-Google-Smtp-Source: AK7set8ElpCpzPrfAHXsRYjPLwbXCs0PHzOeu735K4B3YX3J7MGXmLpZ892gxMOo+HJPzuUDtG1d X-Received: by 2002:aa7:864d:0:b0:581:95a7:d2f4 with SMTP id a13-20020aa7864d000000b0058195a7d2f4mr5169518pfo.9.1674839145143; Fri, 27 Jan 2023 09:05:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674839145; cv=none; d=google.com; s=arc-20160816; b=WRhUYOMRqIJ1kwaShQPrfoQxpHdQCvu6HY2ozPPpfU/A1Q0sNaX4gibPmJUXZP6gc6 J18T8dUZvFXMEx/2SJ/nR3kCZARCgZkg2sKHRj7oDy+66bmItYv1kfW6gU4Sb30+vmR7 nKsFpP35qIzgIdRHWaomIv7ErVbTn7cfCJNSJeq8lNqhR4f+qyj2oE5kDx+FrVa8Smof yjWpYkh4U0Bv5hvPP8x2wrFIBFkBTVGAvyg7V4eynHja7aO3T11sioelHIW/wcUAoDXU II8OXngjv/TBsFetbjSaLBRm31OKizBdO7FivSmzYbGxiEdp69olzGXxbqZg+eLlvJqv JLTQ== 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=M4BYyVhXwUQsgVTFUiG5p2hl3CXDjdoZ/caVa9RDRxcXf7Im+5nqLQzW/aJypbgHlU wf+IUay1MNLKSsRpW8I0Y5FyXh9xUYlAsignYvYA8aCdl3QKo4gV2aawx786cG7Bzyc4 KBpmL2TxkisoNK1yNezT/pg7i3QSOe17FmgcyignucfDY+CVFhR6i2n/1rhO+fO08my7 Zao3cldnlFUeO1F3kxcmDskLwdCdEWvyowBlvpWMnjjjju6/OxPDB4ElqIxGwTLXpYYo eonTFiEzYJaIVkqj9iTmVIKoobyD/euC1NBFms6OEwXUSri5gnI6eiSKvHmf5vn3fMbS PC4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="ljfcj4/W"; 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 x17-20020a656ab1000000b004769983b39asi4878133pgu.667.2023.01.27.09.05.31; Fri, 27 Jan 2023 09:05:45 -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="ljfcj4/W"; 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 S234793AbjA0RDz (ORCPT + 99 others); Fri, 27 Jan 2023 12:03:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234105AbjA0RDq (ORCPT ); Fri, 27 Jan 2023 12:03:46 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 383ED7EFF8; Fri, 27 Jan 2023 09:03:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674838996; x=1706374996; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xv79CpMJX0N54gB4CsU1GJfMgJBj74HpxOAnf609a00=; b=ljfcj4/WheW/9Osj5aXcLUhjczUD6TgbY7uVs+/AMEP3R2c/EWRRnh5K U0jR7LzK1jK3qCkBcNGUNan15BqWs5TS4D5BYQOV9Do4SQS8e3M64OOzw FGv+iAMKpUpgYoVzaeIUyjbCMLzg2CC6NfushB1+/OzlWq1fOTjm+YdPD HwvZEnOTp4l7Vr7jWWsxUh+RuuvU2vo+KiAjjj5xPVvMq4vIS5uFuA+VJ G2izRcsmB9/rp1A2K3rqg8SuEeAIIrqxkBxlCXbRocO3ZXOjWZmWeHIcg OaxpZI2ZR2MTEYdP+c+U8D7zhBYEvgRX0rAcUCdoiKhCI9NfhZsCWv2Az Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10603"; a="310754181" X-IronPort-AV: E=Sophos;i="5.97,251,1669104000"; d="scan'208";a="310754181" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2023 09:02:47 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10603"; a="726739242" X-IronPort-AV: E=Sophos;i="5.97,251,1669104000"; d="scan'208";a="726739242" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.57.171]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2023 09:02:45 -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 6/9] perf symbols: Allow for .plt without header Date: Fri, 27 Jan 2023 19:02:19 +0200 Message-Id: <20230127170222.9895-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127170222.9895-1-adrian.hunter@intel.com> References: <20230127170222.9895-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=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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?1756196131617602679?= X-GMAIL-MSGID: =?utf-8?q?1756196131617602679?= 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.