From patchwork Thu Jun 22 13:08:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 694893 Delivered-To: patch@linaro.org Received: by 2002:adf:e885:0:0:0:0:0 with SMTP id d5csp1391136wrm; Thu, 22 Jun 2023 06:09:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VP0aGrT6f6nWTTRcdVsP8W9BcxtQpb/rtVWTuDQeY4WTQ3s0CWLL/4cFchCJ4RM4jnwGZ X-Received: by 2002:a05:6214:2125:b0:62b:4319:7323 with SMTP id r5-20020a056214212500b0062b43197323mr27383739qvc.43.1687439352683; Thu, 22 Jun 2023 06:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687439352; cv=none; d=google.com; s=arc-20160816; b=lMcLNNMh/5wIuPr+IvZ1nE0iUSmFrRyR+6gzJQ7Yszu5S/6oSLYVJywPC5x/vRrJMR iF3amN9TIOClQ6bLIJHBa/pj359etfKTd+4dWdZL697lLYBX/YOFgH9WKI0ywH7xlYrs sza3x58DGdr3SUFyDO8AdAp+ElagD2lTWcM+3I6VpdQgRRc6JZ5/ebDVR5AERarEVS3C a+bZTfa+UYZHO3PQPTy6jgHQ7WCutR/vNsIvv5M7lHGXwRFqC0oxK3jBZO09uYhnTy73 /vGOOqjs2GiZuhrFJ8mVp2ja39BMUHP40IVolZ/4WtNRjtAUiN8dk8LWnjMJI7wzjpPq Eb5w== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=1vdtz3xBrKH2G9M2G9/DIVn5V1BQ12aeC17aZaNPM38=; b=0b349TYwMeCjyWasBF9GGK+Rji1B8viNNePABiCfr2l+HDPK6w9FA2BYAytCzTN6P+ 6FMjlvSPuIQW4J5Y9XR2GzIOHQsN/8olEU309ecv0bGHJs2TUUrOA9Y5A5R0eiuTTLGj XVSSp0vg0TCn3T4zciKA3u3lbht33ZBPGBeZSGodeInhFGYFaOJuW0hZ38C5V9druVsQ uVSsX1iBret5k8rYCe2KqKNzsehKX+8iX5S7jEvviqvM8mpa+gz4IKFEYTy9aTHTFBIE dQ/ay8IAflLrxDTga+CX0GoDegSBvQ1s0DDA3S507hyfDEVejlwdja/XnbkRCgQCuT85 K1tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ak6sEMJF; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n22-20020a05622a11d600b003ef5008333bsi2666661qtk.431.2023.06.22.06.09.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Jun 2023 06:09:12 -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; dkim=pass header.i=@linaro.org header.s=google header.b=Ak6sEMJF; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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/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é --- 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 +/* + * 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 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 = *pborrow; x = __builtin_subcll(x, y, b, &b); *pborrow = b & 1;