Skip to content

Commit

Permalink
ply: Correct alignment of stack allocations
Browse files Browse the repository at this point in the history
As entries are allocated on the stack the stack pointer is decremented
and then adjusted to meet the requested alignment requirements. The
current math does unfortunately not always provide the requested
alignment.

One example is when the stack pointer is at -1 and an allocation of 4
bytes with alignment of 4 is performed, which results in an allocation
at offset -6. A typical case where this happens is when working with
tracepoints containing boolean fields.

Update the adjustment to properly round the stack pointer down to the
requested alignment.

Signed-off-by: Bjorn Andersson <[email protected]>
  • Loading branch information
quic-bjorande authored and wkz committed Sep 3, 2024
1 parent 7a0f266 commit 7b74c61
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libply/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ ssize_t ir_alloc_stack(struct ir *ir, size_t size, size_t align)
ir->sp -= size;

if (ir->sp % align)
ir->sp -= align - (ir->sp & (align - 1));
ir->sp &= ~(align - 1);

assert(ir->sp > INT16_MIN);

Expand Down

0 comments on commit 7b74c61

Please sign in to comment.