Skip to content

cmake: pre-fill known type sizes for Windows + and more - #16394

Closed
vszakats wants to merge 176 commits into
curl:masterfrom
vszakats:cm-w-cache-sizes
Closed

vszakats wants to merge 176 commits into
curl:masterfrom
vszakats:cm-w-cache-sizes

Conversation

@vszakats
vszakats marked this pull request as draft February 19, 2025 12:28
@github-actions github-actions Bot added Windows Windows-specific CI Continuous Integration labels Feb 19, 2025
@vszakats
vszakats force-pushed the cm-w-cache-sizes branch 2 times, most recently from e587a28 to f957c00 Compare February 19, 2025 16:32
@vszakats vszakats changed the title add more dl-mingw jobs (temp) cmake: pre-fill known type sizes for Windows Feb 19, 2025
@vszakats
vszakats force-pushed the cm-w-cache-sizes branch 3 times, most recently from 4153957 to 29c5e58 Compare February 20, 2025 17:48
@vszakats

vszakats commented Feb 21, 2025 •

Copy link
Copy Markdown
Member Author

As a sub-project I tried figuring out why the VS2008 DEBUGBUILD was
segfaulting when running curl -V:

+ _bld/src/curl.exe --disable --version
./appveyor.sh: line 122:   288 Segmentation fault      "${curl}" --disable --version

https://ci.appveyor.com/project/curlorg/curl/builds/51556762/job/0ttg9j0r9xaa4k63#L219

It turns out it crashes in fputc() called with stderr from curl's
custom fprintf() replacement curl_mfprintf(). It may be caused
by building with CURL_STATIC_CRT=ON (but I cannot run the
thing without this due to missing MSVCR90*.DLL). I've found it
strange, that the built-in fprintf() doesn't have this problem,
when called after #undef fprintf. The stderr value is correct,
and fileno() returns 2.

Why only the debug build is affected? Because in debug builds,
-V starts with showing the special line WARNING: this libcurl is Debug-enabled, do not use in production, that's not present in
normal builds and that goes to stderr. Another strange thing that
non-Debug-enabled builds seem to print happily to stderr (though
not tested with this line specifically).

edit: Yep, it also happens in non-Debug-enabled builds, when the
-V message is shown from it.
So it really has nothing to do with Debug/non-Debug-enabled.
Question why fprintf() works and why stderr outputs later do
work.

@vszakats

vszakats commented Feb 21, 2025 •

Copy link
Copy Markdown
Member Author

A favourite kind of error message is "file not found" without telling the filename:

This time from the Windows OS (or Visual Studio CRT?, or the shell?):

C:/projects/curl/_bld/src/curl.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

https://ci.appveyor.com/project/curlorg/curl/builds/51558941/job/yk0k8nr0s7s851wo#L1140

@vszakats
vszakats force-pushed the cm-w-cache-sizes branch 2 times, most recently from dedcf12 to e40da25 Compare February 22, 2025 00:44
@vszakats

vszakats commented Feb 22, 2025 •

Copy link
Copy Markdown
Member Author

Phew... so linking against the shared CRT fixes the VS2008 crash issue.
Running such curl.exe has a strong retro feel, bringing back
all the unforgettable Windows vibes from the good old days. After finding
the location of the DLL via internet search thanks to a kind soul asking
a question about it in on Stackoverflow years ago, it was easy to find it
deep under a 100+ char long path, complete with spaces, parents,
camel-casing, and all. Copying that in place was a snap. Then, when
running curl.exe, the mysterious terminal error turned into an invisible
GUI popup that hung the CI machine, forever. Picking all the pieces via
CI artifacts for a local run, revealed it's an error about a missing manifest,
with buttons to cancel, retry and continue, with all options failing, the
best one crashing after another popup. Without the manifest it refuses
to load the CRT DLL in the very same directory. This is Microsoft's answer
to the "DLL hell". By trial and error the missing manifest is curl.exe.manifest.
Such file isn't generated, but copying one of the two, auto-generated
libcurl manifests, with slightly different XML formatting, to this filename, and
bang, curl.exe runs flawlessly. It's also the debug version. (The release CRT
DLL is yet to found somewhere else.)

https://ci.appveyor.com/project/curlorg/curl/builds/51564024/job/7o4swgfcrvvd099h/artifacts

So, fputc(x, stderr) in the static CRT that's affected. With the exact
reason and a fix still unknown.

edit: Blindly speculating, the missing curl.exe.manifest may be caused
by curl.rc featuring a built-in manifest, which might suppress the toolchain's
automatism to create an external one, that's supposed to hold this entry:

  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>

