From nobody Mon Nov 18 22:20:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1602546646; cv=none; d=zohomail.com; s=zohoarc; b=Idlrneg8VPTCMS2soJ4DAkDLFcOamKEziW6qgMsgLPs1pcBn1I9e7DVvB1KfENNkPloxxWEZgXOtMhNDyExtuYFfv+3x55J91g786i5eby8OqjDa6lw6mQdC4sowvqawTgsvmgBwZmOsZesKZ5rYvqcXoM2AguDRZsHT9tk9zvU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602546646; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kb7zkZJauBf/oSDNgYK6+uglPqh8gIaGZ4A3meEW04U=; b=JoVj8WHnuLSsg9tK5VYL2qWb5iYTrXYiGy7aPEDKyHW3WmhAmgk3/s3i8oIgFKrt6j+zdSIV7wTSbBHMhIHQSG7zdOFCZAzZD06iAhymuLcqLpM1bn4K/eMMHsSwy3qYQaRQm3rZuYPhTX1KzXETUwqFc4it2lC3r/B1ifzQ6+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602546646194314.12893009433253; Mon, 12 Oct 2020 16:50:46 -0700 (PDT) Received: from localhost ([::1]:49068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kS7aW-000656-QD for importer@patchew.org; Mon, 12 Oct 2020 19:50:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kS7UQ-0000Fk-7I; Mon, 12 Oct 2020 19:44:26 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:40870) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kS7UO-0007ji-1A; Mon, 12 Oct 2020 19:44:25 -0400 Received: by mail-pg1-x542.google.com with SMTP id i2so16023198pgh.7; Mon, 12 Oct 2020 16:44:23 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id j3sm9714890pjv.20.2020.10.12.16.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 16:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kb7zkZJauBf/oSDNgYK6+uglPqh8gIaGZ4A3meEW04U=; b=IMIwXl2KPBuZWXOanJ4qyGSlmY0ujwkk+K/6sflytZUpHMidYbpa9+1L2/1gR/4f4D ZdKPJTpccdP4E8p5L4vZFA3FBOHhVt5hYPJHZBWg0S5Iv+FW9cDiJtxYft7zlm0cADIK 5bIoiryiBUTDQ+Yoy2IdukUnd1KYe48DMdRPdWkH3btkjq7trYhx9nCsBXMcOEBoG+9g FMAMdKlhk5gPTRZn5x1nFiSzYmdkWqBuuiiJnv4nBJBMkUjjazfPjejCNPKcYkg7rF/f 6JW4XTSVkTAXurfKBSgsDr1QrBja0xV/coFQs+RQlccaFN03Y0lpzLY8sKqdzoIOT/4P sioQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kb7zkZJauBf/oSDNgYK6+uglPqh8gIaGZ4A3meEW04U=; b=uS24vR0lkdRLkih/7w0f0L5FKsqxKdgP+En3rbVbkx3hhJXj2YnpN2QS3H0NZyBaDJ svOGfAW14cMr1OuxMrG2baYzD4CrYwlC6VaXK4kkvI5W0XnDF7foEWmSs73aVF5rmw1s W2StuASot0myWmho1kL58Kdg7zngU1+P+OBOr6XtfM2FpCJFufngzUxeJtYf0TitwAy4 vWVD7Hi9w6JFEzQR7r6zrwbz7J+zSi5VDhUUG51XsE0oOFT3holt2kSyJgWOsvJQPyGr sWro8WfS9RPHHBU3JisWfpH/BKVznTBVa4+RsYmi84MCxCDnHrJyXC2YBNBA5Hu+pmTv k1Uw== X-Gm-Message-State: AOAM5334BVVXiGjsslB1vMarrR8zGnMoB1xdE0mQHLkLsv3mProWGzSZ P91Fe/kc1Ffy7oK7xZcup3Qd+rRqABm2AA== X-Google-Smtp-Source: ABdhPJxhjh4sSGSmtBioVF/TkZctgwUB/o94q7SBNzPwqpNSS/M8f2kMUWT8ntlADnbJ/8ksdDj0xg== X-Received: by 2002:a62:d0c1:0:b029:155:2e17:ea0 with SMTP id p184-20020a62d0c10000b02901552e170ea0mr23735480pfg.55.1602546261698; Mon, 12 Oct 2020 16:44:21 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH v9 4/5] win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE are defined on msys2/mingw Date: Tue, 13 Oct 2020 07:43:47 +0800 Message-Id: <20201012234348.1427-5-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201012234348.1427-1-luoyonggang@gmail.com> References: <20201012234348.1427-1-luoyonggang@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2607:f8b0:4864:20::542; envelope-from=luoyonggang@gmail.com; helo=mail-pg1-x542.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: QEMU Trivial , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson , Laurent Vivier , Yonggang Luo , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We remove the CONFIG_LOCALTIME_R detection option in configure, and move th= e check existence of gmtime_r from configure into C header and source directly by u= sing macro `_POSIX_THREAD_SAFE_FUNCTIONS`. Before this patch, the configure script are always assume the compiler does= n't define _POSIX_C_SOURCE macro at all, but that's not true, because thirdparty libra= ry such as ncursesw may define -D_POSIX_C_SOURCE in it's pkg-config file. And that = C Flags will added -D_POSIX_C_SOURCE into each QEMU_CFLAGS. And that's causing the follo= wing compiling error: n file included from C:/work/xemu/qemu/include/qemu/osdep.h:119, from ../softmmu/main.c:25: C:/work/xemu/qemu/include/sysemu/os-win32.h:53:12: error: redundant redecla= ration of 'gmtime_r' [-Werror=3Dredundant-decls] 53 | struct tm *gmtime_r(const time_t *timep, struct tm *result); | ^~~~~~~~ In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94, from ../softmmu/main.c:25: C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:284:36: note: = previous definition of 'gmtime_r' was here 284 | __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, st= ruct tm *_Tm) { | ^~~~~~~~ In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119, from ../softmmu/main.c:25: C:/work/xemu/qemu/include/sysemu/os-win32.h:55:12: error: redundant redecla= ration of 'localtime_r' [-Werror=3Dredundant-decls] 55 | struct tm *localtime_r(const time_t *timep, struct tm *result); | ^~~~~~~~~~~ In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94, from ../softmmu/main.c:25: C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:281:36: note: = previous definition of 'localtime_r' was here 281 | __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time,= struct tm *_Tm) { | ^~~~~~~~~~~ Compiling C object libcommon.fa.p/hw_gpio_zaurus.c.obj In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119, from ../hw/i2c/smbus_slave.c:16: C:/work/xemu/qemu/include/sysemu/os-win32.h:53:12: error: redundant redecla= ration of 'gmtime_r' [-Werror=3Dredundant-decls] 53 | struct tm *gmtime_r(const time_t *timep, struct tm *result); | ^~~~~~~~ In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94, from ../hw/i2c/smbus_slave.c:16: C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:284:36: note: = previous definition of 'gmtime_r' was here 284 | __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, st= ruct tm *_Tm) { | ^~~~~~~~ In file included from C:/work/xemu/qemu/include/qemu/osdep.h:119, from ../hw/i2c/smbus_slave.c:16: C:/work/xemu/qemu/include/sysemu/os-win32.h:55:12: error: redundant redecla= ration of 'localtime_r' [-Werror=3Dredundant-decls] 55 | struct tm *localtime_r(const time_t *timep, struct tm *result); | ^~~~~~~~~~~ In file included from C:/work/xemu/qemu/include/qemu/osdep.h:94, from ../hw/i2c/smbus_slave.c:16: C:/CI-Tools/msys64/mingw64/x86_64-w64-mingw32/include/time.h:281:36: note: = previous definition of 'localtime_r' was here 281 | __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time,= struct tm *_Tm) { | ^~~~~~~~~~~ Compiling C object libcommon.fa.p/hw_dma_xilinx_axidma.c.obj After this patch, whenever ncursesw or other thirdparty libraries tried to = define or not define _POSIX_C_SOURCE, the source will building properly. Because now, we= don't make any assumption if _POSIX_C_SOURCE are defined. We solely relied on if the macro= `_POSIX_THREAD_SAFE_FUNCTIONS` are defined in msys2/mingw header. The _POSIX_THREAD_SAFE_FUNCTIONS are defined in mingw header like this: ``` #if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS) #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L #endif #ifdef _POSIX_THREAD_SAFE_FUNCTIONS __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct = tm *_Tm) { return localtime_s(_Tm, _Time) ? NULL : _Tm; } __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm = *_Tm) { return gmtime_s(_Tm, _Time) ? NULL : _Tm; } __forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) { return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str; } __forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) { return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str; } #endif ``` Signed-off-by: Yonggang Luo Reviewed-by: Daniel P. Berrang=C3=A9 --- configure | 34 ---------------------------------- include/sysemu/os-win32.h | 4 ++-- util/oslib-win32.c | 4 ++-- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/configure b/configure index 71a574f718..9a87685517 100755 --- a/configure +++ b/configure @@ -2386,37 +2386,6 @@ if test "$vhost_net" =3D ""; then test "$vhost_kernel" =3D "yes" && vhost_net=3Dyes fi =20 -########################################## -# MinGW / Mingw-w64 localtime_r/gmtime_r check - -if test "$mingw32" =3D "yes"; then - # Some versions of MinGW / Mingw-w64 lack localtime_r - # and gmtime_r entirely. - # - # Some versions of Mingw-w64 define a macro for - # localtime_r/gmtime_r. - # - # Some versions of Mingw-w64 will define functions - # for localtime_r/gmtime_r, but only if you have - # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun - # though, unistd.h and pthread.h both define - # that for you. - # - # So this #undef localtime_r and #include - # are not in fact redundant. -cat > $TMPC << EOF -#include -#include -#undef localtime_r -int main(void) { localtime_r(NULL, NULL); return 0; } -EOF - if compile_prog "" "" ; then - localtime_r=3D"yes" - else - localtime_r=3D"no" - fi -fi - ########################################## # pkg-config probe =20 @@ -6610,9 +6579,6 @@ if [ "$bsd" =3D "yes" ] ; then echo "CONFIG_BSD=3Dy" >> $config_host_mak fi =20 -if test "$localtime_r" =3D "yes" ; then - echo "CONFIG_LOCALTIME_R=3Dy" >> $config_host_mak -fi if test "$qom_cast_debug" =3D "yes" ; then echo "CONFIG_QOM_CAST_DEBUG=3Dy" >> $config_host_mak fi diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h index d8978e28c0..5346d51e89 100644 --- a/include/sysemu/os-win32.h +++ b/include/sysemu/os-win32.h @@ -48,12 +48,12 @@ #define siglongjmp(env, val) longjmp(env, val) =20 /* Missing POSIX functions. Don't use MinGW-w64 macros. */ -#ifndef CONFIG_LOCALTIME_R +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS #undef gmtime_r struct tm *gmtime_r(const time_t *timep, struct tm *result); #undef localtime_r struct tm *localtime_r(const time_t *timep, struct tm *result); -#endif /* CONFIG_LOCALTIME_R */ +#endif /* _POSIX_THREAD_SAFE_FUNCTIONS */ =20 static inline void os_setup_signal_handling(void) {} static inline void os_daemonize(void) {} diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 051afb217b..e99debfb8d 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -106,7 +106,7 @@ void qemu_anon_ram_free(void *ptr, size_t size) } } =20 -#ifndef CONFIG_LOCALTIME_R +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS /* FIXME: add proper locking */ struct tm *gmtime_r(const time_t *timep, struct tm *result) { @@ -130,7 +130,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *= result) } return p; } -#endif /* CONFIG_LOCALTIME_R */ +#endif /* _POSIX_THREAD_SAFE_FUNCTIONS */ =20 static int socket_error(void) { --=20 2.28.0.windows.1