Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1529501imn; Sun, 31 Jul 2022 10:35:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR4WXgrsj9QA3lusWT9nLgstcFU2ziuLZd6txi2Jzp3O/pnOpFDu9YP9LfbP14twTZy1Vx1S X-Received: by 2002:a17:902:b612:b0:16c:7e2d:ff39 with SMTP id b18-20020a170902b61200b0016c7e2dff39mr13105770pls.111.1659288926416; Sun, 31 Jul 2022 10:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659288926; cv=none; d=google.com; s=arc-20160816; b=q1770zC056dZ7i2n4a2glE3zLeXWybUe3YZOBYbJ/1nFY6DkfE5PW3pnRAd+1LrivM yLfB6nD72FZuq6O7OiF1qQOz7IEpAMngSslfZG1wj+pXXsay63xecZBj5NzuOE6j2JNY fNYgtEzVm0mZABxCr/nJDmYzBSJu8h5f2mXhD7ckt8cYExUNZVygsipP7OjgPQID5OVC 0fq0tyW3N1mcWDqTO9FXed3GhsXw0ubXvOvbyb8ch2nDmXHSDudc3RTbRqfTxDeNH6wg pjb8k1GX5if5+hfFpBvp9C4v6AIv5sFM0L+z/a49mUahgHxDexmsB2vxjgH2GWiE8XD9 fHbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Z1WQwnH+vUxlQu9SIjMUORiE1pIB6GKovp797CtaNYY=; b=08Yo1bTJ7UU6QyzCUwizo1Av1IY2+QzZpaO17k0DYUrIJcSYhu1OlvLmce4S6xDBCP aOYWuakgrURobO9sW3U2SVHx9KlFpCMr5N93a7/Pjpgh2rvvNUXjlnDgNcyDpD7+gA5M y6jJpp7vo78CSbWzLthrsJQuTyuWnP712qCCVP705sNsza9X3lZDb/5WBqRJyqRH172B te7HwYUDuixyRys5SOLIOnBjXSMg68S1EUA2v5e5XHRE6H6ntmigQkwFwJC7Kv7lpP14 sXCiFa9+YSoS2Koo6UqjQIUPf7N0rhWRFQ8EzXZ9mAlmHsvi5oqx7eJRvXFbd71VmxmS 7CXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GK+W5L3V; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mi8-20020a17090b4b4800b001f31f339134si12422584pjb.152.2022.07.31.10.35.11; Sun, 31 Jul 2022 10:35:26 -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=@google.com header.s=20210112 header.b=GK+W5L3V; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237125AbiGaQwL (ORCPT + 99 others); Sun, 31 Jul 2022 12:52:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232158AbiGaQwI (ORCPT ); Sun, 31 Jul 2022 12:52:08 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2737BC11 for ; Sun, 31 Jul 2022 09:52:06 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id ay11-20020a05600c1e0b00b003a3013da120so6335326wmb.5 for ; Sun, 31 Jul 2022 09:52:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Z1WQwnH+vUxlQu9SIjMUORiE1pIB6GKovp797CtaNYY=; b=GK+W5L3VdcugavZwk0SoDUmRg9mNxloRY59ml4fk+OiIArlIEgxhgehmr+jEr+dCha W53vW4JWF9sXMus7ySClo1QPGScpIWT/SX2D3KgC2JdVJw91D5ikKgxGtlTUaKQ1pomu /HALESqpmFJD1h7WmxJDJ/kGYlZJItNJb0dKSeRhRsCZOHRp2wz9Z7iJr/1bVRMMYCsg DJhxUUxZL8mfhZ9OSs5SzS2qv4dCYTNTnVPNYs7Xw9hanP21LwuASvP7FpmgWnp4rOd3 OYVdKj/dZvaWf7AmnRPhClWgOgbySUcd4nH9/RA3wZ4N1cGRWgrYnHrIhSXmshrz1IA/ yu8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Z1WQwnH+vUxlQu9SIjMUORiE1pIB6GKovp797CtaNYY=; b=mPrS59cWgwvicVmA9yvnoF3oZhsHvpQOS3I0d/eThQYMQfsJtR7CcA0txgM4/RKt03 AA+sDCywoFNrjaWEUcn1ED1ycbXj4RLt3S5/xU06GaAHsFVdIaQjF6VAl9QSRk+j2lR/ JGJb+NUVpUUuO1rrLasxGTP/OOb70IhJcJHVXHZLRi0M0YtEa1A68k9aZa2sKV/Gw6W4 ZK9uzi1YvbDjpi71neVGts77fY0wdzozDnu3fRtmfAV2uqAeYzZk2dKhdQkP1wjYJ5Ci vrysetr78U8fx17MFB5ad6+H1oF8aQsGDuwUC36d57nL94eD1LKLKAwI+aGXQD+WspDZ TY+A== X-Gm-Message-State: AJIora/Oeb0Xp6CnA4LmmroMjM72njtGHbW4cpipGmwLk5RRm11EdzSs DoOklky/5B18JNtGeWVdea5BoOy5vb0Qq6yq4PzaHg== X-Received: by 2002:a05:600c:4e86:b0:3a3:417a:2fcd with SMTP id f6-20020a05600c4e8600b003a3417a2fcdmr8933328wmq.149.1659286325289; Sun, 31 Jul 2022 09:52:05 -0700 (PDT) MIME-Version: 1.0 References: <20220724060013.171050-1-leo.yan@linaro.org> <20220724060013.171050-2-leo.yan@linaro.org> <20220730093819.GA574473@leoy-ThinkPad-X240s> <20220731123702.GA205142@leoy-ThinkPad-X240s> In-Reply-To: <20220731123702.GA205142@leoy-ThinkPad-X240s> From: Ian Rogers Date: Sun, 31 Jul 2022 09:51:53 -0700 Message-ID: Subject: Re: [PATCH v3 1/2] perf symbol: Correct address for bss symbols To: Leo Yan Cc: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , Namhyung Kim , Alexander Shishkin , Fangrui Song , Chang Rui , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, URI_HEX,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Sun, Jul 31, 2022 at 5:37 AM Leo Yan wrote: > > On Sat, Jul 30, 2022 at 08:21:10AM -0700, Ian Rogers wrote: > > [...] > > > > On the other hand, I can accept to simply change pr_warning() to > > > pr_debug4() to avoid warning flood, the log still can help us to find > > > potential symbol parsing issue, so far they are not false-positive > > > reporting. > > > > Thanks, I suspect the ELF that the Java agent has created isn't good. > > The Java agent is part of perf as and so is the ELF file generation > > code: > > https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/util/genelf.c?h=perf/core#n367 > > I think it's no need to change the function jit_write_elf(), please see > below comment. > > > I took a quick look but most of the logic is in libelf - it seems less > > obvious the bug would be there rather than perf. Could you take a > > look? Ideally there'd be a quick fix that keeps all the benefits of > > your change and the jvmti code working. > > A bit more finding for java JIT symbols. Let's see below two samples: > > 6.72% java /home/leoy/.debug/jit/java-jit-20220731.XXKRpgmR/jitted-214330-29.so 0x5b54 B [.] Interpreter > 0.90% java /home/leoy/.debug/jit/java-jit-20220731.XXKRpgmR/jitted-214330-3475.so 0x4fc B [.] jdk.internal.math.FloatingDecimal$BinaryToASCIIBuffer.dtoa(int, long, int, boolean) > > I can see the DSO "jitted-214330-29.so" only contains a java JIT symbol > "Interpreter", and I also observed the same behavior for other JIT > symbols, e.g. jitted-214330-3475.so only contains the symbol > "jdk.internal.math.FloatingDecimal$BinaryToASCIIBuffer.dtoa(int, long, > int, boolean)". > > We always see these JIT symbols always have the consistent start file > address, but this would not introduce conflit since every JIT symbol has > its own DSO rather than share the same DSO. > > I think now I understand your meaning, and your below change is fine for > me, I tested it and confirmed it can show up java JIT symbols properly. > Just a comment, it would be better to add a comment for why we need to > add symbols when failed to find program header, like: > > if (elf_read_program_header(syms_ss->elf, > (u64)sym.st_value, &phdr)) { > pr_debug4("%s: failed to find program header for " > "symbol: %s\n", __func__, elf_name); > 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 { > ... > } > > Could you send a formal patch for this? Thanks! Done. Thanks for sanity checking all of this! Please double check and add the reviewed/acked-by: https://lore.kernel.org/lkml/20220731164923.691193-1-irogers@google.com/ Thanks, Ian > Leo > > > > Thanks, > > > Leo > > > > > > > ``` > > > > --- a/tools/perf/util/symbol-elf.c > > > > +++ b/tools/perf/util/symbol-elf.c > > > > @@ -1305,16 +1305,21 @@ 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); > > > > + 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); > > > > ``` > > > > > > > > Thanks, > > > > Ian > > > > > > > > > > > > > > demangled = demangle_sym(dso, kmodule, elf_name); > > > > > -- > > > > > 2.25.1 > > > > >