diff --git a/.github/workflows/root-windows-arm64.yml b/.github/workflows/root-windows-arm64.yml new file mode 100644 index 0000000000000..b9340d4cfed12 --- /dev/null +++ b/.github/workflows/root-windows-arm64.yml @@ -0,0 +1,85 @@ +name: 'Windows ARM64' + +on: + pull_request: + paths-ignore: + - 'doc/**' + - 'documentation/**' + push: + branches: + - 'master' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + build-windows-arm64: + name: Windows 11 ARM64 Release + # GitHub-hosted native Windows on ARM64 runner + runs-on: windows-11-arm + timeout-minutes: 360 + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Setup MSVC developer environment (arm64) + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: arm64 + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + architecture: arm64 + + - name: Install FFTW3 + # RooFFTConvPdf needs FFTW (testRooFitCore, testRooWorkspace). The runner image ships vcpkg. + shell: pwsh + run: | + & "$env:VCPKG_INSTALLATION_ROOT\vcpkg.exe" install fftw3:arm64-windows + if ($LASTEXITCODE) { exit $LASTEXITCODE } + $fftw = "$env:VCPKG_INSTALLATION_ROOT\installed\arm64-windows" + "FFTW_ROOT=$fftw" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV + "$fftw\bin" | Out-File -Append -Encoding utf8 $env:GITHUB_PATH + + - name: Configure + shell: pwsh + run: | + # Same option set as the self-hosted 'windows10' CI configuration, minus the + # GSL-dependent parts: GSL is not preinstalled on GitHub-hosted runners and the + # builtin GSL uses autotools, which does not work with MSVC. + $opts = Get-Content .github/workflows/root-ci-config/buildconfig/windows10.txt | + Where-Object { $_ -match '=' } | + ForEach-Object { "-D$_" } + $opts = $opts -replace '^-Dpyroot3=ON$', '-Dpyroot=OFF' + $opts = $opts | Where-Object { $_ -ne '-Duse_gsl_cblas=ON' } + cmake -S . -B build -G Ninja ` + -DCMAKE_BUILD_TYPE=Release ` + -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl ` + -Dtpython=OFF ` + -Dbuiltin_gsl=OFF -Dmathmore=OFF -Duse_gsl_cblas=OFF -Dtmva-cpu=OFF ` + -Dtesting=ON -Droottest=OFF ` + @opts ` + -Dfftw3=ON -DFFTW_ROOT="$env:FFTW_ROOT" + + - name: Build + run: cmake --build build --parallel + + - name: Test + working-directory: build + # Same flake policy as the upstream Windows CI (build_root.py: --repeat until-pass:5) + run: ctest --output-on-failure --parallel 4 --timeout 600 --repeat until-pass:5 --output-junit TestResults.xml + + - name: Upload test results + if: ${{ !cancelled() }} + uses: actions/upload-artifact@v6 + with: + name: Test Results Windows ARM64 + path: build/TestResults.xml diff --git a/builtins/civetweb/CMakeLists.txt b/builtins/civetweb/CMakeLists.txt index b3167f9eea0b1..a8dff073cd453 100644 --- a/builtins/civetweb/CMakeLists.txt +++ b/builtins/civetweb/CMakeLists.txt @@ -18,6 +18,7 @@ ROOT_BUILTIN_PATCH_COMMAND(ROOT_CIVETWEB_PATCH_COMMAND PATCHES ${CMAKE_CURRENT_SOURCE_DIR}/1385.patch # https://github.com/civetweb/civetweb/pull/1385 ${CMAKE_CURRENT_SOURCE_DIR}/1389.patch # https://github.com/civetweb/civetweb/pull/1389 ${CMAKE_CURRENT_SOURCE_DIR}/1423.patch # https://github.com/civetweb/civetweb/pull/1423 for OpenSSL4 compatibility + ${CMAKE_CURRENT_SOURCE_DIR}/msvc-arm64.patch # MSVC ARM64 target architecture detection GIT_APPLY_ARGS ${GIT_PATCH_ARGS}) include(ExternalProject) diff --git a/builtins/civetweb/msvc-arm64.patch b/builtins/civetweb/msvc-arm64.patch new file mode 100644 index 0000000000000..182334f58e2a2 --- /dev/null +++ b/builtins/civetweb/msvc-arm64.patch @@ -0,0 +1,12 @@ +diff --git a/cmake/DetermineTargetArchitecture.cmake b/cmake/DetermineTargetArchitecture.cmake +--- a/cmake/DetermineTargetArchitecture.cmake ++++ b/cmake/DetermineTargetArchitecture.cmake +@@ -23,6 +23,8 @@ function(determine_target_architecture FLAG) + set(ARCH "x86_64") + elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM") + set(ARCH "arm") ++ elseif("${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM64") ++ set(ARCH "aarch64") + else() + message(FATAL_ERROR "Failed to determine the MSVC target architecture: ${MSVC_C_ARCHITECTURE_ID}") + endif() diff --git a/cmake/modules/SetUpWindows.cmake b/cmake/modules/SetUpWindows.cmake index 14752c4ce13e3..ee4f5f36197d5 100644 --- a/cmake/modules/SetUpWindows.cmake +++ b/cmake/modules/SetUpWindows.cmake @@ -30,7 +30,11 @@ elseif(MSVC) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(ARCH "-wd4267") set(ROOT_ARCHITECTURE win64) - set(MACHINE_ARCH X64) + if(MSVC_CXX_ARCHITECTURE_ID STREQUAL "ARM64") + set(MACHINE_ARCH ARM64) + else() + set(MACHINE_ARCH X64) + endif() else() set(ROOT_ARCHITECTURE win32) set(MACHINE_ARCH X86) diff --git a/core/winnt/src/TWinNTSystem.cxx b/core/winnt/src/TWinNTSystem.cxx index da6337d5678eb..049863e4fdefd 100644 --- a/core/winnt/src/TWinNTSystem.cxx +++ b/core/winnt/src/TWinNTSystem.cxx @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -4313,7 +4314,8 @@ const char *TWinNTSystem::GetLibraries(const char *regexp, const char *options, if ( (opt.First('L')!=kNPOS) ) { libs.ReplaceAll("/","\\"); // get the %LIB% environment path list - std::stringstream libenv(gSystem->Getenv("LIB")); + const char *libvar = gSystem->Getenv("LIB"); + std::stringstream libenv(libvar ? libvar : ""); while (getline(libenv, str, ';')) { libpaths.push_back(str); } @@ -5582,6 +5584,14 @@ typedef LONG (WINAPI *PROCNTQSI) (UINT, PVOID, ULONG, PULONG); static DWORD GetCPUSpeed() { +#if defined(_M_ARM64) || defined(_M_ARM) + // No 'rdtsc' on ARM: read the nominal clock speed (in MHz) reported by Windows. + DWORD mhz = 0, size = sizeof(mhz); + if (RegGetValueA(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", "~MHz", + RRF_RT_REG_DWORD, nullptr, &mhz, &size) != ERROR_SUCCESS) + return 0; + return mhz; +#else LARGE_INTEGER ulFreq, ulTicks, ulValue, ulStartCounter; // Query for high-resolution counter frequency @@ -5604,6 +5614,7 @@ static DWORD GetCPUSpeed() // No high-resolution counter present: return 0; } +#endif } #define BUFSIZE 80 @@ -5834,6 +5845,18 @@ static const char *GetWindowsVersion() static int GetL2CacheSize() { +#if defined(_M_ARM64) || defined(_M_ARM) + // No 'cpuid' on ARM: query the cache topology from Windows (size in KB, as for x86). + DWORD len = 0; + GetLogicalProcessorInformation(nullptr, &len); + std::vector info(len / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) + 1); + if (!GetLogicalProcessorInformation(info.data(), &len)) + return 0; + for (DWORD i = 0; i < len / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); ++i) + if (info[i].Relationship == RelationCache && info[i].Cache.Level == 2) + return (int)(info[i].Cache.Size / 1024); + return 0; +#else unsigned nHighestFeatureEx; int nBuff[4]; @@ -5845,6 +5868,7 @@ static int GetL2CacheSize() return (((unsigned)nBuff[2])>>16); } else return 0; +#endif } //////////////////////////////////////////////////////////////////////////////// diff --git a/gui/webdisplay/test/CMakeLists.txt b/gui/webdisplay/test/CMakeLists.txt index 411e446cb64bf..27e296c2752bd 100644 --- a/gui/webdisplay/test/CMakeLists.txt +++ b/gui/webdisplay/test/CMakeLists.txt @@ -10,7 +10,12 @@ # test only can be run if Firefox or Chrome are detected on the system -if (CHROME_EXECUTABLE OR FIREFOX_EXECUTABLE) +# On Windows, ROOT starts the browser with 'wmic process call create' (RWebDisplayHandle.cxx). +# wmic is no longer installed by default on Windows 11 (24H2 and later), so skip the test there. +if(WIN32) + find_program(WMIC_EXECUTABLE wmic) +endif() +if ((CHROME_EXECUTABLE OR FIREFOX_EXECUTABLE) AND (NOT WIN32 OR WMIC_EXECUTABLE)) ROOT_ADD_TEST(test-webgui-ping RUN_SERIAL COPY_TO_BUILDDIR ${CMAKE_SOURCE_DIR}/tutorials/visualisation/webgui/ping/ping.cxx ${CMAKE_SOURCE_DIR}/tutorials/visualisation/webgui/ping/ping.html diff --git a/interpreter/cling/include/cling/Utils/Platform.h b/interpreter/cling/include/cling/Utils/Platform.h index 29bf69fe78d5c..2050bd4c4726e 100644 --- a/interpreter/cling/include/cling/Utils/Platform.h +++ b/interpreter/cling/include/cling/Utils/Platform.h @@ -86,6 +86,13 @@ namespace platform { inline namespace windows { + ///\brief If Addr (the resolution of Name) lives in the legacy msvcrt.dll, + /// return the ucrtbase.dll export of the same name instead. Interpreted code + /// is compiled against the UCRT headers, so binding it to msvcrt.dll (which + /// some system DLLs load) mixes incompatible CRTs, e.g. FILE layouts. + /// + const void* PreferUCRTSymbol(const void* Addr, const char* Name); + ///\brief Get an error message from the last Windows API /// /// \param [in] Prefix - Prefix the message with this (ex. API call name) diff --git a/interpreter/cling/lib/Interpreter/IncrementalJIT.cpp b/interpreter/cling/lib/Interpreter/IncrementalJIT.cpp index 2be6ea97c7d6e..91c952a85da86 100644 --- a/interpreter/cling/lib/Interpreter/IncrementalJIT.cpp +++ b/interpreter/cling/lib/Interpreter/IncrementalJIT.cpp @@ -13,6 +13,7 @@ #include "IncrementalExecutor.h" #include "cling/Utils/Output.h" +#include "cling/Utils/Platform.h" #include "cling/Utils/Utils.h" #include @@ -27,7 +28,11 @@ #include #include #include +#include +#include +#include #include +#include #include #include #include @@ -260,7 +265,17 @@ namespace { RWDataSize); } - bool needsToReserveAllocationSpace() override { return true; } + bool needsToReserveAllocationSpace() override { +#if defined(_WIN32) && (defined(_M_ARM64) || defined(__aarch64__)) + // The contiguous reservation only matters for libgcc-style .eh_frame + // unwinding. On Windows ARM64, RuntimeDyld's size estimate for + // COFF/AArch64 objects does not account for all the stubs that are + // created later, so the reservation overflows; allocate per section. + return false; +#else + return true; +#endif + } }; /// A JITLinkMemoryManager for Cling that never frees its allocations. @@ -375,6 +390,10 @@ Error RTDynamicLibrarySearchGenerator::tryToGenerate( std::string Tmp((*Name).data() + StripGlobalPrefix, (*Name).size() - StripGlobalPrefix); if (void* P = Dylib.getAddressOfSymbol(Tmp.c_str())) { +#ifdef _WIN32 + P = const_cast( + cling::utils::platform::PreferUCRTSymbol(P, Tmp.c_str())); +#endif NewSymbols[Name] = {orc::ExecutorAddr::fromPtr(P), JITSymbolFlags::Exported}; } @@ -753,6 +772,37 @@ void IncrementalJIT::addModule(Transaction& T) { } } +#if defined(_WIN32) && (defined(_M_ARM64) || defined(__aarch64__)) + // On Windows ARM64 the JIT uses the small code model (COFF has no + // relocations for the large model's MOVZ/MOVK sequences), so references to + // external globals are emitted as ADRP+ADD/LDR pairs with a +-4GB range. + // Symbols living in DLLs (e.g. std::cout in msvcp140.dll) or in far-away JIT + // allocations are out of reach and RuntimeDyld silently truncates the page + // delta. Route such references through an __imp_ pointer instead: RuntimeDyld + // materializes it next to the code and fills it with a 64-bit relocation. + { + llvm::SmallPtrSet Personalities; + for (auto &Fn : module->functions()) + if (Fn.hasPersonalityFn()) + if (auto *P = dyn_cast( + Fn.getPersonalityFn()->stripPointerCasts())) + Personalities.insert(P); + auto MakeImport = [](llvm::GlobalValue &GV) { + GV.setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); + GV.setDSOLocal(false); + }; + for (auto &GV : module->globals()) + if (GV.isDeclaration() && !GV.isThreadLocal() && + !GV.hasDLLImportStorageClass() && !GV.getName().starts_with("llvm.")) + MakeImport(GV); + for (auto &Fn : module->functions()) + if (Fn.isDeclaration() && !Fn.isIntrinsic() && + !Fn.hasDLLImportStorageClass() && !Personalities.count(&Fn) && + Fn.hasAddressTaken()) + MakeImport(Fn); + } +#endif + ThreadSafeModule TSM(std::move(module), SingleThreadedContext); const Module *Unsafe = TSM.getModuleUnlocked(); diff --git a/interpreter/cling/lib/Utils/PlatformWin.cpp b/interpreter/cling/lib/Utils/PlatformWin.cpp index bec4bf980817d..8716d88f5884e 100644 --- a/interpreter/cling/lib/Utils/PlatformWin.cpp +++ b/interpreter/cling/lib/Utils/PlatformWin.cpp @@ -576,6 +576,23 @@ const void *CheckImp(void *addr, bool dllimp) { return (const void *)addr; } +const void* windows::PreferUCRTSymbol(const void* Addr, const char* Name) { + // Not cached: msvcrt.dll may be loaded after the first lookup. + const HMODULE MSVCRT = ::GetModuleHandleA("msvcrt.dll"); + if (!Addr || !MSVCRT) + return Addr; + HMODULE Owner = nullptr; + if (!::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(Addr), &Owner) || + Owner != MSVCRT) + return Addr; + if (HMODULE UCRT = ::GetModuleHandleA("ucrtbase.dll")) + if (FARPROC P = ::GetProcAddress(UCRT, Name)) + return reinterpret_cast(P); + return Addr; +} + const void* DLSym(const std::string& Name, std::string* Err) { #ifdef _WIN64 const DWORD Flags = LIST_MODULES_64BIT; diff --git a/interpreter/llvm-project/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h b/interpreter/llvm-project/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h index 3ca6309874de5..c34cb203c6004 100644 --- a/interpreter/llvm-project/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h +++ b/interpreter/llvm-project/llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldCOFFAArch64.h @@ -233,12 +233,21 @@ class RuntimeDyldCOFFAArch64 : public RuntimeDyldCOFF { Addend = ((orig >> 29) & 0x3) | ((orig >> 3) & 0x1FFFFC); break; } - case COFF::IMAGE_REL_ARM64_PAGEOFFSET_12L: case COFF::IMAGE_REL_ARM64_PAGEOFFSET_12A: { uint32_t orig = read32le(Displacement); Addend = ((orig >> 10) & 0xFFF); break; } + case COFF::IMAGE_REL_ARM64_PAGEOFFSET_12L: { + // The LDR/STR immediate is scaled by the access size, so the embedded + // addend must be scaled back to bytes (mirrors write32AArch64Ldr). + uint32_t orig = read32le(Displacement); + uint32_t size = orig >> 30; + if ((orig & 0x04800000) == 0x04800000) + size += 4; + Addend = ((orig >> 10) & 0xFFF) << size; + break; + } case COFF::IMAGE_REL_ARM64_ADDR64: { Addend = read64le(Displacement); break; diff --git a/interpreter/llvm-project/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp b/interpreter/llvm-project/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp index 7907a3c283624..2fa682bc6a096 100644 --- a/interpreter/llvm-project/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp +++ b/interpreter/llvm-project/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp @@ -594,6 +594,16 @@ bool AArch64CallLowering::fallBackToDAGISel(const MachineFunction &MF) const { Attrs.hasStreamingCompatibleInterface()) return true; + // On Windows, a function with an 'inreg sret' parameter (MSVC C++ instance + // methods returning a class by value) must return the sret pointer in X0. + // SelectionDAG implements this (see AArch64TargetLowering::LowerReturn), but + // GlobalISel does not, so callers compiled by MSVC would read a stale X0. + if (ST.isCallingConvWin64(F.getCallingConv(), F.isVarArg()) && + llvm::any_of(F.args(), [](const Argument &A) { + return A.hasStructRetAttr() && A.hasInRegAttr(); + })) + return true; + return false; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5ffe5ea8953d0..2cad66885068c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -49,7 +49,12 @@ endif() #ROOT_ADD_TEST(test-hsimple COMMAND hsimple) #---invalid pointer checks--------------------------------------------------------------------- -if((NOT (APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES arm64) OR M1_BROKEN_TESTS) AND NOT experimental_adaptivecpp) +# Disabled on Windows ARM64, as on macOS arm64: the null-pointer check reports the error by throwing +# a C++ exception through JIT-compiled frames, and RuntimeDyld does not register unwind information +# (.pdata) for JIT code on COFF/AArch64, so the exception cannot be caught. +if((NOT (APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES arm64) OR M1_BROKEN_TESTS) + AND NOT (MSVC AND MSVC_CXX_ARCHITECTURE_ID STREQUAL "ARM64" AND NOT win_broken_tests) + AND NOT experimental_adaptivecpp) ROOT_ADD_TEST(test-check-nullptr COMMAND ${root_exe} -b -q --ptrcheck -e "int*ptr=(int*)0" -e "*ptr" PASSREGEX "dereference null pointer") @@ -170,7 +175,12 @@ if(opengl AND TARGET TreeViewer) COMMAND stressGraphics -b --web=off -p=svg --svg=${CMAKE_CURRENT_SOURCE_DIR}/svg_ref/ FAILREGEX "FAILED|Error in" LABELS longtest) - if(webgui AND CHROME_EXECUTABLE) + # On Windows, ROOT starts the browser with 'wmic process call create' (RWebDisplayHandle.cxx). + # wmic is no longer installed by default on Windows 11 (24H2 and later), so skip the test there. + if(WIN32) + find_program(WMIC_EXECUTABLE wmic) + endif() + if(webgui AND CHROME_EXECUTABLE AND (NOT WIN32 OR WMIC_EXECUTABLE)) ROOT_ADD_TEST(test-stressgraphics-chrome RUN_SERIAL COMMAND stressGraphics -b -k -p=sgc --web=chrome @@ -198,7 +208,9 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/stressHistogram.5.18.00.root ${CMAKE_ ROOT_EXECUTABLE(stressHistogram stressHistogram.cxx LIBRARIES Hist RIO) ROOT_ADD_TEST(test-stresshistogram COMMAND stressHistogram FAILREGEX "FAILED|Error in" LABELS longtest) # The stresshistogram-interpreted test fails on Windows due to unresolved symbols with Visual Studio 2026 -if(MSVC AND MSVC_VERSION GREATER_EQUAL 1951 AND NOT "${CMAKE_GENERATOR_PLATFORM}" MATCHES "Win32") +# (not on ARM64, where the test passes) +if(MSVC AND MSVC_VERSION GREATER_EQUAL 1951 AND NOT "${CMAKE_GENERATOR_PLATFORM}" MATCHES "Win32" + AND NOT MSVC_CXX_ARCHITECTURE_ID STREQUAL "ARM64") set(_willfail WILLFAIL) endif() ROOT_ADD_TEST(test-stresshistogram-interpreted COMMAND ${root_exe} -b -q ${CMAKE_CURRENT_SOURCE_DIR}/stressHistogram.cxx diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index ca1fe58740f6e..4abdeac1c6d77 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -441,6 +441,15 @@ if(root7) list(APPEND root7_veto visualisation/rcanvas/df105.py) list(APPEND root7_veto visualisation/rcanvas/rbox.py) endif() + # rline.cxx saves the canvas as PNG through headless Chrome. On Windows, ROOT starts the browser + # with 'wmic process call create' (RWebDisplayHandle.cxx), and wmic is no longer installed by + # default on Windows 11 (24H2 and later). + if(WIN32) + find_program(WMIC_EXECUTABLE wmic) + if(NOT WMIC_EXECUTABLE) + list(APPEND root7_veto visualisation/rcanvas/rline.cxx) + endif() + endif() if(NOT xrootd) list(APPEND root7_veto hist/histv7/hist102_NanoAODDimuonAnalysis.C) list(APPEND root7_veto hist/histv7/hist103_NanoAODHiggsAnalysis.C)