From 7b74c61486cbce26d36114b20ac5ce5a2b065d8d Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Tue, 26 Sep 2023 19:09:46 -0500 Subject: [PATCH] ply: Correct alignment of stack allocations 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 --- src/libply/ir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libply/ir.c b/src/libply/ir.c index 8541633..8c546ab 100644 --- a/src/libply/ir.c +++ b/src/libply/ir.c @@ -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);