From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id pxY0LFqCiWoD4zUAWB0awg (envelope-from ) for ; Sat, 22 Aug 2026 07:04:58 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=o2.pl header.i=@o2.pl header.a=rsa-sha256 header.s=20241105 header.b=wotA2vX+; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9D9311E0A3; Sat, 22 Aug 2026 07:04:58 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id EF8FA1E033 for ; Sat, 22 Aug 2026 07:04:57 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 896CA4BB24D1 for ; Sat, 22 Aug 2026 11:04:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 896CA4BB24D1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=o2.pl header.i=@o2.pl header.a=rsa-sha256 header.s=20241105 header.b=wotA2vX+ Received: from mx-out.tlen.pl (mx-out.tlen.pl [193.222.135.142]) by sourceware.org (Postfix) with ESMTPS id C30394B9DB5C for ; Sat, 22 Aug 2026 11:04:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C30394B9DB5C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=o2.pl Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=o2.pl ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C30394B9DB5C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=193.222.135.142 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787396673; cv=none; b=MDObr+b4yFLkxffb8gf90KhTLgSTaQmxFNm2jt8/vXru79aj0uEaDEsNkooeEQBXAKjmyB/gtEl66QSNGxcr6gz+S4yoq360HeKDR0bzFA6QrbWOiekLTsnqf1nZIMW1VYuaxrOR9GaGClK35MAsYAKgOKhpnOPpWMcW1dpKyjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787396673; c=relaxed/simple; bh=MNI8fjbql+BEjJdI74J+GeVo+NvY+QbwAeOtdm9v8VE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=k6cYI7N6SuvGWP+k0TnPzTZhHNr6+ZLB/wIJw1qYv4PViwI+7I3a2QDMfQnhaJAvczYPEucEggTlbrBmxFAij+eirjkl41S8QDu2BjIK1OY5bYZOYVnFJJJaplT8fBv4NnTS3KwnFt7NzFvtzg/qSHHj+mwqiKf3IdTF1MtvsYs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=o2.pl header.i=@o2.pl header.a=rsa-sha256 header.s=20241105 header.b=wotA2vX+ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C30394B9DB5C Received: (wp-smtpd smtp.tlen.pl 44863 invoked from network); 22 Aug 2026 13:04:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=o2.pl; s=20241105; t=1787396669; bh=yiGr2rlosvijUgkfxTf/S1Nau6OeJ/DwCZiHOUcgZGc=; h=From:To:Cc:Subject; b=wotA2vX+zlD7OWzZvdR4mq4qpuBMRrGw+Pa0gBEyAvJ8qv94lcVRjJ34htv5pUGZU eZY/a4PS1quDuy2pG33rShQz4lydCXweXuvd2V3sTU6qmkPvwmOW4X6o82KLXSgE/w h75O45GtZAPA745MHVLMPm5OIzngIxEar4LA3EJ61NfF+6PZKIAhsVr9CGGZIzab0f oC4L7KS/wxigLRnO0cBdXmgei1J61lKIGXLNe7xu8QlrsHDnRv8EVeIwLvSWQLAkSG eLyCItG5HMLoqKiHPmEbiHASVejknkcF0JT4wPDxN2ivcfhzDYaetmHAvctodH4Bdb Q5pViRtjB89mw== Received: from jdxpc (ip-94-42-230-181.multimo.pl [94.42.230.181]) (envelope-sender ) by smtp.tlen.pl (WP-SMTPD) with TLS_AES_256_GCM_SHA384 encrypted SMTP for ; 22 Aug 2026 13:04:29 +0200 From: Jan Dubiec To: gdb-patches@sourceware.org Cc: Jan Dubiec , Jeffrey Law Subject: [PATCH] H8/300: sim: Fix simulator hang caused by qsort on Windows/MinGW. Date: Sat, 22 Aug 2026 13:02:50 +0200 Message-ID: <20260822110423.1569154-1-jdx@o2.pl> X-Mailer: git-send-email 2.55.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-WP-MailID: ce6137d58fc62fd726c6fde67facae8b X-WP-AV: skaner antywirusowy Poczty o2 X-WP-SPAM: NO 0000005 [Aaa9] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org See the comment below. I don't know why qsort behaves so strangely. It could be a bug, or simply a consequence of its being an unstable sort. Unfortunately, I don't have time to investigate the root cause. Signed-off-by: Jan Dubiec --- sim/h8300/compile.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/sim/h8300/compile.c b/sim/h8300/compile.c index 06988095228..c08f7704ef3 100644 --- a/sim/h8300/compile.c +++ b/sim/h8300/compile.c @@ -1568,6 +1568,41 @@ store2 (SIM_DESC sd, ea_type *arg, int n) return store_1 (sd, arg, n, 1); } +#ifdef __MINGW32__ +/* On Windows/MinGW, qsort for some reason produces a "shuffled" opcode +table instead of a sorted one, causing the entire simulator to hang. + +This is a simple insertion sort implementation, but it has virtually +no impact on simulator performance. */ + +#define qsort opcode_insertion_sort + +static void +opcode_insertion_sort(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)) +{ + unsigned char *a = base; + struct h8_opcode tmp; + size_t i, j; + + if (nmemb < 2 || size == 0) + return; + + for (i = 1; i < nmemb; ++i) { + memcpy(&tmp, a + i * size, size); + + j = i; + while (j > 0 && compar(&tmp, a + (j - 1) * size) < 0) { + memcpy(a + j * size, a + (j - 1) * size, size); + --j; + } + + memcpy(a + j * size, &tmp, size); + } + +} +#endif /* #ifdef __MINGW32__ */ + /* Callback for qsort. We sort first based on availability (available instructions sort lower). When availability state is the same, then we use the first 4 bit nibble as a secondary -- 2.55.0