util: fix compilation with mingw-w64 7.0.0#18358
Conversation
|
Concept ACK. |
Does this alternative solution has any downsides? |
|
Concept ACK |
Gitian builds
|
|
Did a bit more digging. Here's what I found: This commmit is the one that caused the change in behaviour. There's a very short mailing list thread about it here. My conversation with the author of the commit on IRC: Here's some more general use information on _POSIX_C_SOURCE and _POSIX_THREAD_SAFE_FUNCTIONS. |
|
Looks like this makes the include order of headers more resilient and fixes a bug I was running in to a year ago: https://github.com/bitcoin/bitcoin/pull/16046/files#r285601479 If you feel like, you might sort the includes in the header now: diff --git a/src/util/time.h b/src/util/time.h
index 77de1e047d..a8c06ef350 100644
--- a/src/util/time.h
+++ b/src/util/time.h
@@ -6,9 +6,9 @@
#ifndef BITCOIN_UTIL_TIME_H
#define BITCOIN_UTIL_TIME_H
+#include <chrono>
#include <stdint.h>
#include <string>
-#include <chrono>
void UninterruptibleSleep(const std::chrono::microseconds& n);
|
|
If I'm thinking about this the right way, your diff implies that previously the If |
e8ca7bd to
1b801e7
Compare
Done.
I've looked into this, and there are some cases where we are using |
maflcko
left a comment
There was a problem hiding this comment.
ACK 1b801e770477e756d67402970694bca73fa0ac7f
cc @sipsorcery
Interesting why master could be built successfully with Ubuntu's g++-mingw-w64 7.3.0? |
The version of |
hebasto
left a comment
There was a problem hiding this comment.
ACK 1b801e770477e756d67402970694bca73fa0ac7f, tested on Ubuntu 20.04 with mingw-w64 7.0.0.
|
From #bitcoin-builds meeting notes today: We should investigate how to detect features (i.e. check for function availability at configure time), rather than detecting platforms. This might be more robust. |
|
@dongcarl Is this a general advise/issue or a blocker on this specific patch set? |
|
@MarcoFalke I think it's a blocker while we investigate if feature detection is the right path take going forward, no point merging this then changing right after (unless the release schedule dictates?) |
|
Here's an alternative: master...Empact:2020-03-gmtime-config Note I haven't run it on windows/mingw, and I'm not sure how to get the test to distinguish between MSC-style Edit: and another more succinct alternative: master...Empact:2020-03-gmtime-check-funcs Inspired by sqlite's handling of the same question: https://github.com/sqlite/sqlite/blob/118efd162632298bccba21b71934f666e556f594/configure.ac#L111 Although they fall back to |
|
ACK 1b801e770477e756d67402970694bca73fa0ac7f. |
|
Using the windows function on windows (instead of mingw's wrapper) makes sense, imo. |
src/util/time.cpp
Outdated
There was a problem hiding this comment.
can't we change this to #ifdef WIN32 ?
|
Hmmm, I think perhaps what we want to do is similar to what's being done here: https://github.com/maru/libmicrohttpd-http2/blob/316af7c06537e524c6ef02bc1d5f59b39af7d1d1/configure.ac#L1033-L1082 It's feature-based detection, and we'll have clarity between |
|
Yeah, that's another way. If we still want this for 0.20, we need to make a decision here quickly though. I'm sorry for starting a bikeshed 😆 |
This improves the portability of the codebase and fixes compilation with mingw-w64 7.0+. Co-authored-by: fanquake <[email protected]>
1b801e7 to
a46484c
Compare
Maybe I was just imaging this.. Have pushed up some new changes. Tested on macOS: checking for gmtime_r... yesmingw-w64 cross compile: checking for gmtime_r... no
checking for gmtime_s... yesdebian: checking for gmtime_r... yesMSVC ✅ |
|
Note one thing I have not tested with this implementation is how it operates if gmtime_r is not present, but C11-style gmtime_s is. |
There was a problem hiding this comment.
Tested a46484c on focal and bionic. Both produce:
$ CONFIG_SITE=$PWD/depends/x86_64-w64-mingw32/share/config.site ./configure
...
checking for gmtime_r... no
checking for gmtime_s... yes
...
To make things clear about cross compiling on systems with pre-7.0 mingw-w64 headers, e.g., on bionic:
on master the gmtime_r() is used, and with this PR the gmtime_s() is used, right?
|
ACK a46484c |
|
Post-merge ACK. Thanks for making this test-based, I think this is a nice improvement. |
@hebasto the breakdown is:
|
f3f3d6c util: fix compilation with mingw-w64 7.0.0 (Fuzzbawls) f24da7d util: Avoid potential uninitialized read in FormatISO8601DateTime (Fuzzbawls) 120a12a util: Add type safe GetTime (Fuzzbawls) be48766 Fix for utiltime to compile with msvc. (Aaron Clauson) 2833406 Avoid std::locale/imbue in DateTimeStrFormat (Pieter Wuille) 3331c25 Format automatic wallet backup file names in ISO 8601 basic format (Fuzzbawls) c32a208 Format timestamps using ISO 8601 formatting (e.g. "2018-02-28T12:34:56Z") (practicalswift) f8bd173 [logging] log system time and mock time (John Newbery) Pull request description: This is a backport of a collection of upstream PRs to bring our time utility more up to date. The following upstream PRs are included: - bitcoin#10383 - bitcoin#12567 - bitcoin#12973 - bitcoin#13031 - bitcoin#16046 - bitcoin#18162 - bitcoin#18358 The two user-facing notable changes here have been documented in the release notes template. I've also connected the functionality that `-logtimemicros` was supposed to provide. ACKs for top commit: furszy: code review ACK f3f3d6c random-zebra: utACK f3f3d6c after rebase, and merging... Tree-SHA512: 64f9cc1f7fc65c192f3b3ab869c057a81e007cf0fae82ecd23993c6b51830e4bc80656c699ba40bb8e019115a24d1ea88a618be0c0d7112749d9ce125d62ce44
merge bitcoin#16117, bitcoin#18358, bitcoin#17383, bitcoin#21052, bitcoin#14424, bitcoin#15159, bitcoin#14689, bitcoin#14978, partial bitcoin#16908, bitcoin#14978, bitcoin#13932: Auxillary Backports
Something has changed in the mingw-w64 headers such that we
no-longer compile when using 7.0.0.
Looking at time.h, it seems that
gmtime_r()is only available when_POSIX_C_SOURCEis defined. This must have been the case for 6.0.0(which we compile fine using), but no-longer seems to be for 7.0.0?
I've checked that adding
-D_POSIX_C_SOURCE=200112Lto our compileflags does fix the issue above.
However, an alternative solution seems to be to just use
gmtime_s()instead, when compiling with
mingw-w64, asgmtime_r()just wrapsgmtime_s()anyways.I've tested this change crosss-compiling on Debian Bullseye (mingw-w64 7.0.0)
and Buster (mingw-w64 6.0.0).