If that's the case I'm not sure how to fix this cleanly.

updates:

  • Manifest issue: There are two issues, one is that CMake doesn't pass -DCURL_EMBED_MANIFEST to rc.exe with the VS2008 generator. The other is that we pass -MANIFEST:NO to avoid MSVC overwriting curl's custom embedded manifest. It makes curl.exe ending up with a manifest that misses both our custom stuff (for correct version detection) and the MSVC auto-generated stuff necessary to find MSVCR90*.DLL. I fixed it by allowing the auto-generated manifest. This is not perfect because the custom manifest is then ignored. Later VS versions don't seem to need this workaround, and/or they somehow fix it up automatically.

update: With -DCURL_EMBED_MANIFEST passed to rc.exe (via set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "CURL_EMBED_MANIFEST")), and -MANIFEST:NO omitted, in some cases the manifests appeared merged in the executable, but something might be wrong, because the sxs part isn't picked up by the OS. Possibly because of colliding internal manifest IDs? VS2008 doesn't support -MANIFEST:EMBED,ID=<x> to set this for the auto-generated sxs manifest.

  • Static CRT crash issue: Turns out that shared curl.exe builds are affected with VS2008, VS2010, VS2012, VS2013 where the static CRT (MSVCR*) ends up not initialized (up to certain point?) causing a crash while writing to stderr early in the code. I don't know how to fix it, so went with a workaround of disallowing static CRT for the affected combinations. VS2015 and newer use UCRT and they do work fine. It happens regardless of Unity mode and affects both x86 and x64.

@vszakats
vszakats force-pushed the cm-w-cache-sizes branch 2 times, most recently from ff0ab3c to c8e9c5f Compare February 23, 2025 01:03
@jay

jay commented Feb 23, 2025 •

Copy link
Copy Markdown
Member

updates:

Manifest issue: There are two issues, one is that CMake doesn't pass -DCURL_EMBED_MANIFEST to rc.exe with the VS2008 generator. The other is that we pass -MANIFEST:NO to avoid MSVC overwriting the custom embedded manifest. It makes curl.exe ending up with a manifest that misses both our custom stuff (for correct version detection) and the auto-generated stuff necessary to find MSVCR90*.DLL. I fixed by allowing the auto-generated manifest. Later VS versions don't seem to need this, or they somehow fix it up automatically.

Static CRT crash issue: Turns out that shared curl.exe builds were affected with VS2008, VS2010, VS2012, VS2013 where the static CRT (MSVCR*) ends up not initialized (up to certain point?) causing a crash while writing to stderr early in the code. I don't know how to fix it, so went with a workaround of disallowing static CRT for the affected combinations. VS2015 and newer use UCRT and they do work fine.

I have Visual Studio 2008 SP1 and cmake 3.18.1 installed on a Windows 7 machine.The reason MSVCR was "missing" is because Visual Studio 2008 uses Microsoft's side-by-side versioning and later Visual Studio versions don't. Without the manifest (ie -MANIFEST:NO is used) it doesn't know where to find MSVCR90.dll since it's not in C:\Windows\System32 (or SysWow64) but instead is in a side by side directory like C:\windows\winsxs\x86_microsoft.vc90.crt_<somehash>

dir /b C:\windows\winsxs\x86_microsoft.vc90.crt_*
x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91
x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_e163563597edeada
x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2
x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_50916076bcb9a742
x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4974_none_50940634bcb759cb
x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57

dir /b C:\windows\winsxs\x86_microsoft.vc90.debugcrt_*
x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2
x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb
x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_2a4cbfc25558bcd3
x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_2a4f639a55563668

I made only one change off of master ea07a64 to comment out the manifest removal and I was able to build curl with Visual Studio 2008 and cmake:

cmake ..\..\curl -A Win32 -G "Visual Studio 9 2008" -DBUILD_STATIC_CURL=ON -DENABLE_DEBUG=ON -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_SCHANNEL=ON -DCURL_ZLIB=OFF -DCURL_USE_LIBPSL=OFF -DBUILD_LIBCURL_DOCS=OFF -DBUILD_MISC_DOCS=OFF -DENABLE_CURL_MANUAL=OFF -DCMAKE_INSTALL_PREFIX:PATH=X:\j\curl\cmake\curl-root-x86
cmake --build . --target INSTALL --config Release

It doesn't crash when I run it. This is in Windows 7 though. I remember at some point I had made some change to stderr to reroute it, so that --stderr would catch more stuff. That could have something to do with it. If there is anything else you want me to try let me know.

