From patchwork Fri Jan 20 12:34:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp172542wrn; Fri, 20 Jan 2023 04:36:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXusP8sCYv4uN7ClJTtPLs5CvY6EiOjHSZIPtwGUVf/I4H/ciJ3iRXUhuTwNcmgRGSwV/9ix X-Received: by 2002:a17:907:2cf3:b0:86c:988d:178c with SMTP id hz19-20020a1709072cf300b0086c988d178cmr14990297ejc.52.1674218160620; Fri, 20 Jan 2023 04:36:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218160; cv=none; d=google.com; s=arc-20160816; b=0EiF3QlzvluUKtNRo2Y2ab+kEox6Kmtaja0eSTeALNRxOtC2ZmU8XFq60wKfhbonev XVMbeaQh0NDibYMKvbBsPs1URwA+sgo5FLarTmx5WuCua5N6uRjmSPyQtWG6nK+3LGwZ E9c0dnZb//AIpW3oS1ArULcfWwQ25kCrJmRpXqwCXvjIyO5uZf2dkKrj4XF1dHTL1DSI ZcTeWTJ2dGmA6UIzK/HjPW4F9xQbFPNUj4zSK62e/+q4iHssP3iMtRnB6+F0lkfqpnJa KezUpkEP7a9Gn0aywE7usz9MdqOC92buxSuORFLaPXPYRVi4/9YKpzOaIjxV+Dp3y4en JZgQ== 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=UCfaPgdW+1Dhk0iQvAbwORuvmMYvZ6sQjFLM6DYLXeU=; b=ajdkUQYxXn+YX1ADyVjg1/255ToefUvoeMSwb1Foqlki17laCJC76EH4EraYrjeuAs pRXeq79fIxG+pP+NEL/IOrsou59szmyS+PthIeKl+bWOQAo5x99lICUXJdi4FejIDba1 M2dOgymwnebB2aH85sw3aEJSCVlO36OtkvTqDXBFh5VXnU+lpM5bKz5Re1CBTyhq2rl7 kHKMg8D2Ch6mqjtiOLmv+XlXeqU/bZLqk26F+O9G9YYtQA1Ojt7c0lhkHm9kHtIw7hUR v9gIMhRrtXTHufKg1KhymB8rcD6US/dyCPRjs7UpSUOfEIskt73isGcF5tqkkBbg7ZGk HmBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BaORSXNN; 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 sd35-20020a1709076e2300b008776a7302e2si6792329ejc.402.2023.01.20.04.35.36; Fri, 20 Jan 2023 04:36:00 -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=BaORSXNN; 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 S230120AbjATMfU (ORCPT + 99 others); Fri, 20 Jan 2023 07:35:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230103AbjATMfR (ORCPT ); Fri, 20 Jan 2023 07:35:17 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95D0C2C656; Fri, 20 Jan 2023 04:35: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=1674218116; x=1705754116; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2X57CfR6KCOC5jRYy3gQh0I2KsDNwZmyV484WgF/6tY=; b=BaORSXNNCFyV3Ccjgv66binl9puWXuicV6Mc+xyypNEgXuIy3Rlsdq4k C1Mgs/GbZH+bwZAAMMgzeklo2mJ0x6D+V/yIiksMznAdouV/93HvbtODr Q57dvr0StG76aGbqYxrqU1caPbGoHyFqityXpUbe+7Jx5xDivrAFGU6I3 wVjHIKpDAVXVGDQIX1NEhMUa0t5M8tEqRI62q77Hu/VlROokImeL5wXXZ 58BxOXtwNmGgz9FRURO+jMffAsbQlVOJbRhMeqHD8D5AREja4G9TyJuCu NTmp4prvrV3g2o+lA7q8LQ2JFYQWnG9iU7uKQDYKP04hsoCokU2dx9IlZ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935149" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935149" 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:16 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847415" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847415" 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:13 -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 01/10] perf test: Add Symbols test Date: Fri, 20 Jan 2023 14:34:47 +0200 Message-Id: <20230120123456.12449-2-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?1755544981581124011?= X-GMAIL-MSGID: =?utf-8?q?1755544981581124011?= Add a test to check function symbols do not overlap and are not zero length. The main motivation for the test is to make it easier to review changes to PLT symbol synthesis i.e. changes to dso__synthesize_plt_symbols(). By default the test uses the perf executable as a test DSO, but a specific DSO can be specified via a new perf test option "--dso". The test is useful in the following ways: - Any DSO can be tested, even ones that do not run on the current architecture. For example, using cross-compiled DSOs to see how well perf handles different architectures. - With verbose > 1 (e.g. -vv), all the symbols are printed, which makes it easier to see issues. - perf removes duplicate symbols and expands zero-length symbols to reach the next symbol, however that is done before adding synthesized symbols, so the test is checking those also. Example: $ perf test -v Symbols 74: Symbols : --- start --- test child forked, pid 154918 Testing /home/user/bin/perf Overlapping symbols: 7d000-7f3a0 g _init 7d030-7d040 g __printf_chk@plt test child finished with -1 ---- end ---- Symbols: FAILED! Note the test fails because perf expands the _init symbol over the PLT because there are no PLT symbols at that point, but then dso__synthesize_plt_symbols() creates them. Signed-off-by: Adrian Hunter --- tools/perf/Documentation/perf-test.txt | 3 + tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 3 + tools/perf/tests/symbols.c | 150 +++++++++++++++++++++++++ tools/perf/tests/tests.h | 3 + 5 files changed, 160 insertions(+) create mode 100644 tools/perf/tests/symbols.c diff --git a/tools/perf/Documentation/perf-test.txt b/tools/perf/Documentation/perf-test.txt index b329c65d7f40..951a2f262872 100644 --- a/tools/perf/Documentation/perf-test.txt +++ b/tools/perf/Documentation/perf-test.txt @@ -34,3 +34,6 @@ OPTIONS -F:: --dont-fork:: Do not fork child for each test, run all tests within single process. + +--dso:: + Specify a DSO for the "Symbols" test. diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 90fd1eb317bb..fb9ac5dc4079 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -68,6 +68,7 @@ perf-y += perf-time-to-tsc.o perf-y += dlfilter-test.o perf-y += sigtrap.o perf-y += event_groups.o +perf-y += symbols.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index cfa61493c750..35cc3807cc9e 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -31,6 +31,7 @@ #include "builtin-test-list.h" static bool dont_fork; +const char *dso_to_test; struct test_suite *__weak arch_tests[] = { NULL, @@ -117,6 +118,7 @@ static struct test_suite *generic_tests[] = { &suite__dlfilter, &suite__sigtrap, &suite__event_groups, + &suite__symbols, NULL, }; @@ -521,6 +523,7 @@ int cmd_test(int argc, const char **argv) OPT_BOOLEAN('F', "dont-fork", &dont_fork, "Do not fork for testcase"), OPT_STRING('w', "workload", &workload, "work", "workload to run for testing"), + OPT_STRING(0, "dso", &dso_to_test, "dso", "dso to test"), OPT_END() }; const char * const test_subcommands[] = { "list", NULL }; diff --git a/tools/perf/tests/symbols.c b/tools/perf/tests/symbols.c new file mode 100644 index 000000000000..057b16df6416 --- /dev/null +++ b/tools/perf/tests/symbols.c @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "debug.h" +#include "dso.h" +#include "machine.h" +#include "thread.h" +#include "symbol.h" +#include "map.h" +#include "util.h" +#include "tests.h" + +struct test_info { + struct machine *machine; + struct thread *thread; +}; + +static int init_test_info(struct test_info *ti) +{ + ti->machine = machine__new_host(); + if (!ti->machine) { + pr_debug("machine__new_host() failed!\n"); + return TEST_FAIL; + } + + /* Create a dummy thread */ + ti->thread = machine__findnew_thread(ti->machine, 100, 100); + if (!ti->thread) { + pr_debug("machine__findnew_thread() failed!\n"); + return TEST_FAIL; + } + + return TEST_OK; +} + +static void exit_test_info(struct test_info *ti) +{ + thread__put(ti->thread); + machine__delete(ti->machine); +} + +static void get_test_dso_filename(char *filename, size_t max_sz) +{ + if (dso_to_test) + strlcpy(filename, dso_to_test, max_sz); + else + perf_exe(filename, max_sz); +} + +static int create_map(struct test_info *ti, char *filename, struct map **map_p) +{ + /* Create a dummy map at 0x100000 */ + *map_p = map__new(ti->machine, 0x100000, 0xffffffff, 0, NULL, + PROT_EXEC, 0, NULL, filename, ti->thread); + if (!*map_p) { + pr_debug("Failed to create map!"); + return TEST_FAIL; + } + + return TEST_OK; +} + +static int test_dso(struct dso *dso) +{ + struct symbol *last_sym = NULL; + struct rb_node *nd; + int ret = TEST_OK; + + /* dso__fprintf() prints all the symbols */ + if (verbose > 1) + dso__fprintf(dso, stderr); + + for (nd = rb_first_cached(&dso->symbols); nd; nd = rb_next(nd)) { + struct symbol *sym = rb_entry(nd, struct symbol, rb_node); + + if (sym->type != STT_FUNC && sym->type != STT_GNU_IFUNC) + continue; + + /* Check for overlapping function symbols */ + if (last_sym && sym->start < last_sym->end) { + pr_debug("Overlapping symbols:\n"); + symbol__fprintf(last_sym, stderr); + symbol__fprintf(sym, stderr); + ret = TEST_FAIL; + } + /* Check for zero-length function symbol */ + if (sym->start == sym->end) { + pr_debug("Zero-length symbol:\n"); + symbol__fprintf(sym, stderr); + ret = TEST_FAIL; + } + last_sym = sym; + } + + return ret; +} + +static int test_file(struct test_info *ti, char *filename) +{ + struct map *map = NULL; + int ret, nr; + + pr_debug("Testing %s\n", filename); + + ret = create_map(ti, filename, &map); + if (ret != TEST_OK) + return ret; + + nr = dso__load(map->dso, map); + if (nr < 0) { + pr_debug("dso__load() failed!\n"); + ret = TEST_FAIL; + goto out_put; + } + + if (nr == 0) { + pr_debug("DSO has no symbols!\n"); + ret = TEST_SKIP; + goto out_put; + } + + ret = test_dso(map->dso); +out_put: + map__put(map); + + return ret; +} + +static int test__symbols(struct test_suite *test __maybe_unused, int subtest __maybe_unused) +{ + char filename[PATH_MAX]; + struct test_info ti; + int ret; + + ret = init_test_info(&ti); + if (ret != TEST_OK) + return ret; + + get_test_dso_filename(filename, sizeof(filename)); + + ret = test_file(&ti, filename); + + exit_test_info(&ti); + + return ret; +} + +DEFINE_SUITE("Symbols", symbols); diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index fb4b5ad4dd0f..9a0f3904e53d 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -148,6 +148,7 @@ DECLARE_SUITE(perf_time_to_tsc); DECLARE_SUITE(dlfilter); DECLARE_SUITE(sigtrap); DECLARE_SUITE(event_groups); +DECLARE_SUITE(symbols); /* * PowerPC and S390 do not support creation of instruction breakpoints using the @@ -208,4 +209,6 @@ DECLARE_WORKLOAD(sqrtloop); DECLARE_WORKLOAD(brstack); DECLARE_WORKLOAD(datasym); +extern const char *dso_to_test; + #endif /* TESTS_H */ From patchwork Fri Jan 20 12:34:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp172591wrn; Fri, 20 Jan 2023 04:36:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRx1IcYfAyEdPaYvFxQOlVy4aXQaAZ7PJ7G96171wXijaGkXoOlNYdkpkMqIXdzmDII9ZX X-Received: by 2002:a05:6402:3226:b0:498:1ca:80d0 with SMTP id g38-20020a056402322600b0049801ca80d0mr18429856eda.28.1674218166780; Fri, 20 Jan 2023 04:36:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218166; cv=none; d=google.com; s=arc-20160816; b=IEqHxr3WhbaPcp+0ZwrzcHpMIv4YZK/bPMoTrQCuE6kT3NgEuWYyAy5E0dV7km1O4g sB69ewcGZR0ae3n9Hgwnt2cM+4SY5wWTmhgx71DGrhU9HJfys/M1FQMljaBv1GvdN53O 4wBCKdIfMdVjZUThlQ9nrCneuPhK/xSeULkI2UlZ6y8c7iV6FlPFYiIar2C187ZPXgmg PQ/X/uLtEfAHQ/nD0TSpE6BWcGNXJzWMgSPIsxsxnzFFjeBgI+Vt7y7I5OkMz/s2Rspn tzYXeBoej61J8WMFrB7hvu/iA6OnOUV0DbrVz4epyLRi3n+4fR2xF6GcdM++UXzn4sMT vFXg== 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=JvmgvNgx6U3fY4wZTCApEqrea8ZP+69ayjLiHX4cpzI=; b=0xPPv/IMOervnxjEEdJhfXpWnEPvFretVMxZZwgNPkqCHrtnfqCWydHL2ufRSeKh4q 1uvvme90xqhAX817Vse2pGIwPP0Qpz1HgpO77n/F4wnzx0a7AFj4REPwkknJI21eiXh4 fentBaP6FFXotLDYHY1u1qr/7qElUBTz58Ii6ro493HX57MhPAWvYZVT38wWkKQK5DpW yn6cLx8LnSOecByyXWt0MMWAx8jPFKK3q8oAhsINO9uKkR2V/tAedQQciV1w3iGzz01H k+fsNdxnc2eefncgMC5fpVZPflxHCX+K0bmFPi9oPgwmMc6kb6DsVD4mrln6WwCRpfFw uPMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OOyQsNNu; 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 l11-20020aa7d94b000000b0048d8fa5851bsi36583463eds.385.2023.01.20.04.35.42; Fri, 20 Jan 2023 04:36:06 -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=OOyQsNNu; 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 S230153AbjATMf0 (ORCPT + 99 others); Fri, 20 Jan 2023 07:35:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbjATMfV (ORCPT ); Fri, 20 Jan 2023 07:35:21 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4057FBC8B9; Fri, 20 Jan 2023 04:35:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218119; x=1705754119; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sAcMYB+GjPlCo4U+0MPqIgbgUDFTYLliCdjAF9kowCQ=; b=OOyQsNNu/VS+Yi5cftaFnpLGNsHcxAK3l0QnzYLrBEx94dveAsGqlm7A mALLQT4HpRz7rUWRRude/tf564MhUUPFk2DX+dYiN0SmlWrp0y/3T+BdY 6wgb82z3HD78hsSCguqUv2+OewGk+dcHmThm3jIGsKWiKG+sF23i+r/He Y/1KrWNyEUJc7z6LesqjrDJFAGiKH1UozO/TQTfMPLs4OAkr0u3VPSxHv YiRW1/2fkHVm2l+CRB8r6rHEPbpMbzwgrh18E/UOUX/CrpGCZxRAwNqm9 8WZEJbxBu+cK9hGcqQlF6r05x7LUqjCR9UsIppuCUEu0GiTY5kr0o6xK7 A==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935170" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935170" 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:18 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847420" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847420" 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:16 -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 02/10] perf symbols: Factor out get_plt_sizes() Date: Fri, 20 Jan 2023 14:34:48 +0200 Message-Id: <20230120123456.12449-3-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?1755544988450372248?= X-GMAIL-MSGID: =?utf-8?q?1755544988450372248?= Factor out get_plt_sizes() to make the code more readable and further changes to dso__synthesize_plt_symbols() easier to follow. Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 54 +++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 96767d1b3f1c..4605680a22a3 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -323,6 +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, + u64 *plt_header_size, u64 *plt_entry_size) +{ + switch (ehdr->e_machine) { + case EM_ARM: + *plt_header_size = 20; + *plt_entry_size = 12; + return; + case EM_AARCH64: + *plt_header_size = 32; + *plt_entry_size = 16; + return; + case EM_SPARC: + *plt_header_size = 48; + *plt_entry_size = 12; + return; + case EM_SPARCV9: + *plt_header_size = 128; + *plt_entry_size = 32; + return; + 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; + } +} + #define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \ for (idx = 0, pos = gelf_getrel(reldata, 0, &pos_mem); \ idx < nr_entries; \ @@ -411,32 +438,7 @@ 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; - switch (ehdr.e_machine) { - case EM_ARM: - plt_header_size = 20; - plt_entry_size = 12; - break; - - case EM_AARCH64: - plt_header_size = 32; - plt_entry_size = 16; - break; - - case EM_SPARC: - plt_header_size = 48; - plt_entry_size = 12; - break; - - case EM_SPARCV9: - plt_header_size = 128; - plt_entry_size = 32; - break; - - 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; - break; - } + get_plt_sizes(&ehdr, &shdr_plt, &plt_header_size, &plt_entry_size); plt_offset += plt_header_size; if (shdr_rel_plt.sh_type == SHT_RELA) { 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) { From patchwork Fri Jan 20 12:34:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46314 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp172701wrn; Fri, 20 Jan 2023 04:36:22 -0800 (PST) X-Google-Smtp-Source: AMrXdXvv5rsAN1Y7E/SYYyGkVPMUEzTz390GrNcxFXxOuhXeUpOY4UneEg9a//JmbVCQ0VvSnME0 X-Received: by 2002:a17:907:96a2:b0:7e0:eed0:8beb with SMTP id hd34-20020a17090796a200b007e0eed08bebmr13671348ejc.41.1674218182367; Fri, 20 Jan 2023 04:36:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218182; cv=none; d=google.com; s=arc-20160816; b=gMyDZ+bCKM4yAki2vgZBIBQqaeQs6qmZJi5hPofKkYIA81ieghklDg7qEG0YFUQvDO iDoOeRHCRgpdHNWo6X/QWEibeV7anurNN3n7JUrxuPd1SiXHWnLCGSLbvj+x1u7prkuy NpdrY+I0BpPf5nazUAJrLCi9rbFdJdZJgzb/jclsQiZajaT/AymnsoOlZ3o9FdQTXN/+ zD2VWSZz/18IhLniXVX130ceA8c1+rOgU39p/hSJreNMFqH5nZMShwFVDe3dqIvUySlh fvezQNTngV9dcmPNscXLmBzcu7MctNg0VIuX1uHaSp/CEXJE/wOknyFBmIct2WJkxYG0 yFXw== 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=RM9vjN/VAVk9YjCQar6K/xpYLwKcqqeqpYuzXn9Ciyo=; b=TYGdpfNFzh4qLZe930bjuhB534hh9eCPi71K3Up6l+OqCk2l4t6d0LRxqLOetcxjUP bfO6r43nslPDWrR02ClsJE603UWtVWQxNocuN0J5ySjY03hQU3SVgXYTQKznVMdqiP6T WHQ33DJF7+mvdfNwNrf26pTKCnTk0KUCgj4DqwLvhCfuAiXfbe/YKx5B+WymFvpssXDh J0afpjEkpvulM8FfJYNw1tiznoG36II/aFVFeSNYtbTe/usTHBGoOscCrjNCidu/PG89 0BVbbBQTQcJPAGtCOsN/sWpJvzrdxcpTPGFLvJh/GlqrKHi1gchaw6I1lh8E6F7o3H3H v/6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UjkGq5EN; 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 co16-20020a0564020c1000b0049e28b8b54fsi12977269edb.213.2023.01.20.04.35.58; Fri, 20 Jan 2023 04:36:22 -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=UjkGq5EN; 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 S230159AbjATMfb (ORCPT + 99 others); Fri, 20 Jan 2023 07:35:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230148AbjATMfZ (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 336DEBC88A; Fri, 20 Jan 2023 04:35:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218124; x=1705754124; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lNQ8moBpynyS7kwekoi/lFg0Su2X2visRdfx5+bbhQc=; b=UjkGq5ENE3mNuNGOAA9xH4MGsf9TDKIRKo241TeLgm3vN5dOrRoOch/c 1GkVpWnBe74zE6zjTorqXb7Pd7zYW6XjcfCiYYsdjKKe1mRO46ngIo05M otdF8jZsRrDxdD55DDPZQgKEDAjA5ryh4SjU4Icgc35pMJJnFSeVTb5Dt LIfvumoC5DTB/y7jbfe2fpgLnLTC+GJ+xv1rMgr6cQf6ZDL0TpM/gR1VW 8Jdo4G+/8wC23LHAQSvwIdEkEVCctYiFy9w/WKIffMF/I04odkhJnk4hN YBnWtxSNRUsojTXNq6K2xL8bKt4IEgJWdrpJqoPaqybClwkROqF8maEDX Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935204" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935204" 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:23 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847434" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847434" 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:21 -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 04/10] perf symbols: Add dso__find_symbol_nocache() Date: Fri, 20 Jan 2023 14:34:50 +0200 Message-Id: <20230120123456.12449-5-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?1755545004995264707?= X-GMAIL-MSGID: =?utf-8?q?1755545004995264707?= Symbols should not be cached when there are more symbols still to add. Add dso__find_symbol_nocache() to facilitate that. Signed-off-by: Adrian Hunter --- tools/perf/util/symbol.c | 5 +++++ tools/perf/util/symbol.h | 1 + 2 files changed, 6 insertions(+) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index a3a165ae933a..a024f06f75d8 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -556,6 +556,11 @@ struct symbol *dso__find_symbol(struct dso *dso, u64 addr) return dso->last_find_result.symbol; } +struct symbol *dso__find_symbol_nocache(struct dso *dso, u64 addr) +{ + return symbols__find(&dso->symbols, addr); +} + struct symbol *dso__first_symbol(struct dso *dso) { return symbols__first(&dso->symbols); diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index f735108c4d4e..2fdeb22bd02f 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -148,6 +148,7 @@ void dso__delete_symbol(struct dso *dso, struct symbol *sym); struct symbol *dso__find_symbol(struct dso *dso, u64 addr); +struct symbol *dso__find_symbol_nocache(struct dso *dso, u64 addr); struct symbol *dso__find_symbol_by_name(struct dso *dso, const char *name); struct symbol *symbol__next_by_name(struct symbol *sym); From patchwork Fri Jan 20 12:34:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp172846wrn; Fri, 20 Jan 2023 04:36:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXvmKZaIIy9rUL/HgMofAlpOTKU/AwazESsrLyeRoI7FKD//KABPD0Raj/TxxXfwXvTRqmnx X-Received: by 2002:a05:6402:35c1:b0:46f:f36b:a471 with SMTP id z1-20020a05640235c100b0046ff36ba471mr20344156edc.22.1674218206968; Fri, 20 Jan 2023 04:36:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218206; cv=none; d=google.com; s=arc-20160816; b=oep3O/bGJOhCXPSSMG2SwoVp1Ezj0q3p3QcJgb9xnSz6RymIXSycuEqgotvK2Y3gB5 4DafZMGARJS8hUviH0aCuDN4SjSCVok86450soNh+M9PAyQqbSXEX5/EiM6B75Xozy6V Z1nSucoCwRFaYUfFbjCFFFtICsuSpc+b58R/tWWfX+BaJnowWy9f9AHBHeXSDRHFLH/i CX/H+2ADHPmHKtDMIhnZwjpjDy+fKBfeL/DIX97bJIxyB4/kWwySPVu3wKYpNVlJGabX lweamXucZyuTtCVF0sYE7Tx/R6V0DRxcJKzHBe+5bKYDaYUBU/sMIVTSKiM9l3hCmk9A 1kwg== 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=2XObSrLPu5WzsAZHskCjh6gmu6CjTjyAX8BgvT+iG4Q=; b=d8VQMuhOkSlyJI62Br2HicNejaL0O3zWLFWROKzVF/ijrlJzYncI/1CLABcwOqYwER dSFNfMEScW6PPp2H8AH14FzlvGRSo5gg2IMgImfbgu006D5czlLO6/qDwJ5O45QN6Rgx o+w+MWLlAD0cISqGEsS/Pmq0IDOl9chYqYs1tANKgxAG1Kg6D3iclLfspm4HDEugRtBS HdiONEKltebiyYEYIPdhKg7K0eZIkykJHpbJEang26dDY/Xk/ZlSp9Jd8GPeGr8YArQu CjoHvjO0ant3UQ4KXP+2hn6KxuMQ5S/MnJY2UG39oteG1MUaX899kiEJQ86N8fm4gXCl tzYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="QnRWmb//"; 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 fd14-20020a056402388e00b0049ea11f77eesi2851951edb.528.2023.01.20.04.36.22; Fri, 20 Jan 2023 04:36:46 -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="QnRWmb//"; 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 S230239AbjATMfr (ORCPT + 99 others); Fri, 20 Jan 2023 07:35:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230180AbjATMfe (ORCPT ); Fri, 20 Jan 2023 07:35:34 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8D26BCE06; Fri, 20 Jan 2023 04:35:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218126; x=1705754126; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UxtJ1rP66dQ3RmSMBjvuUkGyB8tVAPu0JZkPBT1WvxI=; b=QnRWmb//iRSmbXKXl/YpxMmnxA9055P/PIqAqLlpGx2CIvaYpMth528M aodCoRwBm0zLgfA7/0VLCIKZ+pHWdrCrZveC6whsSS9d2bQclf0sV31kZ Ze42hZabzfUKsNDvSwDWM2SUGflevPo5OVYgTsZF9BK8w1NeKT5n3/3st nz+RpoEgvyi8nyHm+QS4sG0tkt2tjb3MlI64NOgyWMWP+XHWZ9bgUgneL NoF3Dwjvlc8j54BlSKAdccK0MUni+HTXUMp8c8IomCOV8WIUd3RDY6sF8 VxRd0+XXrmsi07IBSvBaCg/Ixyfk0jK1plM6RngIOw5ZDGVsOdWy43fIh w==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935223" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935223" 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:26 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847438" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847438" 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:24 -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 05/10] perf symbols: Slightly simplify 'err' usage in dso__synthesize_plt_symbols() Date: Fri, 20 Jan 2023 14:34:51 +0200 Message-Id: <20230120123456.12449-6-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?1755545030456801944?= X-GMAIL-MSGID: =?utf-8?q?1755545030456801944?= Return zero directly instead of needless 'goto out_elf_end' that does the same thing. That allows 'err' to be initialized to -1 instead of having to change its value later. Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index c6a4e6c73990..990a2c6037bb 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -384,7 +384,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) GElf_Ehdr ehdr; char sympltname[1024]; Elf *elf; - int nr = 0, symidx, err = 0; + int nr = 0, symidx, err = -1; if (!ss->dynsym) return 0; @@ -397,7 +397,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) dynsym_idx = ss->dynsym_idx; if (scn_dynsym == NULL) - goto out_elf_end; + return 0; scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, ".rela.plt", NULL); @@ -405,11 +405,9 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) scn_plt_rel = elf_section_by_name(elf, &ehdr, &shdr_rel_plt, ".rel.plt", NULL); if (scn_plt_rel == NULL) - goto out_elf_end; + return 0; } - err = -1; - if (shdr_rel_plt.sh_link != dynsym_idx) goto out_elf_end; From patchwork Fri Jan 20 12:34:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp172854wrn; Fri, 20 Jan 2023 04:36:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXtWlb5Si5Tgks9UiEmxifDD4B9k8mfi5O5RGeiYmDCV26nhvplIMKET682dF6kgq5CicUQr X-Received: by 2002:a17:907:8e86:b0:84d:43c3:a897 with SMTP id tx6-20020a1709078e8600b0084d43c3a897mr31062412ejc.2.1674218208348; Fri, 20 Jan 2023 04:36:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218208; cv=none; d=google.com; s=arc-20160816; b=RRE/e9GIe6rCpmw//AMuguTWyNmcfdjkvbd5NXnT9hp/U5vHv6uKJ7oSjxoGXlXuYp 1ia0txxVNy1w7KwgxcFNyr+pMu+CuWFS9lLmoaCwpC7iRd8hf225kLTqf7lDbhHN/UyI sbCJqj+6bXAMwkSky2eY29CcGXMscioLfG9hDpEUQ5Xl6RY/7PNPd9qxAdSPusuuAk6E kW1vSQ74L/7ET5BH9PePI9vE1h2hRHpYO0v9pbTqdclsMcGBZRL7B/PZu/5KUbU+9Qtc kvanzN3S/lJ7BDY9awduAQwn+tRTWu7F7NuQccGK1fdQthARebOdUFytuUjojNrFwdZl dGgA== 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=scGKwxYiKt0BIryouxDCHOJhYkbLlOTqnA+hG8r0vC4=; b=BnnJxY4JGuG6q5yuUHUBKa/cq15uZUhsWFGUA9c/pmfCX9rDEi79A1vOR0v9syUBM7 zrg9SYARx7H3MKrZPYM0e1inms5SCw+J9sNNuINDjaD0rd8pEDWWa87MauiOzTQP72bC gBkY090B7RTePYX4djX4xVacTthFfyb1wJYSIOcvbh8zRUpzIv2nMsr84QCRUCJp91pq 0Dw7Te4mLWSXxNNPj4e0gLe5j8AO3q+r+fGLLg+RVr4JN1wF4eXMlqr3jEVcSbv5B8fS cWZknvvALXI9k8uEd9gmemrDiwJ+evaXn09mYNSZhB1YjbOMIN0lcy0cDLWb71r/RAGu EOkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HYSip1CF; 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 ae13-20020a17090725cd00b0083b6e04f33esi20891787ejc.280.2023.01.20.04.36.24; Fri, 20 Jan 2023 04:36:48 -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=HYSip1CF; 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 S230234AbjATMf5 (ORCPT + 99 others); Fri, 20 Jan 2023 07:35:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbjATMfv (ORCPT ); Fri, 20 Jan 2023 07:35:51 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCF6CBF5EB; Fri, 20 Jan 2023 04:35:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218129; x=1705754129; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JH3uowZm2/EOmx74lVqvydtWQ0K9xGM+P+gA7PXly5g=; b=HYSip1CFyvJ3Ob6Md91EkTc8u2dj9IfnC7PUrHcByJUwA6dd5vOAax32 1DYVFicwa/S808ZrHAIbXlNA8p9mJF0dsEdNDbQPEyJAfGcD8rF415VcK xVGmJas1ly1P4MHBaOEUQXhIe/KXxBjKQGB+1fEGxa0qaR5ywbIvbeJpt pSFLEm+tpjsykvS2hR+vLsXD41oA72LsRqnPnlbx+m4aIA11Oi8o1lYEH 9k6V+5HzaGJf+0FW3zoUluJK3CXgvURkYlc0RxKwSdR3AIWBj4oXrtHXH ZwH4Pdg60b6mf49awK8YbBZ1wizAKq7bHsaM31UsXfFqjx2RPYd2EM+rL A==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935241" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935241" 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:28 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847442" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847442" 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:26 -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 06/10] perf symbols: Do not check ss->dynsym twice Date: Fri, 20 Jan 2023 14:34:52 +0200 Message-Id: <20230120123456.12449-7-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?1755545032280355053?= X-GMAIL-MSGID: =?utf-8?q?1755545032280355053?= ss->dynsym is checked to be not NULL twice. Remove the first check because, in fact, there can be a plt with no dynsym, which is something that will be dealt with later. Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 990a2c6037bb..87b82507c205 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -386,9 +386,6 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) Elf *elf; int nr = 0, symidx, err = -1; - if (!ss->dynsym) - return 0; - elf = ss->elf; ehdr = ss->ehdr; 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) { From patchwork Fri Jan 20 12:34:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp185448wrn; Fri, 20 Jan 2023 05:04:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXt/AB4bPgdG0ZLM9sjQ6J0fUggE4cv5BZuPoScjZUuVLQ8QpFxZJgu1XE8bmlrLoCSFPZJm X-Received: by 2002:a05:6402:3583:b0:49d:fd6d:925d with SMTP id y3-20020a056402358300b0049dfd6d925dmr20239950edc.23.1674219882215; Fri, 20 Jan 2023 05:04:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674219882; cv=none; d=google.com; s=arc-20160816; b=lqfrBbTmLf+LWUMMft5PyL0v8jEsL7Ky4eB5GsUky0G5b4QfxJzhmVGDqz1/cMKErV P08K2+oREc7lnmesbyE1VJc2HhCQfu1CvqENE8lZ3AQQXZVum/qkSTVdVtWA3zjc6LqF WM5LRIhzO2ug83Bf5TabjvWSYgGWXKPHrBvRUdX9h/AwOJiYu2exlTsITYpsILOZSb57 iL5VQ25uH4f+CqeaTvDhGH1VSnzvU8/ZWT/PHTmu+UtBizUebqO/U6W0SR15JRdtDnqL 2OR3h9iyokQXMeZWMJljHsmLKhevsPJEJyPSA1TS2aVhRcoZDo4U1+yEkwUzbU/1ePyg rs0Q== 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=03XWYm0GNOg2AgTNztgC0eNHz+pnJob7qG22ZD8/Eg0=; b=eQSB3gUSRIJ7qrzb8LiUQA8ApUTBYmEPgTfouqtoq3kE32mM3bzLDoeRnuHB3jBWPo z8MSSJOg3Ji2X4+1Rs6TVOmA6hia3N6aDfPziJIxYg/EU7PykjFlIdk3zB7yAGGlLwSH 4Yxp/Ih5oDa4pISPz8u8ga/b6XTq4xWkU9RLdF35+RasSMeD9yarSxsyUajJN7Hu/8Kq Cm8MhOD79RmpFtl9mvm3T5Tu9wklLACE/zg1UUrVLLrtrpzh3IjhCX2+iWT4YFQh3WCI G60iVW3+9OrVhgd0nAlQPv4r/Mp6YpZJjkT6P5Acebn6C4v3LNX0CmPmjUdUanu9RE7p vBrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=STQG77oK; 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 eb14-20020a0564020d0e00b0047ff112ee12si49861978edb.101.2023.01.20.05.04.02; Fri, 20 Jan 2023 05:04:42 -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=STQG77oK; 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 S230271AbjATMgJ (ORCPT + 99 others); Fri, 20 Jan 2023 07:36:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230168AbjATMgA (ORCPT ); Fri, 20 Jan 2023 07:36:00 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1EDABD15B; Fri, 20 Jan 2023 04:35:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218134; x=1705754134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9Td56AXPQefHBhNcNDmLaayNhsuUevf9TJ/QNvlypS0=; b=STQG77oKiYSw/O0HI1bFpLgstPKox8xkxJIDDRQED4PpUEo+PYQYxlPu 3yVcjaooXfDzuJYXb/W3MbdAvSOpsciGCDG2GvtB9O3f2+3OoJqzZPtu+ w7PT4FxpPYlOABnMYPDFRgXU9MSRvfDfSd3G+dwpBghapnUbgP8xY/FDT uWWT2V0xM0HDCRI5rnIrMlpMM+1qzWuW15OuCMDENotJfg0SQLH9gNuR3 vJ40XOShX6diwxTrO17GT9t1dqLckaXj2+d6Zo3I3j64R6aunDTbtAIwT uMqLPVgWEf+pQCCQXp5uxZMjR0G2eJY9HOZ2HfnH27KdRyb3viXmd76rq A==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935279" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935279" 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:33 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847452" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847452" 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:31 -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 08/10] perf symbols: Allow for .plt entries with no symbol Date: Fri, 20 Jan 2023 14:34:54 +0200 Message-Id: <20230120123456.12449-9-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?1755546787399987781?= X-GMAIL-MSGID: =?utf-8?q?1755546787399987781?= Create a sensible name for .plt entries with no symbol. Example: Before: $ perf test --dso /usr/lib/x86_64-linux-gnu/libc.so.6 -vv Symbols 2>/tmp/cmp1.txt After: $ perf test --dso /usr/lib/x86_64-linux-gnu/libc.so.6 -vv Symbols 2>/tmp/cmp2.txt $ diff /tmp/cmp1.txt /tmp/cmp2.txt 4c4 < test child forked, pid 53043 --- > test child forked, pid 54372 23,62c23,62 < 280f0-28100 g @plt < 28100-28110 g @plt < 28110-28120 g @plt < 28120-28130 g @plt < 28130-28140 g @plt < 28140-28150 g @plt < 28150-28160 g @plt < 28160-28170 g @plt < 28170-28180 g @plt < 28180-28190 g @plt < 28190-281a0 g @plt < 281a0-281b0 g @plt < 281b0-281c0 g @plt < 281c0-281d0 g @plt < 281d0-281e0 g @plt < 281e0-281f0 g @plt < 281f0-28200 g @plt < 28200-28210 g @plt < 28210-28220 g @plt < 28220-28230 g @plt < 28230-28240 g @plt < 28240-28250 g @plt < 28250-28260 g @plt < 28260-28270 g @plt < 28270-28280 g @plt < 28280-28290 g @plt < 28290-282a0 g @plt < 282a0-282b0 g @plt < 282b0-282c0 g @plt < 282c0-282d0 g @plt < 282d0-282e0 g @plt < 282e0-282f0 g @plt < 282f0-28300 g @plt < 28300-28310 g @plt < 28310-28320 g @plt < 28320-28330 g @plt < 28330-28340 g @plt < 28340-28350 g @plt < 28350-28360 g @plt < 28360-28370 g @plt --- > 280f0-28100 g offset_0x280f0@plt > 28100-28110 g offset_0x28100@plt > 28110-28120 g offset_0x28110@plt > 28120-28130 g offset_0x28120@plt > 28130-28140 g offset_0x28130@plt > 28140-28150 g offset_0x28140@plt > 28150-28160 g offset_0x28150@plt > 28160-28170 g offset_0x28160@plt > 28170-28180 g offset_0x28170@plt > 28180-28190 g offset_0x28180@plt > 28190-281a0 g offset_0x28190@plt > 281a0-281b0 g offset_0x281a0@plt > 281b0-281c0 g offset_0x281b0@plt > 281c0-281d0 g offset_0x281c0@plt > 281d0-281e0 g offset_0x281d0@plt > 281e0-281f0 g offset_0x281e0@plt > 281f0-28200 g offset_0x281f0@plt > 28200-28210 g offset_0x28200@plt > 28210-28220 g offset_0x28210@plt > 28220-28230 g offset_0x28220@plt > 28230-28240 g offset_0x28230@plt > 28240-28250 g offset_0x28240@plt > 28250-28260 g offset_0x28250@plt > 28260-28270 g offset_0x28260@plt > 28270-28280 g offset_0x28270@plt > 28280-28290 g offset_0x28280@plt > 28290-282a0 g offset_0x28290@plt > 282a0-282b0 g offset_0x282a0@plt > 282b0-282c0 g offset_0x282b0@plt > 282c0-282d0 g offset_0x282c0@plt > 282d0-282e0 g offset_0x282d0@plt > 282e0-282f0 g offset_0x282e0@plt > 282f0-28300 g offset_0x282f0@plt > 28300-28310 g offset_0x28300@plt > 28310-28320 g offset_0x28310@plt > 28320-28330 g offset_0x28320@plt > 28330-28340 g offset_0x28330@plt > 28340-28350 g offset_0x28340@plt > 28350-28360 g offset_0x28350@plt > 28360-28370 g offset_0x28360@plt Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index a8b7c3860b2d..6e4a22acefba 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -470,8 +470,11 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) demangled = demangle_sym(dso, 0, elf_name); if (demangled != NULL) elf_name = demangled; - snprintf(sympltname, sizeof(sympltname), - "%s@plt", elf_name); + if (*elf_name) + snprintf(sympltname, sizeof(sympltname), "%s@plt", elf_name); + else + snprintf(sympltname, sizeof(sympltname), + "offset_%#" PRIx64 "@plt", plt_offset); free(demangled); f = symbol__new(plt_offset, plt_entry_size, @@ -496,8 +499,11 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) demangled = demangle_sym(dso, 0, elf_name); if (demangled != NULL) elf_name = demangled; - snprintf(sympltname, sizeof(sympltname), - "%s@plt", elf_name); + if (*elf_name) + snprintf(sympltname, sizeof(sympltname), "%s@plt", elf_name); + else + snprintf(sympltname, sizeof(sympltname), + "offset_%#" PRIx64 "@plt", plt_offset); free(demangled); f = symbol__new(plt_offset, plt_entry_size, From patchwork Fri Jan 20 12:34:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp173384wrn; Fri, 20 Jan 2023 04:37:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXvazXvCXlVJOVWnx4a2cL1gxcEZF6UVaaqFZEVRTkpNU/MEKX6UixW0KvlHOEG/kfMfs0lI X-Received: by 2002:a17:906:270f:b0:86c:fa4c:220e with SMTP id z15-20020a170906270f00b0086cfa4c220emr18361065ejc.3.1674218270854; Fri, 20 Jan 2023 04:37:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218270; cv=none; d=google.com; s=arc-20160816; b=Cv5RPrRs2lhFfnPVcV+EqEe+HnOAhOcBKhAd3rsOCPKIMn9qqFGtXFW9XKiPEHSJwY d2ZaK3rm7yvdf44y4T8R8uRa0JKsujFrNeU2ZGerBVcdi5L+ffPYoe+HTFC3SDezqyrl C+QNyvUWe7SbXIu5rsLr7OIIvKtM9jwz22jkojKxPOeWtY2AFJr2qaTK6hVusjUa2Zaw E5YgXJvcyHJsq1bQKaEuCOKmWkEF3/uyx6ZXuOh+BYo0eFw7adjqx1YJXf+nspkORS+r rDUtCgZN0SeDp/U1a/3HNRqvFvAT25bbpQTzrLXzBh6cy24euKtqr7O5+dxmnU2TQHI6 2WiA== 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=x5hmMzuUEbF7WWxsLDt6o0YCRaFMOCsC7dagsQ5NPr4=; b=NN2rmrF5FREvkz0XX59L8Oa+EE7eqY6MfqJ7nHsQphx8JrYTwY9cf7QGyzjySyKn0H r3ED27yy0LXdd2zVkxWM2K0+5x/tc2oHbU0Amqtdak479bISvxpsAPyDZAEjX4c4GP+l w6OQrOyNL2gopJ/JTcgM/uX+Ixp44Qn+X8PV/2fQSGV3hrq9taDuOSPqf6N6n4ACdLyR NKjCbPCAdKmDdIHm2UZsYDXSvhzqJmklqOPedmUavnRiqJuUGMu1Gka6unFOCBoRDVbE i89Z/X9x8wM+at0C821wfDSr6SuxQo6wppmu2+WpK424AebCPokcgZiZCczqa4sAejsb N0EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OJU4Ygzq; 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 hd8-20020a170907968800b0086b6a3fd247si3640212ejc.557.2023.01.20.04.37.26; Fri, 20 Jan 2023 04:37:50 -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=OJU4Ygzq; 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 S230316AbjATMgV (ORCPT + 99 others); Fri, 20 Jan 2023 07:36:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230293AbjATMgM (ORCPT ); Fri, 20 Jan 2023 07:36:12 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31061BF8BF; Fri, 20 Jan 2023 04:35:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218145; x=1705754145; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+4JYvfJ/BZArt9A+5Y2h+61dVJ0kg1blPxurYa6kQaY=; b=OJU4Ygzq7YJHjJqskpX2HyqlMZofw8IMs7KGILuC/QzzW+PZCTe7lj9V iOHvDtlck2oX6O5nsyhY36fsqUg5YH7bHv4atn+6l7+racO3u66YXUbVs seDTCJXEFnGAlLSjjSfTXebnyo5bs7tmipSCPbGYiD+Gdka8faqMDVYEE WFfTU26zjZ5SGiqzGUqAnDjUKsVbna6ynTwu3IbkWtYe2z9I9GdAJ7YDm 3PvPMkR/5NKA7mbV1JB+wcbuIPFStmcef+Hg935kEf926dkdUyFsi/7X8 q+9U6L0UCQMgAg0qbFA9ktG654iuF4/wFc7E4q00JSZbwVr9wNC4R5lRj w==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935298" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935298" 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:36 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847457" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847457" 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:33 -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 09/10] perf symbols: Combine handling for SHT_RELA and SHT_REL Date: Fri, 20 Jan 2023 14:34:55 +0200 Message-Id: <20230120123456.12449-10-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?1755545097470207181?= X-GMAIL-MSGID: =?utf-8?q?1755545097470207181?= SHT_REL and SHT_RELA are handled the same way. Simplify by combining the handling. Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 75 +++++++++++++----------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 6e4a22acefba..e274f646ac32 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -323,6 +323,23 @@ static char *demangle_sym(struct dso *dso, int kmodule, const char *elf_name) return demangled; } +struct rel_info { + bool is_rela; + Elf_Data *reldata; + GElf_Rela rela; + GElf_Rel rel; +}; + +static u32 get_rel_symidx(struct rel_info *ri, u32 idx) +{ + if (ri->is_rela) { + gelf_getrela(ri->reldata, idx, &ri->rela); + return GELF_R_SYM(ri->rela.r_info); + } + gelf_getrel(ri->reldata, idx, &ri->rel); + return GELF_R_SYM(ri->rel.r_info); +} + static bool get_plt_sizes(struct dso *dso, GElf_Ehdr *ehdr, GElf_Shdr *shdr_plt, u64 *plt_header_size, u64 *plt_entry_size) { @@ -353,16 +370,6 @@ static bool get_plt_sizes(struct dso *dso, GElf_Ehdr *ehdr, GElf_Shdr *shdr_plt, } } -#define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \ - for (idx = 0, pos = gelf_getrel(reldata, 0, &pos_mem); \ - idx < nr_entries; \ - ++idx, pos = gelf_getrel(reldata, idx, &pos_mem)) - -#define elf_section__for_each_rela(reldata, pos, pos_mem, idx, nr_entries) \ - for (idx = 0, pos = gelf_getrela(reldata, 0, &pos_mem); \ - idx < nr_entries; \ - ++idx, pos = gelf_getrela(reldata, idx, &pos_mem)) - /* * We need to check if we have a .dynsym, so that we can handle the * .plt, synthesizing its symbols, that aren't on the symtabs (be it @@ -378,13 +385,14 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) GElf_Shdr shdr_plt; struct symbol *f; GElf_Shdr shdr_rel_plt, shdr_dynsym; - Elf_Data *reldata, *syms, *symstrs; + Elf_Data *syms, *symstrs; Elf_Scn *scn_plt_rel, *scn_symstrs, *scn_dynsym; size_t dynsym_idx; GElf_Ehdr ehdr; char sympltname[1024]; Elf *elf; - int nr = 0, symidx, err = -1; + int nr = 0, err = -1; + struct rel_info ri = { .is_rela = false }; elf = ss->elf; ehdr = ss->ehdr; @@ -433,8 +441,8 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) * Fetch the relocation section to find the idxes to the GOT * and the symbols in the .dynsym they refer to. */ - reldata = elf_getdata(scn_plt_rel, NULL); - if (reldata == NULL) + ri.reldata = elf_getdata(scn_plt_rel, NULL); + if (!ri.reldata) goto out_elf_end; syms = elf_getdata(scn_dynsym, NULL); @@ -456,44 +464,15 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) plt_offset = shdr_plt.sh_offset; plt_offset += plt_header_size; - if (shdr_rel_plt.sh_type == SHT_RELA) { - GElf_Rela pos_mem, *pos; + ri.is_rela = shdr_rel_plt.sh_type == SHT_RELA; - elf_section__for_each_rela(reldata, pos, pos_mem, idx, - nr_rel_entries) { + if (shdr_rel_plt.sh_type == SHT_RELA || + shdr_rel_plt.sh_type == SHT_REL) { + for (idx = 0; idx < nr_rel_entries; idx++) { const char *elf_name = NULL; char *demangled = NULL; - symidx = GELF_R_SYM(pos->r_info); - gelf_getsym(syms, symidx, &sym); - - elf_name = elf_sym__name(&sym, symstrs); - demangled = demangle_sym(dso, 0, elf_name); - if (demangled != NULL) - elf_name = demangled; - if (*elf_name) - snprintf(sympltname, sizeof(sympltname), "%s@plt", elf_name); - else - snprintf(sympltname, sizeof(sympltname), - "offset_%#" PRIx64 "@plt", plt_offset); - free(demangled); - f = symbol__new(plt_offset, plt_entry_size, - STB_GLOBAL, STT_FUNC, sympltname); - if (!f) - goto out_elf_end; - - plt_offset += plt_entry_size; - symbols__insert(&dso->symbols, f); - ++nr; - } - } else if (shdr_rel_plt.sh_type == SHT_REL) { - GElf_Rel pos_mem, *pos; - elf_section__for_each_rel(reldata, pos, pos_mem, idx, - nr_rel_entries) { - const char *elf_name = NULL; - char *demangled = NULL; - symidx = GELF_R_SYM(pos->r_info); - gelf_getsym(syms, symidx, &sym); + gelf_getsym(syms, get_rel_symidx(&ri, idx), &sym); elf_name = elf_sym__name(&sym, symstrs); demangled = demangle_sym(dso, 0, elf_name); From patchwork Fri Jan 20 12:34:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 46325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp174629wrn; Fri, 20 Jan 2023 04:40:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXvpe2grRm+/X5clO1GlhzoavBJONsiEdsNIUyXLvWn0jn6/Fdwp+mV8rYAu6lxD6ZZJ2cJg X-Received: by 2002:a17:907:d38a:b0:86e:c9e2:6313 with SMTP id vh10-20020a170907d38a00b0086ec9e26313mr16827729ejc.32.1674218437981; Fri, 20 Jan 2023 04:40:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674218437; cv=none; d=google.com; s=arc-20160816; b=lgfli98Knv3gSMw4zrBET0eeRfXFID52dU/dHcxOE14Z3RKf9jqovy2kdMwdpeptXd ydzaGdwx/E+UGGKLmiAA/qzyBVtG+ItwaP/34ZssSSQYAoB0YjreKa0EY8hEgC5sc5ks SzQ2p2zro7+8sbCTt5ccZHpuIgLwDI2Z0NwQPyGLKC+L9uL2WvOKZoyCRb1OXoxez2W+ IVBFaZu5IGaEMKV6gfqe+zTNw5w5+HBtpyF2Tg/uRg9muKY2IaAzN+rUve9+lU2rPCRs hX0TJtRRG3zkwc0TRrFu0WDbrdkzzTq0OWcRmqZ/ALKZSQloI/Lk9YSSvuq6LTJR6eCe M05g== 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=vKWJ5zZQ4D5TA6+DsY0Gy/c5wpAH+ZGdnA1RUQOmVoU=; b=ezP/uMdkQfLPfw6xuRkj03DqszL8ztij5T22kC1u4YygzjhOhJAnFNGdzo8CKc+EbT STN8i2hivpJmN1VhUdHGXMIB2hHLRpETV/4l5USwKbhPLlms2CtRdsERGrjZZMSv/1IM MLoJv3RR/zuFPWT7Ri8UMPnfN59I8eBLc5k+PlMOL65YgNob+0jBttaB4nhSVAtWqNXX cCHSGoAUkbv2bcvNU4b5sCwCZSZgikkDLs2HCLxYwXapqpO9SZl98U8fmET0GMpDZcLy y956Zzj+FXazjcMkiSur6M1k6o8lsaEFbJl8D0YbjLiO/INW64OnSuIREaqgf0hvfVJt 2ItQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YMWiOHr2; 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 gt37-20020a1709072da500b0084d34979415si21224133ejc.326.2023.01.20.04.40.13; Fri, 20 Jan 2023 04:40:37 -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=YMWiOHr2; 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 S230300AbjATMgc (ORCPT + 99 others); Fri, 20 Jan 2023 07:36:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbjATMgT (ORCPT ); Fri, 20 Jan 2023 07:36:19 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B164BC895; Fri, 20 Jan 2023 04:35:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1674218154; x=1705754154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=usKQ9P+Ke/475dpAvzHSLqve+rQfd02M1v4DhbzDTsE=; b=YMWiOHr2oT+n4EWDUwhX/9KeSFE9aZCWIiS+TBci4MYorF03v1fd8Ycx GAFvJJD5RibI2H/5X58h1mFB5tHvSEev+3aRnSxwjiCJw6YBzgp7V7TbN fPvVp1OWM1J7oh+KaYEosWh7QBMLhWjb5O3GBp3i3Fqukwj8lm58CEumF zTMGgpHtmESF7OuO26nVQaliQs+hUqyc3hoqp0VRnENXUIAOMpTwVKmfu 2B5+V4ThnyXQr7mWCEM9h7rJu4fOEH2BmouBgmSGdw0ZbajZSC4AXoR7V ivV8B4EEPpUPwMNcJf5DuwkBs9pXgILdsDEvmkqdQhNNcie3tPhYeOH9i Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="387935315" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="387935315" 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:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10595"; a="692847463" X-IronPort-AV: E=Sophos;i="5.97,232,1669104000"; d="scan'208";a="692847463" 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:36 -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 10/10] perf symbols: Check SHT_RELA and SHT_REL type earlier Date: Fri, 20 Jan 2023 14:34:56 +0200 Message-Id: <20230120123456.12449-11-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?1755545272824813812?= X-GMAIL-MSGID: =?utf-8?q?1755545272824813812?= Make the code more readable by checking for SHT_RELA and SHT_REL type earlier. Signed-off-by: Adrian Hunter --- tools/perf/util/symbol-elf.c | 54 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index e274f646ac32..aa62735aea7b 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -434,6 +434,10 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) return 0; } + if (shdr_rel_plt.sh_type != SHT_RELA && + shdr_rel_plt.sh_type != SHT_REL) + return 0; + if (shdr_rel_plt.sh_link != dynsym_idx) goto out_elf_end; @@ -466,34 +470,30 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss) ri.is_rela = shdr_rel_plt.sh_type == SHT_RELA; - if (shdr_rel_plt.sh_type == SHT_RELA || - shdr_rel_plt.sh_type == SHT_REL) { - for (idx = 0; idx < nr_rel_entries; idx++) { - const char *elf_name = NULL; - char *demangled = NULL; - - gelf_getsym(syms, get_rel_symidx(&ri, idx), &sym); - - elf_name = elf_sym__name(&sym, symstrs); - demangled = demangle_sym(dso, 0, elf_name); - if (demangled != NULL) - elf_name = demangled; - if (*elf_name) - snprintf(sympltname, sizeof(sympltname), "%s@plt", elf_name); - else - snprintf(sympltname, sizeof(sympltname), - "offset_%#" PRIx64 "@plt", plt_offset); - free(demangled); - - f = symbol__new(plt_offset, plt_entry_size, - STB_GLOBAL, STT_FUNC, sympltname); - if (!f) - goto out_elf_end; + for (idx = 0; idx < nr_rel_entries; idx++) { + const char *elf_name = NULL; + char *demangled = NULL; - plt_offset += plt_entry_size; - symbols__insert(&dso->symbols, f); - ++nr; - } + gelf_getsym(syms, get_rel_symidx(&ri, idx), &sym); + + elf_name = elf_sym__name(&sym, symstrs); + demangled = demangle_sym(dso, 0, elf_name); + if (demangled) + elf_name = demangled; + if (*elf_name) + snprintf(sympltname, sizeof(sympltname), "%s@plt", elf_name); + else + snprintf(sympltname, sizeof(sympltname), + "offset_%#" PRIx64 "@plt", plt_offset); + free(demangled); + + f = symbol__new(plt_offset, plt_entry_size, STB_GLOBAL, STT_FUNC, sympltname); + if (!f) + goto out_elf_end; + + plt_offset += plt_entry_size; + symbols__insert(&dso->symbols, f); + ++nr; } err = 0;