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: 153733 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1607050ljp; Thu, 13 Dec 2018 19:40:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/VqAUop4qXvlKFZ0+tOFsZVZZ3+dovCLi6XgL85t4EKKfEUpPHPi3jB8KQE5bbv3wRKR7MM X-Received: by 2002:ac8:2e22:: with SMTP id r31mr1260135qta.333.1544758848307; Thu, 13 Dec 2018 19:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544758848; cv=none; d=google.com; s=arc-20160816; b=tqsdRWn2xG3YFuoz6CTj+DInGjXKZlS56v86K8szc8FTLMY59MRyjz2/QlGqrVlX1/ +b56wzw5aKjIdyiccxELYvPX0XAO/DgzwsGlYMxDWIYLQWqaCQwAxgEsZyule7tV1zDn IYKKUwEL1rG55ittmcDd9JtGMCiOoaJZuG4zRI+5qMT4Ug2ws7zFncHDxPYoQx2X/nX2 qfSGjsS1CXfn15KOo5gVE1tCTQfxDDsk2C05wNt6KBpbSAira5l0rn8ahQlihxuOtBgb oW/mKYchJWPKGcWFqADIkyrDaTDUk7juVncNr5F4Ux4nW4aorN+jNZoyVuQ5HC2HaZu1 aj0w== 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=5YfinWp16EtRRWgYCiQvOQs4QRZJ2WUsHevk50sUQUk=; b=NDcpl13DErSiF8xjlvsO/qIVhj7oPunqQR07ofk2I9LMy4eLXPxGrbB/X5uprK77jS KE3y4KTAqaZnpwj7t/498mxFa3BEk5Re7ADHQtYsXqzPLODVxcFy1rkAQWNofxlsK9GD oOgbx1nONBJJAgyqC3yBvhcHtvl9H45KzrSWCQw2TYQqXrEPhTvi9jBq7vIcjPe3+r1s Ei2mULOGMDyBekOCy0mggYIXF94Lb7pr32DVbBdMkWiTFTCWfiRqh1vKmq2PhSTpEzxR L991c6bz4cIBAi6VWncn03zrnY2hqUpgQlUEIUTCvrwhdkyMTHRXbxsmNruUG9coowwg Ik0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=hiKXFk+n; 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 r1si2209188qkk.116.2018.12.13.19.40.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Dec 2018 19:40:48 -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=hiKXFk+n; 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]:59174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXeLH-0008HX-SR for patch@linaro.org; Thu, 13 Dec 2018 22:40:47 -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-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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.17.2 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);