Skip to content

Commit f4c05b3

Browse files
committed
Add expected output for macOS
1 parent e1eb85d commit f4c05b3

9 files changed

+300
-21
lines changed

Lib/test/test_jit_stencils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ def test_jit_stencils(self):
6565
self._check_jit_stencils(expected, actual, test_jit_stencils_h)
6666
# This is a local build. If the JIT is available, at least one test should run:
6767
assert found or not sys._jit.is_available(), "No JIT stencils built!"
68+
69+
70+
if __name__ == "__main__":
71+
unittest.main()

Tools/jit/_targets.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
8686
lines = output.splitlines()
8787
started = False
8888
for line in lines:
89-
if not started:
90-
if "_JIT_ENTRY" not in line:
91-
continue
89+
if line.lstrip().startswith("0:"):
9290
started = True
93-
cleaned = line.replace(long, short).expandtabs().strip()
94-
if cleaned:
95-
group.code.disassembly.append(cleaned)
91+
if started:
92+
cleaned = line.replace(long, short).expandtabs().strip()
93+
if cleaned:
94+
group.code.disassembly.append(cleaned)
9695
args = [
9796
"--elf-output-style=JSON",
9897
"--expand-relocs",
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
void
2+
emit_shim(
3+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
4+
const _PyUOpInstruction *instruction, jit_state *state)
5+
{
6+
// 0: 6db63bef stp d15, d14, [sp, #-0xa0]!
7+
// 4: 6d0133ed stp d13, d12, [sp, #0x10]
8+
// 8: 6d022beb stp d11, d10, [sp, #0x20]
9+
// c: 6d0323e9 stp d9, d8, [sp, #0x30]
10+
// 10: a9046ffc stp x28, x27, [sp, #0x40]
11+
// 14: a90567fa stp x26, x25, [sp, #0x50]
12+
// 18: a9065ff8 stp x24, x23, [sp, #0x60]
13+
// 1c: a90757f6 stp x22, x21, [sp, #0x70]
14+
// 20: a9084ff4 stp x20, x19, [sp, #0x80]
15+
// 24: a9097bfd stp x29, x30, [sp, #0x90]
16+
// 28: 910243fd add x29, sp, #0x90
17+
// 2c: aa0003f4 mov x20, x0
18+
// 30: aa0103f5 mov x21, x1
19+
// 34: aa0203f6 mov x22, x2
20+
// 38: 9400000c bl 0x68 <ltmp0+0x68>
21+
// 3c: a9497bfd ldp x29, x30, [sp, #0x90]
22+
// 40: a9484ff4 ldp x20, x19, [sp, #0x80]
23+
// 44: a94757f6 ldp x22, x21, [sp, #0x70]
24+
// 48: a9465ff8 ldp x24, x23, [sp, #0x60]
25+
// 4c: a94567fa ldp x26, x25, [sp, #0x50]
26+
// 50: a9446ffc ldp x28, x27, [sp, #0x40]
27+
// 54: 6d4323e9 ldp d9, d8, [sp, #0x30]
28+
// 58: 6d422beb ldp d11, d10, [sp, #0x20]
29+
// 5c: 6d4133ed ldp d13, d12, [sp, #0x10]
30+
// 60: 6cca3bef ldp d15, d14, [sp], #0xa0
31+
// 64: d65f03c0 ret
32+
const unsigned char code_body[104] = {
33+
0xef, 0x3b, 0xb6, 0x6d, 0xed, 0x33, 0x01, 0x6d,
34+
0xeb, 0x2b, 0x02, 0x6d, 0xe9, 0x23, 0x03, 0x6d,
35+
0xfc, 0x6f, 0x04, 0xa9, 0xfa, 0x67, 0x05, 0xa9,
36+
0xf8, 0x5f, 0x06, 0xa9, 0xf6, 0x57, 0x07, 0xa9,
37+
0xf4, 0x4f, 0x08, 0xa9, 0xfd, 0x7b, 0x09, 0xa9,
38+
0xfd, 0x43, 0x02, 0x91, 0xf4, 0x03, 0x00, 0xaa,
39+
0xf5, 0x03, 0x01, 0xaa, 0xf6, 0x03, 0x02, 0xaa,
40+
0x0c, 0x00, 0x00, 0x94, 0xfd, 0x7b, 0x49, 0xa9,
41+
0xf4, 0x4f, 0x48, 0xa9, 0xf6, 0x57, 0x47, 0xa9,
42+
0xf8, 0x5f, 0x46, 0xa9, 0xfa, 0x67, 0x45, 0xa9,
43+
0xfc, 0x6f, 0x44, 0xa9, 0xe9, 0x23, 0x43, 0x6d,
44+
0xeb, 0x2b, 0x42, 0x6d, 0xed, 0x33, 0x41, 0x6d,
45+
0xef, 0x3b, 0xca, 0x6c, 0xc0, 0x03, 0x5f, 0xd6,
46+
};
47+
memcpy(code, code_body, sizeof(code_body));
48+
}
49+
50+
void
51+
emit_0(
52+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
53+
const _PyUOpInstruction *instruction, jit_state *state)
54+
{
55+
}
56+
57+
void
58+
emit_1(
59+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
60+
const _PyUOpInstruction *instruction, jit_state *state)
61+
{
62+
// 0: a9bf7bfd stp x29, x30, [sp, #-0x10]!
63+
// 4: 910003fd mov x29, sp
64+
// 8: 90000008 adrp x8, 0x0 <ltmp0>
65+
// 0000000000000008: ARM64_RELOC_GOT_LOAD_PAGE21 _sausage
66+
// c: f9400108 ldr x8, [x8]
67+
// 000000000000000c: ARM64_RELOC_GOT_LOAD_PAGEOFF12 _sausage
68+
// 10: 39400108 ldrb w8, [x8]
69+
// 14: 36000068 tbz w8, #0x0, 0x20 <ltmp0+0x20>
70+
// 18: 94000000 bl 0x18 <ltmp0+0x18>
71+
// 0000000000000018: ARM64_RELOC_BRANCH26 _order_eggs_sausage_and_bacon
72+
// 1c: 14000002 b 0x24 <ltmp0+0x24>
73+
// 20: 94000000 bl 0x20 <ltmp0+0x20>
74+
// 0000000000000020: ARM64_RELOC_BRANCH26 _order_eggs_and_bacon
75+
// 24: 90000008 adrp x8, 0x0 <ltmp0>
76+
// 0000000000000024: ARM64_RELOC_GOT_LOAD_PAGE21 _spammed
77+
// 28: f9400108 ldr x8, [x8]
78+
// 0000000000000028: ARM64_RELOC_GOT_LOAD_PAGEOFF12 _spammed
79+
// 2c: 3900011f strb wzr, [x8]
80+
// 30: a8c17bfd ldp x29, x30, [sp], #0x10
81+
const unsigned char code_body[52] = {
82+
0xfd, 0x7b, 0xbf, 0xa9, 0xfd, 0x03, 0x00, 0x91,
83+
0x08, 0x00, 0x00, 0x90, 0x08, 0x01, 0x40, 0xf9,
84+
0x08, 0x01, 0x40, 0x39, 0x68, 0x00, 0x00, 0x36,
85+
0x00, 0x00, 0x00, 0x94, 0x02, 0x00, 0x00, 0x14,
86+
0x00, 0x00, 0x00, 0x94, 0x08, 0x00, 0x00, 0x90,
87+
0x08, 0x01, 0x40, 0xf9, 0x1f, 0x01, 0x00, 0x39,
88+
0xfd, 0x7b, 0xc1, 0xa8,
89+
};
90+
// 0: &spammed+0x0
91+
// 8: &sausage+0x0
92+
patch_64(data + 0x0, (uintptr_t)&spammed);
93+
patch_64(data + 0x8, (uintptr_t)&sausage);
94+
memcpy(code, code_body, sizeof(code_body));
95+
patch_aarch64_33rx(code + 0x8, (uintptr_t)data + 0x8);
96+
patch_aarch64_trampoline(code + 0x18, 0x1, state);
97+
patch_aarch64_trampoline(code + 0x20, 0x0, state);
98+
patch_aarch64_33rx(code + 0x24, (uintptr_t)data);
99+
}
100+
101+
void
102+
emit_2(
103+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
104+
const _PyUOpInstruction *instruction, jit_state *state)
105+
{
106+
// 0: 90000008 adrp x8, 0x0 <ltmp0>
107+
// 0000000000000000: ARM64_RELOC_GOT_LOAD_PAGE21 _spam
108+
// 4: f9400108 ldr x8, [x8]
109+
// 0000000000000004: ARM64_RELOC_GOT_LOAD_PAGEOFF12 _spam
110+
// 8: 39400108 ldrb w8, [x8]
111+
// c: 7100051f cmp w8, #0x1
112+
// 10: 54000041 b.ne 0x18 <ltmp0+0x18>
113+
// 14: 14000000 b 0x14 <ltmp0+0x14>
114+
// 0000000000000014: ARM64_RELOC_BRANCH26 __JIT_ERROR_TARGET
115+
const unsigned char code_body[24] = {
116+
0x08, 0x00, 0x00, 0x90, 0x08, 0x01, 0x40, 0xf9,
117+
0x08, 0x01, 0x40, 0x39, 0x1f, 0x05, 0x00, 0x71,
118+
0x41, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x14,
119+
};
120+
// 0: &spam+0x0
121+
patch_64(data + 0x0, (uintptr_t)&spam);
122+
memcpy(code, code_body, sizeof(code_body));
123+
patch_aarch64_33rx(code + 0x0, (uintptr_t)data);
124+
patch_aarch64_26r(code + 0x14, state->instruction_starts[instruction->error_target]);
125+
}
126+
127+
static_assert(SYMBOL_MASK_WORDS >= 1, "SYMBOL_MASK_WORDS too small");
128+
129+
typedef struct {
130+
void (*emit)(
131+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
132+
const _PyUOpInstruction *instruction, jit_state *state);
133+
size_t code_size;
134+
size_t data_size;
135+
symbol_mask trampoline_mask;
136+
} StencilGroup;
137+
138+
static const StencilGroup shim = {emit_shim, 104, 0, {0}};
139+
140+
static const StencilGroup stencil_groups[MAX_UOP_ID + 1] = {
141+
[0] = {emit_0, 0, 0, {0}},
142+
[1] = {emit_1, 52, 16, {0x03}},
143+
[2] = {emit_2, 24, 8, {0}},
144+
};
145+
146+
static const void * const symbols_map[2] = {
147+
[0] = &order_eggs_and_bacon,
148+
[1] = &order_eggs_sausage_and_bacon,
149+
};

Tools/jit/test/test_jit_stencils-aarch64-pc-windows-msvc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ emit_shim(
33
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
44
const _PyUOpInstruction *instruction, jit_state *state)
55
{
6-
// 0000000000000000 <_JIT_ENTRY>:
76
// 0: 6db63bef stp d15, d14, [sp, #-0xa0]!
87
// 4: a90857f6 stp x22, x21, [sp, #0x80]
98
// 8: aa0103f5 mov x21, x1
@@ -59,7 +58,6 @@ emit_1(
5958
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
6059
const _PyUOpInstruction *instruction, jit_state *state)
6160
{
62-
// 0000000000000000 <_JIT_ENTRY>:
6361
// 0: f81f0ffe str x30, [sp, #-0x10]!
6462
// 4: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
6563
// 0000000000000004: IMAGE_REL_ARM64_PAGEBASE_REL21 __imp_sausage
@@ -113,7 +111,6 @@ emit_2(
113111
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
114112
const _PyUOpInstruction *instruction, jit_state *state)
115113
{
116-
// 0000000000000000 <_JIT_ENTRY>:
117114
// 0: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
118115
// 0000000000000000: IMAGE_REL_ARM64_PAGEBASE_REL21 __imp_spam
119116
// 4: f9400108 ldr x8, [x8]

Tools/jit/test/test_jit_stencils-aarch64-unknown-linux-gnu.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ emit_shim(
33
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
44
const _PyUOpInstruction *instruction, jit_state *state)
55
{
6-
// 0000000000000000 <_JIT_ENTRY>:
76
// 0: 6db63bef stp d15, d14, [sp, #-0xa0]!
87
// 4: a90857f6 stp x22, x21, [sp, #0x80]
98
// 8: aa0103f5 mov x21, x1
@@ -60,7 +59,6 @@ emit_1(
6059
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
6160
const _PyUOpInstruction *instruction, jit_state *state)
6261
{
63-
// 0000000000000000 <_JIT_ENTRY>:
6462
// 0: a9bf7bfd stp x29, x30, [sp, #-0x10]!
6563
// 4: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
6664
// 0000000000000004: R_AARCH64_ADR_GOT_PAGE sausage
@@ -116,7 +114,6 @@ emit_2(
116114
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
117115
const _PyUOpInstruction *instruction, jit_state *state)
118116
{
119-
// 0000000000000000 <_JIT_ENTRY>:
120117
// 0: 90000008 adrp x8, 0x0 <_JIT_ENTRY>
121118
// 0000000000000000: R_AARCH64_ADR_GOT_PAGE spam
122119
// 4: f9400108 ldr x8, [x8]

Tools/jit/test/test_jit_stencils-i686-pc-windows-msvc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ emit_0(
1010
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
1111
const _PyUOpInstruction *instruction, jit_state *state)
1212
{
13-
// 00000000 <__JIT_ENTRY>:
1413
// 0: 8b 44 24 0c movl 0xc(%esp), %eax
1514
// 4: 8b 4c 24 08 movl 0x8(%esp), %ecx
1615
// 8: 8b 54 24 04 movl 0x4(%esp), %edx
@@ -30,7 +29,6 @@ emit_1(
3029
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
3130
const _PyUOpInstruction *instruction, jit_state *state)
3231
{
33-
// 00000000 <__JIT_ENTRY>:
3432
// 0: 53 pushl %ebx
3533
// 1: 57 pushl %edi
3634
// 2: 56 pushl %esi
@@ -75,7 +73,6 @@ emit_2(
7573
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
7674
const _PyUOpInstruction *instruction, jit_state *state)
7775
{
78-
// 00000000 <__JIT_ENTRY>:
7976
// 0: 8b 54 24 0c movl 0xc(%esp), %edx
8077
// 4: 8b 4c 24 08 movl 0x8(%esp), %ecx
8178
// 8: 8b 44 24 04 movl 0x4(%esp), %eax
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
void
2+
emit_shim(
3+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
4+
const _PyUOpInstruction *instruction, jit_state *state)
5+
{
6+
// 0: 55 pushq %rbp
7+
// 1: 48 89 e5 movq %rsp, %rbp
8+
// 4: 41 57 pushq %r15
9+
// 6: 41 56 pushq %r14
10+
// 8: 41 55 pushq %r13
11+
// a: 41 54 pushq %r12
12+
// c: 53 pushq %rbx
13+
// d: 50 pushq %rax
14+
// e: 49 89 fc movq %rdi, %r12
15+
// 11: 49 89 f5 movq %rsi, %r13
16+
// 14: 49 89 d6 movq %rdx, %r14
17+
// 17: e8 0f 00 00 00 callq 0x2b <__JIT_ENTRY+0x2b>
18+
// 1c: 48 83 c4 08 addq $0x8, %rsp
19+
// 20: 5b popq %rbx
20+
// 21: 41 5c popq %r12
21+
// 23: 41 5d popq %r13
22+
// 25: 41 5e popq %r14
23+
// 27: 41 5f popq %r15
24+
// 29: 5d popq %rbp
25+
// 2a: c3 retq
26+
const unsigned char code_body[43] = {
27+
0x55, 0x48, 0x89, 0xe5, 0x41, 0x57, 0x41, 0x56,
28+
0x41, 0x55, 0x41, 0x54, 0x53, 0x50, 0x49, 0x89,
29+
0xfc, 0x49, 0x89, 0xf5, 0x49, 0x89, 0xd6, 0xe8,
30+
0x0f, 0x00, 0x00, 0x00, 0x48, 0x83, 0xc4, 0x08,
31+
0x5b, 0x41, 0x5c, 0x41, 0x5d, 0x41, 0x5e, 0x41,
32+
0x5f, 0x5d, 0xc3,
33+
};
34+
memcpy(code, code_body, sizeof(code_body));
35+
}
36+
37+
void
38+
emit_0(
39+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
40+
const _PyUOpInstruction *instruction, jit_state *state)
41+
{
42+
// 0: 55 pushq %rbp
43+
// 1: 48 89 e5 movq %rsp, %rbp
44+
// 4: 5d popq %rbp
45+
const unsigned char code_body[5] = {
46+
0x55, 0x48, 0x89, 0xe5, 0x5d,
47+
};
48+
memcpy(code, code_body, sizeof(code_body));
49+
}
50+
51+
void
52+
emit_1(
53+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
54+
const _PyUOpInstruction *instruction, jit_state *state)
55+
{
56+
// 0: 55 pushq %rbp
57+
// 1: 48 89 e5 movq %rsp, %rbp
58+
// 4: 48 8b 05 00 00 00 00 movq (%rip), %rax ## 0xb <__JIT_ENTRY+0xb>
59+
// 0000000000000007: X86_64_RELOC_GOT_LOAD _sausage@GOTPCREL
60+
// b: 80 38 00 cmpb $0x0, (%rax)
61+
// e: 74 08 je 0x18 <__JIT_ENTRY+0x18>
62+
// 10: ff 15 00 00 00 00 callq *(%rip) ## 0x16 <__JIT_ENTRY+0x16>
63+
// 0000000000000012: X86_64_RELOC_GOT _order_eggs_sausage_and_bacon@GOTPCREL
64+
// 16: eb 06 jmp 0x1e <__JIT_ENTRY+0x1e>
65+
// 18: ff 15 00 00 00 00 callq *(%rip) ## 0x1e <__JIT_ENTRY+0x1e>
66+
// 000000000000001a: X86_64_RELOC_GOT _order_eggs_and_bacon@GOTPCREL
67+
// 1e: 48 8b 05 00 00 00 00 movq (%rip), %rax ## 0x25 <__JIT_ENTRY+0x25>
68+
// 0000000000000021: X86_64_RELOC_GOT_LOAD _spammed@GOTPCREL
69+
// 25: c6 00 00 movb $0x0, (%rax)
70+
// 28: 5d popq %rbp
71+
const unsigned char code_body[41] = {
72+
0x55, 0x48, 0x89, 0xe5, 0x48, 0x8b, 0x05, 0x00,
73+
0x00, 0x00, 0x00, 0x80, 0x38, 0x00, 0x74, 0x08,
74+
0xff, 0x15, 0x00, 0x00, 0x00, 0x00, 0xeb, 0x06,
75+
0xff, 0x15, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b,
76+
0x05, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00,
77+
0x5d,
78+
};
79+
// 0: &spammed+0x0
80+
// 8: &order_eggs_and_bacon+0x0
81+
// 10: &order_eggs_sausage_and_bacon+0x0
82+
// 18: &sausage+0x0
83+
patch_64(data + 0x0, (uintptr_t)&spammed);
84+
patch_64(data + 0x8, (uintptr_t)&order_eggs_and_bacon);
85+
patch_64(data + 0x10, (uintptr_t)&order_eggs_sausage_and_bacon);
86+
patch_64(data + 0x18, (uintptr_t)&sausage);
87+
memcpy(code, code_body, sizeof(code_body));
88+
patch_x86_64_32rx(code + 0x7, (uintptr_t)data + 0x14);
89+
patch_x86_64_32rx(code + 0x12, (uintptr_t)data + 0xc);
90+
patch_x86_64_32rx(code + 0x1a, (uintptr_t)data + 0x4);
91+
patch_x86_64_32rx(code + 0x21, (uintptr_t)data + -0x4);
92+
}
93+
94+
void
95+
emit_2(
96+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
97+
const _PyUOpInstruction *instruction, jit_state *state)
98+
{
99+
// 0: 55 pushq %rbp
100+
// 1: 48 89 e5 movq %rsp, %rbp
101+
// 4: 48 8b 05 00 00 00 00 movq (%rip), %rax ## 0xb <__JIT_ENTRY+0xb>
102+
// 0000000000000007: X86_64_RELOC_GOT_LOAD _spam@GOTPCREL
103+
// b: 80 38 01 cmpb $0x1, (%rax)
104+
// e: 75 06 jne 0x16 <__JIT_ENTRY+0x16>
105+
// 10: 5d popq %rbp
106+
// 11: e9 00 00 00 00 jmp 0x16 <__JIT_ENTRY+0x16>
107+
// 0000000000000012: X86_64_RELOC_BRANCH __JIT_ERROR_TARGET
108+
// 16: 5d popq %rbp
109+
const unsigned char code_body[23] = {
110+
0x55, 0x48, 0x89, 0xe5, 0x48, 0x8b, 0x05, 0x00,
111+
0x00, 0x00, 0x00, 0x80, 0x38, 0x01, 0x75, 0x06,
112+
0x5d, 0xe9, 0x00, 0x00, 0x00, 0x00, 0x5d,
113+
};
114+
// 0: &spam+0x0
115+
patch_64(data + 0x0, (uintptr_t)&spam);
116+
memcpy(code, code_body, sizeof(code_body));
117+
patch_x86_64_32rx(code + 0x7, (uintptr_t)data + -0x4);
118+
patch_32r(code + 0x12, state->instruction_starts[instruction->error_target] + -0x4);
119+
}
120+
121+
static_assert(SYMBOL_MASK_WORDS >= 1, "SYMBOL_MASK_WORDS too small");
122+
123+
typedef struct {
124+
void (*emit)(
125+
unsigned char *code, unsigned char *data, _PyExecutorObject *executor,
126+
const _PyUOpInstruction *instruction, jit_state *state);
127+
size_t code_size;
128+
size_t data_size;
129+
symbol_mask trampoline_mask;
130+
} StencilGroup;
131+
132+
static const StencilGroup shim = {emit_shim, 43, 0, {0}};
133+
134+
static const StencilGroup stencil_groups[MAX_UOP_ID + 1] = {
135+
[0] = {emit_0, 5, 0, {0}},
136+
[1] = {emit_1, 41, 32, {0}},
137+
[2] = {emit_2, 23, 8, {0}},
138+
};
139+
140+
static const void * const symbols_map[1] = {
141+
0
142+
};

0 commit comments

Comments
 (0)