From patchwork Mon Feb 11 17:01:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 158016 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2859113jaa; Mon, 11 Feb 2019 09:26:38 -0800 (PST) X-Google-Smtp-Source: AHgI3IbUNQcBkdEoLe0UzMHPezWHYf9KVXuCbvGmP+ywrBYucLO1ysqnNaWFyju0xErRXVa+tWpF X-Received: by 2002:a25:b78d:: with SMTP id n13mr28147783ybh.423.1549905998383; Mon, 11 Feb 2019 09:26:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549905998; cv=none; d=google.com; s=arc-20160816; b=d/EoypmzAXa72tefI0HOafCNVfptiemUy0lXRyXBEPeVHIYohY74tJRn7JtGyS2XOt UVkHiCIe4v1HjXwXW+mxCuMPT4R/Z2bq4/KXbeT//tQUUE5FOMoF1bWMY7zC/LMiZDxW ffY8yvvowJhy01Lc5r/GOvJ1uTza0D3BtYogKbILjKXrmYo1Q5u2cEvOSgnF/xjiSyMa QA8dWl0tYqzODkeOwyV78IRwkk5IRmeXYG5toKzomK3vnMZ3Zvxb7yJiNjc30GPTzWR8 o4HFpD8UXZV3/RwdxFN36Rb3hBg/sCFIsZkGtg0+5e46XHhXJ1oxS+p2IVm8+8H5URpm 4Xmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=zs4D8H0jbWCZWQGKUauE35wZw5DaF/qNy92CTv/x36A=; b=ulmiqdoePOxJpQ3dTkulpHSwa7BSGssmF9CEczdR9vDAOQ6scuOjow+MEmSEZK/AQ+ AnsFSNgmZhe9+9tB1oksKST+eJmR9tUoKUYZmyrVXqyOZwrVpP8ETBx72U0YOUjzKp9e 0c8f6Yo04AmuMUel76A8iFWorFaJP4SVdaF00GnH2X9uQraud9MAVwqWiSuA4tBMhF6E 0fC9p+S4Q5hs/75/o2IOB0ORNpvF30bojX8SW5kwmntDhfeFh0ZoOzxQ52meram3kK7j 9U6T3gektPAZAHCXqTuxauufgK601WsL+6Cv60gRw7pCocLm8ydb0x68ln+uchRRGLjS bFgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E1jTql9S; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c184si6570529ywe.156.2019.02.11.09.26.38 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 11 Feb 2019 09:26:38 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=E1jTql9S; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:53536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtFLp-0003Zf-Rg for patch@linaro.org; Mon, 11 Feb 2019 12:26:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtF9E-00020I-Rx for qemu-devel@nongnu.org; Mon, 11 Feb 2019 12:13:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtExk-0000tk-8o for qemu-devel@nongnu.org; Mon, 11 Feb 2019 12:01:47 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:43702) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gtExi-0000s1-AA for qemu-devel@nongnu.org; Mon, 11 Feb 2019 12:01:42 -0500 Received: by mail-pl1-x62d.google.com with SMTP id f90so5336280plb.10 for ; Mon, 11 Feb 2019 09:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zs4D8H0jbWCZWQGKUauE35wZw5DaF/qNy92CTv/x36A=; b=E1jTql9S7GPIKpZgiAzjVtETqgGYiHsRCStKUTe2PojTYLztJHxTdlw6qMa+HnWIby Bb30Qxd5nZTAYIv2YT5P+8qEMdVMO3ZhEkprquFERkGYZDLnIdhQ3sD4O1/ZGvtxsnX5 +DkTHONqVdocfRrkE+RpVXr6AjqluDXx60yYh93HcEMhPBKVx9RhuCRxHB7OTh39A54a GZLCNszgXC7fF9m5YSrUhbSIjcd2ZeArRCrbH5Es/OrLCnxqOkulYLs6GvBpxzyUgjlZ zHWZQ8Az8nr9oI34BWTj4M9WpcM8eahNnSJXSOCPZgFj4YcKja0ykh10xr9+XN5S3tRG 75Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zs4D8H0jbWCZWQGKUauE35wZw5DaF/qNy92CTv/x36A=; b=skgNllvebl74QbPBdYrmk44C8zwqI6huimXd+ANd4mw717P+wURQ+Ys3jDsevgERfA oyn0BI1ABx4OG++DEYD0R2Irhb4bXSmPB/903jZgyFfPx1mIslFzIO8tHs5nhLXZ+7wQ 300q0e6v6YCVVeI36E8TbZTA/PQcGTlFjsgwnBSeHe/QCL3qErwwslf6/Vv3WQLn4kwN Onrf7DM9Sn2j0Pl0vdQ2vyVI+u/25MIVikVuaLsAysVW8zMZAk+6Dc8TCWcM31+HfDMz 0m35enjdIsx91OsKTdYMS5y+bbba1C+aHB3nKlEYSyrxFu6fOOBvwGD4brQ7ANsHKB+H 1hjA== X-Gm-Message-State: AHQUAua6ABAHnAxaa65b4WH0WCWgAYHpPvbfjqFP5EybC0Vy5nVzym7U KS4+ZwTdh/cqC5HCD5/5GwT6+Dm2VIY= X-Received: by 2002:a17:902:8d8e:: with SMTP id v14mr38197755plo.133.1549904500542; Mon, 11 Feb 2019 09:01:40 -0800 (PST) Received: from cloudburst.twiddle.net (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id b24sm15712567pfe.136.2019.02.11.09.01.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Feb 2019 09:01:39 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 11 Feb 2019 09:01:33 -0800 Message-Id: <20190211170136.18680-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190211170136.18680-1-richard.henderson@linaro.org> References: <20190211170136.18680-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::62d Subject: [Qemu-devel] [PULL 1/4] 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: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 block") Reported-by: Roman Kapl Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- tcg/tcg-op.h | 1 + tcg/tcg.h | 12 +++++++++--- tcg/tcg.c | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) -- 2.17.2 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, TCGv_i64 a1, TCGv_i64 a2, static inline void gen_set_label(TCGLabel *l) { + l->present = 1; tcg_gen_op1(INDEX_op_set_label, label_arg(l)); } 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; -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 +}; typedef struct TCGPool { struct TCGPool *next; @@ -685,6 +690,7 @@ struct TCGContext { #endif #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 = (TCGLabel){ .id = s->nb_labels++ }; +#ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_INSERT_TAIL(&s->labels, l, next); +#endif return l; } @@ -1092,6 +1095,9 @@ void tcg_func_start(TCGContext *s) QTAILQ_INIT(&s->ops); QTAILQ_INIT(&s->free_ops); +#ifdef CONFIG_DEBUG_TCG + QSIMPLEQ_INIT(&s->labels); +#endif } static inline TCGTemp *tcg_temp_alloc(TCGContext *s) @@ -3841,6 +3847,23 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) } #endif +#ifdef CONFIG_DEBUG_TCG + /* Ensure all labels referenced have been emitted. */ + { + TCGLabel *l; + bool error = 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 = true; + } + } + assert(!error); + } +#endif + #ifdef CONFIG_PROFILER atomic_set(&prof->opt_time, prof->opt_time - profile_getclock()); #endif