Repository navigation
Conversation
Static CRT crashes both MSVCR* and UCRT MSVC builds according to CI and local tests. This was the reason why we had to skip `curl -V` for VS2008 in CI. Cherry-picked from curl#16394
- appveyor: restore VS2008 job, after fixing its issues. Enable OpenSSL in it. It takes 1 minute. Follow-up to 9b0467b #16453 Follow-up to edfa537 #16456 - appveyor: make a copy of OpenSSL DLLs to have them picked up as an artifact (disabled by default) to aid local tests. - appveyor: dump CMake configuration logs on failure. - appveyor: tidy up job parameter defaults. - GHA/windows: add pre-fill check option for dl-mingw jobs. - GHA/windows: fix pre-fill check option for MSYS jobs by installing `diffutils`. Follow-up to e7adf3e #15841 - GHA/windows: de-duplicate to `PATH` commands for Cygwin. - GHA/windows: drop `$SYSTEMROOT/System32` from `PATH` for Cygwin configure. It's not needed. Follow-up to 36fd2dd #13599 - list `.pdb` files in curl version step for MSVC. Ref: #16439 Cherry-picked from #16394 Closes #16458
|
If there are bugs with static CRT in libcurl.dll then we should address them rather than ban the combo. I am still pondering about the first bug with the stderr redirection. I think I may propose banning the curl tool from setting the option on builds that use a shared libcurl unless I can think of something better. Regarding the other bug I would need a way to reproduce out of CI so that I can debug it. edit: note tool_init_stderr() must be called before writing to stderr (defined as tool_stderr in every unit except tool_stderr.c). the function initializes tool_stderr to the real stderr. could that be the problem? it is called in main before anything else: Lines 234 to 243 in 57495c6 Lines 31 to 37 in 57495c6 |
|
Try reversing this commit to reproduce: d5e55fb I added 4 printf()s in total, of which one of the first two caused this, i think the first one was before the stderr init, this one was after. But to repeat, this was printf and unless it internally wants use stderr somehow, this all goes to stdout. As for the stderr case, the -V output is after stderr init. If this can be refined, fine, but after 3 18 hour days chasing these I run out of interest to narrow it down further. Doing it locally can make this much faster though. For shared exe the static CRT option could indeed be limited to libcurl itself. Whether this is useful and worthy the complexity? Hard to say. |
Static CRT crashes MSVCR* MSVC builds (in VS2008, VS2010, VS2012,
VS2013) according to CI and local tests. The reproducible crash happens
in `curl_mfprintf() -> fputc(s, stderr)` when trying to display the
warning message in `curl -V`. `stderr` is non-NULL and resolves to `2`.
This reproducer needs a debug-enabled build, but it's unrelated to debug
features or curl's memory tracker. It happens regardless of unity build,
CPU architecture or `DllMain()` use. Example from VS2013:
```
+ _bld/src/Debug/curl.exe --disable --version
./appveyor.sh: line 124: 203 Segmentation fault "${curl}" --disable --version
```
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/51570451/job/ojpdqrsm1hmpmq6a#L210
Another crash happened in an UCRT build (VS2017) with a couple of
`printf()`s added to curl's `main()` function:
```
Microsoft Visual C++ Runtime Library
Debug Assertion Failed!
Program: C:/projects/curl/bld/src/Debug/curl.exe
File: minkernel/crts/ucrt/src/appcrt/heap/debug_heap.cpp
Line: 996
Expression: _act_first_block == header
```
(it hangs the job in CI due to the GUI popup)
Ref: curl#16394 (comment)
To avoid actual and potential issues, this patch issues a warning on
the shared-libcurl + static-CRT combination and falls back to the
default, shared CRT. IOW a static CRT build now requires a static curl
exe when using the `CURL_STATIC_CRT=ON` option.
Follow-up to 4fc6ebe curl#1621
Cherry-picked from curl#16394 (with more details there)
Closes curl#16456
- appveyor: restore VS2008 job, after fixing its issues. Enable OpenSSL in it. It takes 1 minute. Follow-up to 9b0467b curl#16453 Follow-up to edfa537 curl#16456 - appveyor: make a copy of OpenSSL DLLs to have them picked up as an artifact (disabled by default) to aid local tests. - appveyor: dump CMake configuration logs on failure. - appveyor: tidy up job parameter defaults. - GHA/windows: add pre-fill check option for dl-mingw jobs. - GHA/windows: fix pre-fill check option for MSYS jobs by installing `diffutils`. Follow-up to e7adf3e curl#15841 - GHA/windows: de-duplicate to `PATH` commands for Cygwin. - GHA/windows: drop `$SYSTEMROOT/System32` from `PATH` for Cygwin configure. It's not needed. Follow-up to 36fd2dd curl#13599 - list `.pdb` files in curl version step for MSVC. Ref: curl#16439 Cherry-picked from curl#16394 Closes curl#16458
|
MSDN says this: Also, would this help? I'm think maybe non-curl tool libcurl users might work fine with a statically linked libcurl DLL. --- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -352,7 +352,7 @@ endif()
if(WIN32)
option(CURL_STATIC_CRT "Build libcurl with static CRT with MSVC (/MT)" OFF)
if(CURL_STATIC_CRT AND MSVC)
- if(BUILD_STATIC_CURL)
+ if(BUILD_STATIC_CURL OR NOT BUILD_CURL_EXE)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
string(APPEND CMAKE_C_FLAGS_RELEASE " -MT")
string(APPEND CMAKE_C_FLAGS_DEBUG " -MTd") |
|
Sure, there are disadvantages to using a static CRT. I certainly wouldn't recommend it but I don't want to ban it if we don't have to. If it doesn't work then probably there is a bug somewhere. Or CI weirdness? Don't know. That printf causing a crash makes no sense to me. I haven't tried to repro yet. It's taking a little more time than I thought to get it set up. AFAICT we make no change to stdout except in tool_operate to set it to binary mode during transfer. The libcurl stdout is not modified in this case since it's separate crt, but it's not used so it should be fine. For future reference I had some trouble figuring out how to retrieve the "unreachable" commit from your repo because those commits are not normally downloaded with the (Newer git versions may allow the short format, I don't know.) That's where I'm at so far but out of time tonight. I will look into it as time allows. No objections to your related pr, cheers |
|
It also works to append a Barefoot, but works. More follow-ups under #16522, with the reproducer and trying to narrow it down further in CI. |
After this patch, we're back to 8.12.1, but disallowing `CURL_STATIC_CRT=ON` with shared curl exe built with VS2013 or older. Because those may crash. A stable reprducer is with `ENABLE_DEBUG=ON` and calling `curl.exe -V`. You can pass the necessary CMake and MSVC linker options manually, to get around this condition. Shared build with static UCRT may be crashing too, depending on conditions. Consult the documentation about limitations of static CRT: https://learn.microsoft.com/cpp/c-runtime-library/crt-library-features Follow-up to 049352d #16516 Follow-up to edfa537 #16456 Ref: #16394 Closes #16522
Static CRT crashes MSVCR* MSVC builds (in VS2008, VS2010, VS2012,
VS2013) according to CI and local tests. The reproducible crash happens
in `curl_mfprintf() -> fputc(s, stderr)` when trying to display the
warning message in `curl -V`. `stderr` is non-NULL and resolves to `2`.
This reproducer needs a debug-enabled build, but it's unrelated to debug
features or curl's memory tracker. It happens regardless of unity build,
CPU architecture or `DllMain()` use. Example from VS2013:
```
+ _bld/src/Debug/curl.exe --disable --version
./appveyor.sh: line 124: 203 Segmentation fault "${curl}" --disable --version
```
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/51570451/job/ojpdqrsm1hmpmq6a#L210
Another crash happened in an UCRT build (VS2017) with a couple of
`printf()`s added to curl's `main()` function:
```
Microsoft Visual C++ Runtime Library
Debug Assertion Failed!
Program: C:/projects/curl/bld/src/Debug/curl.exe
File: minkernel/crts/ucrt/src/appcrt/heap/debug_heap.cpp
Line: 996
Expression: _act_first_block == header
```
(it hangs the job in CI due to the GUI popup)
Ref: curl#16394 (comment)
To avoid actual and potential issues, this patch issues a warning on
the shared-libcurl + static-CRT combination and falls back to the
default, shared CRT. IOW a static CRT build now requires a static curl
exe when using the `CURL_STATIC_CRT=ON` option.
Follow-up to 4fc6ebe curl#1621
Cherry-picked from curl#16394 (with more details there)
Closes curl#16456
- appveyor: restore VS2008 job, after fixing its issues. Enable OpenSSL in it. It takes 1 minute. Follow-up to 9b0467b curl#16453 Follow-up to edfa537 curl#16456 - appveyor: make a copy of OpenSSL DLLs to have them picked up as an artifact (disabled by default) to aid local tests. - appveyor: dump CMake configuration logs on failure. - appveyor: tidy up job parameter defaults. - GHA/windows: add pre-fill check option for dl-mingw jobs. - GHA/windows: fix pre-fill check option for MSYS jobs by installing `diffutils`. Follow-up to e7adf3e curl#15841 - GHA/windows: de-duplicate to `PATH` commands for Cygwin. - GHA/windows: drop `$SYSTEMROOT/System32` from `PATH` for Cygwin configure. It's not needed. Follow-up to 36fd2dd curl#13599 - list `.pdb` files in curl version step for MSVC. Ref: curl#16439 Cherry-picked from curl#16394 Closes curl#16458
After this patch, we're back to 8.12.1, but disallowing `CURL_STATIC_CRT=ON` with shared curl exe built with VS2013 or older. Because those may crash. A stable reprducer is with `ENABLE_DEBUG=ON` and calling `curl.exe -V`. You can pass the necessary CMake and MSVC linker options manually, to get around this condition. Shared build with static UCRT may be crashing too, depending on conditions. Consult the documentation about limitations of static CRT: https://learn.microsoft.com/cpp/c-runtime-library/crt-library-features Follow-up to 049352d curl#16516 Follow-up to edfa537 curl#16456 Ref: curl#16394 Closes curl#16522
When a curl binary is built with Visual Studio in debug mode, it uses the matching, debug-enabled CRT. The debug CRT by default pops up an interactive GUI dialog by default, also on CI machines, both on AppVeyor CI and GHA, on `assert()` and other low-level failures. This causes the CI job to appear hung, with nothing printed to the CI log, invisibly waiting for someone clicking on a GUI MessageBox. On a remote/headless CI machine this is unworkable. The job then quits on timeout, after blocking other queued tasks (for 1 hour on AppVeyor CI, 10-15 minutes in GHA/windows). To make such failures CI-friendly, fix by configuring this behavior in `curl.exe`, `servers.exe` and unit test binaries, to output all errors to stderr, and to `OutputDebugString()`, overiding the GUI popup. This can save a lot of hair-pulling. Example output, after this patch: ``` Assertion failed: r == 10, file C:\projects\curl\tests\libtest\first.c, line 272 abort() has been called ``` Note, the default debug CRT behavior depends on a number of things, e.g. on a Server Core (or similar) Windows edition, or when run under a debugger. Assuming the default behavior is the expected one in most cases, this patch only reconfigures it for builds made in the curl CI. If you want to enable it, set the `CURL_CI` env to non-empty at configure time, or build with the `-DCURL_DEBUG_MSVC_CRTDBG` C macro. This issue does not apply to mingw-w64 builds, as tested with both UCRT and MSVCRT. They output the assert text to the CI logs out-of-the-box. Refs: https://learn.microsoft.com/cpp/c-runtime-library/reference/crtsetreportfile https://learn.microsoft.com/cpp/c-runtime-library/reference/crtsetreportmode https://learn.microsoft.com/cpp/c-runtime-library/reference/set-error-mode Ref: #23336 Ref: edfa537 #16456 Ref: #14854 Cherry-picked from #23306 Closes #23400
Limit this option to static-only curl builds. Enabling the static CRT for other configurations may successfuly build them, but executing them do run into nasty problems due to using two CRT copies at the same time. Also note that the static CRT setting applies to tests too, which revealed these issues. Also: - as it turns out, static CRT may be enabled for non-UCRT builds. After this patch, such configuration is possible again. - note, if these preconditions prevent doing a desired static-CRT build variation (e.g. a libcurl.dll built against static CRT). You can pass the necessary compiler/linker options via standard CMake options/envs. I discovered these issues while enabling test runs on AppVeyor CI with all supported MSVC version in various configurations, and `-DCURL_STATIC_CRT=ON` set. Symptoms of double CRT: - `curl -V` output with newline missing between 'Protocols:' and 'Features:' lines, then runtests unable to detect feature and emitting a Perl warning for uninitialized `$feat` variable. (due to parallel output buffering for `puts()` and `curl_mprintf()`) This is visible in master builds, e.g.: CM VS2019, Debug, x64, OpenSSL 3.0 + Schannel, Shared, !verbose, Build-tests: ``` WARNING: this libcurl is Debug-enabled, do not use in production curl 8.23.0-DEV (Windows) libcurl/8.23.0-DEV OpenSSL/3.0.18 (Schannel) WinLDAP Release-Date: [unreleased] Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt mqtts pop3 pop3s rtsp smtp smtps telnet tftp ws wssFeatures: alt-svc AsynchDNS Debug HSTS HTTPS-proxy HTTPSIG IPv6 Kerberos Largefile MultiSSL SPNEGO SSL SSPI threadsafe UnixSockets ``` Ref: https://ci.appveyor.com/project/curlorg/curl/builds/54865570/job/urr2rgnr32hwllw2#L246 Notice the missing newline before `Features:`, and appearing above `WARNING:` instead. - test1622 failing. - 'Debug Assertion Failed! Expression: _acrt_first_block == header' crashed in both the app and the libcurl.dll it loaded. (possibly) Follow-up to 6140746 #16522 Follow-up to 049352d #16516 Follow-up to edfa537 #16456 #16394 Follow-up to 4fc6ebe #1621 Cherry-picked from #23306 Closes #23336
Static CRT crashes MSVCR* MSVC builds (in VS2008, VS2010, VS2012,
VS2013) according to CI and local tests. The reproducible crash happens
in
curl_mfprintf() → fputc(s, stderr)when trying to display thewarning message in
curl -V.stderris non-NULL and resolves to2.This reproducer needs a debug-enabled build, but it's unrelated to debug
features or curl's memory tracker. It happens regardless of unity build,
CPU architecture or
DllMain()use. Example from VS2013:Ref: https://ci.appveyor.com/project/curlorg/curl/builds/51570451/job/ojpdqrsm1hmpmq6a#L210
Another crash happened in an UCRT build (VS2017) with a couple of
printf()s added to curl'smain()function:(it hangs the job in CI due to the GUI popup)
Ref: #16394 (comment)
To avoid actual and potential issues, this patch issues a warning on
the shared-libcurl + static-CRT combination and falls back to the
default, shared CRT. IOW a static CRT build now requires a static curl
exe when using the
CURL_STATIC_CRT=ONoption.Follow-up to 4fc6ebe #1621
Cherry-picked from #16394 (with more details there)