From patchwork Fri Dec 14 03:19:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153721 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1601235ljp; Thu, 13 Dec 2018 19:31:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/V9+kcbReVB5HJiQhgc05V0s2RqNnz6ysNB2bUVCwmITphhtThcV2p47c6VyIKWN238rwjK X-Received: by 2002:a37:a483:: with SMTP id n125mr1146789qke.184.1544758273990; Thu, 13 Dec 2018 19:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544758273; cv=none; d=google.com; s=arc-20160816; b=kg3oOMOGLGOBLFgECedSe/UAxFSq0+fA8TnDuxaTysE+OTfisqQ182ZboUSpgyoReT itnOZ+CC5Pxw59+NHJy3KuSm6UZZJX24GrLuS6/Z6CV7+sD7prByAgEBicpz1T1/QvD3 gHjUk/5vJjNor+Ueprt5pbFexgxv0NyoT8aCPbVxFH0RDkmFKbgGq0BBwuePeEq7qRxR 5sDcJxegcW0yYan625ApwQegG0iSDhNvaUNRH+CLOJTEIrqL7HCBEIdP8x6JMKNZ4nXk s/yEwbAPzDV65LawSjDI4TuHQ9RlKJ1jE0dgs6y4+s3aRXpLrAB5KMhFrHfFYZ4ZoWf/ EmuQ== 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=xvjP2G4QREW4vGKsLkdyqEmRLoa4L5gxnmBP6Wt9koU=; b=kpg3RV4U6iNwkaZFRyjMD9ZDj2iO8r7zJZqx9GS970pJLbVSrmfmzJ5FHl7IZcI5Zd HYD8jVRwroYjhOoqa7vnV28Q3vYVbu8t3r2/l9yZ5ide6aOHQvDm8m7fgYuarYSAJemU dOr4l179fmX9wjy8SyiLrGzIcv9RIVdjm1anDIOAA3H3KLoqI7hU+KGZBW1gd6Kq6441 5EjzLPFY0VXlzRaj2vXpvvurDiOspXu/t1133tu8Fvg1ZFF+yLSQ8qbmc+lhmJm9iDpd P/b3NImjsPskKpGJdU8tMJ1h7T0X+33F/ux4s5QBRHvfbQjuoRM2cl86/dekEFcrhogO B64g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=M9pWvzOj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n86si1832882qkh.253.2018.12.13.19.31.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Dec 2018 19:31:13 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=M9pWvzOj; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 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 ([::1]:59109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXeC1-0007Kh-EE for patch@linaro.org; Thu, 13 Dec 2018 22:31:13 -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) 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-Received: by 2002:aca:be41:: with SMTP id o62mr794446oif.206.1544757583100; Thu, 13 Dec 2018 19:19:43 -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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The reloc_pc{14,24}_val routines retain their asserts. Use these directly within the slow paths. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.inc.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) -- 2.17.2 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; } -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 = (*pc & ~0x3fffffc) | reloc_pc24_val(pc, target); + ptrdiff_t disp = tcg_ptr_byte_diff(target, pc); + if (in_range_b(disp)) { + *pc = (*pc & ~0x3fffffc) | (disp & 0x3fffffc); + return true; + } + return false; } 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; } -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 = (*pc & ~0xfffc) | reloc_pc14_val(pc, target); + ptrdiff_t disp = tcg_ptr_byte_diff(target, pc); + if (disp == (int16_t) disp) { + *pc = (*pc & ~0xfffc) | (disp & 0xfffc); + return true; + } + return false; } /* parse target specific constraints */ @@ -524,11 +534,9 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, 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 type, } else { int16_t lo = value; int hi = value - lo; - assert(hi + lo == value); + if (hi + lo != value) { + return false; + } code_ptr[0] = deposit32(code_ptr[0], 0, 16, hi >> 16); code_ptr[1] = 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 = get_memop(oi); TCGReg hi, lo, arg = TCG_REG_R3; - reloc_pc14(lb->label_ptr[0], s->code_ptr); + **lb->label_ptr |= reloc_pc14_val(*lb->label_ptr, s->code_ptr); tcg_out_mov(s, TCG_TYPE_PTR, arg++, TCG_AREG0); @@ -1683,7 +1693,7 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) TCGMemOp s_bits = opc & MO_SIZE; TCGReg hi, lo, arg = TCG_REG_R3; - reloc_pc14(lb->label_ptr[0], s->code_ptr); + **lb->label_ptr |= reloc_pc14_val(*lb->label_ptr, s->code_ptr); tcg_out_mov(s, TCG_TYPE_PTR, arg++, TCG_AREG0);