Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3027640rwb; Mon, 15 Aug 2022 16:26:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR5I9xOLyXKh+hU9U3j/1s6o08xWctB21+DWzKrjQRn4nZdVpL1KbhTFL9XmDzTgY1KNvekQ X-Received: by 2002:a17:907:6eaa:b0:730:cae8:3088 with SMTP id sh42-20020a1709076eaa00b00730cae83088mr12161224ejc.27.1660605960683; Mon, 15 Aug 2022 16:26:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605960; cv=none; d=google.com; s=arc-20160816; b=rQaQNvsWwdoeQhEQ/sNprc8pI/KzrVKEiFgKnXot2GTeDaeWwkZfBpD42oi3/bJyo2 6TP2hyA5yS6aJ2CSsF9d10P2tdStVTg+u6Oqpdc+Od3F3qSqFe648NGrBxLzgN+I3qxR LnBbrVz30NH9RbPSs+5YBTpZUWkW9hB13pyJ9AqqCn3UfqAp5V1xvm2CPYy2Zv/V5GVh 4rj28g/24A+kWmTUq0JOarD338ewhDbqleW+0WAMvDnfovESb+TQMzyxF3dC2vmwz6zC 7RrFO1oKAwRY5s2xTd9Htq0uDJLUcmCBroTJODUfFDfCVUMhi5BfIxpLqdYMY9XE2HHp 844w== 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=6WC9Q09GD5j7lEOcCdxp8HTHkR7YQ7d1+6/QsWv9rVM=; b=uU7Tg157x1ZIafuXluhE6CL87o3g9mNro+Qh+xUtKhZXCNmbzN8eRIL9O4WIvc09da RWIKVUsu6qtr0XCuz1PYcPJKv1fj9QDWU+X9JBtCDNNzj1m5AyHyYL8tIUqZ1IMcM1Rg XM7bCckAzgMplbaX7zT1zs6v5kzOIubxkoFucg7XJqzKAwkQX4u11EZh4UeBtT8O/qKv NRnyZeZEZot2/5hyvu4/tkVuPIKxb/uWUINAepjOlVf+qaHqeHLIJ14HhyAqm5AGfJzT o1Wfe4zx6mkmzYyxppcTsuxQPHDoNrIg5Iv1K/Nuw8fABfVo7iJebwMfiIZ+mpqMdFNW Ry5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wDUCGWni; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h4-20020a056402280400b0043d100bcf3bsi10427953ede.538.2022.08.15.16.25.33; Mon, 15 Aug 2022 16:26:00 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=wDUCGWni; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244119AbiHOXAV (ORCPT + 99 others); Mon, 15 Aug 2022 19:00:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346663AbiHOW6d (ORCPT ); Mon, 15 Aug 2022 18:58:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C2F760C0; Mon, 15 Aug 2022 12:56:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6549AB80EAD; Mon, 15 Aug 2022 19:56:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 975FFC433D6; Mon, 15 Aug 2022 19:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593391; bh=wDfmcr8hqpXBUVKskBOJMr0tIJOdTKM3fBqq+O/LQL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wDUCGWni8H85LLNHmdeh8ahoSkzYPlPeZu/15aElcUkw7my7K9CMvIXpu3Ptg6kWK uVjxheY2rDpR8l/J7cNJMryyK+tV1vBxLnq8jkKoClC1h91/LYInkIwS88WgUrRcpn b3bdmpYsMn3YPwKQRHx6njbuRfjHV5GSvXv8I/XE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Ian Rogers , Alexander Shishkin , Jiri Olsa , Mark Rutland , Namhyung Kim , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.18 0939/1095] perf symbol: Fail to read phdr workaround Date: Mon, 15 Aug 2022 20:05:38 +0200 Message-Id: <20220815180508.040651404@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URI_HEX 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 From: Ian Rogers [ Upstream commit 6d518ac7be6223811ab947897273b1bbef846180 ] The perf jvmti agent doesn't create program headers, in this case fallback on section headers as happened previously. Committer notes: To test this, from a public post by Ian: 1) download a Java workload dacapo-9.12-MR1-bach.jar from https://sourceforge.net/projects/dacapobench/ 2) build perf such as "make -C tools/perf O=/tmp/perf NO_LIBBFD=1" it should detect Java and create /tmp/perf/libperf-jvmti.so 3) run perf with the jvmti agent: perf record -k 1 java -agentpath:/tmp/perf/libperf-jvmti.so -jar dacapo-9.12-MR1-bach.jar -n 10 fop 4) run perf inject: perf inject -i perf.data -o perf-injected.data -j 5) run perf report perf report -i perf-injected.data | grep org.apache.fop With this patch reverted I see lots of symbols like: 0.00% java jitted-388040-4656.so [.] org.apache.fop.fo.FObj.bind(org.apache.fop.fo.PropertyList) With the patch (2d86612aacb7805f ("perf symbol: Correct address for bss symbols")) I see lots of: dso__load_sym_internal: failed to find program header for symbol: Lorg/apache/fop/fo/FObj;bind(Lorg/apache/fop/fo/PropertyList;)V st_value: 0x40 Fixes: 2d86612aacb7805f ("perf symbol: Correct address for bss symbols") Reviewed-by: Leo Yan Signed-off-by: Ian Rogers Tested-by: Leo Yan Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Leo Yan Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20220731164923.691193-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/symbol-elf.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index ef6ced5c5746..cb7b24493782 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1294,16 +1294,29 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss, if (elf_read_program_header(syms_ss->elf, (u64)sym.st_value, &phdr)) { - pr_warning("%s: failed to find program header for " + pr_debug4("%s: failed to find program header for " "symbol: %s st_value: %#" PRIx64 "\n", __func__, elf_name, (u64)sym.st_value); - continue; + pr_debug4("%s: adjusting symbol: st_value: %#" PRIx64 " " + "sh_addr: %#" PRIx64 " sh_offset: %#" PRIx64 "\n", + __func__, (u64)sym.st_value, (u64)shdr.sh_addr, + (u64)shdr.sh_offset); + /* + * Fail to find program header, let's rollback + * to use shdr.sh_addr and shdr.sh_offset to + * calibrate symbol's file address, though this + * is not necessary for normal C ELF file, we + * still need to handle java JIT symbols in this + * case. + */ + sym.st_value -= shdr.sh_addr - shdr.sh_offset; + } else { + pr_debug4("%s: adjusting symbol: st_value: %#" PRIx64 " " + "p_vaddr: %#" PRIx64 " p_offset: %#" PRIx64 "\n", + __func__, (u64)sym.st_value, (u64)phdr.p_vaddr, + (u64)phdr.p_offset); + sym.st_value -= phdr.p_vaddr - phdr.p_offset; } - pr_debug4("%s: adjusting symbol: st_value: %#" PRIx64 " " - "p_vaddr: %#" PRIx64 " p_offset: %#" PRIx64 "\n", - __func__, (u64)sym.st_value, (u64)phdr.p_vaddr, - (u64)phdr.p_offset); - sym.st_value -= phdr.p_vaddr - phdr.p_offset; } demangled = demangle_sym(dso, kmodule, elf_name); -- 2.35.1