Skip to content

Commit e36f2af

Browse files
committed
Fix alignment
1 parent daa5f57 commit e36f2af

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct trampoline_api_st {
7373
int (*free_state)(void* state);
7474
void *state;
7575
Py_ssize_t code_padding;
76+
Py_ssize_t code_alignment;
7677
};
7778
#endif
7879

Python/perf_trampoline.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ perf_map_init_state(void)
230230
{
231231
PyUnstable_PerfMapState_Init();
232232
trampoline_api.code_padding = 0;
233+
trampoline_api.code_alignment = 32;
233234
perf_trampoline_type = PERF_TRAMPOLINE_TYPE_MAP;
234235
return NULL;
235236
}
@@ -291,7 +292,9 @@ new_code_arena(void)
291292
void *start = &_Py_trampoline_func_start;
292293
void *end = &_Py_trampoline_func_end;
293294
size_t code_size = end - start;
294-
size_t chunk_size = round_up(code_size + trampoline_api.code_padding, 16);
295+
size_t unaligned_size = code_size + trampoline_api.code_padding;
296+
size_t chunk_size = round_up(unaligned_size, trampoline_api.code_alignment);
297+
assert(chunk_size % trampoline_api.code_alignment == 0);
295298
// TODO: Check the effect of alignment of the code chunks. Initial investigation
296299
// showed that this has no effect on performance in x86-64 or aarch64 and the current
297300
// version has the advantage that the unwinder in GDB can unwind across JIT-ed code.
@@ -356,7 +359,9 @@ static inline py_trampoline
356359
code_arena_new_code(code_arena_t *code_arena)
357360
{
358361
py_trampoline trampoline = (py_trampoline)code_arena->current_addr;
359-
size_t total_code_size = round_up(code_arena->code_size + trampoline_api.code_padding, 16);
362+
size_t total_code_size = round_up(code_arena->code_size + trampoline_api.code_padding,
363+
trampoline_api.code_alignment);
364+
assert(total_code_size % trampoline_api.code_alignment == 0);
360365
code_arena->size_left -= total_code_size;
361366
code_arena->current_addr += total_code_size;
362367
return trampoline;

0 commit comments

Comments
 (0)