Bug 109125 - [13 regression] SIGBUS in m2pim_ldtoa_ldtoa
Summary: [13 regression] SIGBUS in m2pim_ldtoa_ldtoa
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: modula2 (show other bugs)
Version: 13.0
: P4 normal
Target Milestone: 13.0
Assignee: Gaius Mulley
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-14 10:08 UTC by Rainer Orth
Modified: 2023-03-21 18:26 UTC (History)
1 user (show)

See Also:
Host: sparc-sun-solaris2.11
Target: sparc-sun-solaris2.11
Build: sparc-sun-solaris2.11
Known to work:
Known to fail:
Last reconfirmed: 2023-03-14 00:00:00


Attachments
Proposed fix (7.39 KB, patch)
2023-03-14 16:41 UTC, Gaius Mulley
Details | Diff
Proposed fix v2 (8.59 KB, patch)
2023-03-14 17:27 UTC, Gaius Mulley
Details | Diff
Proposed fix v3 (872 bytes, patch)
2023-03-15 20:09 UTC, Gaius Mulley
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rainer Orth 2023-03-14 10:08:21 UTC
Between 20230310 (2eb0191aa104badf3cab127f7f87d371c0fef92b) and 20230313 (7ef44579787af646d5bae13a91a49ef5d2048f5c),
a large number of gm2 tests began to FAIL on Solaris/SPARC (both 32 and 64-bit):

+FAIL: gm2/extensions/run/pass/real32.mod execution,  -O 
+FAIL: gm2/extensions/run/pass/real32.mod execution,  -O -g 
+FAIL: gm2/extensions/run/pass/real32.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/extensions/run/pass/real32.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/extensions/run/pass/real32.mod execution,  -Os 
+FAIL: gm2/extensions/run/pass/real32.mod execution,  -g 

and many more.

The last failure reports

RTExceptions.mod:649:35: In invalidloc
RTExceptions.mod:649:35:invalid address referenced

and gdb shows

Thread 2 received signal SIGBUS, Bus error.
[Switching to Thread 1 (LWP 1)]
0x00027f8c in m2pim_ldtoa_ldtoa (d=<optimized out>, mode=1, ndigits=100, 
    decpt=0xffbfe7ec, sign=0xffbfe7eb)
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/ldtoa.cc:162
162	      *sign = IMPORT(dtoa,calcsign) (p, MAX_FP_DIGITS + 20);
(gdb) bt
#0  0x00027f8c in m2pim_ldtoa_ldtoa (d=<optimized out>, mode=1, ndigits=100, 
    decpt=0xffbfe7ec, sign=0xffbfe7eb)
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/ldtoa.cc:162
#1  0x00025abc in m2pim_StringConvert_LongrealToString (x=<optimized out>, 
    TotalWidth=9, FractionWidth=8)
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/../../gcc/m2/gm2-libs/StringConvert.mod:758
#2  0x0001a0f8 in _M2_real32_init (argc=1, argv=0xffbfea64, envp=0xffbfea6c)
    at /vol/gcc/src/hg/master/local/gcc/testsuite/gm2/extensions/run/pass/real32.mod:32
#3  0x0001cfc8 in m2pim_M2Dependent_ConstructModules (
    applicationmodule=<optimized out>, libname=<optimized out>, argc=1, 
    argv=0xffbfea64, envp=0xffbfea6c)
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/../../gcc/m2/gm2-libs/M2Dependent.mod:813
#4  0x0001a7c8 in _M2_init (argc=1, argv=0xffbfea64, envp=0xffbfea6c)
    at /vol/gcc/src/hg/master/local/gcc/testsuite/gm2/extensions/run/pass/real32.mod:18
#5  0x0001a840 in main (argc=1, argv=0xffbfea64, envp=0xffbfea6c)
    at /vol/gcc/src/hg/master/local/gcc/testsuite/gm2/extensions/run/pass/real32.mod:18

(gdb) display/i $pc
1: x/i $pc
=> 0x27f8c <m2pim_ldtoa_ldtoa(long double, int, int, int*, int*)+124>:	
    st  %o0, [ %i4 ]
