From nobody Sun May  4 10:18:22 2025
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;
	dkim=fail;
	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;
	dmarc=fail(p=none dis=none)  header.from=linaro.org
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by
 mx.zohomail.com
	with SMTPS id 1544758059507187.87565728289724;
 Thu, 13 Dec 2018 19:27:39 -0800 (PST)
Received: from localhost ([::1]:59097 helo=lists.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>)
	id 1gXe8Y-0004ME-8t
	for importer@patchew.org; Thu, 13 Dec 2018 22:27:38 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:58789)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <richard.henderson@linaro.org>) id 1gXe0r-0005wM-Fp
	for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:42 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <richard.henderson@linaro.org>) id 1gXe0q-0006lv-10
	for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:41 -0500
Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:39969)
	by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
	(Exim 4.71) (envelope-from <richard.henderson@linaro.org>)
	id 1gXe0p-0006jt-PZ
	for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:39 -0500
Received: by mail-ot1-x344.google.com with SMTP id s5so4108816oth.7
	for <qemu-devel@nongnu.org>; Thu, 13 Dec 2018 19:19:39 -0800 (PST)
Received: from cloudburst.twiddle.net ([187.217.227.243])
	by smtp.gmail.com with ESMTPSA id
	g138sm2367537oib.26.2018.12.13.19.19.37
	(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
	Thu, 13 Dec 2018 19:19:38 -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=NWDBLg4EJPpGo+Tg/cnkYmTbp1eugTTZ/aHQeyIz28k=;
	b=jK2NvlPwntaZ+RI9c0jFRvGf4Ovcs2CxO9BY662alr0JJd2GXkrER+wtqERcPTgFaQ
	RkGcjdOkyMFS6F1Ma+Ex82OUX0oek19onZinb3le+hJyeUSJzC7w3KmU7LTH5jJX+o+x
	+F4Bcrd68hbnWkPt31PXxk32DzihPEW63Nmuw=
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=NWDBLg4EJPpGo+Tg/cnkYmTbp1eugTTZ/aHQeyIz28k=;
	b=BGTefJLzyI8LjnByDUt0JUxeNQAb3sMR+nRUF0OUkkhxKlxOkn5oF6OIjUfLbQzJ5s
	/3FuwSTaKZ4TE38NcpG0sofGaayzUj2b/HpbnPN9C6/JxsvMKv3/2IkB5gIW35+74aWc
	oU+/ep9fDTOITRV1VdsEv1ERpWk0Smkex+f52506SMHl/NSBMGe8ODG1AbwngvLy+4hG
	VVOqbm480z9tbwlVkuC9TFsGl+S2zZu+163wap+FM4iFG1ccAJVfchPvY+yHnqYuslA2
	Qp/yIx/cao9VViw2gy4IzkUpFlcRBHOaU1xoRGn0x0tIPOzeYL0vHTWrwX5WsXpZh3KE
	Nj6w==
X-Gm-Message-State: AA+aEWZAxSUwAPgNVnI06GWgKdsQ8PH/6bxI4+/A9okupIHFToY85rvK
	GN+JQH/lNcjxxCumKnlhrA6S5IwvFgYdUw==
X-Google-Smtp-Source: 
 AFSGD/UE2s7JS66VurreLX65/qli/SRBydAb2wvFL5TKfQetBQiigwqMAhL1r2OpfeqVJ51nugDwlQ==
X-Received: by 2002:a9d:1b67:: with SMTP id l94mr894089otl.147.1544757578678;
	Thu, 13 Dec 2018 19:19:38 -0800 (PST)
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Date: Thu, 13 Dec 2018 21:19:02 -0600
Message-Id: <20181214031923.29527-13-richard.henderson@linaro.org>
X-Mailer: git-send-email 2.17.2
In-Reply-To: <20181214031923.29527-1-richard.henderson@linaro.org>
References: <20181214031923.29527-1-richard.henderson@linaro.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
	recognized.
X-Received-From: 2607:f8b0:4864:20::344
Subject: [Qemu-devel] [PULL 11/32] tcg: Return success from patch_reloc
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
	<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <http://lists.nongnu.org/archive/html/qemu-devel/>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
	<mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Cc: peter.maydell@linaro.org
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org>
X-ZohoMail-DKIM: fail (Header signature does not verify)

This will move the assert for success from within (subroutines of)
patch_reloc into the callers.  It will also let new code do something
different when a relocation is out of range.

For the moment, all backends are trivially converted to return true.

Reviewed-by: Alex Benn=C3=A9e <alex.bennee@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tcg/aarch64/tcg-target.inc.c | 3 ++-
 tcg/arm/tcg-target.inc.c     | 3 ++-
 tcg/i386/tcg-target.inc.c    | 3 ++-
 tcg/mips/tcg-target.inc.c    | 3 ++-
 tcg/ppc/tcg-target.inc.c     | 3 ++-
 tcg/s390/tcg-target.inc.c    | 3 ++-
 tcg/sparc/tcg-target.inc.c   | 5 +++--
 tcg/tcg.c                    | 8 +++++---
 tcg/tci/tcg-target.inc.c     | 3 ++-
 9 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c
index 28de0226fb..16f08c59c4 100644
--- a/tcg/aarch64/tcg-target.inc.c
+++ b/tcg/aarch64/tcg-target.inc.c
@@ -94,7 +94,7 @@ static inline void reloc_pc19(tcg_insn_unit *code_ptr, tc=
g_insn_unit *target)
     *code_ptr =3D deposit32(*code_ptr, 5, 19, offset);
 }
