From cd663cf29fab90c9b89d9f0a493db2f7eb23451f Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Fri, 18 Jul 2025 10:41:42 +0200 Subject: [PATCH 1/6] [win] Fix build and tests with winrtdebug=ON - Add the -RTC1 (runtime check) compiler flag with winrtdebug=ON and dev=ON - Add the -D_ITERATOR_DEBUG_LEVEL=0 flag where needed, to work-around the issue with STL iterators and I/O. This produce incompatible debug binaries, but allows to debug ROOT - Add the LLVM_ENABLE_DUMP=TRUE option when LLVM_BUILD_TYPE is Debug or RelWithDebInfo - Fix gtest-tree-ntuple-ntuple-packing, which was failing for one bit difference --- cmake/modules/SetUpWindows.cmake | 7 +++++-- cmake/scripts/compiledata.win32.in | 4 ++-- core/base/src/TSystem.cxx | 11 ++++++++++- core/dictgen/src/rootcling_impl.cxx | 4 ++++ graf2d/win32gdk/gdk/src/glib/gmessages.c | 3 ++- interpreter/CMakeLists.txt | 2 ++ interpreter/cling/lib/Interpreter/CIFactory.cpp | 3 +++ io/io/src/TFile.cxx | 5 +++++ tree/ntuple/src/RColumnElement.hxx | 2 +- 9 files changed, 34 insertions(+), 7 deletions(-) diff --git a/cmake/modules/SetUpWindows.cmake b/cmake/modules/SetUpWindows.cmake index 09879e526b2af..a2ddaa23f49cf 100644 --- a/cmake/modules/SetUpWindows.cmake +++ b/cmake/modules/SetUpWindows.cmake @@ -31,14 +31,17 @@ elseif(MSVC) math(EXPR VC_MINOR "${MSVC_VERSION} % 100") #---Select compiler flags---------------------------------------------------------------- + if(winrtdebug AND dev) + set(ROOT_RTC_FLAGS "-RTC1") + endif() set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-MD -O2 -Ob2 -Z7 -DNDEBUG") set(CMAKE_CXX_FLAGS_MINSIZEREL "-MD -O1 -Ob1 -DNDEBUG") set(CMAKE_CXX_FLAGS_RELEASE "-MD -O2 -Ob2 -DNDEBUG") - set(CMAKE_CXX_FLAGS_DEBUG "-MDd -Od -Ob0 -Z7") + set(CMAKE_CXX_FLAGS_DEBUG "-MDd -Od -Ob0 -Z7 ${ROOT_RTC_FLAGS}") set(CMAKE_C_FLAGS_RELWITHDEBINFO "-MD -O2 -Ob2 -Z7 -DNDEBUG") set(CMAKE_C_FLAGS_MINSIZEREL "-MD -O1 -Ob1 -DNDEBUG") set(CMAKE_C_FLAGS_RELEASE "-MD -O2 -Ob2 -DNDEBUG") - set(CMAKE_C_FLAGS_DEBUG "-MDd -Od -Ob0 -Z7") + set(CMAKE_C_FLAGS_DEBUG "-MDd -Od -Ob0 -Z7 ${ROOT_RTC_FLAGS}") if(winrtdebug) if (CMAKE_SIZEOF_VOID_P EQUAL 8) diff --git a/cmake/scripts/compiledata.win32.in b/cmake/scripts/compiledata.win32.in index cff8d4d3558f5..2f64008f983ed 100644 --- a/cmake/scripts/compiledata.win32.in +++ b/cmake/scripts/compiledata.win32.in @@ -7,8 +7,8 @@ #define COMPILERVERSSTR "@CMAKE_CXX_COMPILER_ID@ @CMAKE_CXX_COMPILER_VERSION@" #define MAKESHAREDLIB "cl $Opt -nologo -TP -c @CMAKE_CXX_FLAGS@ @BLDCXXFLAGS@ $IncludePath $SourceFiles -Fo$ObjectFiles && bindexplib $LibName $ObjectFiles > $BuildDir\\$LibName.def && lib -nologo -MACHINE:@MACHINE_ARCH@ -out:$BuildDir\\$LibName.lib $ObjectFiles -def:$BuildDir\\$LibName.def && link -nologo $ObjectFiles -DLL -out:$BuildDir\\$LibName.dll $BuildDir\\$LibName.exp -LIBPATH:%ROOTSYS%\\lib $LinkedLibs libCore.lib kernel32.lib advapi32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib && if EXIST \"$BuildDir\\$LibName.dll.manifest\" ( mt -nologo -manifest \"$BuildDir\\$LibName.dll.manifest\" \"-outputresource:$BuildDir\\$LibName.dll;2\" && del \"$BuildDir\\$LibName.dll.manifest\" )" #define MAKEEXE "cl -nologo -TP -Iinclude -I..\\include -c $Opt @CMAKE_CXX_FLAGS@ @BLDCXXFLAGS@ $IncludePath $SourceFiles && link -opt:ref @CMAKE_EXE_FLAGS@ $ObjectFiles $LinkedLibs advapi32.lib -out:$ExeName && if EXIST \"$ExeName.exe.manifest\" ( mt -nologo -manifest \"$ExeName.exe.manifest\" \"-outputresource:$ExeName.exe;1\" && del \"$ExeName.exe.manifest\" )" -#define CXXOPT "@CMAKE_CXX_FLAGS_RELEASE@" -#define CXXDEBUG "@CMAKE_CXX_FLAGS_DEBUG@" +#define CXXOPT "@CMAKE_CXX_FLAGS_RELEASE@ @BLDCXXFLAGS@" +#define CXXDEBUG "@CMAKE_CXX_FLAGS_DEBUG@ @BLDCXXFLAGS@" #define ROOTBUILD "release" #define LINKEDLIBS "-LIBPATH:%ROOTSYS%\\lib libCore.lib " #define INCLUDEPATH "-I%ROOTSYS%\\include" diff --git a/core/base/src/TSystem.cxx b/core/base/src/TSystem.cxx index a02fba94e1c5b..611ba99477e53 100644 --- a/core/base/src/TSystem.cxx +++ b/core/base/src/TSystem.cxx @@ -2885,6 +2885,12 @@ int TSystem::CompileMacro(const char *filename, Option_t *opt, mode = kDebug; } } +#if defined(_MSC_VER) && defined(_DEBUG) + // if ROOT is build in debug mode, ACLiC must also build in debug mode + // for compatibility reasons + if (!(mode & kDebug)) + mode |= kDebug; +#endif UInt_t verboseLevel = verbose ? 7 : gDebug; Bool_t flatBuildDir = (fAclicProperties & kFlatBuildDir) || (opt && strchr(opt,'-')!=nullptr); @@ -3729,12 +3735,15 @@ int TSystem::CompileMacro(const char *filename, Option_t *opt, TString optdebFlags; if (mode & kDebug) optdebFlags = fFlagsDebug + " "; - if (mode & kOpt) + else if (mode & kOpt) optdebFlags += fFlagsOpt; cmd.ReplaceAll("$Opt", optdebFlags); #ifdef WIN32 R__FixLink(cmd); cmd.ReplaceAll("-std=", "-std:"); + if (mode & kDebug) { + cmd.ReplaceAll(" && link ", "&& link /DEBUG "); + } #endif TString testcmd = fMakeExe; diff --git a/core/dictgen/src/rootcling_impl.cxx b/core/dictgen/src/rootcling_impl.cxx index e6e56da005292..32faf06421946 100644 --- a/core/dictgen/src/rootcling_impl.cxx +++ b/core/dictgen/src/rootcling_impl.cxx @@ -2135,6 +2135,10 @@ void AddPlatformDefines(std::vector &clingArgs) clingArgs.push_back(platformDefines); snprintf(platformDefines, 64, "-DG__VISUAL=%ld", (long)_MSC_VER); clingArgs.push_back(platformDefines); +#if defined(_WIN64) && defined(_DEBUG) + snprintf(platformDefines, 64, "-D_ITERATOR_DEBUG_LEVEL=0"); + clingArgs.push_back(platformDefines); +#endif #endif } diff --git a/graf2d/win32gdk/gdk/src/glib/gmessages.c b/graf2d/win32gdk/gdk/src/glib/gmessages.c index ac1fef072dc15..c915f4e8fbd13 100644 --- a/graf2d/win32gdk/gdk/src/glib/gmessages.c +++ b/graf2d/win32gdk/gdk/src/glib/gmessages.c @@ -544,7 +544,8 @@ g_logv (const gchar *log_domain, #endif # if defined (_MSC_VER) && defined (_DEBUG) /* let's see the call stack ... */ - __asm int 3 + /* __asm int 3 */ + __debugbreak(); # endif abort (); #endif /* !G_ENABLE_DEBUG || !SIGTRAP */ diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 7131b1453dcf8..4b12f03f78ece 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -176,8 +176,10 @@ if(builtin_llvm) if(CMAKE_BUILD_TYPE MATCHES "Debug" OR LLVM_BUILD_TYPE MATCHES "(Debug|RelWithDebInfo)") set(LLVM_ENABLE_ASSERTIONS TRUE) + set(LLVM_ENABLE_DUMP TRUE) else() set(LLVM_ENABLE_ASSERTIONS FALSE) + set(LLVM_ENABLE_DUMP FALSE) endif() endif() diff --git a/interpreter/cling/lib/Interpreter/CIFactory.cpp b/interpreter/cling/lib/Interpreter/CIFactory.cpp index 3d7fcf58231bf..594df5b62243e 100644 --- a/interpreter/cling/lib/Interpreter/CIFactory.cpp +++ b/interpreter/cling/lib/Interpreter/CIFactory.cpp @@ -849,6 +849,9 @@ namespace { PPOpts.addMacroDef("__CLING__GNUC_MINOR__=" ClingStringify(__GNUC_MINOR__)); #elif defined(_MSC_VER) PPOpts.addMacroDef("__CLING__MSVC__=" ClingStringify(_MSC_VER)); +#if defined(_WIN64) && defined(_DEBUG) + PPOpts.addMacroDef("_ITERATOR_DEBUG_LEVEL=0"); +#endif #endif // https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx index 4565fa1f45019..a4162bffbe56c 100644 --- a/io/io/src/TFile.cxx +++ b/io/io/src/TFile.cxx @@ -3222,6 +3222,11 @@ void TFile::MakeProject(const char *dirname, const char * /*classes*/, } else { sOpt = gSystem->GetFlagsDebug(); } +#if defined(_MSC_VER) && defined(_DEBUG) + // if ROOT is build in debug mode, ACLiC must also build in debug mode + // for compatibility reasons + sOpt = gSystem->GetFlagsDebug(); +#endif cmd.ReplaceAll("$Opt", sOpt); if (genreflex) { diff --git a/tree/ntuple/src/RColumnElement.hxx b/tree/ntuple/src/RColumnElement.hxx index c7a008a9c213f..2e8f680274d2a 100644 --- a/tree/ntuple/src/RColumnElement.hxx +++ b/tree/ntuple/src/RColumnElement.hxx @@ -993,7 +993,7 @@ using Quantized_t = std::uint32_t; #ifdef _MSC_VER unsigned long idx = 0; if (_BitScanReverse(&idx, x)) - return static_cast(31 - idx); + return static_cast(32 - idx); return 32; #else return static_cast(__builtin_clzl(x)); From 4f4d7a2266ce91c01772b1d12277751ea77bc3c4 Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Fri, 18 Jul 2025 11:35:47 +0200 Subject: [PATCH 2/6] Update interpreter/CMakeLists.txt Co-authored-by: Vassil Vassilev --- interpreter/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 4b12f03f78ece..44f96872fefe5 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -176,7 +176,8 @@ if(builtin_llvm) if(CMAKE_BUILD_TYPE MATCHES "Debug" OR LLVM_BUILD_TYPE MATCHES "(Debug|RelWithDebInfo)") set(LLVM_ENABLE_ASSERTIONS TRUE) - set(LLVM_ENABLE_DUMP TRUE) + if(NOT DEFINED LLVM_ENABLE_DUMP) + set(LLVM_ENABLE_DUMP TRUE) else() set(LLVM_ENABLE_ASSERTIONS FALSE) set(LLVM_ENABLE_DUMP FALSE) From 5a17bb5357f6602109b649272b426b8b5b92d037 Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Fri, 18 Jul 2025 11:40:07 +0200 Subject: [PATCH 3/6] Update interpreter/CMakeLists.txt --- interpreter/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 44f96872fefe5..59edaca886021 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -178,6 +178,7 @@ if(builtin_llvm) set(LLVM_ENABLE_ASSERTIONS TRUE) if(NOT DEFINED LLVM_ENABLE_DUMP) set(LLVM_ENABLE_DUMP TRUE) + endif() else() set(LLVM_ENABLE_ASSERTIONS FALSE) set(LLVM_ENABLE_DUMP FALSE) From b58e159cf2f5767e1da89b64862b81c47f6527ef Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Fri, 18 Jul 2025 11:41:06 +0200 Subject: [PATCH 4/6] Update interpreter/CMakeLists.txt --- interpreter/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interpreter/CMakeLists.txt b/interpreter/CMakeLists.txt index 59edaca886021..dbcdf669b9d3f 100644 --- a/interpreter/CMakeLists.txt +++ b/interpreter/CMakeLists.txt @@ -176,9 +176,9 @@ if(builtin_llvm) if(CMAKE_BUILD_TYPE MATCHES "Debug" OR LLVM_BUILD_TYPE MATCHES "(Debug|RelWithDebInfo)") set(LLVM_ENABLE_ASSERTIONS TRUE) - if(NOT DEFINED LLVM_ENABLE_DUMP) - set(LLVM_ENABLE_DUMP TRUE) - endif() + if(NOT DEFINED LLVM_ENABLE_DUMP) + set(LLVM_ENABLE_DUMP TRUE) + endif() else() set(LLVM_ENABLE_ASSERTIONS FALSE) set(LLVM_ENABLE_DUMP FALSE) From 0de1fcb1a1e0409a76fe180ea0aff00ab736cdd2 Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Fri, 18 Jul 2025 16:19:45 +0200 Subject: [PATCH 5/6] Revert changes in tree/ntuple/src/RColumnElement.hxx --- tree/ntuple/src/RColumnElement.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tree/ntuple/src/RColumnElement.hxx b/tree/ntuple/src/RColumnElement.hxx index 2e8f680274d2a..c7a008a9c213f 100644 --- a/tree/ntuple/src/RColumnElement.hxx +++ b/tree/ntuple/src/RColumnElement.hxx @@ -993,7 +993,7 @@ using Quantized_t = std::uint32_t; #ifdef _MSC_VER unsigned long idx = 0; if (_BitScanReverse(&idx, x)) - return static_cast(32 - idx); + return static_cast(31 - idx); return 32; #else return static_cast(__builtin_clzl(x)); From b39ed30c17112c87cbce8fe8748da77b736033bc Mon Sep 17 00:00:00 2001 From: Bertrand Bellenot Date: Fri, 18 Jul 2025 18:24:39 +0200 Subject: [PATCH 6/6] debug and optimized are exclusive on Windows only --- core/base/src/TSystem.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/base/src/TSystem.cxx b/core/base/src/TSystem.cxx index 611ba99477e53..7b169455ccab3 100644 --- a/core/base/src/TSystem.cxx +++ b/core/base/src/TSystem.cxx @@ -3735,7 +3735,10 @@ int TSystem::CompileMacro(const char *filename, Option_t *opt, TString optdebFlags; if (mode & kDebug) optdebFlags = fFlagsDebug + " "; - else if (mode & kOpt) +#ifdef WIN32 + else +#endif + if (mode & kOpt) optdebFlags += fFlagsOpt; cmd.ReplaceAll("$Opt", optdebFlags); #ifdef WIN32