(gdb) p/x $o0
$1 = 0x0
(gdb) p/x $i4
$2 = 0xffbfe7eb

Storing a 32-bit variable into an non-32-bit aligned destination is a no-no
on strict-alignment targets like SPARC.

This is no doubt due to

commit 431c06691dcbb84c7d999d91202537442e6a60f0
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Sun Mar 12 13:27:23 2023 +0000

    [PR modula2/109089] implementation of boolean should be C++/C bool
Comment 1 Gaius Mulley 2023-03-14 16:41:28 UTC
Created attachment 54662 [details]
Proposed fix

Thanks for the bug report - here is a proposed patch for ldtoa, dtoa and also termios all of which contained bool int mismatches between the C++/C and their m2 definition modules.
Comment 2 Gaius Mulley 2023-03-14 17:27:30 UTC
Created attachment 54663 [details]
Proposed fix v2

Version 2 of the patch catches some more cases found in the iso libraries.
Comment 3 GCC Commits 2023-03-14 19:55:11 UTC
The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>:

https://gcc.gnu.org/g:19c5dfc29d83101e415590e778b99e7c37d9b730

commit r13-6671-g19c5dfc29d83101e415590e778b99e7c37d9b730
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Tue Mar 14 19:52:11 2023 +0000

    PR 109125 Modula2 SIGBUS in m2pim_ldtoa_ldtoa
    
    13 regression failures seen on sparc SIGBUS in m2pim_ldtoa_ldtoa.
    This patch fixes int bool parameter mismatches between the
    definition modules and their C/C++ implementations.
    
    gcc/m2/ChangeLog:
    
            PR modula2/109125
            * gm2-libs-ch/cgetopt.c (cgetopt_SetOption): Replace int
            for bool.
            * gm2-libs-ch/termios.c (doSetUnset): Replace int for bool.
            * gm2-libs/Builtins.mod (isfinitef): Correct typo in return
            statement.
    
    libgm2/ChangeLog:
    
            PR modula2/109125
            * libm2iso/ErrnoCategory.cc (FALSE): Remove.
            (TRUE): Remove.
            * libm2iso/wrapsock.c (TRUE): Remove.
            (FALSE): Remove.
            * libm2iso/wraptime.cc (TRUE): Remove.
            (FALSE): Remove.
            * libm2pim/cgetopt.cc: Replace int for bool for every BOOLEAN
            parameter in the definition module.
            * libm2pim/dtoa.cc: Ditto.
            * libm2pim/ldtoa.cc: Ditto.
            * libm2pim/termios.cc: Ditto.
            (doSetUnset): Replace int for bool.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Comment 4 ro@CeBiTec.Uni-Bielefeld.DE 2023-03-15 09:05:49 UTC
> --- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
[...]
> Version 2 of the patch catches some more cases found in the iso libraries.

I've tried that one last night and most of the failures are gone.
Thanks for the super-fix patch.

Some failures remain, however, both 32 and 64-bit again:

+FAIL: gm2/isolib/run/pass/readreal.mod execution,  -O 
+FAIL: gm2/isolib/run/pass/readreal.mod execution,  -O -g 
+FAIL: gm2/isolib/run/pass/readreal.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/isolib/run/pass/readreal.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/isolib/run/pass/readreal.mod execution,  -Os 
+FAIL: gm2/isolib/run/pass/readreal.mod execution,  -g 
+FAIL: gm2/isolib/run/pass/real3.mod execution,  -O 
+FAIL: gm2/isolib/run/pass/real3.mod execution,  -O -g 
+FAIL: gm2/isolib/run/pass/real3.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/isolib/run/pass/real3.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/isolib/run/pass/real3.mod execution,  -Os 
+FAIL: gm2/isolib/run/pass/real3.mod execution,  -g 

