From 163a91b05a96dfd5482c8685aa0d1fbc6770497f Mon Sep 17 00:00:00 2001 From: Yi Liu Date: Mon, 9 Mar 2026 10:09:28 +0800 Subject: [PATCH] Fix relocation addend sign extension on 32-bit platforms (#4846) * Fix relocation addend sign extension on 32-bit platforms When loading relocations on 32-bit platforms, the addend is read as uint32 and zero-extended to uint64, which corrupts negative addends. For example, -4 (0xFFFFFFFC) becomes 4294967292 instead of remaining -4. Use int32 with sign extension to int64, matching the Windows code path which already handles this correctly. --- core/iwasm/aot/aot_loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/iwasm/aot/aot_loader.c b/core/iwasm/aot/aot_loader.c index b77ecfab8..19985444d 100644 --- a/core/iwasm/aot/aot_loader.c +++ b/core/iwasm/aot/aot_loader.c @@ -3872,7 +3872,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end, read_uint32(buf, buf_end, offset32); relocation->relocation_offset = (uint64)offset32; read_uint32(buf, buf_end, addend32); - relocation->relocation_addend = (uint64)addend32; + relocation->relocation_addend = (int64)(int32)addend32; } read_uint32(buf, buf_end, relocation->relocation_type); read_uint32(buf, buf_end, symbol_index);