From c58aa48c3e72181e6912e933c1ab3265ee20fa0b Mon Sep 17 00:00:00 2001 From: NOT XVilka Date: Mon, 8 Jun 2026 00:20:46 +0800 Subject: [PATCH] librz/egg: fix endian-dependent x86/x64 string immediates and refresh rz-gg tests (#6481) Use rz_read_le32() in the x86/x64 egg emitter so 4-byte string immediates are no longer byte-reversed on big-endian hosts (System Z/s390); little-endian output is unchanged. Regenerate the stale 32-bit x86 (#1889) and 32-bit arm rz-gg goldens to match the tool's actual output, drop BROKEN markers from the simple_cmp tests that already pass, and annotate the remaining broken tests (no AArch64 egg backend; compiler-dependent C output) with the reason. Closes #3486 Closes #1889 Co-authored-by: Anton Kochkov --- librz/egg/emit/x86.c | 10 ++++++---- test/db/tools/rz_gg | 35 +++++++++++++++-------------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/librz/egg/emit/x86.c b/librz/egg/emit/x86.c index d84b4ff458..417d074a8b 100644 --- a/librz/egg/emit/x86.c +++ b/librz/egg/emit/x86.c @@ -173,13 +173,15 @@ static void emit_string(RzEgg *egg, const char *dstvar, const char *str, int j) #define M32(x) (unsigned int)((x) & 0xffffffff) /* XXX: Assumes sizeof(ut32) == 4 */ for (i = 4; i <= oj; i += 4) { - /* XXX endian issues (non-portable asm) */ - ut32 *n = (ut32 *)(s + i - 4); + /* x86 is always little-endian: read the chunk as LE so the emitted + * immediate (and thus the assembled bytes) does not depend on the + * host endianness. */ + ut32 n = rz_read_le32(s + i - 4); p = rz_egg_lang_mkvar(egg, str2, dstvar, i + BPOFF); if (attsyntax) { - rz_egg_printf(egg, " movl $0x%x, %s\n", M32(*n), p); + rz_egg_printf(egg, " movl $0x%x, %s\n", M32(n), p); } else { - rz_egg_printf(egg, " mov dword %s, 0x%x\n", p, M32(*n)); + rz_egg_printf(egg, " mov dword %s, 0x%x\n", p, M32(n)); } free(p); j -= 4; diff --git a/test/db/tools/rz_gg b/test/db/tools/rz_gg index 69ed196f78..5513a45e5c 100644 --- a/test/db/tools/rz_gg +++ b/test/db/tools/rz_gg @@ -93,17 +93,16 @@ EOF RUN NAME=rz-gg -k linux -a x86 -b32 simple_cmp.r -BROKEN=1 TOOL=rz-gg ARGS=-k linux -a x86 -b32 bins/other/rz-gg/simple_cmp.r EXPECT=<