Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/root-windows-arm64.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions builtins/civetweb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions builtins/civetweb/msvc-arm64.patch
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 5 additions & 1 deletion cmake/modules/SetUpWindows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion core/winnt/src/TWinNTSystem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include <sstream>
#include <iostream>
#include <list>
#include <vector>
#include <shlobj.h>
#include <conio.h>
#include <ctime>
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -5604,6 +5614,7 @@ static DWORD GetCPUSpeed()
// No high-resolution counter present:
return 0;
}
#endif
}

#define BUFSIZE 80
Expand Down Expand Up @@ -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<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> 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];

Expand All @@ -5845,6 +5868,7 @@ static int GetL2CacheSize()
return (((unsigned)nBuff[2])>>16);
}
else return 0;
#endif
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 6 additions & 1 deletion gui/webdisplay/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions interpreter/cling/include/cling/Utils/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 51 additions & 1 deletion interpreter/cling/lib/Interpreter/IncrementalJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "IncrementalExecutor.h"

#include "cling/Utils/Output.h"
#include "cling/Utils/Platform.h"
#include "cling/Utils/Utils.h"

#include <clang/Basic/TargetInfo.h>
Expand All @@ -27,7 +28,11 @@
#include <llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h>
#include <llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/ADT/SmallPtrSet.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/GlobalVariable.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/MC/TargetRegistry.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Target/TargetMachine.h>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<void*>(
cling::utils::platform::PreferUCRTSymbol(P, Tmp.c_str()));
#endif
NewSymbols[Name] = {orc::ExecutorAddr::fromPtr(P),
JITSymbolFlags::Exported};
}
Expand Down Expand Up @@ -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<const llvm::Function*, 4> Personalities;
for (auto &Fn : module->functions())
if (Fn.hasPersonalityFn())
if (auto *P = dyn_cast<llvm::Function>(
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();
Expand Down
17 changes: 17 additions & 0 deletions interpreter/cling/lib/Utils/PlatformWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LPCSTR>(Addr), &Owner) ||
Owner != MSVCRT)
return Addr;
if (HMODULE UCRT = ::GetModuleHandleA("ucrtbase.dll"))
if (FARPROC P = ::GetProcAddress(UCRT, Name))
return reinterpret_cast<const void*>(P);
return Addr;
}

const void* DLSym(const std::string& Name, std::string* Err) {
#ifdef _WIN64
const DWORD Flags = LIST_MODULES_64BIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading