From patchwork Mon Jun 26 18:58:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 696478 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp3389607wrm; Mon, 26 Jun 2023 12:10:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7yr7XmGajsSv88yMb1L0WFVR2vi+U7TrVyZb9uqTqjqOPhzlZsYUD7avCrTkdvOWna43qg X-Received: by 2002:a05:6214:2426:b0:626:1b09:1d4f with SMTP id gy6-20020a056214242600b006261b091d4fmr37484213qvb.46.1687806624205; Mon, 26 Jun 2023 12:10:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687806624; cv=none; d=google.com; s=arc-20160816; b=D35pKZxi/lWdV71lGSd4N49mzPzk8kfUufrmtKNqpEk0lznMjZQo7+X0de+74TOPWo cGzhq8ZzI2dtmhZC+uWdtot585zJhCDJ15Hfs7PZPufTgLfoXlpaqlr314KmdFDxThix 5G9BSg0hjl5aDv0bonzFkrchF2T99ahfjmS5LhHUvQjQJe7mlZ1AZdtkfLAtJxCsGDjc jqGb5FRONkMQvZag7amHanXuUr+2zgwlHpYrUnNXTQ3d1Wkrhjhq7WVDFdCPcGvRo8z/ czxaLCuXHKdT28IsnAUSbQMO9ENsNKLl9kiYtRRFfpi/twIwJ4DJ/hkLQ3U7Ro6iKd4l FDHQ== 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=PKdG5zBlRii32b3yk+Z/rsxcHJ+zHxKrMbz8RsdLgII=; fh=JfuprfCedaaH4bwbV1+UfSdrVnNu3JN+V+yaHHqBUgY=; b=t1wZ0CjqaiML2BD8LSapnppGATanx2WkxzlY2Pm8BxeuoGkv2AbWqzSex5nLaDIPEs JGQ2AvA6ANAnvccV03EY6OCp5aa7KAClAFHc6QfsOWH2anO0jDjjBpu7+fAWOX7ihgCI kCKzTNCOWXiR6so0OsN8T1IxO7RVLT9+ARDlrcH8MD3v90hehgljgv1tr/9GiyGpO63c UYnVvHmJru1t9MemFcWG8MqzbfaA6GUd2ZVfXYp1IKRMtIdmMhW+IsKvAZtlZoPKHTCh bSOHc91c5Lx7JJXcLXxWhEaTnu2QWr9LYKQsnaysXhaDj4ppOC3Na5Z0vbE/iac5IV03 4ICA== 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 a3-20020ad45c43000000b00635db21d14esi1364527qva.303.2023.06.26.12.10.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2023 12:10:24 -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 1qDrTy-0002o5-4J; Mon, 26 Jun 2023 15:02:38 -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 1qDrTJ-0000sK-Sr; Mon, 26 Jun 2023 15:01:57 -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 1qDrTH-0007sI-SJ; Mon, 26 Jun 2023 15:01:57 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 8C191EFC5; Mon, 26 Jun 2023 21:59:14 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id 08FA9F800; Mon, 26 Jun 2023 21:59:13 +0300 (MSK) Received: (nullmailer pid 1575382 invoked by uid 1000); Mon, 26 Jun 2023 18:59:05 -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-7.2.4 35/43] host-utils: Avoid using __builtin_subcll on buggy versions of Apple Clang Date: Mon, 26 Jun 2023 21:58:53 +0300 Message-Id: <20230626185902.1575177-35-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 f20a76e4a2..c7ffcaba43 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 88d476161c..b3434ec0bc 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -596,7 +596,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;