(edit: I've since tried --config Debug as well).

Also, have you ever tried CI jobs interactively like is it possible to remote desktop in and experiment that way?

@vszakats

Copy link
Copy Markdown
Member Author

Thanks Jay. I figured the manifest thing out with some sweat and tears. Do you know a way to include our custom embedded manifest and also the auto-generated, sxs, one at the same time? (Out of curiosity, it's very niche and nobody ever reported it so not critical.)

As for the crash it's a different issue, see my latest edits to the original message. It's happening with MSVCR* when linking curl with libcurl.dll and using CURL_STATIC_CRT=ON. (It's fine with UCRT)

I used the interactive access in the past with curl-for-win, would have been handy now in retrospect, but slipped out of my mind. (Also contributed a security patch to it back then)

@jay

jay commented Feb 23, 2025

Copy link
Copy Markdown
Member

I added -DCURL_STATIC_CRT=ON to the cmake command but I still can't reproduce.

Thanks Jay. I figured the manifest thing out with some sweat and tears. Do you know a way to include our custom embedded manifest and also the auto-generated, sxs, one at the same time? (Out of curiosity, it's very niche and nobody ever reported it so not critical.)

In some Visual Studio versions it's possible to use multiple manifests as long as the manifest is set to embed. In that case Visual Studio will merge the manifests. It may be possible by specifying the additional manifest file to embed unless Visual Studio 2008 doesn't support that.

@vszakats

vszakats commented Feb 23, 2025 •

Copy link
Copy Markdown
Member Author

I added -DCURL_STATIC_CRT=ON to the cmake command but I still can't reproduce.

Have you tried with debug-enabled?:
-DCURL_STATIC_CRT=ON -DENABLE_DEBUG=ON
then running curl -V?

Release/Debug mode doesn't affect this, neither does Unity mode, according to CI tests.
ENABLE_DEBUG=ON triggers it via the extra -V message telling "WARNING: this libcurl
is debug-enabled [...]" and putting it to stderr. It crashes there in fputs().

In some Visual Studio versions it's possible to use multiple manifests as long as the manifest is set to embed. In that case Visual Studio will merge the manifests. It may be possible by specifying the additional manifest file to embed unless Visual Studio 2008 doesn't support that.

This would need to maintain a separate copy of our custom manifest just for VS2008.
After some tests I have doubts multiple manifests can be done: I managed to have both
manifests included by changing the manifest ID of the custom one, but it seems that the
manifest ID has to be 1 for the supportedOS entries be picked up by ths OS. The
other option is to tell VS2008 to use an alternate ID for the sxs manifest, which can be
done in theory using -MANIFEST:EMBED,ID=<n>. But VS2008 doesn't support this
option, I tried it earlier.

But, but, supportedOS in the custom manifest is only required for recent curl when
targeting Windows NT (for GetVersionEx()). Do we support that OS at all? Isn't the
lower limit Windows XP?:

curl/lib/version_win32.c

Lines 116 to 124 in 4c50998

#elif !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_WIN2K) || \
(_WIN32_WINNT < _WIN32_WINNT_WIN2K)
OSVERSIONINFO osver;
memset(&osver, 0, sizeof(osver));
osver.dwOSVersionInfoSize = sizeof(osver);
/* Find out Windows version */
if(GetVersionEx(&osver)) {

curl/docs/INSTALL.md

Lines 179 to 181 in e1b3d46

# Windows
Building for Windows XP is required as a minimum.

Unless I'm missing other reasons, the curl exe custom manifest seems safe to delete, along
with the GetVersionEx() branch in curlx_verify_windows_version().

@vszakats
vszakats force-pushed the cm-w-cache-sizes branch 3 times, most recently from 91ff123 to 82c9a55 Compare February 23, 2025 21:28
@github-actions github-actions Bot added the tests label Feb 23, 2025
@vszakats

vszakats commented Feb 23, 2025 •

Copy link
Copy Markdown
Member Author

After more tests I'm convinced that static CRT isn't meant for a shared
curl exe. I could trigger an assert inside UCRT by adding a printf() call
to main():
CMake, VS2017, Debug, x64, OpenSSL 1.1.1, Shared, Build-only:
CMake, VS2017, Debug, x64, OpenSSL 1 1 1, Shared, Build-only copy
https://ci.appveyor.com/project/curlorg/curl/builds/51570342/job/ki79tf27jkwh765t#L221

Reverse this to repreduce: d5e55fb

Which makes sense when we consider shared builds having two static CRTs
linked to libcurl and curl exe respectively.

Option added in #1621, and I don't think this was ever considered then
or since.

I'll fix by limiting this option to static curl exe builds. Which is the same
as the fix so far, but making it apply to all VS versions, not just MSVCR*
ones.

vszakats added a commit that referenced this pull request Feb 24, 2025
vszakats added a commit that referenced this pull request Feb 24, 2025
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: #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)

Closes #16456
vszakats added a commit that referenced this pull request Feb 24, 2025
vszakats added a commit that referenced this pull request Feb 24, 2025
- 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
@vszakats vszakats changed the title cmake: pre-fill known type sizes for Windows cmake: pre-fill known type sizes for Windows + and more Feb 24, 2025
vszakats added a commit to vszakats/curl that referenced this pull request Feb 24, 2025
To save configuration time. After this patch, on Windows there remains
3 size detections. Those depend on 32/64-bitness and on other things
for `time_t`.

Cherry-picked from curl#16394
@vszakats

Copy link
Copy Markdown
Member Author

Closing in favour of the PRs this got split into.

@vszakats vszakats closed this Feb 24, 2025
@vszakats
vszakats deleted the cm-w-cache-sizes branch February 24, 2025 23:21
icing pushed a commit to icing/curl that referenced this pull request Feb 25, 2025
Support multi-target cmake builds via `CURL_DIRSUFFIX` env. For example:
`export CURL_DIRSUFFIX=Debug/`.

Multi-target generators place their output to `src/<subdir>/`,
`lib/<subdir>/`, `tests/server/<subdir>`, `tests/libtest/<subdir>` and
`tests/unit/<subdir>/` by default. Before this patch, `runtests.pl`
couldn't run on such builds because it expected the binaries under the
their `<subdir>`-less directories. This patch allows to set such subdir
and make `runtests.pl` find the binaries. In CI we use multi-target
builds with tests for MSVC. It also helps Xcode-generator builds, though
in CI we don't have such job running tests.

There may be better solutions to configure this, but passing a custom
value to `runtests.pl` including its subprocesses is somewhat tricky.
The reason the configuration value expects the slash at the end is
because MSYS is automagically expanding the env to a (wrong) absolute
path if the slash is in the front.

Also:
- drop the `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_*=` workaround from CI.
- replace `resolve` references in tests with a new `%RESOLVE` variable.
  It didn't use a filename extension before. After this patch it uses
  `exe_ext('TOOL')`. I'm not sure if this is the correct choice vs.
  `exe_ext('SRV')`.
- fix `-c` option format in manual.
- fix some whitespace.

Note, in CI we still tweak `CMAKE_RUNTIME_OUTPUT_DIRECTORY_*` in jobs
which share steps between `./configure` and cmake. It's easier that way.

Ref: curl#15000
Cherry-picked from curl#16394

Closes curl#16452
icing pushed a commit to icing/curl that referenced this pull request Feb 25, 2025
curl requires Windows XP since 2023. Drop version detection code using
`GetVersionEx()` aimed to support earlier Windows versions. With that
call deleted, the embedded manifest in `curl.rc` becomes unnecessary.
Delete it too, along with the enabler logic in build systems.

This allows to stop forcing `/MANIFEST:NO` for MSVC builds. Dropping it
fixes VS2008 shared builds, that require an auto-generated SxS
(side-by-side assembly) manifest to find their CRT DLLs. This was the
issue that prevented VS2008 `curl.exe` launching on AppVeyor CI:
```
src/curl.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
```
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/51577006/job/eitypvwlb1rxr11d#L261

FWIW the `curl.rc` embedded manifest wasn't ever enabled for VS2008 CI
builds either, because CMake did not pass our custom macro via
`CMAKE_RC_FLAGS` to `rc.exe`. For reasons I could not figure out.

After this patch the curl build no longer inject its own manifest, and
lets the default be applied by linkers and toolchains. It fixes VS2008
shared builds. curl continues to detect the real Windows version via
`RtlVerifyVersionInfo()` from `ntdll`.

Follow-up to 960d601 curl#12225
Follow-up to 5044909 curl#7810
Follow-up to ebd2132 curl#1221
Ref: curl#15972
Cherry-picked from curl#16394

Closes curl#16453
icing pushed a commit to icing/curl that referenced this pull request Feb 25, 2025
icing pushed a commit to icing/curl that referenced this pull request Feb 25, 2025
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
icing pushed a commit to icing/curl that referenced this pull request Feb 25, 2025
icing pushed a commit to icing/curl that referenced this pull request Feb 25, 2025
- 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
vszakats added a commit that referenced this pull request Feb 25, 2025
To save configuration time.

After this patch, for mingw-w64 and MSVC curl's CMake builds pre-fill
almost all type sizes without auto-detection. In most cases this leaves
3 type size auto-detections. Those depend on 64/32-bitness, and `time_t`
also depends on CRT and custom options. Old mingw-w64 versions require
some extra detections. We recommend v3.0 or newer to avoid them.

For Windows CE, this patch pre-fills all type sizes.

If this is causing any issue, please report it and disable pre-filling
with `-D_CURL_PREFILL=OFF` in the meantime.

Cherry-picked from #16394
Closes #16464
vszakats added a commit that referenced this pull request Mar 4, 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 #16516
Follow-up to edfa537 #16456
Ref: #16394
Closes #16522
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
Support multi-target cmake builds via `CURL_DIRSUFFIX` env. For example:
`export CURL_DIRSUFFIX=Debug/`.

Multi-target generators place their output to `src/<subdir>/`,
`lib/<subdir>/`, `tests/server/<subdir>`, `tests/libtest/<subdir>` and
`tests/unit/<subdir>/` by default. Before this patch, `runtests.pl`
couldn't run on such builds because it expected the binaries under the
their `<subdir>`-less directories. This patch allows to set such subdir
and make `runtests.pl` find the binaries. In CI we use multi-target
builds with tests for MSVC. It also helps Xcode-generator builds, though
in CI we don't have such job running tests.

There may be better solutions to configure this, but passing a custom
value to `runtests.pl` including its subprocesses is somewhat tricky.
The reason the configuration value expects the slash at the end is
because MSYS is automagically expanding the env to a (wrong) absolute
path if the slash is in the front.

Also:
- drop the `-DCMAKE_RUNTIME_OUTPUT_DIRECTORY_*=` workaround from CI.
- replace `resolve` references in tests with a new `%RESOLVE` variable.
  It didn't use a filename extension before. After this patch it uses
  `exe_ext('TOOL')`. I'm not sure if this is the correct choice vs.
  `exe_ext('SRV')`.
- fix `-c` option format in manual.
- fix some whitespace.

Note, in CI we still tweak `CMAKE_RUNTIME_OUTPUT_DIRECTORY_*` in jobs
which share steps between `./configure` and cmake. It's easier that way.

Ref: curl#15000
Cherry-picked from curl#16394

Closes curl#16452
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
curl requires Windows XP since 2023. Drop version detection code using
`GetVersionEx()` aimed to support earlier Windows versions. With that
call deleted, the embedded manifest in `curl.rc` becomes unnecessary.
Delete it too, along with the enabler logic in build systems.

This allows to stop forcing `/MANIFEST:NO` for MSVC builds. Dropping it
fixes VS2008 shared builds, that require an auto-generated SxS
(side-by-side assembly) manifest to find their CRT DLLs. This was the
issue that prevented VS2008 `curl.exe` launching on AppVeyor CI:
```
src/curl.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
```
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/51577006/job/eitypvwlb1rxr11d#L261

FWIW the `curl.rc` embedded manifest wasn't ever enabled for VS2008 CI
builds either, because CMake did not pass our custom macro via
`CMAKE_RC_FLAGS` to `rc.exe`. For reasons I could not figure out.

After this patch the curl build no longer inject its own manifest, and
lets the default be applied by linkers and toolchains. It fixes VS2008
shared builds. curl continues to detect the real Windows version via
`RtlVerifyVersionInfo()` from `ntdll`.

Follow-up to 960d601 curl#12225
Follow-up to 5044909 curl#7810
Follow-up to ebd2132 curl#1221
Ref: curl#15972
Cherry-picked from curl#16394

Closes curl#16453
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
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
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
- 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
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
To save configuration time.

After this patch, for mingw-w64 and MSVC curl's CMake builds pre-fill
almost all type sizes without auto-detection. In most cases this leaves
3 type size auto-detections. Those depend on 64/32-bitness, and `time_t`
also depends on CRT and custom options. Old mingw-w64 versions require
some extra detections. We recommend v3.0 or newer to avoid them.

For Windows CE, this patch pre-fills all type sizes.

If this is causing any issue, please report it and disable pre-filling
with `-D_CURL_PREFILL=OFF` in the meantime.

Cherry-picked from curl#16394
Closes curl#16464
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

Development

Successfully merging this pull request may close these issues.

2 participants