From nobody Sun Feb 8 04:49:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153520543030535.09686076595574; Sat, 25 Aug 2018 06:57:10 -0700 (PDT) Received: from localhost ([::1]:45921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftZ3s-0000ol-KE for importer@patchew.org; Sat, 25 Aug 2018 09:57:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftWPx-0007hO-FS for qemu-devel@nongnu.org; Sat, 25 Aug 2018 07:07:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftWPs-0008Vm-25 for qemu-devel@nongnu.org; Sat, 25 Aug 2018 07:07:45 -0400 Received: from droplet.rkapl.cz ([46.101.253.207]:49332) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ftWPr-0008Kn-Nx for qemu-devel@nongnu.org; Sat, 25 Aug 2018 07:07:39 -0400 Received: from localhost (unknown [IPv6:2a02:8308:bd:5c00:612:c66e:ed7f:6db]) by droplet.rkapl.cz (Postfix) with ESMTPSA id 5A7CD80E0A; Sat, 25 Aug 2018 13:06:59 +0200 (CEST) From: Roman Kapl To: Richard Henderson , qemu-devel@nongnu.org Date: Sat, 25 Aug 2018 13:06:34 +0200 Message-Id: <20180825110634.16573-1-code@rkapl.cz> X-Mailer: git-send-email 2.18.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 46.101.253.207 X-Mailman-Approved-At: Sat, 25 Aug 2018 09:56:09 -0400 Subject: [Qemu-devel] [PATCH] tcg: check for undefined labels X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Kapl Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, if a jump to a label that is not defined anywhere in the code is generated, QEMU will hapilly emit the code, but with effectively random jump target (no relocation done). At least check that there are no unprocessed relocations remaining when running a debug build and print a warning message. This could help debug or detect earlier errors like c2d9644e6d ("target/arm: Fix crash on conditional instruction in an IT bloc= k") Signed-off-by: Roman Kapl --- tcg/tcg.c | 29 +++++++++++++++++++++++++++++ tcg/tcg.h | 3 ++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tcg/tcg.c b/tcg/tcg.c index f27b22bd3c..3412502069 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -256,6 +256,21 @@ static __attribute__((unused)) inline void tcg_patch64= (tcg_insn_unit *p, } #endif =20 +static void tcg_pending_relocs_inc(TCGContext *s) +{ +#ifdef CONFIG_DEBUG_TCG + s->pending_relocs++; +#endif +} + +static void tcg_pending_relocs_dec(TCGContext *s) +{ +#ifdef CONFIG_DEBUG_TCG + tcg_debug_assert(s->pending_relocs > 0); + s->pending_relocs--; +#endif +} + /* label relocation processing */ =20 static void tcg_out_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type, @@ -276,6 +291,7 @@ static void tcg_out_reloc(TCGContext *s, tcg_insn_unit = *code_ptr, int type, r->addend =3D addend; r->next =3D l->u.first_reloc; l->u.first_reloc =3D r; + tcg_pending_relocs_inc(s); } } =20 @@ -287,6 +303,7 @@ static void tcg_out_label(TCGContext *s, TCGLabel *l, t= cg_insn_unit *ptr) tcg_debug_assert(!l->has_value); =20 for (r =3D l->u.first_reloc; r !=3D NULL; r =3D r->next) { + tcg_pending_relocs_dec(s); patch_reloc(r->ptr, r->type, value, r->addend); } =20 @@ -3518,6 +3535,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef TCG_TARGET_NEED_POOL_LABELS s->pool_labels =3D NULL; #endif +#ifdef CONFIG_DEBUG_TCG + s->pending_relocs =3D 0; +#endif =20 num_insns =3D -1; QTAILQ_FOREACH(op, &s->ops, link) { @@ -3587,6 +3607,15 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } } tcg_debug_assert(num_insns >=3D 0); + +#ifdef CONFIG_DEBUG_TCG + if (s->pending_relocs) { + qemu_log("warning: block at " TARGET_FMT_lx " has " + "%d unresolved references to jump labels\n", + tb->pc, s->pending_relocs); + } +#endif + s->gen_insn_end_off[num_insns] =3D tcg_current_code_size(s); =20 /* Generate TB finalization at the end of block */ diff --git a/tcg/tcg.h b/tcg/tcg.h index f9f12378e9..e80c511f7c 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -241,7 +241,7 @@ typedef struct TCGRelocation { int type; tcg_insn_unit *ptr; intptr_t addend; -} TCGRelocation;=20 +} TCGRelocation; =20 typedef struct TCGLabel { unsigned has_value : 1; @@ -679,6 +679,7 @@ struct TCGContext { #ifdef CONFIG_DEBUG_TCG int temps_in_use; int goto_tb_issue_mask; + int pending_relocs; #endif =20 /* Code generation. Note that we specifically do not use tcg_insn_unit --=20 2.18.0