=20
-static inline void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static inline bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                                intptr_t value, intptr_t addend)
 {
     tcg_debug_assert(addend =3D=3D 0);
@@ -109,6 +109,7 @@ static inline void patch_reloc(tcg_insn_unit *code_ptr,=
 int type,
     default:
         tcg_abort();
     }
+    return true;
 }
=20
 #define TCG_CT_CONST_AIMM 0x100
diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c
index 1651f00281..deefa20fbf 100644
--- a/tcg/arm/tcg-target.inc.c
+++ b/tcg/arm/tcg-target.inc.c
@@ -193,7 +193,7 @@ static inline void reloc_pc24(tcg_insn_unit *code_ptr, =
tcg_insn_unit *target)
     *code_ptr =3D (*code_ptr & ~0xffffff) | (offset & 0xffffff);
 }
=20
-static void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                         intptr_t value, intptr_t addend)
 {
     tcg_debug_assert(addend =3D=3D 0);
@@ -229,6 +229,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int ty=
pe,
     } else {
         g_assert_not_reached();
     }
+    return true;
 }
=20
 #define TCG_CT_CONST_ARM  0x100
diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c
index 436195894b..5c88f1f36b 100644
--- a/tcg/i386/tcg-target.inc.c
+++ b/tcg/i386/tcg-target.inc.c
@@ -167,7 +167,7 @@ static bool have_lzcnt;
=20
 static tcg_insn_unit *tb_ret_addr;
=20
-static void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                         intptr_t value, intptr_t addend)
 {
     value +=3D addend;
@@ -191,6 +191,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int ty=
pe,
     default:
         tcg_abort();
     }
+    return true;
 }
=20
 #if TCG_TARGET_REG_BITS =3D=3D 64
diff --git a/tcg/mips/tcg-target.inc.c b/tcg/mips/tcg-target.inc.c
index e21cb1ae28..a06ff257fa 100644
--- a/tcg/mips/tcg-target.inc.c
+++ b/tcg/mips/tcg-target.inc.c
@@ -168,12 +168,13 @@ static inline void reloc_26(tcg_insn_unit *pc, tcg_in=
sn_unit *target)
     *pc =3D deposit32(*pc, 0, 26, reloc_26_val(pc, target));
 }
=20
-static void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                         intptr_t value, intptr_t addend)
 {
     tcg_debug_assert(type =3D=3D R_MIPS_PC16);
     tcg_debug_assert(addend =3D=3D 0);
     reloc_pc16(code_ptr, (tcg_insn_unit *)value);
+    return true;
 }
=20
 #define TCG_CT_CONST_ZERO 0x100
diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c
index 2e2a22f579..860b0d36e1 100644
--- a/tcg/ppc/tcg-target.inc.c
+++ b/tcg/ppc/tcg-target.inc.c
@@ -513,7 +513,7 @@ static const uint32_t tcg_to_isel[] =3D {
     [TCG_COND_GTU] =3D ISEL | BC_(7, CR_GT),
 };
