Skip to content

Commit 5d8db36

Browse files
authored
GH-115802: JIT using the "medium" code model on x86_64-unknown-linux-gnu (GH-130097)
1 parent d7bb7c7 commit 5d8db36

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use the more efficient "medium" code model for JIT-compiled code on
2+
supported platforms.

Tools/jit/_stencils.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ class HoleValue(enum.Enum):
8484
"R_AARCH64_MOVW_UABS_G3": "patch_aarch64_16d",
8585
# x86_64-unknown-linux-gnu:
8686
"R_X86_64_64": "patch_64",
87-
"R_X86_64_GOTPCREL": "patch_32r",
8887
"R_X86_64_GOTPCRELX": "patch_x86_64_32rx",
89-
"R_X86_64_PC32": "patch_32r",
88+
"R_X86_64_PLT32": "patch_32r",
9089
"R_X86_64_REX_GOTPCRELX": "patch_x86_64_32rx",
9190
# x86_64-apple-darwin:
9291
"X86_64_RELOC_BRANCH": "patch_32r",
@@ -226,11 +225,11 @@ def remove_jump(self, *, alignment: int = 1) -> None:
226225
offset -= 3
227226
case Hole(
228227
offset=offset,
229-
kind="IMAGE_REL_I386_REL32" | "X86_64_RELOC_BRANCH",
228+
kind="IMAGE_REL_I386_REL32" | "R_X86_64_PLT32" | "X86_64_RELOC_BRANCH",
230229
value=HoleValue.CONTINUE,
231230
symbol=None,
232-
addend=-4,
233-
) as hole:
231+
addend=addend,
232+
) as hole if _signed(addend) == -4:
234233
# jmp 5
235234
jump = b"\xE9\x00\x00\x00\x00"
236235
offset -= 1
@@ -243,17 +242,6 @@ def remove_jump(self, *, alignment: int = 1) -> None:
243242
) as hole:
244243
# b #4
245244
jump = b"\x00\x00\x00\x14"
246-
case Hole(
247-
offset=offset,
248-
kind="R_X86_64_GOTPCRELX",
249-
value=HoleValue.GOT,
250-
symbol="_JIT_CONTINUE",
251-
addend=addend,
252-
) as hole:
253-
assert _signed(addend) == -4
254-
# jmp qword ptr [rip]
255-
jump = b"\xFF\x25\x00\x00\x00\x00"
256-
offset -= 2
257245
case _:
258246
return
259247
if self.body[offset:] == jump and offset % alignment == 0:

Tools/jit/_targets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
522522
args = ["-fms-runtime-lib=dll"]
523523
target = _COFF(host, args=args)
524524
elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
525-
args = ["-fpic"]
525+
args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0"]
526526
target = _ELF(host, args=args)
527527
else:
528528
raise ValueError(host)

0 commit comments

Comments
 (0)