From patchwork Fri Dec 14 03:19:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 10730451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A847E174F for ; Fri, 14 Dec 2018 03:41:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94FC72CFC4 for ; Fri, 14 Dec 2018 03:41:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 83E0F2CFD7; Fri, 14 Dec 2018 03:41:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 22FB22CFC4 for ; Fri, 14 Dec 2018 03:41:39 +0000 (UTC) Received: from localhost ([::1]:59174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXeM6-0008HX-Cu for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Dec 2018 22:41:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXe0u-0005zj-AN for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXe0t-0006vU-BX for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:44 -0500 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]:36795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXe0s-0006tM-VJ for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:43 -0500 Received: by mail-oi1-x234.google.com with SMTP id x23so3480325oix.3 for ; 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=5YfinWp16EtRRWgYCiQvOQs4QRZJ2WUsHevk50sUQUk=; b=hiKXFk+n+RLebfW48h8YMVOVglld2L+Xf/lMedBMN3RlrMGyfPKnZ6LkgYYGyB5IRW ntkkdy/7U/eDTeabXjLa5ZrzNm686Ys4va8tkPAWpuImT0rVjAdSLThfNAL5++81Yjq/ Be1D3ZKErrEDJjH9BpV1C6UZcLA9TuobnwGcw= 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=5YfinWp16EtRRWgYCiQvOQs4QRZJ2WUsHevk50sUQUk=; b=e/Pbw/tTen6VriSM22k9cpLMArli1Mve6tYA2ay8RmSfoFGGNpZ7iAXD1iFC/xA3qp kKErjId3rNal3u81tHTI2wt+HoiWxWeDoVDcwN2Ef1GPTPfKTqa2SdXP7LRabyG5ughq Ra74SBwwG39nTfVeaGeGZWKS5CHOdXHqNhO3BN744rGwgi1jNQeTzXtmsaDjz74MqH3q pt4w86mzHAWY5eeh0Cz4BSIlYLPP863qKKY6Mxfop5h1K+cHFD1/YbbPQilp4IC5cRjN rXA4YUnV31GuA3Yg9jAuh+a1OeblwQQSIisOOshwbVHDSQgJscfYZjkQfoIL7ntQz8Ss b+Ow== X-Gm-Message-State: AA+aEWb92cR66H98dukMZegxsLvsJmtMrhPDVEeQ8esMkzdsKaONsMe+ sUUXreqHFAeBfuNS2hSYtaUOKl2s32vabQ== X-Google-Smtp-Source: AFSGD/XBsbp+FrzkjG6nQ/iYLHg1V5yKqAzJ7pCNvhqVtpp9spHYlf+646n4I+JfEd4LWoRarQlNbw== X-Received: by 2002:aca:c443:: with SMTP id u64mr855349oif.136.1544757581999; Thu, 13 Dec 2018 19:19:41 -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.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 19:19:41 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2018 21:19:05 -0600 Message-Id: <20181214031923.29527-16-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::234 Subject: [Qemu-devel] [PULL 14/32] tcg/arm: 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This does require an extra two checks within the slow paths to replace the assert that we're moving. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index deefa20fbf..49f57d655e 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -187,10 +187,14 @@ static const uint8_t tcg_cond_to_arm_cond[] = { [TCG_COND_GTU] = COND_HI, }; -static inline void reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static inline bool reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { ptrdiff_t offset = (tcg_ptr_byte_diff(target, code_ptr) - 8) >> 2; - *code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff); + if (offset == sextract32(offset, 0, 24)) { + *code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff); + return true; + } + return false; } static bool patch_reloc(tcg_insn_unit *code_ptr, int type, @@ -199,7 +203,7 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, tcg_debug_assert(addend == 0); if (type == R_ARM_PC24) { - reloc_pc24(code_ptr, (tcg_insn_unit *)value); + return reloc_pc24(code_ptr, (tcg_insn_unit *)value); } else if (type == R_ARM_PC13) { intptr_t diff = value - (uintptr_t)(code_ptr + 2); tcg_insn_unit insn = *code_ptr; @@ -213,7 +217,11 @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, } else { int rd = extract32(insn, 12, 4); int rt = rd == TCG_REG_PC ? TCG_REG_TMP : rd; - assert(diff >= 0x1000 && diff < 0x100000); + + if (diff < 0x1000 || diff >= 0x100000) { + return false; + } + /* add rt, pc, #high */ *code_ptr++ = ((insn & 0xf0000000) | (1 << 25) | ARITH_ADD | (TCG_REG_PC << 16) | (rt << 12) @@ -1372,7 +1380,8 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) TCGMemOp opc = get_memop(oi); void *func; - reloc_pc24(lb->label_ptr[0], s->code_ptr); + bool ok = reloc_pc24(lb->label_ptr[0], s->code_ptr); + tcg_debug_assert(ok); argreg = tcg_out_arg_reg32(s, TCG_REG_R0, TCG_AREG0); if (TARGET_LONG_BITS == 64) { @@ -1432,7 +1441,8 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) TCGMemOpIdx oi = lb->oi; TCGMemOp opc = get_memop(oi); - reloc_pc24(lb->label_ptr[0], s->code_ptr); + bool ok = reloc_pc24(lb->label_ptr[0], s->code_ptr); + tcg_debug_assert(ok); argreg = TCG_REG_R0; argreg = tcg_out_arg_reg32(s, argreg, TCG_AREG0);