GH-116134: JIT aarch64-pc-windows-msvc (GH-116130)

This commit is contained in:
Brandt Bucher 2024-03-04 10:16:56 -08:00 committed by GitHub
parent 981f27dcc4
commit ffed8d985b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 3 deletions

View file

@ -29,6 +29,7 @@ jobs:
target: target:
- i686-pc-windows-msvc/msvc - i686-pc-windows-msvc/msvc
- x86_64-pc-windows-msvc/msvc - x86_64-pc-windows-msvc/msvc
- aarch64-pc-windows-msvc/msvc
- x86_64-apple-darwin/clang - x86_64-apple-darwin/clang
- aarch64-apple-darwin/clang - aarch64-apple-darwin/clang
- x86_64-unknown-linux-gnu/gcc - x86_64-unknown-linux-gnu/gcc
@ -49,6 +50,10 @@ jobs:
architecture: x64 architecture: x64
runner: windows-latest runner: windows-latest
compiler: msvc compiler: msvc
- target: aarch64-pc-windows-msvc/msvc
architecture: ARM64
runner: windows-latest
compiler: msvc
- target: x86_64-apple-darwin/clang - target: x86_64-apple-darwin/clang
architecture: x86_64 architecture: x86_64
runner: macos-13 runner: macos-13
@ -85,14 +90,21 @@ jobs:
with: with:
python-version: '3.11' python-version: '3.11'
- name: Windows - name: Native Windows
if: runner.os == 'Windows' if: runner.os == 'Windows' && matrix.architecture != 'ARM64'
run: | run: |
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }} choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}
./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '--pgo' }} -p ${{ matrix.architecture }} ./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 ./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' if: runner.os == 'macOS'
run: | run: |
brew install llvm@${{ matrix.llvm }} brew install llvm@${{ matrix.llvm }}

View 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/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.cpp
// - https://github.com/llvm/llvm-project/blob/main/lld/MachO/Arch/ARM64Common.h // - 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: // - aarch64-unknown-linux-gnu:
// - https://github.com/llvm/llvm-project/blob/main/lld/ELF/Arch/AArch64.cpp // - https://github.com/llvm/llvm-project/blob/main/lld/ELF/Arch/AArch64.cpp
// - i686-pc-windows-msvc: // - i686-pc-windows-msvc:
@ -252,6 +254,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
assert((int64_t)value < (1LL << 31)); assert((int64_t)value < (1LL << 31));
*loc32 = (uint32_t)value; *loc32 = (uint32_t)value;
continue; continue;
case HoleKind_IMAGE_REL_ARM64_BRANCH26:
case HoleKind_R_AARCH64_CALL26: case HoleKind_R_AARCH64_CALL26:
case HoleKind_R_AARCH64_JUMP26: case HoleKind_R_AARCH64_JUMP26:
// 28-bit relative branch. // 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); set_bits(loc32, 5, value, 48, 16);
continue; continue;
case HoleKind_ARM64_RELOC_GOT_LOAD_PAGE21: case HoleKind_ARM64_RELOC_GOT_LOAD_PAGE21:
case HoleKind_IMAGE_REL_ARM64_PAGEBASE_REL21:
case HoleKind_R_AARCH64_ADR_GOT_PAGE: case HoleKind_R_AARCH64_ADR_GOT_PAGE:
// 21-bit count of pages between this page and an absolute address's // 21-bit count of pages between this page and an absolute address's
// page... I know, I know, it's weird. Pairs nicely with // 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]; const Hole *next_hole = &stencil->holes[i + 1];
if (i + 1 < stencil->holes_size && if (i + 1 < stencil->holes_size &&
(next_hole->kind == HoleKind_ARM64_RELOC_GOT_LOAD_PAGEOFF12 || (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->kind == HoleKind_R_AARCH64_LD64_GOT_LO12_NC) &&
next_hole->offset == hole->offset + 4 && next_hole->offset == hole->offset + 4 &&
next_hole->symbol == hole->symbol && next_hole->symbol == hole->symbol &&
@ -354,6 +359,8 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
continue; continue;
case HoleKind_ARM64_RELOC_GOT_LOAD_PAGEOFF12: case HoleKind_ARM64_RELOC_GOT_LOAD_PAGEOFF12:
case HoleKind_ARM64_RELOC_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: case HoleKind_R_AARCH64_LD64_GOT_LO12_NC:
// 12-bit low part of an absolute address. Pairs nicely with // 12-bit low part of an absolute address. Pairs nicely with
// ARM64_RELOC_GOT_LOAD_PAGE21 (above). // ARM64_RELOC_GOT_LOAD_PAGE21 (above).

View file

@ -8,6 +8,10 @@ HoleKind: typing.TypeAlias = typing.Literal[
"ARM64_RELOC_PAGEOFF12", "ARM64_RELOC_PAGEOFF12",
"ARM64_RELOC_UNSIGNED", "ARM64_RELOC_UNSIGNED",
"IMAGE_REL_AMD64_REL32", "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_DIR32",
"IMAGE_REL_I386_REL32", "IMAGE_REL_I386_REL32",
"R_AARCH64_ABS64", "R_AARCH64_ABS64",

View file

@ -238,6 +238,19 @@ class _COFF(
addend = ( addend = (
int.from_bytes(raw[offset : offset + 4], "little", signed=True) - 4 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 _: case _:
raise NotImplementedError(relocation) raise NotImplementedError(relocation)
return _stencils.Hole(offset, kind, value, symbol, addend) 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): if re.fullmatch(r"aarch64-apple-darwin.*", host):
args = ["-mcmodel=large"] args = ["-mcmodel=large"]
return _MachO(host, alignment=8, args=args, prefix="_") 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): if re.fullmatch(r"aarch64-.*-linux-gnu", host):
args = ["-mcmodel=large"] args = ["-mcmodel=large"]
return _ELF(host, alignment=8, args=args) return _ELF(host, alignment=8, args=args)