NetBSD Problem Report #57592

From www@netbsd.org  Wed Aug 23 02:39:12 2023
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 E9E711A9238
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 23 Aug 2023 02:39:11 +0000 (UTC)
Message-Id: <20230823023910.E53351A9239@mollari.NetBSD.org>
Date: Wed, 23 Aug 2023 02:39:10 +0000 (UTC)
From: rokuyama.rk@gmail.com
Reply-To: rokuyama.rk@gmail.com
To: gnats-bugs@NetBSD.org
Subject: curses: aspell clears screen if no correction found
X-Send-Pr-Version: www-1.0

>Number:         57592
>Category:       lib
>Synopsis:       curses: aspell clears screen if no correction found
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Aug 23 02:40:00 +0000 2023
>Last-Modified:  Mon Sep 11 10:50:01 +0000 2023
>Originator:     Rin Okuyama
>Release:        10.99.7
>Organization:
Internet Initiative Japan Inc.
>Environment:
NetBSD netbsd 10.99.7 NetBSD 10.99.7 (AMD64_NET_MPSAFE) #2: Tue Aug 15 12:13:48 JST 2023  rin@netbsd:/home/rin/src/sys/arch/amd64/compile/AMD64_NET_MPSAFE amd64
>Description:
With recent version (9.1) of curses:
-r--r--r-- 1 root wheel 206472 Aug 15 11:13 /usr/lib/libcurses.so.9.1
pkgsrc/textproc/aspell 0.60.8nb4 clears screen on exit if no
correction was found.

This is a behavior different to old curses, e.g.:
-r--r--r-- 1 root wheel 201048 May 10 2021 /usr/lib/libcurses.so.9.0
nor pkgsrc/devel/ncursesw 6.4; if aspell is linked against these,
it silently exits on success without modifying screen.

I don't know whether this is a regression for our curses, or something
wrong for aspell (depending on some unspecified implement details?).
>How-To-Repeat:
Install textproc/aspell and aspell-en from pkgsrc.

% cat foo.txt
only correct words
% aspell -c foo.txt

Then, if it is linked to old curses (9.0) or ncursesw, it silently
exits. However, it clears screen for recent curses (9.1).
>Fix:
N/A

>Audit-Trail:
From: RVP <rvp@SDF.ORG>
To: gnats-bugs@netbsd.org
Cc: rokuyama.rk@gmail.com
Subject: Re: lib/57592: curses: aspell clears screen if no correction found
Date: Thu, 7 Sep 2023 09:24:04 +0000 (UTC)

 On Wed, 23 Aug 2023, rokuyama.rk@gmail.com wrote:

 >> How-To-Repeat:
 > Install textproc/aspell and aspell-en from pkgsrc.
 >
 > % cat foo.txt
 > only correct words
 > % aspell -c foo.txt
 >
 > Then, if it is linked to old curses (9.0) or ncursesw, it silently
 > exits. However, it clears screen for recent curses (9.1).
 >

 Can you show the output of these commands:

 $ echo $TERM
 $ ldd $(which aspell)
 $ aspell -c foo.txt | sed -n l		# repeat for 9.0, 9.1, ncurses

 Thx,
 -RVP

