From nobody Tue Apr 15 02:55:39 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: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544758218514703.0166553235093; Thu, 13 Dec 2018 19:30:18 -0800 (PST) Received: from localhost ([::1]:59109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXeB7-0007Kh-Ar for importer@patchew.org; Thu, 13 Dec 2018 22:30:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58856) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXe0y-000635-Bw for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXe0u-0006yP-Ak for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:46 -0500 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]:45961) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXe0u-0006wi-2W for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:44 -0500 Received: by mail-oi1-x233.google.com with SMTP id y1so3443140oie.12 for ; Thu, 13 Dec 2018 19:19:44 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 19:19:42 -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=xvjP2G4QREW4vGKsLkdyqEmRLoa4L5gxnmBP6Wt9koU=; b=M9pWvzOjW6LjFuBUunBOQXveKmmkORJM/3jQe6ep0JxCC8/JkSBSLNUenkwLj6NQca 5T47jdT2DVkW3rPaNuKdV/Wi0HtQxvjwJN5MkPK1eUzJ6AzV6WQavkHSfdLBefhQWIng eyrGAP3Op98A5dFdfXkcCndOJAHzMQ77n8vn4= 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=xvjP2G4QREW4vGKsLkdyqEmRLoa4L5gxnmBP6Wt9koU=; b=FcpMpoX/n7V1ZVDkGYL5VZx3LoMBThRaF8QVyqUk+OaOhMrTBQO1uCIFDAHKYU5CkL 51j2qxJ/uF9JIGEV8CEjwnOh0SztPmBRVk0mha+q2yf4G+BkTPvcxarsRS9LtACVNWWF 9x9M2v8wpsHd15C15xgOQFAeXdbeeEg8nNk/1cc9uOzFbnM68dRRyzEW+wu4p90fI0p7 NRKXa0LIvw2DrhcsWLrnY0qtD3jNluPRjrKIMthdXMdvjRjSsfvoNTD1BgbJo8Tv98og mj34GfaDbyaviSFB7O7A1ixCJtcTOspZQmXCQngmGijm06OaGI+/SrCJZWtYyhOO8Pz6 zquw== X-Gm-Message-State: AA+aEWbszA97TDBb/sCM0yYG5n/nSwgz4+XS7KelDs2ZPoejXxR5g6ui cwoZUKz69iq/dh6Oaod3joeHwhoNaY+Gqg== X-Google-Smtp-Source: AFSGD/VsQ01PvE+4i4lLzlPKGJNT1a+SPmJQR2tXRbq2bV7+iQ5VY8ponr0rZlPIZC6h9tBVZTk9/A== X-Received: by 2002:aca:be41:: with SMTP id o62mr794446oif.206.1544757583100; Thu, 13 Dec 2018 19:19:43 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2018 21:19:06 -0600 Message-Id: <20181214031923.29527-17-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::233 Subject: [Qemu-devel] [PULL 15/32] tcg/ppc: Return false on failure from patch_reloc 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The reloc_pc{14,24}_val routines retain their asserts. Use these directly within the slow paths. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.inc.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index 860b0d36e1..8c1cfdd7ac 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -193,9 +193,14 @@ static uint32_t reloc_pc24_val(tcg_insn_unit *pc, tcg_= insn_unit *target) return disp & 0x3fffffc; } =20 -static void reloc_pc24(tcg_insn_unit *pc, tcg_insn_unit *target) +static bool reloc_pc24(tcg_insn_unit *pc, tcg_insn_unit *target) { - *pc =3D (*pc & ~0x3fffffc) | reloc_pc24_val(pc, target); + ptrdiff_t disp =3D tcg_ptr_byte_diff(target, pc); + if (in_range_b(disp)) { + *pc =3D (*pc & ~0x3fffffc) | (disp & 0x3fffffc); + return true; + } + return false; } =20 static uint16_t reloc_pc14_val(tcg_insn_unit *pc, tcg_insn_unit *target) @@ -205,9 +210,14 @@ static uint16_t reloc_pc14_val(tcg_insn_unit *pc, tcg_= insn_unit *target) return disp & 0xfffc; } =20 -static void reloc_pc14(tcg_insn_unit *pc, tcg_insn_unit *target) +static bool reloc_pc14(tcg_insn_unit *pc, tcg_insn_unit *target) { - *pc =3D (*pc & ~0xfffc) | reloc_pc14_val(pc, target); + ptrdiff_t disp =3D tcg_ptr_byte_diff(target, pc); + if (disp =3D=3D (int16_t) disp) { + *pc =3D (*pc & ~0xfffc) | (disp & 0xfffc); + return true; + } + return false; } =20 /* parse target specific constraints */ @@ -524,11 +534,9 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int t= ype, =20 switch (type) { case R_PPC_REL14: - reloc_pc14(code_ptr, target); - break; + return reloc_pc14(code_ptr, target); case R_PPC_REL24: - reloc_pc24(code_ptr, target); - break; + return reloc_pc24(code_ptr, target); case R_PPC_ADDR16: /* We are abusing this relocation type. This points to a pair of insns, addis + load. If the displacement is small, we @@ -540,7 +548,9 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int ty= pe, } else { int16_t lo =3D value; int hi =3D value - lo; - assert(hi + lo =3D=3D value); + if (hi + lo !=3D value) { + return false; + } code_ptr[0] =3D deposit32(code_ptr[0], 0, 16, hi >> 16); code_ptr[1] =3D deposit32(code_ptr[1], 0, 16, lo); } @@ -1638,7 +1648,7 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, = TCGLabelQemuLdst *lb) TCGMemOp opc =3D get_memop(oi); TCGReg hi, lo, arg =3D TCG_REG_R3; =20 - reloc_pc14(lb->label_ptr[0], s->code_ptr); + **lb->label_ptr |=3D reloc_pc14_val(*lb->label_ptr, s->code_ptr); =20 tcg_out_mov(s, TCG_TYPE_PTR, arg++, TCG_AREG0); =20 @@ -1683,7 +1693,7 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, = TCGLabelQemuLdst *lb) TCGMemOp s_bits =3D opc & MO_SIZE; TCGReg hi, lo, arg =3D TCG_REG_R3; =20 - reloc_pc14(lb->label_ptr[0], s->code_ptr); + **lb->label_ptr |=3D reloc_pc14_val(*lb->label_ptr, s->code_ptr); =20 tcg_out_mov(s, TCG_TYPE_PTR, arg++, TCG_AREG0); =20 --=20 2.17.2