]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-116134: JIT aarch64-pc-windows-msvc (GH-116130)
authorBrandt Bucher <brandtbucher@microsoft.com>
Mon, 4 Mar 2024 18:16:56 +0000 (10:16 -0800)
committerGitHub <noreply@github.com>
Mon, 4 Mar 2024 18:16:56 +0000 (10:16 -0800)
.github/workflows/jit.yml
Python/jit.c
Tools/jit/_schema.py
Tools/jit/_targets.py

index 43d0b2c1b4016cae2ca1b81fea01061cfaad1304..809ac45919fe74674321396dbb120d262c1144c9 100644 (file)
@@ -29,6 +29,7 @@ jobs:
         target:
           - i686-pc-windows-msvc/msvc
           - x86_64-pc-windows-msvc/msvc
+          - aarch64-pc-windows-msvc/msvc
           - x86_64-apple-darwin/clang
           - aarch64-apple-darwin/clang
           - x86_64-unknown-linux-gnu/gcc
@@ -49,6 +50,10 @@ jobs:
             architecture: x64
             runner: windows-latest
             compiler: msvc
+          - target: aarch64-pc-windows-msvc/msvc
+            architecture: ARM64
+            runner: windows-latest
+            compiler: msvc
           - target: x86_64-apple-darwin/clang
             architecture: x86_64
             runner: macos-13
@@ -85,14 +90,21 @@ jobs:
         with:
           python-version: '3.11'
 
-      - name: Windows
-        if: runner.os == 'Windows'
+      - name: Native Windows
+        if: runner.os == 'Windows' && matrix.architecture != 'ARM64'
         run: |
           choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}
           ./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '--pgo' }} -p ${{ matrix.architecture }}
           ./PCbuild/rt.bat ${{ matrix.debug && '-d' }} -p ${{ matrix.architecture }} -q --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 3600 --verbose2 --verbose3
 
-      - name: macOS
+      # No PGO or tests (yet):
+      - name: Emulated Windows
+        if: runner.os == 'Windows' && matrix.architecture == 'ARM64'
+        run: |
+          choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}
+          ./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }}
+
+      - name: Native macOS
         if: runner.os == 'macOS'
         run: |
           brew install llvm@${{ matrix.llvm }}
index 9f9e123ab91fef4b3630022bb55344ccad4b5601..dae25166b1f106554b05b1bce0c15df19dcbe82f 100644 (file)
@@ -185,6 +185,8 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
         //   - https://github.com/llvm/llvm-project/blob/main/lld/MachO/Arch/ARM64.cpp
         //   - https://github.com/llvm/llvm-project/blob/main/lld/MachO/Arch/ARM64Common.cpp
         //   - https://github.com/llvm/llvm-project/blob/main/lld/MachO/Arch/ARM64Common.h
+        // - aarch64-pc-windows-msvc:
+        //   - https://github.com/llvm/llvm-project/blob/main/lld/COFF/Chunks.cpp
         // - aarch64-unknown-linux-gnu:
         //   - https://github.com/llvm/llvm-project/blob/main/lld/ELF/Arch/AArch64.cpp
         // - i686-pc-windows-msvc:
@@ -252,6 +254,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
                 assert((int64_t)value < (1LL << 31));
                 *loc32 = (uint32_t)value;
                 continue;
+            case HoleKind_IMAGE_REL_ARM64_BRANCH26:
             case HoleKind_R_AARCH64_CALL26:
             case HoleKind_R_AARCH64_JUMP26:
                 // 28-bit relative branch.
@@ -293,6 +296,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
                 set_bits(loc32, 5, value, 48, 16);
                 continue;
             case HoleKind_ARM64_RELOC_GOT_LOAD_PAGE21:
+            case HoleKind_IMAGE_REL_ARM64_PAGEBASE_REL21:
             case HoleKind_R_AARCH64_ADR_GOT_PAGE:
                 // 21-bit count of pages between this page and an absolute address's
                 // page... I know, I know, it's weird. Pairs nicely with
@@ -302,6 +306,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
                 const Hole *next_hole = &stencil->holes[i + 1];
                 if (i + 1 < stencil->holes_size &&
                     (next_hole->kind == HoleKind_ARM64_RELOC_GOT_LOAD_PAGEOFF12 ||
+                     next_hole->kind == HoleKind_IMAGE_REL_ARM64_PAGEOFFSET_12L ||
                      next_hole->kind == HoleKind_R_AARCH64_LD64_GOT_LO12_NC) &&
                     next_hole->offset == hole->offset + 4 &&
                     next_hole->symbol == hole->symbol &&
@@ -354,6 +359,8 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
                 continue;
             case HoleKind_ARM64_RELOC_GOT_LOAD_PAGEOFF12:
             case HoleKind_ARM64_RELOC_PAGEOFF12:
+            case HoleKind_IMAGE_REL_ARM64_PAGEOFFSET_12A:
+            case HoleKind_IMAGE_REL_ARM64_PAGEOFFSET_12L:
             case HoleKind_R_AARCH64_LD64_GOT_LO12_NC:
                 // 12-bit low part of an absolute address. Pairs nicely with
                 // ARM64_RELOC_GOT_LOAD_PAGE21 (above).
index 14e5fc2aae80ef824e7662cf75ef23d73fedd6db..045fd502a03c12b0bcb76e92b6ee4b97a5b38257 100644 (file)
@@ -8,6 +8,10 @@ HoleKind: typing.TypeAlias = typing.Literal[
     "ARM64_RELOC_PAGEOFF12",
     "ARM64_RELOC_UNSIGNED",
     "IMAGE_REL_AMD64_REL32",
+    "IMAGE_REL_ARM64_BRANCH26",
+    "IMAGE_REL_ARM64_PAGEBASE_REL21",
+    "IMAGE_REL_ARM64_PAGEOFFSET_12A",
+    "IMAGE_REL_ARM64_PAGEOFFSET_12L",
     "IMAGE_REL_I386_DIR32",
     "IMAGE_REL_I386_REL32",
     "R_AARCH64_ABS64",
index 07959b15b6c4b9f8b0e70a58a306a0d76074a66e..417fdb56ccf7a1b8b1708aa143dd19bde1578c06 100644 (file)
@@ -238,6 +238,19 @@ class _COFF(
                 addend = (
                     int.from_bytes(raw[offset : offset + 4], "little", signed=True) - 4
                 )
+            case {
+                "Offset": offset,
+                "Symbol": s,
+                "Type": {
+                    "Value": "IMAGE_REL_ARM64_BRANCH26"
+                    | "IMAGE_REL_ARM64_PAGEBASE_REL21"
+                    | "IMAGE_REL_ARM64_PAGEOFFSET_12A"
+                    | "IMAGE_REL_ARM64_PAGEOFFSET_12L" as kind
+                },
+            }:
+                offset += base
+                value, symbol = self._unwrap_dllimport(s)
+                addend = 0
             case _:
                 raise NotImplementedError(relocation)
         return _stencils.Hole(offset, kind, value, symbol, addend)
@@ -435,6 +448,9 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
     if re.fullmatch(r"aarch64-apple-darwin.*", host):
         args = ["-mcmodel=large"]
         return _MachO(host, alignment=8, args=args, prefix="_")
+    if re.fullmatch(r"aarch64-pc-windows-msvc", host):
+        args = ["-fms-runtime-lib=dll"]
+        return _COFF(host, alignment=8, args=args)
     if re.fullmatch(r"aarch64-.*-linux-gnu", host):
         args = ["-mcmodel=large"]
         return _ELF(host, alignment=8, args=args)