From 24a722545f6da456e230c9300d22ecdc49f0bf4a Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin <6576495+widgetii@users.noreply.github.com> Date: Mon, 13 Apr 2026 21:40:07 +0300 Subject: [PATCH] uclibc-compat: fix __aeabi_d2iz infinite recursion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC converts `(int)x` (double-to-int cast) into a call to __aeabi_d2iz, which is the function itself — causing infinite recursion and a stack overflow. Found via AddressSanitizer on hi3516cv100 hardware. Replace with manual IEEE 754 double field extraction that uses only integer operations, breaking the recursion. Ref: #1992 Co-Authored-By: Claude Opus 4.6 (1M context) --- .../package/uclibc-compat/src/uclibc-compat.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/general/package/uclibc-compat/src/uclibc-compat.c b/general/package/uclibc-compat/src/uclibc-compat.c index 7a3770fc7b..2da256e140 100644 --- a/general/package/uclibc-compat/src/uclibc-compat.c +++ b/general/package/uclibc-compat/src/uclibc-compat.c @@ -134,11 +134,25 @@ size_t _stdlib_mb_cur_max(void) return 1; } -/* __aeabi_d2iz -- ARM EABI double-to-int, missing from musl */ +/* __aeabi_d2iz -- ARM EABI double-to-int, missing from musl. + * Cannot use C cast (int)x because GCC emits __aeabi_d2iz for it, + * causing infinite recursion. Implement the conversion manually + * by extracting the IEEE 754 double fields. */ __attribute__((visibility("default"))) int __aeabi_d2iz(double x) { - return (int)x; + union { double d; unsigned long long u; } u = { .d = x }; + int sign = (u.u >> 63) ? -1 : 1; + int exp = ((u.u >> 52) & 0x7FF) - 1023; + if (exp < 0) return 0; + if (exp > 30) return sign > 0 ? 0x7FFFFFFF : (int)0x80000000; + unsigned long long mantissa = (u.u & 0x000FFFFFFFFFFFFFULL) | 0x0010000000000000ULL; + int result; + if (exp >= 52) + result = (int)(mantissa << (exp - 52)); + else + result = (int)(mantissa >> (52 - exp)); + return sign * result; } /* ======================================================================