@@ -106,7 +106,7 @@ patch_one(unsigned char *location, HoleKind kind, uint64_t patch)
106
106
* addr = (uint32_t )patch ;
107
107
return ;
108
108
}
109
- case R_386_PC32 :
109
+ case R_386_PC32 :
110
110
case R_X86_64_GOTPC32 :
111
111
case R_X86_64_GOTPCRELX :
112
112
case R_X86_64_PC32 :
@@ -255,12 +255,15 @@ initialize_jit(void)
255
255
}
256
256
uint64_t patches [] = GET_PATCHES ();
257
257
patches [_JIT_BODY ] = (uintptr_t )deoptimize_stub ;
258
- patches [_JIT_DATA ] = (uintptr_t )deoptimize_stub + stencil -> nbytes ;
258
+ patches [_JIT_DATA ] = (uintptr_t )data ;
259
259
patches [_JIT_ZERO ] = 0 ;
260
260
copy_and_patch (deoptimize_stub , data , stencil , patches );
261
261
if (mark_executable (deoptimize_stub , stencil -> nbytes )) {
262
262
return needs_initializing ;
263
263
}
264
+ if (mark_executable (data , stencil -> nbytes_data )) {
265
+ return needs_initializing ;
266
+ }
264
267
}
265
268
// Write our error stub:
266
269
{
@@ -275,12 +278,15 @@ initialize_jit(void)
275
278
}
276
279
uint64_t patches [] = GET_PATCHES ();
277
280
patches [_JIT_BODY ] = (uintptr_t )error_stub ;
278
- patches [_JIT_DATA ] = (uintptr_t )error_stub + stencil -> nbytes ;
281
+ patches [_JIT_DATA ] = (uintptr_t )data ;
279
282
patches [_JIT_ZERO ] = 0 ;
280
283
copy_and_patch (error_stub , data , stencil , patches );
281
284
if (mark_executable (error_stub , stencil -> nbytes )) {
282
285
return needs_initializing ;
283
286
}
287
+ if (mark_executable (data , stencil -> nbytes_data )) {
288
+ return needs_initializing ;
289
+ }
284
290
}
285
291
// Done:
286
292
needs_initializing = 0 ;
@@ -329,16 +335,17 @@ _PyJIT_CompileTrace(_PyUOpInstruction *trace, int size)
329
335
return NULL ;
330
336
}
331
337
unsigned char * head = memory ;
338
+ unsigned char * head_data = data ;
332
339
// First, the trampoline:
333
340
const Stencil * stencil = & trampoline_stencil ;
334
341
uint64_t patches [] = GET_PATCHES ();
335
342
patches [_JIT_BODY ] = (uintptr_t )head ;
336
- patches [_JIT_DATA ] = (uintptr_t )data ;
343
+ patches [_JIT_DATA ] = (uintptr_t )head_data ;
337
344
patches [_JIT_CONTINUE ] = (uintptr_t )head + stencil -> nbytes ;
338
345
patches [_JIT_ZERO ] = 0 ;
339
- copy_and_patch (head , data , stencil , patches );
346
+ copy_and_patch (head , head_data , stencil , patches );
340
347
head += stencil -> nbytes ;
341
- data += stencil -> nbytes_data ;
348
+ head_data += stencil -> nbytes_data ;
342
349
// Then, all of the stencils:
343
350
for (int i = 0 ; i < size ; i ++ ) {
344
351
_PyUOpInstruction * instruction = & trace [i ];
@@ -355,44 +362,48 @@ _PyJIT_CompileTrace(_PyUOpInstruction *trace, int size)
355
362
const Stencil * stencil = & oparg_stencil ;
356
363
uint64_t patches [] = GET_PATCHES ();
357
364
patches [_JIT_BODY ] = (uintptr_t )head ;
358
- patches [_JIT_DATA ] = (uintptr_t )data ;
365
+ patches [_JIT_DATA ] = (uintptr_t )head_data ;
359
366
patches [_JIT_CONTINUE ] = (uintptr_t )head + stencil -> nbytes ;
360
367
patches [_JIT_OPARG ] = instruction -> oparg ;
361
368
patches [_JIT_ZERO ] = 0 ;
362
- copy_and_patch (head , data , stencil , patches );
369
+ copy_and_patch (head , head_data , stencil , patches );
363
370
head += stencil -> nbytes ;
364
- data += stencil -> nbytes_data ;
371
+ head_data += stencil -> nbytes_data ;
365
372
}
366
373
if (OPCODE_HAS_OPERAND (instruction -> opcode )) {
367
374
const Stencil * stencil = & operand_stencil ;
368
375
uint64_t patches [] = GET_PATCHES ();
369
376
patches [_JIT_BODY ] = (uintptr_t )head ;
370
- patches [_JIT_DATA ] = (uintptr_t )data ;
377
+ patches [_JIT_DATA ] = (uintptr_t )head_data ;
371
378
patches [_JIT_CONTINUE ] = (uintptr_t )head + stencil -> nbytes ;
372
379
patches [_JIT_OPERAND ] = instruction -> operand ;
373
380
patches [_JIT_ZERO ] = 0 ;
374
- copy_and_patch (head , data , stencil , patches );
381
+ copy_and_patch (head , head_data , stencil , patches );
375
382
head += stencil -> nbytes ;
376
- data += stencil -> nbytes_data ;
383
+ head_data += stencil -> nbytes_data ;
377
384
}
378
385
const Stencil * stencil = & stencils [instruction -> opcode ];
379
386
uint64_t patches [] = GET_PATCHES ();
380
387
patches [_JIT_BODY ] = (uintptr_t )head ;
381
- patches [_JIT_DATA ] = (uintptr_t )data ;
388
+ patches [_JIT_DATA ] = (uintptr_t )head_data ;
382
389
patches [_JIT_CONTINUE ] = (uintptr_t )head + stencil -> nbytes ;
383
390
patches [_JIT_DEOPTIMIZE ] = (uintptr_t )deoptimize_stub ;
384
391
patches [_JIT_ERROR ] = (uintptr_t )error_stub ;
385
392
patches [_JIT_JUMP ] = (uintptr_t )memory + offsets [instruction -> oparg % size ];
386
393
patches [_JIT_ZERO ] = 0 ;
387
- copy_and_patch (head , data , stencil , patches );
394
+ copy_and_patch (head , head_data , stencil , patches );
388
395
head += stencil -> nbytes ;
389
- data += stencil -> nbytes_data ;
396
+ head_data += stencil -> nbytes_data ;
390
397
};
391
398
PyMem_Free (offsets );
392
399
if (mark_executable (memory , nbytes )) {
393
400
return NULL ;
394
401
}
402
+ if (mark_executable (data , nbytes_data )) {
403
+ return needs_initializing ;
404
+ }
395
405
// Wow, done already?
396
406
assert (memory + nbytes == head );
407
+ assert (data + nbytes_data == head_data );
397
408
return (_PyJITFunction )memory ;
398
409
}
0 commit comments