Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1810365pxm; Thu, 24 Feb 2022 09:43:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5OKzUGvYy1pSX9yQBb7ELL0hoC9/ZtmZHAeh7yzZcUUd5ETkC6CPt/wKedJ8B8NzsKUaa X-Received: by 2002:a17:906:358e:b0:6cf:61dd:5a1f with SMTP id o14-20020a170906358e00b006cf61dd5a1fmr3218985ejb.416.1645724623884; Thu, 24 Feb 2022 09:43:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645724623; cv=none; d=google.com; s=arc-20160816; b=Tkkc4AGUBzWlNxel8Q1DDSsbbRlYK0++LYzgcIDqKRYfIW3sDj84iB96zbZHwZWElF D0qHwmFhHAuSm/Y5MEfS19ycXk5QAawgjFFHV4surq/k7ewkMzrxrS+3TpSoogTxrwKP RSp/EfsJN8s9wKkIzq8P+fB7jEqgMv/7Q+XL3nQGwkx7MeZAXZJlb6ttVZI7tUfB5QKY 7I8Hecw5frcjoOYEkjuOqV+0XdH9jxzy9Ht4DZ7kCBHG7KRN01LfFmhAi18PE1p1FYrq SsobXq3sGRNGdv4ump5wHbUoJyly+ZdT7UDJtnRw1Xjb8269NPOG4whDnHTl5bvi9ZcI WRHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9dFm5pqEP5kuXg0A5bucKMw20hnpVVibo3ozMg7l1CM=; b=S0TMz4+1SySRURcUHbHc7RwCr75SIlmIHV6dLgdiSx6RJJECluF/JPt6dTbn7n1nCS 3Ng604UR0SzRu5GbBRW0Prz7LEu269JElhkht5li/fFOGLP8zBjf4wo6fkOFMXxybxGY UV7rhqr4dCqTTvURWTC1VwTPTbX5wvEZhfIzvUW6K/CQo6asEzmKU2H/FnERCMfFd5qg +Inzt9kdmHriuo8LdUkYhdsNm6+AifOa01fGfVv8MEZ5h0BvgNBZvwm7PnNo8nIQxKhF hN+Bfujzm9GDdIRSY7Ws3TuOIQNMCmB6j8A9zm1Q8t4Zw6h10UDirwkFrRmkVVOW9hpH p31A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5si1846353eja.996.2022.02.24.09.43.07; Thu, 24 Feb 2022 09:43:43 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231290AbiBXRUn (ORCPT + 99 others); Thu, 24 Feb 2022 12:20:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbiBXRUi (ORCPT ); Thu, 24 Feb 2022 12:20:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3EDE829EBB7; Thu, 24 Feb 2022 09:20:08 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0C16C1476; Thu, 24 Feb 2022 09:20:08 -0800 (PST) Received: from e121896.arm.com (unknown [10.57.37.201]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 692EB3F70D; Thu, 24 Feb 2022 09:20:06 -0800 (PST) From: James Clark To: acme@kernel.org, linux-perf-users@vger.kernel.org, coresight@lists.linaro.org Cc: James Clark , Denis Nikitin , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org Subject: [PATCH 1/1] perf: Set build-id using build-id header on new mmap records Date: Thu, 24 Feb 2022 17:19:55 +0000 Message-Id: <20220224171955.862983-2-james.clark@arm.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20220224171955.862983-1-james.clark@arm.com> References: <20220224171955.862983-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 MMAP records that occur after the build-id header is parsed do not have their build-id set even if the filename matches an entry from the header. Set the build-id on these dsos as long as the MMAP record doesn't have its own build-id set. This fixes an issue with off target analysis where the local version of a dso is loaded rather than one from ~/.debug via a build-id. Reported-by: Denis Nikitin Signed-off-by: James Clark --- tools/perf/util/dso.h | 1 + tools/perf/util/header.c | 1 + tools/perf/util/map.c | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 011da3924fc1..3a9fd4d389b5 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -167,6 +167,7 @@ struct dso { enum dso_load_errno load_errno; u8 adjust_symbols:1; u8 has_build_id:1; + u8 header_build_id:1; u8 has_srcline:1; u8 hit:1; u8 annotate_warned:1; diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 6da12e522edc..571d73d4f976 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -2200,6 +2200,7 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev, build_id__init(&bid, bev->data, size); dso__set_build_id(dso, &bid); + dso->header_build_id = 1; if (dso_space != DSO_SPACE__USER) { struct kmod_path m = { .name = NULL, }; diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 1803d3887afe..4ae91e491e23 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -127,7 +127,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, if (map != NULL) { char newfilename[PATH_MAX]; - struct dso *dso; + struct dso *dso, *header_bid_dso; int anon, no_dso, vdso, android; android = is_android_lib(filename); @@ -185,7 +185,19 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, if (build_id__is_defined(bid)) dso__set_build_id(dso, bid); - + else { + /* + * If the mmap event had no build ID, search for an existing dso from the + * build ID header by name. Otherwise only the dso loaded at the time of + * reading the header will have the build ID set and all future mmaps will + * have it missing. + */ + header_bid_dso = __dsos__find(&machine->dsos, filename, false); + if (header_bid_dso && header_bid_dso->header_build_id) { + dso__set_build_id(dso, &header_bid_dso->bid); + dso->header_build_id = 1; + } + } dso__put(dso); } return map; -- 2.28.0