From patchwork Fri Dec 14 03:19:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 153716 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1599430ljp; Thu, 13 Dec 2018 19:28:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/XuQXqz2nyldkTYnNlL53I/QzDN8/c8qR16B6hsN8sVYPNbc/RbfM1CReKzq/SYMvo13dDc X-Received: by 2002:aed:2b01:: with SMTP id p1mr1238945qtd.101.1544758096945; Thu, 13 Dec 2018 19:28:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544758096; cv=none; d=google.com; s=arc-20160816; b=RMllzCyw0wKf/hWeREJoYqiI13f0eDi1ToBpqhAX4YWMzMffN3/y6q7MhSHR5nCEw9 gJGOgqa6exyarGywOYz7bITNr0DU/3YARAb+P7iTfTKldoZ68eLZI4w9a2Bzq7z0MU/5 XJ4cCkM4oqwotJnbYINEPi5eUU4Vcn5yGQdSBi+LIzKRXfjaPzJm+vgU6BwFP+dijl95 N8rRF4+U8xzwQtN78oUjS+rTuOGI5+9uxF3bo6WhP7TfsIXtZtlgMjeBEWQezuKddYcd zpYD3i1LtTuyx7LFnpr7jigWaqSd5qnvcWDuQYVBt6LFjOYV3bT5jREFCIAaFeHA6el2 ha7Q== 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=tf1fH1QCj4h1v07jYuR/vhe6G4F8YsGZZLEPQJ0aYfc=; b=HA9l0PU7hJYzgMk3Qu5e3T03zXUuN8j0auBzUoRV4R8bKr4l0eJRIQMCkylVEc82fM SjrxMA77yQsFm6tHrDErtQvFijfjX5g+L/Q1LKEy3atqfrCKNPk1T6A/KLpFAv0ZQZZZ H0bMJ2Ze8UWiXbYaEcI4+sFwUinSV1JMey6WEvlIA5/xgKwv6Qh2NTES+zgKltsUJGZG hKWNCrbHQSVF/9YkQcoyUOFpLTsQkjlLYzdJyFqLwJCgg019gjz2KHV3r5IHr+X2psN4 gWih3wucrpiFS08uYn/43f3lHmZ7NZTZcyvTfuN90viFU18H/PhiqM4nQbZ4jrduryOv R64Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HIX62xd2; 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 n31si2147249qte.393.2018.12.13.19.28.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Dec 2018 19:28:16 -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=HIX62xd2; 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]:59095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXe9A-0004ED-F9 for patch@linaro.org; Thu, 13 Dec 2018 22:28:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gXe0t-0005yg-E2 for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gXe0s-0006rv-3x for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:43 -0500 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]:43030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gXe0r-0006qJ-UU for qemu-devel@nongnu.org; Thu, 13 Dec 2018 22:19:42 -0500 Received: by mail-ot1-x330.google.com with SMTP id a11so4088270otr.10 for ; Thu, 13 Dec 2018 19:19:41 -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=tf1fH1QCj4h1v07jYuR/vhe6G4F8YsGZZLEPQJ0aYfc=; b=HIX62xd2a5FwMiSyE4lcp4d4VWKWA2uwIaP5XzRBVoZsQjt0a0FapI2VKyqLVrgJMe DrBQUNf8qA9kh0W9OlZDygFButgmx0By76HPYauKp5V9rr1g7KJyo1r8H271Wd3gmluJ IbfkC77Y6t+xNR5WPclO2A4Kb6CGJspNAgLi4= 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=tf1fH1QCj4h1v07jYuR/vhe6G4F8YsGZZLEPQJ0aYfc=; b=lBlH9YZs87Oag8vphhlF2tdv+6x506YqVCpqK3X3+lewitdYQfC/tCWWoPWCP6JayY 5c6erMR/I2eUBm/9J9520YegqOefdrBqamtXacMmNh+noeDPW+FfnimETfUz5nfIem82 Jsg1v6KzpMjmvMEd5BGzk1Q6u9fWKDAhhGrYhs77sGjLwEUTz2lCFhMQxRwOUXSX/lHj iEFLpsNpMtbc+lka8d5fFAMlDVqV5WhaSfcAMYgE0BmwEY86x4RpIxYRe9yUpqK7XO/x fRAjWFpqH0/nnOIzY4biGqK9OwqUx0mNyHvXYnLypoLFKTYn51sCvutVTJfCl0HpU61s OJQQ== X-Gm-Message-State: AA+aEWatZyUIcb5zHt7XhykgcGe3H3fIUDKg7kmfvPA5vaFB7oPH4OWX BqPuO4Je6Yv506feiEJD64Z22eTAzOO2GQ== X-Received: by 2002:a9d:d83:: with SMTP id 3mr885668ots.361.1544757580915; Thu, 13 Dec 2018 19:19:40 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Dec 2018 19:19:40 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2018 21:19:04 -0600 Message-Id: <20181214031923.29527-15-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::330 Subject: [Qemu-devel] [PULL 13/32] tcg/aarch64: 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/aarch64/tcg-target.inc.c | 37 ++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) -- 2.17.2 diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c index 16f08c59c4..0562e0aa40 100644 --- a/tcg/aarch64/tcg-target.inc.c +++ b/tcg/aarch64/tcg-target.inc.c @@ -78,20 +78,26 @@ static const int tcg_target_call_oarg_regs[1] = { #define TCG_REG_GUEST_BASE TCG_REG_X28 #endif -static inline void reloc_pc26(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static inline bool reloc_pc26(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { ptrdiff_t offset = target - code_ptr; - tcg_debug_assert(offset == sextract64(offset, 0, 26)); - /* read instruction, mask away previous PC_REL26 parameter contents, - set the proper offset, then write back the instruction. */ - *code_ptr = deposit32(*code_ptr, 0, 26, offset); + if (offset == sextract64(offset, 0, 26)) { + /* read instruction, mask away previous PC_REL26 parameter contents, + set the proper offset, then write back the instruction. */ + *code_ptr = deposit32(*code_ptr, 0, 26, offset); + return true; + } + return false; } -static inline void reloc_pc19(tcg_insn_unit *code_ptr, tcg_insn_unit *target) +static inline bool reloc_pc19(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { ptrdiff_t offset = target - code_ptr; - tcg_debug_assert(offset == sextract64(offset, 0, 19)); - *code_ptr = deposit32(*code_ptr, 5, 19, offset); + if (offset == sextract64(offset, 0, 19)) { + *code_ptr = deposit32(*code_ptr, 5, 19, offset); + return true; + } + return false; } static inline bool patch_reloc(tcg_insn_unit *code_ptr, int type, @@ -101,15 +107,12 @@ static inline bool patch_reloc(tcg_insn_unit *code_ptr, int type, switch (type) { case R_AARCH64_JUMP26: case R_AARCH64_CALL26: - reloc_pc26(code_ptr, (tcg_insn_unit *)value); - break; + return reloc_pc26(code_ptr, (tcg_insn_unit *)value); case R_AARCH64_CONDBR19: - reloc_pc19(code_ptr, (tcg_insn_unit *)value); - break; + return reloc_pc19(code_ptr, (tcg_insn_unit *)value); default: - tcg_abort(); + g_assert_not_reached(); } - return true; } #define TCG_CT_CONST_AIMM 0x100 @@ -1387,7 +1390,8 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) TCGMemOp opc = get_memop(oi); TCGMemOp size = opc & MO_SIZE; - reloc_pc19(lb->label_ptr[0], s->code_ptr); + bool ok = reloc_pc19(lb->label_ptr[0], s->code_ptr); + tcg_debug_assert(ok); tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_X0, TCG_AREG0); tcg_out_mov(s, TARGET_LONG_BITS == 64, TCG_REG_X1, lb->addrlo_reg); @@ -1409,7 +1413,8 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) TCGMemOp opc = get_memop(oi); TCGMemOp size = opc & MO_SIZE; - reloc_pc19(lb->label_ptr[0], s->code_ptr); + bool ok = reloc_pc19(lb->label_ptr[0], s->code_ptr); + tcg_debug_assert(ok); tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_X0, TCG_AREG0); tcg_out_mov(s, TARGET_LONG_BITS == 64, TCG_REG_X1, lb->addrlo_reg);