Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp667272lqt; Mon, 18 Mar 2024 22:54:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVW7gGpAMrecxM4VtN5N05aJ4Ow9kkp6y9ClcYks00DEYKzd8MhvvEk/kA6bvVCqiPGbStoP3R2cKN4Xde57+CVbo4PzsZbBiKQhWIwTQ== X-Google-Smtp-Source: AGHT+IEy2x2/CrXX+Sx6MtGumkvrPDnFH0x9s7UTL47AakuzjolCCSqBE/5sCUcWajOtYq2yLLrp X-Received: by 2002:a05:622a:407:b0:42e:984f:1497 with SMTP id n7-20020a05622a040700b0042e984f1497mr1583012qtx.17.1710827642487; Mon, 18 Mar 2024 22:54:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710827642; cv=pass; d=google.com; s=arc-20160816; b=jI0oEo3iKevL9X+40lauE2KHS8gcdIrsPF2P7CPA81CdZptib88Ey79N51NMp2z2kL fDW+lkW5/TLKArm4TPR0YP4PLwtIrKTMnOnoLyIr/0J+B7Bw7zglGfAZgBe27hxTVrKN WPPjdsTF9ca+IKNo5Yc5rHpnKPA4enIsAstaWgjq0JvTaelay6kpQsEmJ4V6+HsA8ieO pyRq1nVs+Qwd/aIxIQ3qmmgzUuuQnV4L3LWOyhMXPnaqa/+7UHAUPQ5PcBO8apWEhbCX qV5XoypzBmvOJyzGPYVLRaWrMtsPe0y9klSwxl29FdaahgEhxpTRJ14HEkNe70Egqr/b sWQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=onnOspV8DQsJL3qStBwSxnIf9/MgqYLdOM+ftO2uGGw=; fh=44lErbL5kvNUjSV6UDWgBEjJyOJpjjMpxi6K+HFi+Bc=; b=YtFOwo83Q3qVmHn6J8xyZEhcuwiDJAdoXswIN7iqw3IIO1jchzwGsP2KKdraEHbERb FsmgM/zYghg1oBX8U2KzyxCT1LS5Np2e2V29rGJxhUrFhNPoPU9NHawQZBJZv5uNbNzS KmqWM4IiisjWAvObwuqHC6KPQzXKS+JzcmU+9p3hFZ3bn2vVdjwUCNCz/FJ4s/Oj9D8u x+Pu1Qo9LH+NFpyq4y1oIoMPCD/s7pieMR9EFRb9VgzxJ+21mTt0ZFVZUbTFFxFTnAuI ttk0MPUf3fsudZMwgXIFYbcFyHrZ9Kgtqi8tGnd7H1B+xH8dZPUcMSyG3qhPY2MsOTCX dtAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PtntBRFh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107038-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107038-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id g1-20020ac85801000000b004309f6ee62asi10181531qtg.265.2024.03.18.22.54.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 22:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107038-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PtntBRFh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107038-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107038-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3C2721C21170 for ; Tue, 19 Mar 2024 05:54:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E40647EF1D; Tue, 19 Mar 2024 05:51:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PtntBRFh" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E993D7CF0F; Tue, 19 Mar 2024 05:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710827485; cv=none; b=lWvV/kueXZU+HoMQnGOBJxoFGcH0+p3GPgwivLD/3phf3zXob+LN8n36MCiN4Ep6tMnvnosdhrV8EF6xaO2+X4m8DJc5qWRzeWHaahjEuZdcAJIVTTtCd34Sx2T7mH0BycXZ0vX0/O8DeplqHCEWm+VseTanRXNDY4f7BpMHWcg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710827485; c=relaxed/simple; bh=mf4B7dqQYwBHEG3EOUsWTWvUmMNcxn199ikuZuyHXX8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o4qK6TIcNLcxiwPga/MlDeGAeVghAo5XvvwK3K0q2Fl067ktReu84DRnXNpwjAnkASwtXtri1xXc7Hyd2I1uaVbOlDQv40nJAONnIwUNiNGU/0xtyOHDDuBDOiqoYWiTaSBK1lSqg1IK/H9F9eFGVPujv1IyFJv4WhQSbolu2Dk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PtntBRFh; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D482C433F1; Tue, 19 Mar 2024 05:51:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710827484; bh=mf4B7dqQYwBHEG3EOUsWTWvUmMNcxn199ikuZuyHXX8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PtntBRFhqkLS5FmNGg+r5hCM/LibLByTtcRTYcUZS4WhOEBtA6e1h9EC+UTF8bsk3 2BAs9ycu3t/noS9sFCgmj3Dk7/OnFa4YvDS44zv1optsRmoBG48nDordgE1bBBtM7+ CON6Tazc+SSp1/iXmc0zphTvnKSZ3QxuY5LEd5eDioMb1wFaYamqBCqnp2j4E1Sk5A 6FIDni12uTX/TtFwBpIMjB/H//f6XYvtewyTpR1UvEBkcMc3cljr/VhxOeMRgIF2Yb tLp7KFfnhCqD2klAv2K0xR3/gHQZNgt0MIwti/fPEfFBzcfRaulxon78tlwQAmyKip mTB8uVqXvXV9A== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 12/23] perf annotate-data: Handle global variable access Date: Mon, 18 Mar 2024 22:51:04 -0700 Message-ID: <20240319055115.4063940-13-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog In-Reply-To: <20240319055115.4063940-1-namhyung@kernel.org> References: <20240319055115.4063940-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When updating the instruction states, it also needs to handle global variable accesses. Same as it does for PC-relative addressing, it can look up the type by address (if it's defined in the same file), or by name after finding the symbol by address (for declarations). Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 46 ++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index 3b661e693410..2cc9f56e3eea 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -89,7 +89,7 @@ void exit_type_state(struct type_state *state); void update_var_state(struct type_state *state, struct data_loc_info *dloc, u64 addr, u64 insn_offset, struct die_var_type *var_types); void update_insn_state(struct type_state *state, struct data_loc_info *dloc, - struct disasm_line *dl); + Dwarf_Die *cu_die, struct disasm_line *dl); void init_type_state(struct type_state *state, struct arch *arch __maybe_unused) { @@ -485,7 +485,7 @@ void update_var_state(struct type_state *state, struct data_loc_info *dloc, } static void update_insn_state_x86(struct type_state *state, - struct data_loc_info *dloc, + struct data_loc_info *dloc, Dwarf_Die *cu_die, struct disasm_line *dl) { struct annotated_insn_loc loc; @@ -577,6 +577,29 @@ static void update_insn_state_x86(struct type_state *state, insn_offset, src->offset, sreg, dst->reg1); pr_debug_type_name(&tsr->type); } + /* Or check if it's a global variable */ + else if (sreg == DWARF_REG_PC) { + struct map_symbol *ms = dloc->ms; + u64 ip = ms->sym->start + dl->al.offset; + u64 addr; + int offset; + + addr = annotate_calc_pcrel(ms, ip, src->offset, dl); + + if (!get_global_var_type(cu_die, dloc, ip, addr, &offset, + &type_die) || + !die_get_member_type(&type_die, offset, &type_die)) { + tsr->ok = false; + return; + } + + tsr->type = type_die; + tsr->ok = true; + + pr_debug_dtp("mov [%x] global addr=%"PRIx64" -> reg%d", + insn_offset, addr, dst->reg1); + pr_debug_type_name(&type_die); + } /* Or try another register if any */ else if (src->multi_regs && sreg == src->reg1 && src->reg1 != src->reg2) { @@ -628,11 +651,26 @@ static void update_insn_state_x86(struct type_state *state, /* Case 4. memory to memory transfers (not handled for now) */ } +/** + * update_insn_state - Update type state for an instruction + * @state: type state table + * @dloc: data location info + * @cu_die: compile unit debug entry + * @dl: disasm line for the instruction + * + * This function updates the @state table for the target operand of the + * instruction at @dl if it transfers the type like MOV on x86. Since it + * tracks the type, it won't care about the values like in arithmetic + * instructions like ADD/SUB/MUL/DIV and INC/DEC. + * + * Note that ops->reg2 is only available when both mem_ref and multi_regs + * are true. + */ void update_insn_state(struct type_state *state, struct data_loc_info *dloc, - struct disasm_line *dl) + Dwarf_Die *cu_die, struct disasm_line *dl) { if (arch__is(dloc->arch, "x86")) - update_insn_state_x86(state, dloc, dl); + update_insn_state_x86(state, dloc, cu_die, dl); } /* The result will be saved in @type_die */ -- 2.44.0.291.gc1ea87d7ee-goog