=20
-static void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                         intptr_t value, intptr_t addend)
 {
     tcg_insn_unit *target;
@@ -548,6 +548,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int ty=
pe,
     default:
         g_assert_not_reached();
     }
+    return true;
 }
=20
 static void tcg_out_mem_long(TCGContext *s, int opi, int opx, TCGReg rt,
diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c
index 96c344142e..68a4c60394 100644
--- a/tcg/s390/tcg-target.inc.c
+++ b/tcg/s390/tcg-target.inc.c
@@ -366,7 +366,7 @@ static void * const qemu_st_helpers[16] =3D {
 static tcg_insn_unit *tb_ret_addr;
 uint64_t s390_facilities;
=20
-static void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                         intptr_t value, intptr_t addend)
 {
     intptr_t pcrel2;
@@ -393,6 +393,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int ty=
pe,
     default:
         g_assert_not_reached();
     }
+    return true;
 }
=20
 /* parse target specific constraints */
diff --git a/tcg/sparc/tcg-target.inc.c b/tcg/sparc/tcg-target.inc.c
index 671a04c54b..cadda770c4 100644
--- a/tcg/sparc/tcg-target.inc.c
+++ b/tcg/sparc/tcg-target.inc.c
@@ -291,7 +291,7 @@ static inline int check_fit_i32(int32_t val, unsigned i=
nt bits)
 # define check_fit_ptr  check_fit_i32
 #endif
=20
-static void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                         intptr_t value, intptr_t addend)
 {
     uint32_t insn =3D *code_ptr;
@@ -328,12 +328,13 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int =
type,
         /* Note that we're abusing this reloc type for our own needs.  */
         code_ptr[0] =3D deposit32(code_ptr[0], 0, 22, value >> 10);
         code_ptr[1] =3D deposit32(code_ptr[1], 0, 10, value);
-        return;
+        return true;
     default:
         g_assert_not_reached();
     }
=20
     *code_ptr =3D insn;
+    return true;
 }
=20
 /* parse target specific constraints */
diff --git a/tcg/tcg.c b/tcg/tcg.c
index e85133ef05..54f1272187 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -66,7 +66,7 @@
 static void tcg_target_init(TCGContext *s);
 static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode);
 static void tcg_target_qemu_prologue(TCGContext *s);
-static void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                         intptr_t value, intptr_t addend);
=20
 /* The CIE and FDE header definitions will be common to all hosts.  */
@@ -268,7 +268,8 @@ static void tcg_out_reloc(TCGContext *s, tcg_insn_unit =
*code_ptr, int type,
         /* FIXME: This may break relocations on RISC targets that
            modify instruction fields in place.  The caller may not have=20
            written the initial value.  */
-        patch_reloc(code_ptr, type, l->u.value, addend);
+        bool ok =3D patch_reloc(code_ptr, type, l->u.value, addend);
+        tcg_debug_assert(ok);
     } else {
         /* add a new relocation entry */
         r =3D tcg_malloc(sizeof(TCGRelocation));
@@ -288,7 +289,8 @@ 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) {
-        patch_reloc(r->ptr, r->type, value, r->addend);
+        bool ok =3D patch_reloc(r->ptr, r->type, value, r->addend);
+        tcg_debug_assert(ok);
     }
=20
     l->has_value =3D 1;
diff --git a/tcg/tci/tcg-target.inc.c b/tcg/tci/tcg-target.inc.c
index 62ed097254..0015a98485 100644
--- a/tcg/tci/tcg-target.inc.c
+++ b/tcg/tci/tcg-target.inc.c
@@ -369,7 +369,7 @@ static const char *const tcg_target_reg_names[TCG_TARGE=
T_NB_REGS] =3D {
 };
 #endif
=20
-static void patch_reloc(tcg_insn_unit *code_ptr, int type,
+static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
                         intptr_t value, intptr_t addend)
 {
     /* tcg_out_reloc always uses the same type, addend. */
@@ -381,6 +381,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int ty=
pe,
     } else {
         tcg_patch64(code_ptr, value);
     }
+    return true;
 }
=20
 /* Parse target specific constraints. */
--=20
2.17.2