From nobody Thu Apr 25 07:36:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549598232940491.2411265961575; Thu, 7 Feb 2019 19:57:12 -0800 (PST) Received: from localhost ([127.0.0.1]:50637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grxHk-0000YK-DD for importer@patchew.org; Thu, 07 Feb 2019 22:57:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grxGg-00008h-Bt for qemu-devel@nongnu.org; Thu, 07 Feb 2019 22:55:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grxGf-0001AU-5H for qemu-devel@nongnu.org; Thu, 07 Feb 2019 22:55:58 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:46417) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1grxGe-00018O-MT for qemu-devel@nongnu.org; Thu, 07 Feb 2019 22:55:57 -0500 Received: by mail-pf1-x442.google.com with SMTP id c73so1023910pfe.13 for ; Thu, 07 Feb 2019 19:55:56 -0800 (PST) Received: from cloudburst.twiddle.net (97-126-115-157.tukw.qwest.net. [97.126.115.157]) by smtp.gmail.com with ESMTPSA id a13sm636729pgw.34.2019.02.07.19.55.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Feb 2019 19:55:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=fi6acWPf3UyoRRL12cPTLC97twqnz7bd3AIrFLxzYE0=; b=a0q8e8ROpGiZZaC5EjWBlp1ArMQfffBL6zEHGKkGuvG/xPH8oOPSNAmYjsTlNCCVCa woYJr12oFc6veCDt7K+oGDpmh/Qib7XtUcczcCVv5omZYfPyMg1QgzM7ib1OejdJK+nS OxO1KZTfHf9jeaMA9+e5GGfkW7C+wqjNVKjoRXurOg7EIRu4GjqIpL5ds5wd3Z3VBp1U 0Rv1/CHtr18kUalPJaCTmztbOUJOSY5bwKiObf3Cku+elcGNGoYl1I1tuWtTh3GWWktA NfMZmTvToE0hYyjx6IDimPZyPfr05J7hdIGXN54chbmcBEqK/+OqLpf/GyBzdMkGHlr5 cghg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=fi6acWPf3UyoRRL12cPTLC97twqnz7bd3AIrFLxzYE0=; b=RDuP+sYae4BXq0P2K/SEZbH1Uj2m+V9oYhZQ/383DqyY+NdnpaEYnM59E+eBNqRmSW 2i4Ua02RsGj9Jv57msoy52WLLqQXRGVJ9G0UTb3QmueSfLXOdqYI4yahXCLd+hFEA1pU Csqzygu3yP6/cghm70b2Q2+ws2Shic0uIERbqTm/HfBx+jjyKy/9oz+kTMLtTHnEvahz QVH6MVs6hKno86LGtbjPx9gAW/Mg1YiyTl+R6DEqgDPwl+VsaoNDWsrTSK6Z9fkgR1MZ jO4Gh4msXvfrj7Xw7HamuvAx2efQMOLG/lbfVQY7+1m1OtdNclh6d1BoCBs9g9vTmRwQ D4/w== X-Gm-Message-State: AHQUAuZMSztvp8QzqzBrCwB5P5c2wwxqxCKzgoap+ZOBkehZx2Voq67S +53flzaHcaRBaieJpXJnYgDlCwLl+LmvhQ== X-Google-Smtp-Source: AHgI3IbL1zIR2eI030wRcm2Q9UHMn0wITDFGJwdbW/mA/hHs2zVmNTYAPjYZIE7x0yx7EuloRY4iYw== X-Received: by 2002:a62:3ad1:: with SMTP id v78mr19546729pfj.85.1549598154906; Thu, 07 Feb 2019 19:55:54 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Feb 2019 19:55:51 -0800 Message-Id: <20190208035551.3036-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH] tcg: Diagnose referenced labels that have not been emitted 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, a jump to a label that is not defined anywhere will be emitted not be relocated. This results in a jump to a random jump target. With tcg debugging, print a diagnostic to the -d op file and abort. This could help debug or detect errors like c2d9644e6d ("target/arm: Fix crash on conditional instruction in an IT bloc= k") Reported-by: Roman Kapl Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tcg/tcg-op.h | 1 + tcg/tcg.h | 12 +++++++++--- tcg/tcg.c | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) --- This detects errors earlier than the patch that Roman posted. r~ diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index 2d98868d8f..d3e51b15af 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -255,6 +255,7 @@ static inline void tcg_gen_op6ii_i64(TCGOpcode opc, TCG= v_i64 a1, TCGv_i64 a2, =20 static inline void gen_set_label(TCGLabel *l) { + l->present =3D 1; tcg_gen_op1(INDEX_op_set_label, label_arg(l)); } =20 diff --git a/tcg/tcg.h b/tcg/tcg.h index 045c24a357..32b7cf3489 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -244,16 +244,21 @@ typedef struct TCGRelocation { intptr_t addend; } TCGRelocation;=20 =20 -typedef struct TCGLabel { +typedef struct TCGLabel TCGLabel; +struct TCGLabel { + unsigned present : 1; unsigned has_value : 1; - unsigned id : 15; + unsigned id : 14; unsigned refs : 16; union { uintptr_t value; tcg_insn_unit *value_ptr; TCGRelocation *first_reloc; } u; -} TCGLabel; +#ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_ENTRY(TCGLabel) next; +#endif +}; =20 typedef struct TCGPool { struct TCGPool *next; @@ -685,6 +690,7 @@ struct TCGContext { #endif =20 #ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_HEAD(, TCGLabel) labels; int temps_in_use; int goto_tb_issue_mask; #endif diff --git a/tcg/tcg.c b/tcg/tcg.c index 20a5d8f315..9b2bf7f439 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -305,6 +305,9 @@ TCGLabel *gen_new_label(void) *l =3D (TCGLabel){ .id =3D s->nb_labels++ }; +#ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_INSERT_TAIL(&s->labels, l, next); +#endif =20 return l; } @@ -1092,6 +1095,9 @@ void tcg_func_start(TCGContext *s) =20 QTAILQ_INIT(&s->ops); QTAILQ_INIT(&s->free_ops); +#ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_INIT(&s->labels); +#endif } =20 static inline TCGTemp *tcg_temp_alloc(TCGContext *s) @@ -3841,6 +3847,23 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } #endif =20 +#ifdef CONFIG_DEBUG_TCG + /* Ensure all labels referenced have been emitted. */ + { + TCGLabel *l; + bool error =3D false; + + QSIMPLEQ_FOREACH(l, &s->labels, next) { + if (unlikely(!l->present) && l->refs) { + qemu_log_mask(CPU_LOG_TB_OP, + "$L%d referenced but not present.\n", l->id); + error =3D true; + } + } + assert(!error); + } +#endif + #ifdef CONFIG_PROFILER atomic_set(&prof->opt_time, prof->opt_time - profile_getclock()); #endif --=20 2.17.2