From nobody Tue Dec 16 11:05:29 2025 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=1601914891; cv=none; d=zohomail.com; s=zohoarc; b=GKhlzcWt26vmVwJ3wGCv4joBkdnp29WFy+9sdQPnzuAnT2OznjM2bofmkCSu+nouyv1/asiMD8S0jJ5N063Sj1RONTc8ZjA0l2EV7jyH0CrGJWUsugjfom53NKBzJAfdPHz3K39cozwm3bHb2eCElyDO+MMQuMgzZbsf7tf4h+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601914891; 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=SrkVSypShhYA6dpxFUnwCp8qnWAZDmqFXRpgTELiGHU=; b=dPzlIg+SrL+0TLVuUM+tx8hzDgYRw8sZKVQxAu76Ih2LgC8c8u4OL8aluzO8AsskFbzerjxnCa0vJ9SQmrbQL5+haafA70QP6zBK4oDnea2zJpxL9LBSU94gIBZvWaavSj64/6yuYB0IvImd3XHqSLXZrG+I5DUD8ZnMi9hZXwM= 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 1601914891559521.4047549636048; Mon, 5 Oct 2020 09:21:31 -0700 (PDT) Received: from localhost ([::1]:50238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPTEw-0001Cm-6F for importer@patchew.org; Mon, 05 Oct 2020 12:21:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPSqF-0004Ao-TB; Mon, 05 Oct 2020 11:56:00 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:40729) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kPSqC-0001YE-QB; Mon, 05 Oct 2020 11:55:59 -0400 Received: by mail-pf1-x443.google.com with SMTP id w21so7193576pfc.7; Mon, 05 Oct 2020 08:55:55 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id u22sm34803pgi.85.2020.10.05.08.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 08:55:53 -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=SrkVSypShhYA6dpxFUnwCp8qnWAZDmqFXRpgTELiGHU=; b=X/D7KW/fx9ziudkt+fjyondUMfrOwwCHJGW7d5mK9eFLxudVgDXO6FvIusjNQqBII+ Zggwzy91ynhVaTKrffjQBFNDyos3RqSDWSrMoAjl0BigI0fnI+cIYHayzlz+K/gNZuBb cj6/BtYu+luSVzyoEw3ubYT3OrhPP9CTzxWSCa8I0nn4qf9oPOWw+0yjOZMxGpezG/tt rlrve6svPHzTVQ5YJt30q5qj4PBgCM6KY2d3uSDTs2akmW5bbSPbikQG0pqy/oKxj0ql NVokl8tloXJZCBAfvioOdNERC4g2/YZ9IPGVb7yGYCdOeUZBMLB/Cx09DZ1ddigb/Shm StTw== 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=SrkVSypShhYA6dpxFUnwCp8qnWAZDmqFXRpgTELiGHU=; b=WmEcUCj2g/CCdByMtEsZXp2Ocxiz4IQCQYP3lTIrICP+JEQZ9xZzWhwbrGW5lTmYCV xsyyKV6HFP0AS66Gg5AHUF8BiKEM//h/ZXKUb6rxodLrUOET77TZsxG1XXkpl6je+19A SktesSSESC6Dtn17ZBHbSJLbqU7PtqKsTzizQOPaodRBMjhxxYr54/ibz0SeCMM8/wlQ DtUkUZnydoqxgUf2xKdFMmsxWh5E+MZMfVuKzhSi8fqWlReIjgI3PVmuHELG7qAZu2pU zylz8UiDMYQpZ4Dr0SJymVIN3rKn1Ro6d8nC4uIYrsK3EL0PHriI8PrxKyUJicLDBqKd IAOw== X-Gm-Message-State: AOAM533A86ZWOlucS8dBITOQ6O6RvbgG6foeMy6gn5O6Lo+ZpgbMNbcR xhPyBvgIX8SqnFbyIQUipphpB3sr9Om6mA== X-Google-Smtp-Source: ABdhPJw3QTCnBM8mvRSSTiDYjcLUk5jjNSrKrfbqCtuIfK5GTtVHJslbAU/vwfINBGyy7vQhWBxwKQ== X-Received: by 2002:a63:f04c:: with SMTP id s12mr80653pgj.425.1601913354325; Mon, 05 Oct 2020 08:55:54 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH v8 4/4] win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE are defined on msys2/mingw Date: Mon, 5 Oct 2020 23:55:24 +0800 Message-Id: <20201005155524.442-5-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20201005155524.442-1-luoyonggang@gmail.com> References: <20201005155524.442-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::443; envelope-from=luoyonggang@gmail.com; helo=mail-pf1-x443.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 6acdd6fa88..19813935b3 100755 --- a/configure +++ b/configure @@ -2378,37 +2378,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 @@ -6715,9 +6684,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