Skip to content

cmake: allow CURL_STATIC_CRT with UCRT VS2015+ builds - #16522

Closed
vszakats wants to merge 10 commits into
curl:masterfrom
vszakats:cm-stacrt-3
Closed

vszakats wants to merge 10 commits into
curl:masterfrom
vszakats:cm-stacrt-3

Conversation

@vszakats

@vszakats vszakats commented Feb 28, 2025 •

Copy link
Copy Markdown
Member

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

@vszakats vszakats added cmake Windows Windows-specific labels Feb 28, 2025
@vszakats vszakats changed the title [TEST] cmake: further CURL_STATIC_CRT patch and test (UCRT) [TEST] cmake: CURL_STATIC_CRT patch and test (UCRT) Feb 28, 2025
@github-actions github-actions Bot added the CI Continuous Integration label Feb 28, 2025
@vszakats

vszakats commented Feb 28, 2025 •

Copy link
Copy Markdown
Member Author

The crasher printf() is before stderr init, I wonder if there is any way
that it touches stderr internally somehow anyway?

Here's the reproducer PR and CI VS2017 job:
#16522
https://ci.appveyor.com/project/curlorg/curl/builds/51605732/job/12n581uytend97mx
it's a hung job due to the GUI popup.

OK:

Hang:

So far it seems in crashes on these conditions:

It's very odd.

Seeing these it seems slighly more likely that curl's printf() might be touching stderr
in debug builds. Pure guessing based on the alignments above.

@vszakats vszakats changed the title [TEST] cmake: CURL_STATIC_CRT patch and test (UCRT) [TEST] cmake: CURL_STATIC_CRT with UCRT Feb 28, 2025
@github-actions github-actions Bot added the build label Feb 28, 2025
@vszakats vszakats changed the title [TEST] cmake: CURL_STATIC_CRT with UCRT cmake: allow CURL_STATIC_CRT with UCRT (VS2015+) builds Feb 28, 2025
@vszakats vszakats changed the title cmake: allow CURL_STATIC_CRT with UCRT (VS2015+) builds cmake: allow CURL_STATIC_CRT with UCRT (VS2015+) builds Feb 28, 2025
@vszakats vszakats changed the title cmake: allow CURL_STATIC_CRT with UCRT (VS2015+) builds cmake: allow CURL_STATIC_CRT with all UCRT (VS2015+) builds Feb 28, 2025
@vszakats vszakats changed the title cmake: allow CURL_STATIC_CRT with all UCRT (VS2015+) builds cmake: allow CURL_STATIC_CRT with UCRT VS2015+ builds Feb 28, 2025
@vszakats vszakats closed this in 6140746 Mar 4, 2025
@vszakats
vszakats deleted the cm-stacrt-3 branch March 4, 2025 00:03
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
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
vszakats added a commit that referenced this pull request Oct 16, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build CI Continuous Integration cmake cmdline tool Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant