From patchwork Fri Jan 20 12:34:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp172609wrn; Fri, 20 Jan 2023 04:36:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXuCybVpN37VSkfaWl+Ra2N4dm4c+iycL9SCj/xkFw9ijSna3kKsUThZUwpHQQlMujbyrIuh X-Received: by 2002:aa7:cc81:0:b0:47e:eaae:9a5b with SMTP id p1-20020aa7cc81000000b0047eeaae9a5bmr14410233edt.42.1674218169158; Fri, 20 Jan 2023 04:36:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218169; cv=none; d=google.com; s=arc-20160816; b=XnkX6Ga7k4WA5T5UU+q/5vwPaCcjEMtxLC7Sbt+2AItl8GKjvnIr1b0aYIfnnIYWNk 98WHnP59hPWQZAplIq9BSoKwDCK0nNd5f7zIwHq5DDChLah/G16X2SNnsby6bQM12weI r3kpqTmuzzrbvcAo6Cidb4koaNOp57AjQlupXez3vcPZJ74o7caPs+WtbiD5sF4AyF8Q Fqe5SWlkLzM1nUYYIE/wDcda9Gt5d6WXvxOT8gS4tW9jLuWe66VHHxAXyYvg79ELoW8D HO8+ujMTUxyfC+xZWojWyJQNx3RhAQ93Gm5NQBChyyaodvYEmpBe5lFKy94IS7+R85LF gfNA== 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=Kr2oEOVHftWIqmUVwiKnoS7wQ9snZKIs/qsygAu2xRQ=; b=Aj5JYF8NwqJG//hJxK2mvK4d/r5fv2RxnjXlrFFIrvn+elW4Ed4Uiazj/B8y6mQ7BR 5LPi92D1Ku09DNnMgqL4t+H37WnD2F3/akVOyN9zEA3TYFHQHI0ykrOspYo97vY1yeN/ sS9BZ6+0lNmU6Z9xDXkh+LaFiWTd20PqT+mIUf7N+m+UibSmWZe7ptMl+xxAc8GKjuZV O8PR2lFetABcn5ask3dtgxyEmGQ7ICQ56LcBUkdy/1eZH7ekc97kadYR96xeTF2EVyKF hUtdtFHUHpfK8Rc6Fm/gdd3JWRtilLH3eXh4peRRtXc5oF94QUY1DOJZgnYgltDTuhJ2 tclA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lhDrKApw; 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 u1-20020a50a401000000b0048ee37983a0si44040231edb.178.2023.01.20.04.35.45; Fri, 20 Jan 2023 04:36:09 -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=lhDrKApw; 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 S230127AbjATMf3 (ORCPT + 99 others); Fri, 20 Jan 2023 07:35:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230123AbjATMfZ (ORCPT ); Fri, 20 Jan 2023 07:35:25 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA1ECBC89B; Fri, 20 Jan 2023 04:35:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218121; x=1705754121; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hqHivyH65I+zqpnOfFxb+qPLJLaHYIND6bguoxV+hQg=; b=lhDrKApw185+HQTFm8vX/tWsbEQaC1oGaqnc3jOaUtnPt/CYJEgJ+QsE uaZWlDAt8CAxnZttKJ5j62s8afaLliUZaZcVenKd2IAEbbTnkAgqBcDnC 6HT4s0D7FhUeX0UcIAaNiPIGjRjWWxRlf1bD5tg2b613U36mKV8xOVQaD xFFdkr6ZLMaz9dbk3WvyMdGlaPcnnmClPXcIWnG47cpMWBcljikIEKixN crXm+DY9MMKQuCCbUAJzrB/R+GAzqFhsUuyEbqqvkBOQTwKvNW/FXVwih /IRLGZVZeci35iHLmTpTq6cnzXvIMklL8eOFUQdLDfYtCBVHKmELURw7K A==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935186" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935186" 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:21 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847425" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847425" 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:18 -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 03/10] perf symbols: Check plt_entry_size is not zero Date: Fri, 20 Jan 2023 14:34:49 +0200 Message-Id: <20230120123456.12449-4-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?1755544990747281946?= X-GMAIL-MSGID: =?utf-8?q?1755544990747281946?= The code expects non-zero plt_entry_size. Check it and add a debug message to print if it is zero. Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 4605680a22a3..c6a4e6c73990 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -323,30 +323,33 @@ static char *demangle_sym(struct dso *dso, int kmodule, const char *elf_name) return demangled; } -static void get_plt_sizes(GElf_Ehdr *ehdr, GElf_Shdr *shdr_plt, +static bool get_plt_sizes(struct dso *dso, GElf_Ehdr *ehdr, GElf_Shdr *shdr_plt, u64 *plt_header_size, u64 *plt_entry_size) { switch (ehdr->e_machine) { case EM_ARM: *plt_header_size = 20; *plt_entry_size = 12; - return; + return true; case EM_AARCH64: *plt_header_size = 32; *plt_entry_size = 16; - return; + return true; case EM_SPARC: *plt_header_size = 48; *plt_entry_size = 12; - return; + return true; case EM_SPARCV9: *plt_header_size = 128; *plt_entry_size = 32; - return; + return true; default: /* FIXME: s390/alpha/mips/parisc/poperpc/sh/xtensa need to be checked */ *plt_header_size = shdr_plt->sh_entsize; *plt_entry_size = shdr_plt->sh_entsize; - return; + if (*plt_entry_size) + return true; + pr_debug("Missing PLT entry size for %s\n", dso->long_name); + return false; } } @@ -438,7 +441,8 @@ 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; - get_plt_sizes(&ehdr, &shdr_plt, &plt_header_size, &plt_entry_size); + 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) {