From patchwork Mon Jun 26 18:49:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 696479 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp3389650wrm; Mon, 26 Jun 2023 12:10:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4H7hGgLwBSS50sEYmIcnU1Wth3ChNujSg76SAH4vGgjNJxujh7lPiQB/BJmkaUD0njnkEt X-Received: by 2002:a05:6214:d69:b0:623:64cd:941d with SMTP id 9-20020a0562140d6900b0062364cd941dmr5172925qvs.2.1687806630197; Mon, 26 Jun 2023 12:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687806630; cv=none; d=google.com; s=arc-20160816; b=R3ZfXZ2U58chCjx99K5w9WizmpHpN0TEoQLWTExIMBgDvgWIM5UHRFVvzyZk9ABvBk t/uEa2R7MkKOqeJjye5zmvBfQxNaYTcev89qDdXy7ciE1Dz7MixzGAtF0mqMmDV7JAMR t+On1F5EwOIpjCufmQbuCRkVarWFG2PenK/eTw3/ocZs39jxVI7AbfN40jY3roYPA40e OXUKrJOW4a4MoRrzdQuJbIxUI+/LLP6B6JkERAuyHFAMFeVln3KrlP9MJIuJbE6Ij6xe axJjvO8auYRlLs/z6FbEmcv5aKeOvlrUIWO7XeTIlg9X/OqyYEEGFOFfhV9aQGlkAjv8 K55w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=kElnPohoo4QBoWSSyxFSdF/NIIn2PJdLO6bV3HJlBO0=; fh=JfuprfCedaaH4bwbV1+UfSdrVnNu3JN+V+yaHHqBUgY=; b=FUvAkEetGTYJ33i+el95rbesw1tb/ER6VFjWjTkoETUUPZsew9K6sadIXgryqIwOTS qqqxSwoSNEzR7J952Q5MyK/61xiw36HIX6Xb3gqGAszEKuqdE59Y6CqNJYKtC4rnso1V +jOircDqQ6+/bOr+3w3EwoC2cXf/nDZi1lfYBHwBAPJs/sn6GxE9BCJb8Nl+uVQ5ggYN MyQxSjDoXZoEY2i2UzWbuLpYNg6jlzGd5CLBqakQqjQH9RMSt1iU2u4lMsLizbB1FgT6 NXU0h3GHyGAa2g6edYL8syrKBU2QmFlo43B9D8eduWdE6yDvVweDbEWVeFUHPjXKf6AE eAbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id pt5-20020a056214048500b00631f3773d37si2340790qvb.245.2023.06.26.12.10.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2023 12:10:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qDrN7-0003lX-Rz; Mon, 26 Jun 2023 14:55:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qDrMR-00020Z-Oo; Mon, 26 Jun 2023 14:54:51 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qDrLu-0005jp-IX; Mon, 26 Jun 2023 14:54:20 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id E1E48EF44; Mon, 26 Jun 2023 21:50:29 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 6DBB2F7D3; Mon, 26 Jun 2023 21:50:28 +0300 (MSK) Received: (nullmailer pid 1574094 invoked by uid 1000); Mon, 26 Jun 2023 18:50:16 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org, qemu-stable@nongnu.org Cc: Peter Maydell , Richard Henderson , =?utf-8?q?Daniel_P_=2E_Be?= =?utf-8?q?rrang=C3=A9?= , Daniel Bertalan , "Tested-By : Solra Bizna" , Michael Tokarev Subject: [Stable-8.0.3 45/54] host-utils: Avoid using __builtin_subcll on buggy versions of Apple Clang Date: Mon, 26 Jun 2023 21:49:52 +0300 Message-Id: <20230626185002.1573836-45-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Peter Maydell We use __builtin_subcll() to do a 64-bit subtract with borrow-in and borrow-out when the host compiler supports it. Unfortunately some versions of Apple Clang have a bug in their implementation of this intrinsic which means it returns the wrong value. The effect is that a QEMU built with the affected compiler will hang when emulating x86 or m68k float80 division. The upstream LLVM issue is: https://github.com/llvm/llvm-project/issues/55253 The commit that introduced the bug apparently never made it into an upstream LLVM release without the subsequent fix https://github.com/llvm/llvm-project/commit/fffb6e6afdbaba563189c1f715058ed401fbc88d but unfortunately it did make it into Apple Clang 14.0, as shipped in Xcode 14.3 (14.2 is reported to be OK). The Apple bug number is FB12210478. Add ifdefs to avoid use of __builtin_subcll() on Apple Clang version 14 or greater. There is not currently a version of Apple Clang which has the bug fix -- when one appears we should be able to add an upper bound to the ifdef condition so we can start using the builtin again. We make the lower bound a conservative "any Apple clang with major version 14 or greater" because the consequences of incorrectly disabling the builtin when it would work are pretty small and the consequences of not disabling it when we should are pretty bad. Many thanks to those users who both reported this bug and also did a lot of work in identifying the root cause; in particular to Daniel Bertalan and osy. Cc: qemu-stable@nongnu.org Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1631 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1659 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Daniel P. Berrangé Tested-by: Daniel Bertalan Tested-by: Tested-By: Solra Bizna Message-id: 20230622130823.1631719-1-peter.maydell@linaro.org (cherry picked from commit b0438861efe1dfbdfdd9fa1d9aa05100d37ea8ee) Signed-off-by: Michael Tokarev diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index c2f49df1f9..a309f90c76 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -184,4 +184,17 @@ #define QEMU_DISABLE_CFI #endif +/* + * Apple clang version 14 has a bug in its __builtin_subcll(); define + * BUILTIN_SUBCLL_BROKEN for the offending versions so we can avoid it. + * When a version of Apple clang which has this bug fixed is released + * we can add an upper bound to this check. + * See https://gitlab.com/qemu-project/qemu/-/issues/1631 + * and https://gitlab.com/qemu-project/qemu/-/issues/1659 for details. + * The bug never made it into any upstream LLVM releases, only Apple ones. + */ +#if defined(__apple_build_version__) && __clang_major__ >= 14 +#define BUILTIN_SUBCLL_BROKEN +#endif + #endif /* COMPILER_H */ diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 3ce62bf4a5..6519238774 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -595,7 +595,7 @@ static inline uint64_t uadd64_carry(uint64_t x, uint64_t y, bool *pcarry) */ static inline uint64_t usub64_borrow(uint64_t x, uint64_t y, bool *pborrow) { -#if __has_builtin(__builtin_subcll) +#if __has_builtin(__builtin_subcll) && !defined(BUILTIN_SUBCLL_BROKEN) unsigned long long b = *pborrow; x = __builtin_subcll(x, y, b, &b); *pborrow = b & 1;