-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmake: restrict static CRT builds to static curl exe, test in CI #16456
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 thewarning message in
curl -V
.stderr
is 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=ON
option.Follow-up to 4fc6ebe #1621
Cherry-picked from #16394 (with more details there)