From nobody Fri Nov 15 06:29:23 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1687439353; cv=none; d=zohomail.com; s=zohoarc; b=MeqfuDO/n4EuZRagGs1a1w0L88GJUm4ESUz63Nt9CE5hT7svdjJwJ0rgFzwKlMLXGa0TQdc3d6rhxD19EtZbgea0YjPp3PoPwUZH0FqCH2CYpQbmS1YKmn9oEpjBIFk4ihkWOYLpDvXvn1Zz5K5iJ9rJF9zlSwzasZJWpvgAhoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687439353; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=1vdtz3xBrKH2G9M2G9/DIVn5V1BQ12aeC17aZaNPM38=; b=CjmKxj5ihZ+/OCPoFFnVXL/EwHLTp9PQG+KxZrsdRWC5lPWMeNLY6plzoPJIeoMgr1FY/kApa1ycby/JQOtg2UQehGZ1tU59DTsfCL5lcve9lMJCjAUS6uCNhJkn+rgIRFdTTNOvL0XrygzIyUK1J5RZF0x/k2Ewi/Q4JS4ezrY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687439353046757.8089370300544; Thu, 22 Jun 2023 06:09:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qCK37-0005YZ-Fz; Thu, 22 Jun 2023 09:08: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 1qCK34-0005Wb-Dc for qemu-devel@nongnu.org; Thu, 22 Jun 2023 09:08:30 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qCK32-0003oA-Ci for qemu-devel@nongnu.org; Thu, 22 Jun 2023 09:08:30 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3f9b258f3a2so47388575e9.0 for ; Thu, 22 Jun 2023 06:08:26 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id y17-20020a1c4b11000000b003f7f249e7dfsm17933825wma.4.2023.06.22.06.08.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 06:08:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1687439305; x=1690031305; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1vdtz3xBrKH2G9M2G9/DIVn5V1BQ12aeC17aZaNPM38=; b=Ak6sEMJFnyL68GDAyvq2ZUUcJloI9xz8HrzYYKGA0pwbR8TQ4+grTOFWIIi8muPa1T aV4ExcQP/E76+ODO6/UhmBsLrP+Rxq76eZtlvprGTN7dEwR88okY+i+jrCVfCw0YMOY6 2G/BuAtcZeeg4MAxHWl4h1LN9+oolRFGWwr738GE+es5u8Y8m4TJpIA+j7o+bTLyusHe t4AVtqmOnUAOKD7xzuLqnvnt1UJXlwsx7kae2kF2rrbZMaO88eBDPpBOviKMrdw1nplF 2tCnbjyL7Wkls35y5Uqswf+Ss5myNqh3gSKbF46hwBMj/bXCKdq9x6bPdraP46a/LkF7 gRZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687439305; x=1690031305; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1vdtz3xBrKH2G9M2G9/DIVn5V1BQ12aeC17aZaNPM38=; b=NDIV6ODCXDO0iH4gUJzAYGIE6xaDxycahBMEYdgKNUo5LQRumzKAGWRqaNjol3s1pH qI/lqQ8Bk9UxNxeiJ2MdlDv/zD355b9y6XotRqnFmLT4CdH9KYKNYMrrVgqUitqo08P4 WCYQks1csqkIpes1JLJLxszBkXzyxibpFPE3yo20MPp883rkoFk6atFRBBhK9gu1hyzs yHxB4ljU3aoxHEl2lSy6CWda0nYmDnLZsDNbK/qf/nPtHjo8DIBFIg/+IcCAKO4aI+nz EQhzmWLl7QaV5uKm4FBgXttfdo/+ZKij65+Xn5gSKwaoXNM6Mm1jgiW+oyYjzQ3uXXUy AS+A== X-Gm-Message-State: AC+VfDzVr1fwB2bex97HkorQG42xO4k4dvgPSPPW/1qtZgZM/tkRaq8T OzsfyptlJ/e5kmWRok1W7sYBI6kLpSGxdQ1cQl0= X-Google-Smtp-Source: ACHHUZ5T/JRNIQvaSOYsmDjpsScV/mRz4DBc6d//uuquVHZEF60U6RWrvpAZCra+EZbEmfWB8Fpq/Q== X-Received: by 2002:a1c:7708:0:b0:3f9:ba2:5d1c with SMTP id t8-20020a1c7708000000b003f90ba25d1cmr11408669wmi.9.1687439305143; Thu, 22 Jun 2023 06:08:25 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH] host-utils: Avoid using __builtin_subcll on buggy versions of Apple Clang Date: Thu, 22 Jun 2023 14:08:23 +0100 Message-Id: <20230622130823.1631719-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1687439354916100007 Content-Type: text/plain; charset="utf-8" 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 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/fffb6e6afdbaba563189c1f715058ed= 401fbc88d 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: Daniel P. Berrang=C3=A9 Reviewed-by: Richard Henderson --- I don't have a setup to test this, so this needs testing by the people who've encountered this compiler bug to confirm it does the right thing... --- include/qemu/compiler.h | 13 +++++++++++++ include/qemu/host-utils.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index c2f49df1f91..a309f90c768 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -184,4 +184,17 @@ #define QEMU_DISABLE_CFI #endif =20 +/* + * 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__ >=3D 14 +#define BUILTIN_SUBCLL_BROKEN +#endif + #endif /* COMPILER_H */ diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index d3b4dce6a93..011618373e5 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -649,7 +649,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 =3D *pborrow; x =3D __builtin_subcll(x, y, b, &b); *pborrow =3D b & 1; --=20 2.34.1