From fef6cc0a0d4217e88682c8d28ef50104a42bc1aa Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 20:18:09 -0700 Subject: [PATCH 01/26] Works for Linux Arm, Mac Arm broken --- Python/jit.c | 2 ++ Tools/jit/README.md | 10 +++++++--- Tools/jit/_llvm.py | 2 +- Tools/jit/_schema.py | 8 ++++++-- Tools/jit/_targets.py | 23 +++++++++++------------ 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Python/jit.c b/Python/jit.c index 8782adb847cfd6..7ac9ac6dfe6d60 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -278,6 +278,7 @@ patch(unsigned char *base, const Stencil *stencil, uintptr_t patches[]) case HoleKind_ARM64_RELOC_GOT_LOAD_PAGE21: case HoleKind_IMAGE_REL_ARM64_PAGEBASE_REL21: case HoleKind_R_AARCH64_ADR_GOT_PAGE: + case HoleKind_ARM64_RELOC_BRANCH26: // 21-bit count of pages between this page and an absolute address's // page... I know, I know, it's weird. Pairs nicely with // ARM64_RELOC_GOT_LOAD_PAGEOFF12 (below). @@ -287,6 +288,7 @@ patch(unsigned char *base, const Stencil *stencil, uintptr_t patches[]) 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_ARM64_RELOC_BRANCH26 || next_hole->kind == HoleKind_R_AARCH64_LD64_GOT_LO12_NC) && next_hole->offset == hole->offset + 4 && next_hole->symbol == hole->symbol && diff --git a/Tools/jit/README.md b/Tools/jit/README.md index 04a6c0780bf972..e78f1ea3a35279 100644 --- a/Tools/jit/README.md +++ b/Tools/jit/README.md @@ -23,17 +23,21 @@ sudo ./llvm.sh 16 ### macOS -Install LLVM 16 with [Homebrew](https://brew.sh): +Install LLVM 18 with [Homebrew](https://brew.sh): ```sh -brew install llvm@16 +brew install llvm@18 ``` Homebrew won't add any of the tools to your `$PATH`. That's okay; the build script knows how to find them. ### Windows -Install LLVM 16 [by searching for it on LLVM's GitHub releases page](https://github.com/llvm/llvm-project/releases?q=16), clicking on "Assets", downloading the appropriate Windows installer for your platform (likely the file ending with `-win64.exe`), and running it. **When installing, be sure to select the option labeled "Add LLVM to the system PATH".** +Install LLVM 18 [by searching for it on LLVM's GitHub releases page](https://github.com/llvm/llvm-project/releases?q=18), clicking on "Assets", downloading the appropriate Windows installer for your platform (likely the file ending with `-win64.exe`), and running it. **When installing, be sure to select the option labeled "Add LLVM to the system PATH".** + +## Devcontainers + +If you are working CPython in a [Codespaces instance](https://devguide.python.org/getting-started/setup-building/#using-codespaces), there's no need to install LLVM as the Fedora 40 base image includes LLVM 18 out of the box. ## Building diff --git a/Tools/jit/_llvm.py b/Tools/jit/_llvm.py index 603bbef59ba2e6..74a048ccbfcc58 100644 --- a/Tools/jit/_llvm.py +++ b/Tools/jit/_llvm.py @@ -7,7 +7,7 @@ import subprocess import typing -_LLVM_VERSION = 16 +_LLVM_VERSION = 18 _LLVM_VERSION_PATTERN = re.compile(rf"version\s+{_LLVM_VERSION}\.\d+\.\d+\s+") _P = typing.ParamSpec("_P") diff --git a/Tools/jit/_schema.py b/Tools/jit/_schema.py index 045fd502a03c12..b7da4356d80df4 100644 --- a/Tools/jit/_schema.py +++ b/Tools/jit/_schema.py @@ -2,6 +2,7 @@ import typing HoleKind: typing.TypeAlias = typing.Literal[ + "ARM64_RELOC_BRANCH26", "ARM64_RELOC_GOT_LOAD_PAGE21", "ARM64_RELOC_GOT_LOAD_PAGEOFF12", "ARM64_RELOC_PAGE21", @@ -89,6 +90,10 @@ class COFFSection(typing.TypedDict): SectionData: typing.NotRequired[dict[typing.Literal["Bytes"], list[int]]] Symbols: list[dict[typing.Literal["Symbol"], _COFFSymbol]] +class _ElfSectionType(typing.TypedDict): + """An ELF object file section type.""" + Name: str + Value: int class ELFSection(typing.TypedDict): """An ELF object file section.""" @@ -99,8 +104,7 @@ class ELFSection(typing.TypedDict): Relocations: list[dict[typing.Literal["Relocation"], ELFRelocation]] SectionData: dict[typing.Literal["Bytes"], list[int]] Symbols: list[dict[typing.Literal["Symbol"], _ELFSymbol]] - Type: dict[typing.Literal["Value"], str] - + Type: _ElfSectionType class MachOSection(typing.TypedDict): """A Mach-O object file section.""" diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 66db358679239e..c1b89da8dd0ec8 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -127,7 +127,7 @@ async def _compile( # Emit relaxable 64-bit calls/jumps, so we don't have to worry about # about emitting in-range trampolines for out-of-range targets. # We can probably remove this and emit trampolines in the future: - "-fno-plt", + # "-fno-plt", # Don't call stack-smashing canaries that we can't find or patch: "-fno-stack-protector", "-o", @@ -262,7 +262,7 @@ class _ELF( def _handle_section( self, section: _schema.ELFSection, group: _stencils.StencilGroup ) -> None: - section_type = section["Type"]["Value"] + section_type = section["Type"]["Name"] flags = {flag["Name"] for flag in section["Flags"]["Flags"]} if section_type == "SHT_RELA": assert "SHF_INFO_LINK" in flags, flags @@ -290,7 +290,7 @@ def _handle_section( for wrapped_symbol in section["Symbols"]: symbol = wrapped_symbol["Symbol"] offset = len(stencil.body) + symbol["Value"] - name = symbol["Name"]["Value"] + name = symbol["Name"]["Name"] name = name.removeprefix(self.prefix) group.symbols[name] = value, offset stencil.body.extend(section["SectionData"]["Bytes"]) @@ -312,9 +312,9 @@ def _handle_relocation( case { "Addend": addend, "Offset": offset, - "Symbol": {"Value": s}, + "Symbol": {"Name": s}, "Type": { - "Value": "R_AARCH64_ADR_GOT_PAGE" + "Name": "R_AARCH64_ADR_GOT_PAGE" | "R_AARCH64_LD64_GOT_LO12_NC" | "R_X86_64_GOTPCREL" | "R_X86_64_GOTPCRELX" @@ -327,8 +327,8 @@ def _handle_relocation( case { "Addend": addend, "Offset": offset, - "Symbol": {"Value": s}, - "Type": {"Value": kind}, + "Symbol": {"Name": s}, + "Type": {"Name": kind}, }: offset += base s = s.removeprefix(self.prefix) @@ -371,7 +371,7 @@ def _handle_section( for wrapped_symbol in section["Symbols"]: symbol = wrapped_symbol["Symbol"] offset = symbol["Value"] - start_address - name = symbol["Name"]["Value"] + name = symbol["Name"]["Name"] name = name.removeprefix(self.prefix) group.symbols[name] = value, offset assert "Relocations" in section @@ -431,8 +431,8 @@ def _handle_relocation( "Type": {"Value": kind}, } | { "Offset": offset, - "Symbol": {"Value": s}, - "Type": {"Value": kind}, + "Symbol": {"Name": s}, + "Type": {"Name": kind}, }: offset += base s = s.removeprefix(self.prefix) @@ -446,8 +446,7 @@ def _handle_relocation( def get_target(host: str) -> _COFF | _ELF | _MachO: """Build a _Target for the given host "triple" and options.""" if re.fullmatch(r"aarch64-apple-darwin.*", host): - args = ["-mcmodel=large"] - return _MachO(host, alignment=8, args=args, prefix="_") + return _MachO(host, alignment=8, prefix="_") if re.fullmatch(r"aarch64-pc-windows-msvc", host): args = ["-fms-runtime-lib=dll"] return _COFF(host, alignment=8, args=args) From 3a5a0e914b016ea3a2bc92f09d0b5618d04ee9b5 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 20:37:13 -0700 Subject: [PATCH 02/26] uncomment --- Tools/jit/_targets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index c1b89da8dd0ec8..150b94a119c990 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -127,7 +127,7 @@ async def _compile( # Emit relaxable 64-bit calls/jumps, so we don't have to worry about # about emitting in-range trampolines for out-of-range targets. # We can probably remove this and emit trampolines in the future: - # "-fno-plt", + "-fno-plt", # Don't call stack-smashing canaries that we can't find or patch: "-fno-stack-protector", "-o", From 186fef05f4c8cdaa6fadc3a00413fbcef8b728dc Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 21:46:22 -0700 Subject: [PATCH 03/26] Minor updates for windows --- Tools/jit/_targets.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 150b94a119c990..bb2590604d3d59 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -221,7 +221,7 @@ def _handle_relocation( case { "Offset": offset, "Symbol": s, - "Type": {"Value": "IMAGE_REL_I386_DIR32" as kind}, + "Type": {"Name": "IMAGE_REL_I386_DIR32" as kind}, }: offset += base value, symbol = self._unwrap_dllimport(s) @@ -230,7 +230,7 @@ def _handle_relocation( "Offset": offset, "Symbol": s, "Type": { - "Value": "IMAGE_REL_AMD64_REL32" | "IMAGE_REL_I386_REL32" as kind + "Name": "IMAGE_REL_AMD64_REL32" | "IMAGE_REL_I386_REL32" as kind }, }: offset += base @@ -242,7 +242,7 @@ def _handle_relocation( "Offset": offset, "Symbol": s, "Type": { - "Value": "IMAGE_REL_ARM64_BRANCH26" + "Name": "IMAGE_REL_ARM64_BRANCH26" | "IMAGE_REL_ARM64_PAGEBASE_REL21" | "IMAGE_REL_ARM64_PAGEOFFSET_12A" | "IMAGE_REL_ARM64_PAGEOFFSET_12L" as kind From c0b63d27fc10894d96bc60593eafa8bb994ee5d1 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 21:53:00 -0700 Subject: [PATCH 04/26] llvm in CI --- .github/workflows/jit.yml | 2 +- Tools/jit/_targets.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index b37eb727955909..dc6eba0341f444 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -41,7 +41,7 @@ jobs: - true - false llvm: - - 16 + - 18 include: - target: i686-pc-windows-msvc/msvc architecture: Win32 diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index bb2590604d3d59..ee2dbf1ab83c14 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -446,7 +446,8 @@ def _handle_relocation( def get_target(host: str) -> _COFF | _ELF | _MachO: """Build a _Target for the given host "triple" and options.""" if re.fullmatch(r"aarch64-apple-darwin.*", host): - return _MachO(host, alignment=8, prefix="_") + 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) From 8e318695452407df31443e371d50a78aae38b81b Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 22:08:50 -0700 Subject: [PATCH 05/26] add brew update to gha --- .github/workflows/jit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index dc6eba0341f444..a4bb411d04f6f4 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -108,6 +108,7 @@ jobs: - name: Native macOS if: runner.os == 'macOS' run: | + brew update brew install llvm@${{ matrix.llvm }} SDKROOT="$(xcrun --show-sdk-path)" \ ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations --with-lto' }} From ad6d55468da41a3adb84beaf49830917dfd9ee32 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 22:13:18 -0700 Subject: [PATCH 06/26] remove file --- .github/workflows/jit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index a4bb411d04f6f4..937f976d9b25c0 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -94,6 +94,7 @@ jobs: - name: Native Windows if: runner.os == 'Windows' && matrix.architecture != 'ARM64' run: | + choco upgrade chocolatey 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 4500 --verbose2 --verbose3 From d546621f013acc00f38757c09f90f8749bd9b85f Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 22:19:43 -0700 Subject: [PATCH 07/26] choco? --- .github/workflows/jit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 937f976d9b25c0..a4ac4aa6592891 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -94,7 +94,7 @@ jobs: - name: Native Windows if: runner.os == 'Windows' && matrix.architecture != 'ARM64' run: | - choco upgrade chocolatey + choco upgrade all 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 4500 --verbose2 --verbose3 From 2526e81883a50219051f25bfbc98f781e7bec4bd Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 22:27:21 -0700 Subject: [PATCH 08/26] debugging windows runners --- .github/workflows/jit.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index a4ac4aa6592891..f63f3aa6a3a55c 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -95,7 +95,7 @@ jobs: if: runner.os == 'Windows' && matrix.architecture != 'ARM64' run: | choco upgrade all - choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }} + choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }} --debug --verbose --noop ./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 4500 --verbose2 --verbose3 @@ -103,6 +103,7 @@ jobs: - name: Emulated Windows if: runner.os == 'Windows' && matrix.architecture == 'ARM64' run: | + choco upgrade all --debug --verbose --noop choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }} ./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} From 9e0afdf1a4d6fcf0df03ab55f4936a32376c21ea Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 22:33:53 -0700 Subject: [PATCH 09/26] add -y --- .github/workflows/jit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index f63f3aa6a3a55c..83c9c175fa7e6b 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -94,7 +94,7 @@ jobs: - name: Native Windows if: runner.os == 'Windows' && matrix.architecture != 'ARM64' run: | - choco upgrade all + choco upgrade all -y choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }} --debug --verbose --noop ./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 4500 --verbose2 --verbose3 From b0ed125e79ef8c044335eccf91150b8143119377 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 24 Apr 2024 22:39:03 -0700 Subject: [PATCH 10/26] add -y to choco for emulated windows --- .github/workflows/jit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 83c9c175fa7e6b..cd098e87bff89b 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -94,7 +94,7 @@ jobs: - name: Native Windows if: runner.os == 'Windows' && matrix.architecture != 'ARM64' run: | - choco upgrade all -y + choco upgrade llvm -y choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }} --debug --verbose --noop ./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 4500 --verbose2 --verbose3 @@ -103,7 +103,7 @@ jobs: - name: Emulated Windows if: runner.os == 'Windows' && matrix.architecture == 'ARM64' run: | - choco upgrade all --debug --verbose --noop + choco upgrade llvm -y choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }} ./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} From 3eeb3f072cfa0ad5a835d157e7c59d1f67916a29 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 19:40:04 -0700 Subject: [PATCH 11/26] instruction in jit.c and remove -mcmodel=large --- Python/jit.c | 3 +-- Tools/jit/_stencils.py | 2 +- Tools/jit/_targets.py | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Python/jit.c b/Python/jit.c index 7ac9ac6dfe6d60..987b5c7946c93f 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -237,6 +237,7 @@ patch(unsigned char *base, const Stencil *stencil, uintptr_t patches[]) case HoleKind_IMAGE_REL_ARM64_BRANCH26: case HoleKind_R_AARCH64_CALL26: case HoleKind_R_AARCH64_JUMP26: + case HoleKind_ARM64_RELOC_BRANCH26: // 28-bit relative branch. assert(IS_AARCH64_BRANCH(*loc32)); value -= (uintptr_t)location; @@ -278,7 +279,6 @@ patch(unsigned char *base, const Stencil *stencil, uintptr_t patches[]) case HoleKind_ARM64_RELOC_GOT_LOAD_PAGE21: case HoleKind_IMAGE_REL_ARM64_PAGEBASE_REL21: case HoleKind_R_AARCH64_ADR_GOT_PAGE: - case HoleKind_ARM64_RELOC_BRANCH26: // 21-bit count of pages between this page and an absolute address's // page... I know, I know, it's weird. Pairs nicely with // ARM64_RELOC_GOT_LOAD_PAGEOFF12 (below). @@ -288,7 +288,6 @@ patch(unsigned char *base, const Stencil *stencil, uintptr_t patches[]) 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_ARM64_RELOC_BRANCH26 || next_hole->kind == HoleKind_R_AARCH64_LD64_GOT_LO12_NC) && next_hole->offset == hole->offset + 4 && next_hole->symbol == hole->symbol && diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 243bb3dd134f70..3cf6f424355236 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -203,7 +203,7 @@ def process_relocations(self, *, alignment: int = 1) -> None: """Fix up all GOT and internal relocations for this stencil group.""" for hole in self.code.holes.copy(): if ( - hole.kind in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26"} + hole.kind in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM_RELOC_BRANCH26"} and hole.value is HoleValue.ZERO ): self.code.pad(alignment) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index ee2dbf1ab83c14..a6e33ef4631cae 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -136,6 +136,7 @@ async def _compile( f"{c}", *self.args, ] + print(args) await _llvm.run("clang", args, echo=self.verbose) return await self._parse(o) @@ -446,8 +447,9 @@ def _handle_relocation( def get_target(host: str) -> _COFF | _ELF | _MachO: """Build a _Target for the given host "triple" and options.""" if re.fullmatch(r"aarch64-apple-darwin.*", host): - args = ["-mcmodel=large"] - return _MachO(host, alignment=8, args=args, prefix="_") + # -mcmodel=large is unsupported in LLVM 18 + # (see https://github.com/llvm/llvm-project/pull/70262) + return _MachO(host, alignment=8, prefix="_") if re.fullmatch(r"aarch64-pc-windows-msvc", host): args = ["-fms-runtime-lib=dll"] return _COFF(host, alignment=8, args=args) From 40bcebf4186ee7aa287ca7ec4decdfe57c5fa807 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 20:37:16 -0700 Subject: [PATCH 12/26] Fix instructions and MachO parsing --- Tools/jit/_stencils.py | 2 +- Tools/jit/_targets.py | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 3cf6f424355236..0be3f5b48ad823 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -203,7 +203,7 @@ def process_relocations(self, *, alignment: int = 1) -> None: """Fix up all GOT and internal relocations for this stencil group.""" for hole in self.code.holes.copy(): if ( - hole.kind in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM_RELOC_BRANCH26"} + hole.kind in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"} and hole.value is HoleValue.ZERO ): self.code.pad(alignment) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index a6e33ef4631cae..644efc0ae9135b 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -136,7 +136,6 @@ async def _compile( f"{c}", *self.args, ] - print(args) await _llvm.run("clang", args, echo=self.verbose) return await self._parse(o) @@ -388,9 +387,9 @@ def _handle_relocation( match relocation: case { "Offset": offset, - "Symbol": {"Value": s}, + "Symbol": {"Name": s}, "Type": { - "Value": "ARM64_RELOC_GOT_LOAD_PAGE21" + "Name": "ARM64_RELOC_GOT_LOAD_PAGE21" | "ARM64_RELOC_GOT_LOAD_PAGEOFF12" as kind }, }: @@ -400,8 +399,8 @@ def _handle_relocation( addend = 0 case { "Offset": offset, - "Symbol": {"Value": s}, - "Type": {"Value": "X86_64_RELOC_GOT" | "X86_64_RELOC_GOT_LOAD" as kind}, + "Symbol": {"Name": s}, + "Type": {"Name": "X86_64_RELOC_GOT" | "X86_64_RELOC_GOT_LOAD" as kind}, }: offset += base s = s.removeprefix(self.prefix) @@ -411,13 +410,13 @@ def _handle_relocation( ) case { "Offset": offset, - "Section": {"Value": s}, - "Type": {"Value": "X86_64_RELOC_SIGNED" as kind}, + "Section": {"Name": s}, + "Type": {"Name": "X86_64_RELOC_SIGNED" as kind}, } | { "Offset": offset, - "Symbol": {"Value": s}, + "Symbol": {"Name": s}, "Type": { - "Value": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind + "Name": "X86_64_RELOC_BRANCH" | "X86_64_RELOC_SIGNED" as kind }, }: offset += base @@ -428,8 +427,8 @@ def _handle_relocation( ) case { "Offset": offset, - "Section": {"Value": s}, - "Type": {"Value": kind}, + "Section": {"Name": s}, + "Type": {"Name": kind}, } | { "Offset": offset, "Symbol": {"Name": s}, From c02ec004d0db201f97ce8a95b9cbdef4bed586a3 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 20:49:42 -0700 Subject: [PATCH 13/26] remove mcmodel=large for aarch linux --- Tools/jit/_targets.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 644efc0ae9135b..99e1580dfb78e9 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -453,8 +453,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO: 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) + return _ELF(host, alignment=8) if re.fullmatch(r"i686-pc-windows-msvc", host): args = ["-DPy_NO_ENABLE_SHARED"] return _COFF(host, args=args, prefix="_") From 5d4dede022b5d1e81c230ac805f931b25a1072e7 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 21:28:55 -0700 Subject: [PATCH 14/26] add unhandled ELF instructions; --- Python/jit.c | 2 ++ Tools/jit/_schema.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Python/jit.c b/Python/jit.c index 987b5c7946c93f..2947376bb78619 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -279,6 +279,7 @@ patch(unsigned char *base, const Stencil *stencil, uintptr_t patches[]) 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_PREL_PG_HI21: // 21-bit count of pages between this page and an absolute address's // page... I know, I know, it's weird. Pairs nicely with // ARM64_RELOC_GOT_LOAD_PAGEOFF12 (below). @@ -342,6 +343,7 @@ patch(unsigned char *base, const Stencil *stencil, uintptr_t patches[]) case HoleKind_ARM64_RELOC_PAGEOFF12: case HoleKind_IMAGE_REL_ARM64_PAGEOFFSET_12A: case HoleKind_IMAGE_REL_ARM64_PAGEOFFSET_12L: + case HoleKind_R_AARCH64_ADD_ABS_LO12_NC: 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). diff --git a/Tools/jit/_schema.py b/Tools/jit/_schema.py index b7da4356d80df4..418c9c930549aa 100644 --- a/Tools/jit/_schema.py +++ b/Tools/jit/_schema.py @@ -17,8 +17,10 @@ "IMAGE_REL_I386_REL32", "R_AARCH64_ABS64", "R_AARCH64_ADR_GOT_PAGE", + "R_AARCH64_ADR_PREL_PG_HI21", "R_AARCH64_CALL26", "R_AARCH64_JUMP26", + "R_AARCH64_ADD_ABS_LO12_NC", "R_AARCH64_LD64_GOT_LO12_NC", "R_AARCH64_MOVW_UABS_G0_NC", "R_AARCH64_MOVW_UABS_G1_NC", From bf5aa36b8767afa16a011e790b3f0c5d86a8c8c5 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 21:42:27 -0700 Subject: [PATCH 15/26] update workflow to install all llvm on native linux --- .github/workflows/jit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index cd098e87bff89b..3344932a310b3c 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -120,7 +120,7 @@ jobs: - name: Native Linux if: runner.os == 'Linux' && matrix.architecture == 'x86_64' run: | - sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }} + sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }} all export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH" ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations --with-lto' }} make all --jobs 4 From a79a39b29aa1468337172dc6860d6f8fe68cf880 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 21:51:59 -0700 Subject: [PATCH 16/26] remove --with-lto --- .github/workflows/jit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 3344932a310b3c..a8f78881271ecc 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -122,7 +122,7 @@ jobs: run: | sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }} all export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH" - ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations --with-lto' }} + ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations' }} make all --jobs 4 ./python -m test --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 4500 --verbose2 --verbose3 From dd283e3e7579a4e4ee6cf73665f6ab548fd0c01e Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 22:01:22 -0700 Subject: [PATCH 17/26] remove lto from emulated linux --- .github/workflows/jit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index a8f78881271ecc..bd6b32f342ca02 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -120,7 +120,7 @@ jobs: - name: Native Linux if: runner.os == 'Linux' && matrix.architecture == 'x86_64' run: | - sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }} all + sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }} export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH" ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations' }} make all --jobs 4 @@ -142,6 +142,6 @@ jobs: CC="${{ matrix.compiler == 'clang' && 'clang --target=$HOST' || '$HOST-gcc' }}" \ CPP="$CC --preprocess" \ HOSTRUNNER=qemu-${{ matrix.architecture }} \ - ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations --with-lto' }} --build=x86_64-linux-gnu --host="$HOST" --with-build-python=../build/bin/python3 --with-pkg-config=no ac_cv_buggy_getaddrinfo=no ac_cv_file__dev_ptc=no ac_cv_file__dev_ptmx=yes + ./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations ' }} --build=x86_64-linux-gnu --host="$HOST" --with-build-python=../build/bin/python3 --with-pkg-config=no ac_cv_buggy_getaddrinfo=no ac_cv_file__dev_ptc=no ac_cv_file__dev_ptmx=yes make all --jobs 4 ./python -m test --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 4500 --verbose2 --verbose3 From 8d59ff8366bb041fc00d303503cf1a6feb4a8448 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 22:36:31 -0700 Subject: [PATCH 18/26] update comments --- .github/workflows/jit.yml | 2 ++ Tools/jit/_targets.py | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index bd6b32f342ca02..6098c93abca6b6 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -117,6 +117,7 @@ jobs: make all --jobs 4 ./python.exe -m test --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 4500 --verbose2 --verbose3 + # --with-lto has been removed temporarily as a result of an open issue in LLVM 18 (see https://github.com/llvm/llvm-project/issues/87553) - name: Native Linux if: runner.os == 'Linux' && matrix.architecture == 'x86_64' run: | @@ -126,6 +127,7 @@ jobs: make all --jobs 4 ./python -m test --exclude ${{ matrix.exclude }} --multiprocess 0 --timeout 4500 --verbose2 --verbose3 + # --with-lto has been removed temporarily as a result of an open issue in LLVM 18 (see https://github.com/llvm/llvm-project/issues/87553) - name: Emulated Linux if: runner.os == 'Linux' && matrix.architecture != 'x86_64' run: | diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 99e1580dfb78e9..8cc4441f8e3dff 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -446,8 +446,6 @@ def _handle_relocation( def get_target(host: str) -> _COFF | _ELF | _MachO: """Build a _Target for the given host "triple" and options.""" if re.fullmatch(r"aarch64-apple-darwin.*", host): - # -mcmodel=large is unsupported in LLVM 18 - # (see https://github.com/llvm/llvm-project/pull/70262) return _MachO(host, alignment=8, prefix="_") if re.fullmatch(r"aarch64-pc-windows-msvc", host): args = ["-fms-runtime-lib=dll"] From 9433e30f0567b020560a4d1406ae71b080263636 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 26 Apr 2024 05:38:19 +0000 Subject: [PATCH 19/26] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-04-26-05-38-18.gh-issue-118306.vRUEOU.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-04-26-05-38-18.gh-issue-118306.vRUEOU.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-26-05-38-18.gh-issue-118306.vRUEOU.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-26-05-38-18.gh-issue-118306.vRUEOU.rst new file mode 100644 index 00000000000000..051295541ab7e2 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-26-05-38-18.gh-issue-118306.vRUEOU.rst @@ -0,0 +1 @@ +Update JIT compilation to use LLVM 18 From 6617ad45bd814b265de216cc12a65231838b2d57 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 25 Apr 2024 22:49:00 -0700 Subject: [PATCH 20/26] update classes for ELF and MachO symbol types --- Tools/jit/_schema.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/jit/_schema.py b/Tools/jit/_schema.py index 418c9c930549aa..7ad0526a89d755 100644 --- a/Tools/jit/_schema.py +++ b/Tools/jit/_schema.py @@ -71,12 +71,12 @@ class _COFFSymbol(typing.TypedDict): class _ELFSymbol(typing.TypedDict): - Name: dict[typing.Literal["Value"], str] + Name: dict[typing.Literal["Name"], str] Value: int class _MachOSymbol(typing.TypedDict): - Name: dict[typing.Literal["Value"], str] + Name: dict[typing.Literal["Name"], str] Value: int From 8d9855fb1607ba255f6957048740735277d3a619 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 26 Apr 2024 12:04:09 -0700 Subject: [PATCH 21/26] Update .github/workflows/jit.yml Co-authored-by: Brandt Bucher --- .github/workflows/jit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 6098c93abca6b6..b969e6d13e61a3 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -95,7 +95,7 @@ jobs: if: runner.os == 'Windows' && matrix.architecture != 'ARM64' run: | choco upgrade llvm -y - choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }} --debug --verbose --noop + 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 4500 --verbose2 --verbose3 From 72d366aea1e6e3a9d072fd7fab21641e331b1f35 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 26 Apr 2024 13:26:53 -0700 Subject: [PATCH 22/26] Update Tools/jit/_stencils.py Co-authored-by: Brandt Bucher --- Tools/jit/_stencils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 0be3f5b48ad823..f8ecffcf3ddda2 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -203,7 +203,9 @@ def process_relocations(self, *, alignment: int = 1) -> None: """Fix up all GOT and internal relocations for this stencil group.""" for hole in self.code.holes.copy(): if ( - hole.kind in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"} + hole.kind in { + "R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26" + } and hole.value is HoleValue.ZERO ): self.code.pad(alignment) From 71954a04a8e2219bc625561b20113c2ef1ef60d8 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Fri, 26 Apr 2024 15:02:31 -0700 Subject: [PATCH 23/26] address PR comments --- Python/jit.c | 2 +- Tools/jit/_schema.py | 7 +------ Tools/jit/_stencils.py | 4 +++- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Python/jit.c b/Python/jit.c index 2947376bb78619..75ec4fb9756eb7 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -234,10 +234,10 @@ patch(unsigned char *base, const Stencil *stencil, uintptr_t patches[]) assert((int64_t)value < (1LL << 31)); *loc32 = (uint32_t)value; continue; + case HoleKind_ARM64_RELOC_BRANCH26: case HoleKind_IMAGE_REL_ARM64_BRANCH26: case HoleKind_R_AARCH64_CALL26: case HoleKind_R_AARCH64_JUMP26: - case HoleKind_ARM64_RELOC_BRANCH26: // 28-bit relative branch. assert(IS_AARCH64_BRANCH(*loc32)); value -= (uintptr_t)location; diff --git a/Tools/jit/_schema.py b/Tools/jit/_schema.py index 7ad0526a89d755..6ec9eb29b1eba9 100644 --- a/Tools/jit/_schema.py +++ b/Tools/jit/_schema.py @@ -92,11 +92,6 @@ class COFFSection(typing.TypedDict): SectionData: typing.NotRequired[dict[typing.Literal["Bytes"], list[int]]] Symbols: list[dict[typing.Literal["Symbol"], _COFFSymbol]] -class _ElfSectionType(typing.TypedDict): - """An ELF object file section type.""" - Name: str - Value: int - class ELFSection(typing.TypedDict): """An ELF object file section.""" @@ -106,7 +101,7 @@ class ELFSection(typing.TypedDict): Relocations: list[dict[typing.Literal["Relocation"], ELFRelocation]] SectionData: dict[typing.Literal["Bytes"], list[int]] Symbols: list[dict[typing.Literal["Symbol"], _ELFSymbol]] - Type: _ElfSectionType + Type: dict[typing.Literal["Name"], str] class MachOSection(typing.TypedDict): """A Mach-O object file section.""" diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 0be3f5b48ad823..f8ecffcf3ddda2 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -203,7 +203,9 @@ def process_relocations(self, *, alignment: int = 1) -> None: """Fix up all GOT and internal relocations for this stencil group.""" for hole in self.code.holes.copy(): if ( - hole.kind in {"R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26"} + hole.kind in { + "R_AARCH64_CALL26", "R_AARCH64_JUMP26", "ARM64_RELOC_BRANCH26" + } and hole.value is HoleValue.ZERO ): self.code.pad(alignment) From 80b9e1c2fb2bc85c5021ea5ad9a0b358f340c6dc Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sat, 27 Apr 2024 18:03:14 +0000 Subject: [PATCH 24/26] add -fPIC --- Tools/jit/_targets.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 8cc4441f8e3dff..fee447bf2d1707 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -451,7 +451,8 @@ def get_target(host: str) -> _COFF | _ELF | _MachO: args = ["-fms-runtime-lib=dll"] return _COFF(host, alignment=8, args=args) if re.fullmatch(r"aarch64-.*-linux-gnu", host): - return _ELF(host, alignment=8) + args = ["-fPIC"] + return _ELF(host, args=args, alignment=8) if re.fullmatch(r"i686-pc-windows-msvc", host): args = ["-DPy_NO_ENABLE_SHARED"] return _COFF(host, args=args, prefix="_") @@ -461,5 +462,6 @@ def get_target(host: str) -> _COFF | _ELF | _MachO: args = ["-fms-runtime-lib=dll"] return _COFF(host, args=args) if re.fullmatch(r"x86_64-.*-linux-gnu", host): - return _ELF(host) + args = ["-fPIC"] + return _ELF(host, args=args) raise ValueError(host) From 1808f6aa61816ac52a282cb87e8ca727e2f0574a Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sat, 27 Apr 2024 11:35:47 -0700 Subject: [PATCH 25/26] fix ordering of args for consistency --- Tools/jit/_targets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index fee447bf2d1707..5582066a635b83 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -452,7 +452,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO: return _COFF(host, alignment=8, args=args) if re.fullmatch(r"aarch64-.*-linux-gnu", host): args = ["-fPIC"] - return _ELF(host, args=args, alignment=8) + return _ELF(host, alignment=8, args=args) if re.fullmatch(r"i686-pc-windows-msvc", host): args = ["-DPy_NO_ENABLE_SHARED"] return _COFF(host, args=args, prefix="_") From 5717a819ac4fb1f11fa53a44d5715e0ec013e5fe Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Mon, 29 Apr 2024 11:52:26 -0700 Subject: [PATCH 26/26] Formatting nits --- Tools/jit/README.md | 2 +- Tools/jit/_schema.py | 2 ++ Tools/jit/_targets.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Tools/jit/README.md b/Tools/jit/README.md index e78f1ea3a35279..7b33f99d23f75d 100644 --- a/Tools/jit/README.md +++ b/Tools/jit/README.md @@ -35,7 +35,7 @@ Homebrew won't add any of the tools to your `$PATH`. That's okay; the build scri Install LLVM 18 [by searching for it on LLVM's GitHub releases page](https://github.com/llvm/llvm-project/releases?q=18), clicking on "Assets", downloading the appropriate Windows installer for your platform (likely the file ending with `-win64.exe`), and running it. **When installing, be sure to select the option labeled "Add LLVM to the system PATH".** -## Devcontainers +### Dev Containers If you are working CPython in a [Codespaces instance](https://devguide.python.org/getting-started/setup-building/#using-codespaces), there's no need to install LLVM as the Fedora 40 base image includes LLVM 18 out of the box. diff --git a/Tools/jit/_schema.py b/Tools/jit/_schema.py index 6ec9eb29b1eba9..6aef887e12475b 100644 --- a/Tools/jit/_schema.py +++ b/Tools/jit/_schema.py @@ -92,6 +92,7 @@ class COFFSection(typing.TypedDict): SectionData: typing.NotRequired[dict[typing.Literal["Bytes"], list[int]]] Symbols: list[dict[typing.Literal["Symbol"], _COFFSymbol]] + class ELFSection(typing.TypedDict): """An ELF object file section.""" @@ -103,6 +104,7 @@ class ELFSection(typing.TypedDict): Symbols: list[dict[typing.Literal["Symbol"], _ELFSymbol]] Type: dict[typing.Literal["Name"], str] + class MachOSection(typing.TypedDict): """A Mach-O object file section.""" diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 5582066a635b83..91734b36b4ab1b 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -451,7 +451,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO: args = ["-fms-runtime-lib=dll"] return _COFF(host, alignment=8, args=args) if re.fullmatch(r"aarch64-.*-linux-gnu", host): - args = ["-fPIC"] + args = ["-fpic"] return _ELF(host, alignment=8, args=args) if re.fullmatch(r"i686-pc-windows-msvc", host): args = ["-DPy_NO_ENABLE_SHARED"] @@ -462,6 +462,6 @@ def get_target(host: str) -> _COFF | _ELF | _MachO: args = ["-fms-runtime-lib=dll"] return _COFF(host, args=args) if re.fullmatch(r"x86_64-.*-linux-gnu", host): - args = ["-fPIC"] + args = ["-fpic"] return _ELF(host, args=args) raise ValueError(host)