From patchwork Mon Oct 10 14:38:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 680429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3st2pq1vXDz9ryQ for ; Tue, 11 Oct 2016 01:40:19 +1100 (AEDT) Received: from localhost ([::1]:50604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btbkW-0001gR-5Q for incoming@patchwork.ozlabs.org; Mon, 10 Oct 2016 10:40:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btbix-0000dv-Rf for qemu-devel@nongnu.org; Mon, 10 Oct 2016 10:38:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btbiw-00088C-H5 for qemu-devel@nongnu.org; Mon, 10 Oct 2016 10:38:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33550) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btbip-00084W-JX; Mon, 10 Oct 2016 10:38:31 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1618C8E3FA; Mon, 10 Oct 2016 14:38:31 +0000 (UTC) Received: from red.redhat.com (ovpn-116-125.phx2.redhat.com [10.3.116.125]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9AEcUW5012974; Mon, 10 Oct 2016 10:38:30 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 10 Oct 2016 09:38:26 -0500 Message-Id: <1476110306-23754-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 10 Oct 2016 14:38:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] build: Work around SIZE_MAX bug in OSX headers 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: kwolf@redhat.com, peter.maydell@linaro.org, ashijeetacharya@gmail.com, armbru@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" C99 requires SIZE_MAX to be declared with the same type as the integral promotion of size_t, but OSX mistakenly defines it as an 'unsigned long long' expression even though size_t is only 'unsigned long'. Rather than futzing around with whether size_t is 32- or 64-bits wide (which would be needed if we cared about using SIZE_T in a #if expression), let the compiler get the right type for us by virtue of integer promotion. See also https://patchwork.ozlabs.org/patch/542327/ for an instance where the wrong type trips us up if we don't fix it for good in osdep.h. Some versions of glibc make a similar mistake with SSIZE_MAX; the goal is that the approach of this patch could be copied to work around that problem if it ever becomes important to us. Signed-off-by: Eric Blake --- v1 was here: https://lists.gnu.org/archive/html/qemu-devel/2016-07/msg02520.html The topic recently came up again, and I noticed this patch sitting on one of my older branches, so I've taken another shot at it. https://lists.gnu.org/archive/html/qemu-devel/2016-10/msg00950.html v2: rewrite into a configure check (not sure if directly adding a -D to QEMU_CFLAGS is the best, so advice welcome) I lack easy access to a Mac box, so this is untested as to whether it actually solves the issue... --- include/qemu/osdep.h | 8 ++++++++ configure | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 9e9fa61..22667f6 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -141,6 +141,14 @@ extern int daemon(int, int); # error Unknown pointer size #endif +/* Mac OSX has a bug that incorrectly defines SIZE_MAX with + * the wrong type. Our replacement isn't usable in preprocessor + * expressions, but it is sufficient for our needs. */ +#ifdef SIZE_MAX_BROKEN +#undef SIZE_MAX +#define SIZE_MAX ((sizeof(char)) * -1) +#endif + #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif diff --git a/configure b/configure index 5751d8e..137ebb8 100755 --- a/configure +++ b/configure @@ -1725,6 +1725,19 @@ if test "$cocoa" = "yes"; then sdl=no fi +# Some versions of Mac OS X incorrectly define SIZE_MAX +cat > $TMPC << EOF +#include +#include +int main(int argc, char *argv[]) { + return printf("%zu", SIZE_MAX); +} +EOF + +if ! compile_object -Werror ; then + QEMU_CFLAGS="-DSIZE_MAX_BROKEN $QEMU_CFLAGS" +fi + ########################################## # L2TPV3 probe