NetBSD Problem Report #57056

From www@netbsd.org  Thu Oct 13 23:53:45 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 026DA1A9239
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 13 Oct 2022 23:53:45 +0000 (UTC)
Message-Id: <20221013235343.CE4F61A923A@mollari.NetBSD.org>
Date: Thu, 13 Oct 2022 23:53:43 +0000 (UTC)
From: vms@usa.com
Reply-To: vms@usa.com
To: gnats-bugs@NetBSD.org
Subject: spim and xspim run in an endless loop due to a bug in CPU/scanner.l
X-Send-Pr-Version: www-1.0

>Number:         57056
>Category:       pkg
>Synopsis:       spim and xspim run in an endless loop due to a bug in CPU/scanner.l
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 13 23:55:00 +0000 2022
>Closed-Date:    Tue May 09 21:00:49 +0000 2023
>Last-Modified:  Tue May 09 21:00:49 +0000 2023
>Originator:     .:VMS:.
>Release:        9.3 current Thu Oct 13 23:40:26 UTC 2022
>Organization:
hahahah
>Environment:
NetBSD localhost 9.3 NetBSD 9.3 (GENERIC) #0: Thu Aug  4 15:30:37 UTC 2022  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
spim and xspim run an endless loop because a bug related with flex.

It seems to use flex to parse assembly instructions, as it's a mips assembly interpreter, you give it asm code and it executes it.

The bug is at file CPU/scanner.l at line 319

#if (YY_FLEX_MAJOR_VERSION==2 && YY_FLEX_MINOR_VERSION==5 && YY_FLEX_SUBMINOR_VERSION>=33)
  /* flex 2.5.33 flipped the polarity of this flag (sigh) */
  yy_init = 0;                                                                                                     
#else
  yy_init = 1;    


This is the bug

it seems flex versions prior to that one needed that variable to be 1 instead of 0, the thing is the NetBSD flex's version does not match with this #if directive so yy_init is set to 1 when it should be a 0.

in my case I've just typed 'make' to download the source code and removed this stuff and just put 'yy_init = 0;'

this solves the problem and now xspim seems to work and I assume spim will do too.

I have no idea on how to make a patch file so I can't help more than that.

Anyways that's the source of the bug and it's avoided by just setting yy_init to 0.

Note that it's mlelstv who spotted the bug as I would have no idea if not :D so thank him instead, I'm just sending the pr so the mantainer can fix that.


>How-To-Repeat:
install spim and run spim or xspim, it won't work.

>Fix:
set yy_init to 0 or fix that #if directive to match that flex version and possible future ones 

>Release-Note:

>Audit-Trail:
From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57056 CVS commit: pkgsrc/emulators/spim
Date: Tue, 9 May 2023 20:43:23 +0000

 Module Name:	pkgsrc
 Committed By:	dholland
 Date:		Tue May  9 20:43:23 UTC 2023

 Modified Files:
 	pkgsrc/emulators/spim: Makefile distinfo
 Added Files:
 	pkgsrc/emulators/spim/patches: patch-scanner.l

 Log Message:
 emulators/spim: fix incorrect version comparisons, PR 57056 from "VMS"

 It seems the lexer logic was checking the flex version with #if to
 perform undocumented/unsupported frobs of the generated scanner's
 internal state, but it had the version test wrong and so would have
 been failing since flex's last minor version bump. The consequences
 are apparently an infinite loop.

 With the fix it no longer loops, but it still doesn't pass its own
 very basic tests. It also uses its own builtin assembler (hence flex)
 with nonstandard syntax (looks like also nonstandard semantics) and
 who knows what else, so you're probably better off looking for a
 different emulator.


 To generate a diff of this commit:
 cvs rdiff -u -r1.46 -r1.47 pkgsrc/emulators/spim/Makefile
 cvs rdiff -u -r1.16 -r1.17 pkgsrc/emulators/spim/distinfo
 cvs rdiff -u -r0 -r1.1 pkgsrc/emulators/spim/patches/patch-scanner.l

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: David Holland <dholland-pbugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/57056: spim and xspim run in an endless loop due to a bug in
 CPU/scanner.l
Date: Tue, 9 May 2023 20:45:58 +0000

 On Thu, Oct 13, 2022 at 11:55:00PM +0000, vms@usa.com wrote:
  > #if (YY_FLEX_MAJOR_VERSION==2 && YY_FLEX_MINOR_VERSION==5 && YY_FLEX_SUBMINOR_VERSION>=33)
  >   /* flex 2.5.33 flipped the polarity of this flag (sigh) */
  >   yy_init = 0;                                                                                                     
  > #else
  >   yy_init = 1;    

 Yeah, the problem is that these days YY_FLEX_MINOR_VERSION is 6.

 I've patched it, but the thing also apparently fails its own very
 basic internal tests.

 If it still has an upstream, you probably want to talk to them. If it
 doesn't, you may want to look for alternatives...

 -- 
 David A. Holland
 dholland@netbsd.org

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Tue, 09 May 2023 21:00:49 +0000
State-Changed-Why:
fixed


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.