From: Rin Okuyama <rokuyama.rk@gmail.com>
To: RVP <rvp@SDF.ORG>, gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/57592: curses: aspell clears screen if no correction found
Date: Sun, 10 Sep 2023 20:30:33 +0900

 On 2023/09/07 18:24, RVP wrote:
 > Can you show the output of these commands:
 > 
 > $ echo $TERM
 > $ ldd $(which aspell)
 > $ aspell -c foo.txt | sed -n l        # repeat for 9.0, 9.1, ncurses

 Thanks for useful comment!

 aspell linked against libcurses.so.9.1 outputs additional ``^[[H'' and
 ``^[[2J'' that cause screen clear.

 However, this is not a regression for our curses; aspell compiled for
 libcurses.so.9.0 and 9.1 are built with bunutils 2.34 and 2.39,
 respectively. And for the latter, a test in configure for aspell
 unexpectedly fails, which results in different behavior of aspell:

 ----
 configure:18529: checking if curses workaround I will work
 configure:18548: c++ -o conftest -O2 -fPIC -D_FORTIFY_SOURCE=2 -I/usr/include -fno-exceptions  -I/usr/include -I/usr/pkg/include -Wl,-zrelro -L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib conftest.cpp -lcurses  >&5
 ld: /tmp/cccBukDq.o: undefined reference to symbol 'tigetstr'
 ld: /usr/lib/libterminfo.so.2: error adding symbols: DSO missing from command line
 ----

 If ld 2.34 is used on a system itself built by 2.39, this test passes.

 As libncurses includes terminfo(3) functions, this test also passes
 for ncurses.

 This patch for pkgsrc/textproc/aspell works around the problem:
 https://gist.github.com/rokuyama/d5ad1e9f323e3773dae9c35e272f18a5

 Thanks,
 rin

From: Valery Ushakov <uwe@stderr.spb.ru>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: lib/57592: curses: aspell clears screen if no correction found
Date: Sun, 10 Sep 2023 15:18:57 +0300

 >  configure:18548: c++ -o conftest -O2 -fPIC -D_FORTIFY_SOURCE=2 -I/usr/include -fno-exceptions  -I/usr/include -I/usr/pkg/include -Wl,-zrelro -L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib conftest.cpp -lcurses  >&5
 >  ld: /tmp/cccBukDq.o: undefined reference to symbol 'tigetstr'
 >  ld: /usr/lib/libterminfo.so.2: error adding symbols: DSO missing from command line
 [...]
 >  This patch for pkgsrc/textproc/aspell works around the problem:
 >  https://gist.github.com/rokuyama/d5ad1e9f323e3773dae9c35e272f18a5

 libcurses.so lists libterminfo.so as NEEDED.  I vaguely recall that
 the new binutils are more strict about exposing such symbols to the
 main program (that explicitly lists only -lcurses, but also refers a
 symbol that curses brings in via its NEEDED list).

 The dynamic linker knowledge is completely swapped out of my head, but
 we need to arrange for -lcurses to make terminfo symbols available b/c
 that's how x/open specifies it.

 -uwe

From: RVP <rvp@SDF.ORG>
To: gnats-bugs@NetBSD.org
Cc: Rin Okuyama <rokuyama.rk@gmail.com>
Subject: Re: lib/57592: curses: aspell clears screen if no correction found
Date: Sun, 10 Sep 2023 22:48:29 +0000 (UTC)

 On Sun, 10 Sep 2023, Rin Okuyama wrote:

 > aspell linked against libcurses.so.9.1 outputs additional ``^[[H'' and
 > ``^[[2J'' that cause screen clear.
 >

 Yes, it's the 2nd (unpaired) rmcup which clears the screen (ncurses+Rxvt only).

 > However, this is not a regression for our curses [...]
 >

 My analysis is that aspell will only clear the screen like this, if
 a) TERM=rxvt
 b) curses is ncurses.

 I made some notes (and also a patch) a couple of days ago. I've added this
 as-is below. Okuyama-san, can you check this please?


 --- NOTES: Aspell + ncurses + TERM=rxvt clearing the screen ---
 To trigger this issue you must:

 1. Call endwin() twice.
     (See: aspell-0.60.8/prog/check_funs.cpp:begin_check())

 2. Have a curses with non-idempotent endwin() (like ncurses; BSD curses
     is not affected by this).

 3. Have a termcap/terminfo entry where the `te'/`rmcup' capability has an
     Erase in Display (ED) string `\E[2J' in it (like for rxvt).

 This should reproduce the issue more simply:

 ```
 $ (export TERM=rxvt; tput smcup; tput rmcup; tput rmcup)
 ```

 The second `rmcup' will clear the current screen instead of the alt. screen.
 Fix:

 ```
 diff -urN aspell-0.60.8.orig/prog/check_funs.cpp aspell-0.60.8/prog/check_funs.cpp
 --- aspell-0.60.8.orig/prog/check_funs.cpp	2019-10-08 00:15:21.000000000 +0000
 +++ aspell-0.60.8/prog/check_funs.cpp	2023-09-07 07:31:11.452543000 +0000
 @@ -110,6 +110,9 @@
   #endif

   static void cleanup (void) {
 +  static int done = 0;
 +  if (done)
 +    return;    /* do cleanup only once (for ncurses; see NetBSD PR #57592) */
   #if   HAVE_LIBCURSES
     if (use_curses) {
       endwin();
 @@ -120,6 +123,7 @@
       tcsetattr (STDIN_FILENO, TCSANOW, &saved_attributes);
   #endif
     }
 +  done = 1;
   }

   #if   HAVE_LIBCURSES
 ```

 --- END of NOTES ---

 -RVP

From: "Rin Okuyama" <rin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57592 CVS commit: src/external/gpl3/binutils/dist/ld/emultempl
Date: Mon, 11 Sep 2023 01:54:18 +0000

 Module Name:	src
 Committed By:	rin
 Date:		Mon Sep 11 01:54:18 UTC 2023

 Modified Files:
 	src/external/gpl3/binutils/dist/ld/emultempl: aarch64elf.em armelf.em
 	    elf.em

 Log Message:
 ld: Enable --copy-dt-needed-entries by default again

 Otherwise, terminfo(3) symbols referenced from curses(3)-based applications
 are not resolved, unless -lterminfo is explicitly specified.

 See, e.g., PR lib/57592

 We had locally enabled this by default:

 http://cvsweb.netbsd.org/bsdweb.cgi/src/external/gpl3/binutils/dist/ld/emultempl/elf.em#rev1.2

 But this was lost during 2.39 merge.

 Thanks uwe@ for hints!


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 \
     src/external/gpl3/binutils/dist/ld/emultempl/aarch64elf.em \
     src/external/gpl3/binutils/dist/ld/emultempl/armelf.em
 cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/binutils/dist/ld/emultempl/elf.em

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

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: PR/57592 CVS commit: src/external/gpl3/binutils/dist/ld/emultempl
Date: Mon, 11 Sep 2023 12:45:47 +0200

 On Mon, Sep 11, 2023 at 01:55:01AM +0000, Rin Okuyama wrote:
 >  ld: Enable --copy-dt-needed-entries by default again
 >  
 >  Otherwise, terminfo(3) symbols referenced from curses(3)-based applications
 >  are not resolved, unless -lterminfo is explicitly specified.
 >  
 >  See, e.g., PR lib/57592

 Wouldn't it be enough to arrange for --copy-dt-needed-entries being used
 when we link libcurses?

 It seems most other software nowadays can deal with the new binutils default.

 Martin

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.