+FAIL: gm2/pim/run/pass/cycles.mod execution,  -O 
+FAIL: gm2/pim/run/pass/cycles.mod execution,  -O -g 
+FAIL: gm2/pim/run/pass/cycles.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/pim/run/pass/cycles.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/pim/run/pass/cycles.mod execution,  -Os 
+FAIL: gm2/pim/run/pass/cycles.mod execution,  -g 
+FAIL: gm2/pimlib/logitech/run/pass/realconv.mod execution,  -O 
+FAIL: gm2/pimlib/logitech/run/pass/realconv.mod execution,  -O -g 
+FAIL: gm2/pimlib/logitech/run/pass/realconv.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/pimlib/logitech/run/pass/realconv.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/pimlib/logitech/run/pass/realconv.mod execution,  -Os 
+FAIL: gm2/pimlib/logitech/run/pass/realconv.mod execution,  -g 
+FAIL: gm2/pimlib/logitech/run/pass/realinput.mod execution,  -O 
+FAIL: gm2/pimlib/logitech/run/pass/realinput.mod execution,  -O -g 
+FAIL: gm2/pimlib/logitech/run/pass/realinput.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/pimlib/logitech/run/pass/realinput.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/pimlib/logitech/run/pass/realinput.mod execution,  -Os 
+FAIL: gm2/pimlib/logitech/run/pass/realinput.mod execution,  -g 
+FAIL: gm2/pimlib/logitech/run/pass/realinput2.mod execution,  -O 
+FAIL: gm2/pimlib/logitech/run/pass/realinput2.mod execution,  -O -g 
+FAIL: gm2/pimlib/logitech/run/pass/realinput2.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/pimlib/logitech/run/pass/realinput2.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/pimlib/logitech/run/pass/realinput2.mod execution,  -Os 
+FAIL: gm2/pimlib/logitech/run/pass/realinput2.mod execution,  -g 
+FAIL: gm2/pimlib/logitech/run/pass/realinput3.mod execution,  -O 
+FAIL: gm2/pimlib/logitech/run/pass/realinput3.mod execution,  -O -g 
+FAIL: gm2/pimlib/logitech/run/pass/realinput3.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/pimlib/logitech/run/pass/realinput3.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/pimlib/logitech/run/pass/realinput3.mod execution,  -Os 
+FAIL: gm2/pimlib/logitech/run/pass/realinput3.mod execution,  -g 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -O 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -O -g 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -O3 -fomit-frame-pointer -finline-functions 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -Os 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -g 

I've had a look at the readreal.mod one: gm2.log shows

enter a real number: RTExceptions.mod:649:35: In invalidloc
RTExceptions.mod:649:35:invalid address referenced
executed /var/gcc/regression/master/11.4-gcc/build/gcc/testsuite/gm2/readreal.x0 with result fail

This seems to be the same failure in all affected cases.

However, when I compile that testcase manually, the exception is
different:

enter a real number: EXCEPTIONS.mod:65:56: In RAISE
EXCEPTIONS.mod:65:56:IOChan: ChanId specified is invalid
[New Thread 1 (LWP 1)]

Thread 2 received signal SIGABRT, Aborted.
[Switching to Thread 1 (LWP 1)]
0xfec18838 in __lwp_sigqueue () from /lib/libc.so.1
1: x/i $pc
=> 0xfec18838 <__lwp_sigqueue+8>:	
    bcc,a   %icc, 0xfec18848 <__lwp_sigqueue+24>
   0xfec1883c <__lwp_sigqueue+12>:	mov  %g0, %o0
(gdb) bt
#0  0xfec18838 in __lwp_sigqueue () from /lib/libc.so.1
#1  0xfeb56a54 in raise () from /lib/libc.so.1
#2  0xfeb27fe0 in abort () from /lib/libc.so.1
#3  0x0002bb60 in m2pim_M2RTS_HALT (exitcode=-1)
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/../../gcc/m2/gm2-libs/M2RTS.mod:238
#4  0x00037284 in m2pim_RTExceptions_DefaultErrorCatch ()
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/../../gcc/m2/gm2-libs/RTExceptions.mod:156
#5  0x00022728 in main (argc=1, argv=0xffbfebec, envp=0xffbfebf4)
    at /vol/gcc/src/hg/master/local/gcc/testsuite/gm2/isolib/run/pass/readreal.mod:18

Maybe I'm missing some env variable passed in by the test framework?
Comment 5 Gaius Mulley 2023-03-15 13:53:31 UTC
readreal.mod requires the input file testnumber to be in the same directory as the executable invocation.

Or manually create a text file containing:

cat << EOF > testnumber
12.3456
EOF
Comment 6 ro@CeBiTec.Uni-Bielefeld.DE 2023-03-15 14:00:18 UTC
> --- Comment #5 from Gaius Mulley <gaius at gcc dot gnu.org> ---
> readreal.mod requires the input file testnumber to be in the same directory as
> the executable invocation.
>
> Or manually create a text file containing:
>
> cat << EOF > testnumber
> 12.3456
> EOF

Got it, thanks.  It's another unaligned access:

Thread 2 received signal SIGBUS, Bus error.
[Switching to Thread 1 (LWP 1)]
0x00037a40 in m2pim_dtoa_strtod (s=0x54c90 "12.3456", error=0xffbfe96f)
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/dtoa.cc:124
124	    *error = (errno != 0);
1: x/i $pc
=> 0x37a40 <m2pim_dtoa_strtod(char const*, int*)+76>:	st  %g2, [ %i1 ]
(gdb) bt
#0  0x00037a40 in m2pim_dtoa_strtod (s=0x54c90 "12.3456", error=0xffbfe96f)
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/dtoa.cc:124
#1  0x000263b0 in m2iso_RealIO_ReadReal (cid=0x594a0, real=@0x4e3a8: 0)
    at /vol/gcc/src/hg/master/local/libgm2/libm2iso/../../gcc/m2/gm2-libs-iso/RealIO.mod:75
#2  0x00021cac in _M2_readreal_init (argc=1, argv=0xffbfebcc, envp=0xffbfebd4)
    at /vol/gcc/src/hg/master/local/gcc/testsuite/gm2/isolib/run/pass/readreal.mod:31
#3  0x0002d560 in m2pim_M2Dependent_ConstructModules (
    applicationmodule=<optimized out>, libname=<optimized out>, argc=1, 
    argv=0xffbfebcc, envp=0xffbfebd4)
    at /vol/gcc/src/hg/master/local/libgm2/libm2pim/../../gcc/m2/gm2-libs/M2Dependent.mod:813
#4  0x00022660 in _M2_init (argc=1, argv=0xffbfebcc, envp=0xffbfebd4)
    at /vol/gcc/src/hg/master/local/gcc/testsuite/gm2/isolib/run/pass/readreal.mod:18
#5  0x000226d8 in main (argc=1, argv=0xffbfebcc, envp=0xffbfebd4)
    at /vol/gcc/src/hg/master/local/gcc/testsuite/gm2/isolib/run/pass/readreal.mod:18
(gdb) p/x $i1
$1 = 0xffbfe96f
Comment 7 Gaius Mulley 2023-03-15 20:09:54 UTC
Created attachment 54675 [details]
Proposed fix v3

Many thanks for testing and diagnosing the latest bugs.  Here is a proposed fix for the bool parameters in dtoa and ldtoa:
Comment 8 GCC Commits 2023-03-15 21:31:19 UTC
The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>:

https://gcc.gnu.org/g:8f1711ef3486b0727ccf6b5aabddda5c7d986457

commit r13-6700-g8f1711ef3486b0727ccf6b5aabddda5c7d986457
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Wed Mar 15 21:30:33 2023 +0000

    PR 109125 13 regression SIGBUS in m2pim_ldtoa_ldtoa
    
    This patch fixes more bool int parameter mismatches
    found in dtoa and ldtoa.
    
    gcc/m2/ChangeLog:
    
            PR modula2/109125
            * gm2-libs-ch/dtoa.cc (dtoa_strtod): Replace int with bool.
            * gm2-libs-ch/ldtoa.cc (ldtoa_strtold): Replace int with bool.
    
    libgm2/ChangeLog:
    
            PR modula2/109125
            * libm2pim/dtoa.cc (TRUE): Remove.
            (FALSE): Remove.  Replace int with bool.
            * libm2pim/ldtoa.cc (TRUE): Remove.
            (FALSE): Remove.  Replace int with bool.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Comment 9 ro@CeBiTec.Uni-Bielefeld.DE 2023-03-16 14:43:04 UTC
> --- Comment #7 from Gaius Mulley <gaius at gcc dot gnu.org> ---
> Created attachment 54675 [details]
>   --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54675&action=edit
> Proposed fix v3
>
> Many thanks for testing and diagnosing the latest bugs.  Here is a proposed fix
> for the bool parameters in dtoa and ldtoa:

This fixes all but one last failure:

+FAIL: gm2/types/run/pass/varient4.mod execution,  -O 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -O -g 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -O3 -fomit-frame-pointer 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -O3 -fomit-frame-pointer -fin
line-functions 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -Os 
+FAIL: gm2/types/run/pass/varient4.mod execution,  -g 

gm2.log shows

executed /var/gcc/regression/master/11.4-gcc/build/gcc/testsuite/gm2/varient4.x0 with result failFAIL: gm2/types/run/pass/varient4.mod execution,  -g 

There's one unrelated issue here: the "excuted...with result fail"
message needs to end in a newline so you can grep for ^FAIL: in the log
file.  This is from gm2-torture.exp (gm2-torture-execute), where the
send_log call needs an "\n"appended.  gm2-simple.exp
(gm2-simple-execute) has the same issue.

The failing test just exits with status 1.

Running it under gdb shows that the exit happens after this:

36	   zero ; hmm.bar   := TRUE ; test(hmm, 3, 1) ;

Thread 2 hit Breakpoint 4, d_test (s=0x34bc0 <hmm>, n=3, v=1)
    at /vol/gcc/src/hg/master/local/gcc/testsuite/gm2/types/run/pass/d.c:44
44	  switch (n) {

(gdb) p s
$1 = (this *) 0x34bc0 <hmm>
(gdb) p *$1
$2 = {tag = 0, that = {first = {foo = 0, bar = 16777216, inner = {bt = 0, 
        bf = 0}}, an = 0}, final = 0}
(gdb) n
48	  case 3: assert(s->that.first.bar == v); break;
(gdb) p s->that.first.bar
$3 = 16777216
(gdb) p v
$4 = 1
Comment 10 GCC Commits 2023-03-16 20:42:01 UTC
The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>:

https://gcc.gnu.org/g:f231bca93ca92f6fd55de6fbe4bf8935f9ec558a

commit r13-6719-gf231bca93ca92f6fd55de6fbe4bf8935f9ec558a
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Thu Mar 16 20:41:20 2023 +0000

    PR modula2/109125 SIGBUS in m2pim_ldtoa_ldtoa
    
    13 regression failures seen on sparc SIGBUS in m2pim_ldtoa_ldtoa.
    This patch fixes int bool struct field mismatches between the
    definition modules and their C/C++ implementations.
    
    gcc/testsuite/ChangeLog:
    
            PR modula2/109125
            * gm2/types/run/pass/d.c: Convert data structure from
            BOOLEAN int to bool and cast int to bool in test function.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Comment 11 ro@CeBiTec.Uni-Bielefeld.DE 2023-03-21 10:32:02 UTC
> --- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
> The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>:
>
> https://gcc.gnu.org/g:f231bca93ca92f6fd55de6fbe4bf8935f9ec558a
>
> commit r13-6719-gf231bca93ca92f6fd55de6fbe4bf8935f9ec558a
> Author: Gaius Mulley <gaiusmod2@gmail.com>
> Date:   Thu Mar 16 20:41:20 2023 +0000
>
>     PR modula2/109125 SIGBUS in m2pim_ldtoa_ldtoa

Just to confirm: this patch fixes the last of the SIGBUS failures.  Thanks!
Comment 12 Gaius Mulley 2023-03-21 18:26:45 UTC
Thanks for the bug reports - closing as all resolved.