]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: fix unity with Windows Unicode + TrackMemory
authorViktor Szakats <commit@vsz.me>
Tue, 3 Oct 2023 02:27:05 +0000 (02:27 +0000)
committerViktor Szakats <commit@vsz.me>
Tue, 3 Oct 2023 09:43:46 +0000 (09:43 +0000)
Found the root cause of the startup crash in unity builds with Unicode
and TrackMemory enabled at the same time.

We must make sure that the `memdebug.h` header doesn't apply to
`lib/curl_multibyte.c` (as even noted in a comment there.) In unity
builds all headers apply to all sources, including `curl_multibyte.c`.
This probably resulted in an infinite loop on startup.

Exclude this source from unity compilation with TrackMemory enabled,
in both libcurl and curl tool. Enable unity mode for a debug Unicode
CI job to keep it tested. Also delete the earlier workaround that
fully disabled unity for affected builds.

Follow-up to d82b080f6374433ce7c98241329189ad2d3976f8 #12005
Follow-up to 3f8fc25720900b14b7432f4bd93407ca15311719 #11095

Closes #11928

CMakeLists.txt
appveyor.yml
lib/CMakeLists.txt
src/CMakeLists.txt

index e6d0e5190e84f670e7fe411b3d58456251f3c3db..f1de3843a0247b5248ca68388ad196d59b0fe6a5 100644 (file)
@@ -144,16 +144,6 @@ if(ENABLE_CURLDEBUG)
   set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
 endif()
 
-# This combination results in curl tool crashing on startup when run on native
-# Windows (it was seen to work when run under WINE though). We disable UNITY
-# mode as a workaround.
-if(ENABLE_UNICODE AND ENABLE_CURLDEBUG)
-  set(CMAKE_UNITY_BUILD OFF)
-  message(WARNING "Unity builds are not supported with Windows Unicode and "
-    "TrackMemory (-DCURLDEBUG) enabled at the same time. Unity mode has been "
-    "disabled.")
-endif()
-
 # For debug libs and exes, add "-d" postfix
 if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
   set(CMAKE_DEBUG_POSTFIX "-d")
index 70da472ded0fb4a2c551f4b23a4dde5c355358f8..7d0be9bcc21502c24e6f4dcc24cec712df6f4851 100644 (file)
@@ -121,7 +121,7 @@ environment:
       DISABLED_TESTS: '!1139 !1501'
       ADD_PATH: 'C:\msys64\usr\bin'
     # generated CMake-based MSYS Makefiles builds (mingw cross-compiling)
-    - job_name: 'CMake, mingw-w64, gcc 8, Debug x64, Schannel, Static, Unicode'
+    - job_name: 'CMake, mingw-w64, gcc 8, Debug x64, Schannel, Static, Unicode, Unity'
       APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2015'
       BUILD_SYSTEM: CMake
       PRJ_GEN: 'MSYS Makefiles'
@@ -134,6 +134,7 @@ environment:
       ADD_PATH: 'C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;C:\msys64\usr\bin'
       MSYS2_ARG_CONV_EXCL: '/*'
       BUILD_OPT: -k
+      UNITY: 'ON'
     - job_name: 'CMake, mingw-w64, gcc 7, Debug x64, Schannel, Static, Unicode'
       APPVEYOR_BUILD_WORKER_IMAGE: 'Visual Studio 2017'
       BUILD_SYSTEM: CMake
index 83c0a53f286b079bd3c9d373066e2ffdee2e33b9..6f849199cba78423da9342ff2f5e7b4a188bbfff 100644 (file)
@@ -56,9 +56,9 @@ add_library(
 target_compile_definitions(curlu PUBLIC UNITTESTS CURL_STATICLIB)
 
 if(ENABLE_CURLDEBUG)
-  # We must compile memdebug.c separately to avoid memdebug.h redefinitions
-  # being applied to memdebug.c itself.
-  set_source_files_properties(memdebug.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
+  # We must compile these sources separately to avoid memdebug.h redefinitions
+  # applying to them.
+  set_source_files_properties(memdebug.c curl_multibyte.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
 endif()
 target_link_libraries(curlu PRIVATE ${CURL_LIBS})
 
index 3d6334b2cfa3bccbd97127777bdee52dabde4a5d..f6517c703633f9b62d9c1c284a6ba37563df223c 100644 (file)
@@ -67,6 +67,12 @@ if(BUILD_STATIC_CURL)
   set(CURLX_CFILES ${CURLTOOL_LIBCURL_CFILES})
 endif()
 
+if(ENABLE_CURLDEBUG)
+  # We must compile this source separately to avoid memdebug.h redefinitions
+  # applying to them.
+  set_source_files_properties(../lib/curl_multibyte.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
+endif()
+
 add_executable(
   ${EXE_NAME}
   ${CURL_CFILES} ${CURLX_CFILES} ${CURL_HFILES}