Skip to content

GH-115802: JIT "small" code for macOS and Linux #115826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 26, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove references to IMAGE_REL_AMD64_REL32 and clean up comments
  • Loading branch information
brandtbucher committed Feb 22, 2024
commit 36de1cd4a879d9d6401008c5e52b7d75ac8c30f3
34 changes: 6 additions & 28 deletions Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,31 +221,18 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
(int64_t)relaxed - (int64_t)location + 1 < (1LL << 31))
{
if (loc8[-2] == 0x8B) {
// Before: mov eax, dword ptr [rip + AAA]
// After: lea eax, [rip + XXX]
assert(hole->kind == HoleKind_IMAGE_REL_AMD64_REL32 ||
hole->kind == HoleKind_R_X86_64_GOTPCRELX ||
hole->kind == HoleKind_R_X86_64_REX_GOTPCRELX ||
hole->kind == HoleKind_X86_64_RELOC_GOT_LOAD);
// mov reg, dword ptr [rip + AAA] -> lea reg, [rip + XXX]
loc8[-2] = 0x8D;
value = relaxed;
}
else if (loc8[-2] == 0xFF && loc8[-1] == 0x15) {
// Before: call qword ptr [rip + AAA]
// After: nop
// call XXX
assert(hole->kind == HoleKind_R_X86_64_GOTPCRELX ||
hole->kind == HoleKind_X86_64_RELOC_GOT);
// call qword ptr [rip + AAA] -> nop; call XXX
loc8[-2] = 0x90;
loc8[-1] = 0xE8;
value = relaxed;
}
else if (loc8[-2] == 0xFF && loc8[-1] == 0x25) {
// Before: jmp qword ptr [rip + AAA]
// After: nop
// jmp XXX
assert(hole->kind == HoleKind_IMAGE_REL_AMD64_REL32 ||
hole->kind == HoleKind_R_X86_64_GOTPCRELX);
// jmp qword ptr [rip + AAA] -> nop; jmp XXX
loc8[-2] = 0x90;
loc8[-1] = 0xE9;
value = relaxed;
Expand Down Expand Up @@ -326,20 +313,14 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
assert(rd == rn && rn == rt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert(rd == rn && rn == rt);
assert(rd == get_bits(loc32[1], 5, 5) && rd == get_bits(loc32[1], 0, 5));

uint64_t relaxed = *(uint64_t *)value;
if (relaxed < (1UL << 16)) {
// Before: adrp x0, AAA
// ldr x0, [x0 + BBB]
// After: movz x0, XXX
// nop
// adrp reg, AAA; ldr reg, [reg + BBB] -> movz reg, XXX; nop
loc32[0] = 0xD2800000 | (get_bits(relaxed, 0, 16) << 5) | rd;
loc32[1] = 0xD503201F;
i++;
continue;
}
if (relaxed < (1ULL << 32)) {
// Before: adrp x0, AAA
// ldr x0, [x0 + BBB]
// After: movz x0, XXX
// movk x0, YYY
// adrp reg, AAA; ldr reg, [reg + BBB] -> movz reg, XXX; movk reg, YYY
loc32[0] = 0xD2800000 | (get_bits(relaxed, 0, 16) << 5) | rd;
loc32[1] = 0xF2A00000 | (get_bits(relaxed, 16, 16) << 5) | rd;
i++;
Expand All @@ -350,10 +331,7 @@ patch(unsigned char *base, const Stencil *stencil, uint64_t *patches)
(int64_t)relaxed >= -(1L << 19) &&
(int64_t)relaxed < (1L << 19))
{
// Before: adrp x0, AAA
// ldr x0, [x0 + BBB]
// After: ldr x0, XXX
// nop
// adrp reg, AAA; ldr reg, [reg + BBB] -> ldr x0, XXX; nop
loc32[0] = 0x58000000 | (get_bits(relaxed, 2, 19) << 5) | rd;
loc32[1] = 0xD503201F;
i++;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy