Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1839183pxb; Fri, 24 Sep 2021 13:12:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp4PNfYG29EY9EUbFUEz5oRA74uFJEb+lvmyYNQgMLISJwVwSxcv1Zep751vPIpT4H7g1T X-Received: by 2002:a50:bf49:: with SMTP id g9mr7345596edk.262.1632514337119; Fri, 24 Sep 2021 13:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632514337; cv=none; d=google.com; s=arc-20160816; b=N2SCeDRRbBgJuKja7Bm+SVms3150f9hYIz5jETScZBhYXrF2jLzJ4gw9GmXNHBr/Su VtkPWQMqD+wkuWaptV/Q0gpSM/+84chl/g2ue7QeuntWUCcuDnS1Gx/peVDbH19qOOXv FEHjCgzlYMDLH1MaU5NcHIvAUAXr9F51agsSw0HhcJ22QUBmkS+64Sj3lAh0FB9wBJ/7 gMkWfNtDhMF0BOBbj4Yb8qkWFW4fsR8div5+wAyXKGDmwS1O1RGDBSvOalWrc3FV4N+B /Z+sCIxegCTuP3mky4ImYWpiC6rez1un3hcCJxJdUwi05PEgR9SSWJBbDiJ7vdVqdzGd m50w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UKOeNGX1Cj7shSplDpmMiDFjbJFhPFpof0xcd7x2kDQ=; b=OXmVEHkV27I1UgCFCL4sPOnJDfKv4UkENY+VUmSctHZ9CRN0rBBvtTwlwcaGnzVNsS ThZzUFjw1hAS8gQ4oV9nxIX3WXktWcKk+ZC+bIpP8ZBYYdv64j0OSvJFI9UMo/LHPZCw fLzGdAW817y6NplqFlhAvhAA53TMQxyzkB5Yt01hM818g7mBfxbM38dKeLb0mE/ldnvX Dr45RWo5owu7LARgf2Om2eQLy+C8ykuyJWQSq/Qz9bLrmj1RhHe/L3Lny3CzJB2apWpl z2298FWOalUJOLcIebvn10obKR8grKBbptPYtq4+YhnW8IshMTN0kRI6U23wqIdXEXVD cdUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qnzA4vKf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zd20si10675553ejb.778.2021.09.24.13.11.53; Fri, 24 Sep 2021 13:12:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qnzA4vKf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346333AbhIXNKC (ORCPT + 99 others); Fri, 24 Sep 2021 09:10:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:34644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345477AbhIXNGl (ORCPT ); Fri, 24 Sep 2021 09:06:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7CFC36136F; Fri, 24 Sep 2021 12:56:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632488187; bh=i50Q+2odLvoFw3UCo6bLvVHGv28CMrkLdVV9jE1sgjc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qnzA4vKfPvCr0wH2L92RCHdSG50qGFsI2/6RSpIBXnl1qqdV9QkuksyLaCeGssZWu Hd5iC2IGSi2/I85IknuY44ZORp/V0JYKpXPHBEVUR1+ICB4D2M22+BEQqvSpARpe9a MTU+548laqa9AXHCqHJJjIcpNNB2VSLKd9yE+CIQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namhyung Kim , Jiri Olsa , Andi Kleen , Ian Rogers , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 5.10 18/63] perf tools: Allow build-id with trailing zeros Date: Fri, 24 Sep 2021 14:44:18 +0200 Message-Id: <20210924124334.879177912@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210924124334.228235870@linuxfoundation.org> References: <20210924124334.228235870@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Namhyung Kim commit 4a86d41404005a3c7e7b6065e8169ac6202887a9 upstream. Currently perf saves a build-id with size but old versions assumes the size of 20. In case the build-id is less than 20 (like for MD5), it'd fill the rest with 0s. I saw a problem when old version of perf record saved a binary in the build-id cache and new version of perf reads the data. The symbols should be read from the build-id cache (as the path no longer has the same binary) but it failed due to mismatch in the build-id. symsrc__init: build id mismatch for /home/namhyung/.debug/.build-id/53/e4c2f42a4c61a2d632d92a72afa08f00000000/elf. The build-id event in the data has 20 byte build-ids, but it saw a different size (16) when it reads the build-id of the elf file in the build-id cache. $ readelf -n ~/.debug/.build-id/53/e4c2f42a4c61a2d632d92a72afa08f00000000/elf Displaying notes found in: .note.gnu.build-id Owner Data size Description GNU 0x00000010 NT_GNU_BUILD_ID (unique build ID bitstring) Build ID: 53e4c2f42a4c61a2d632d92a72afa08f Let's fix this by allowing trailing zeros if the size is different. Fixes: 39be8d0115b321ed ("perf tools: Pass build_id object to dso__build_id_equal()") Signed-off-by: Namhyung Kim Acked-by: Jiri Olsa Cc: Andi Kleen Cc: Ian Rogers Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/20210910224630.1084877-1-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/dso.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1336,6 +1336,16 @@ void dso__set_build_id(struct dso *dso, bool dso__build_id_equal(const struct dso *dso, struct build_id *bid) { + if (dso->bid.size > bid->size && dso->bid.size == BUILD_ID_SIZE) { + /* + * For the backward compatibility, it allows a build-id has + * trailing zeros. + */ + return !memcmp(dso->bid.data, bid->data, bid->size) && + !memchr_inv(&dso->bid.data[bid->size], 0, + dso->bid.size - bid->size); + } + return dso->bid.size == bid->size && memcmp(dso->bid.data, bid->data, dso->bid.size) == 0; }