racket icon indicating copy to clipboard operation
racket copied to clipboard

Error [ARITH] 1878 in bc/src/bignum.c: suspicious arithmetic, LHS ends d_digs.

Open riastradh opened this issue 2 years ago • 6 comments

What version of Racket are you using? 8.10 [bconly]

What program did you run?

./configure --enable-bconly ...
gmake

What should have happened? Racket should have built.

If you got an error message, please include it here.

bc/racketcgc -O info'@'compiler/cm -l- setup --boot setup-go.rkt bc/compiled --tag ++out bc/gc2/xform-mod.rkt --depends --cpp cc" "-E" "-Ibc" "-Ibc/src" "-Ibc/include" "-Iversion" "-Irktio" "-Ibc/rktio" "-Ibc/phase2" "-O2" "-g" "-pthread" "-I/home/riastradh/pkgsrc/current/pkg/include" "-I/home/riastradh/pkgsrc/current/pkg/include/ncurses" "-I/usr/include" "-I/home/riastradh/pkgsrc/current/pkg/include/freetype2" "-I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0" "-I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0" "-I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include" "-I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz" "-I/home/riastradh/pkgsrc/current/pkg/include" "-I/home/riastradh/pkgsrc/current/pkg/include/ncurses" "-I/usr/include" "-I/home/riastradh/pkgsrc/current/pkg/include/freetype2" "-I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0" "-I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0" "-I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include" "-I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz" "-I/home/riastradh/pkgsrc/current/pkg/include" "-DUSE_SENORA_GC --keep-lines -o ++out bc/xsrc/bignum.c bc/src/bignum.c
Error [ARITH] 1878 in bc/src/bignum.c: suspicious arithmetic, LHS ends d_digs.
Error [ARITH] 1870 in bc/src/bignum.c: suspicious arithmetic, LHS ends n_digs.
xform: Errors converting
[91mfailed
[0m in xform
 in build-one
 in loop
 in module->hash
gmake: *** [Makefile:18: all] Error 1

Please include any other relevant details NetBSD 9

riastradh avatar Sep 01 '23 11:09 riastradh

The only file with the text suspicious arithmetic is collects/compiler/private/xform.rkt:

https://github.com/racket/racket/blob/b10ecfb8311fca2d42636eea2ca12aff0b76b208/racket/collects/compiler/private/xform.rkt#L3995-L3999

This appears to be trying to parse C preprocessor output on the file src/bc/src/bignum.c, and is choking on the following two lines:

https://github.com/racket/racket/blob/b10ecfb8311fca2d42636eea2ca12aff0b76b208/racket/src/bc/src/bignum.c#L1870 https://github.com/racket/racket/blob/b10ecfb8311fca2d42636eea2ca12aff0b76b208/racket/src/bc/src/bignum.c#L1878

My guess is that when this C file is compiled with the hardening option -D_FORTIFY_SOURCE=2, which pkgsrc applies by default to eliminate a large class of buffer overrun vulnerabilities, memmove is defined as a macro in string.h (via ssp/string.h):

https://nxr.netbsd.org/xref/src/include/string.h?r=1.54#127

    127 #if _FORTIFY_SOURCE > 0
    128 #include <ssp/string.h>
    129 #endif

https://nxr.netbsd.org/xref/src/include/ssp/string.h?r=1.14#96

     96 #define memmove(dst, src, len) __ssp_bos_check3(memmove, dst, src, len)

https://nxr.netbsd.org/xref/src/include/ssp/string.h?r=1.14#50

     50 #define __ssp_bos_check3(fun, dst, src, len) \
     51     ((__ssp_bos0(dst) != (size_t)-1) ? \
     52     __builtin___ ## fun ## _chk(dst, src, len, __ssp_bos0(dst)) : \
     53     __ ## fun ## _ichk(dst, src, len))

I don't know what this xform.rkt process is trying to do, but it seems fragile and imprudent to try to parse the C preprocessor output of general C code in an arbitrary compiler, host, and build environment without nailing down every relevant detail.

If you must make a function call to the libc symbol, not invoke a macro, you can use (memmove)(...) instead of memmove(...). But, of course, this bypasses the stack smashing protection.

If I build with fortify disabled, I get an even more inscrutable error message:

compiler/cm:   finish-compile: /home/riastradh/pkgsrc/current/work/lang/racket/work/racket-8.10/src/bc/gc2/xform-mod.rkt
bc/racketcgc -O info'@'compiler/cm -l- setup --boot setup-go.rkt bc/compiled --tag ++out bc/gc2/xform-mod.rkt --depends --cpp cc" "-E" "-Ibc" "-Ibc/src" "-Ibc/include" "-Iversion" "-Irktio" "-Ibc/rktio" "-Ibc/phase2" "-O2" "-g" "-pthread" "-I/home/riastradh/pkgsrc/current/pkg/include" "-I/home/riastradh/pkgsrc/current/pkg/include/ncurses" "-I/usr/include" "-I/home/riastradh/pkgsrc/current/pkg/include/freetype2" "-I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0" "-I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0" "-I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include" "-I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz" "-I/home/riastradh/pkgsrc/current/pkg/include" "-I/home/riastradh/pkgsrc/current/pkg/include/ncurses" "-I/usr/include" "-I/home/riastradh/pkgsrc/current/pkg/include/freetype2" "-I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0" "-I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0" "-I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include" "-I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz" "-I/home/riastradh/pkgsrc/current/pkg/include" "-DUSE_SENORA_GC --keep-lines -o ++out bc/xsrc/startup.c bc/src/startup.c
failed
 in xform
 in build-one
 in loop
 in module->hash
gmake: *** [Makefile:18: all] Error 1

The line with startup.c occurs before the failing line with bignum.c in the output with --enable-bconly, however, so it's not clear whether this fixes anything -- the build fails too soon to say. I'm also not 100% sure these failed errors are deterministic.

riastradh avatar Sep 01 '23 13:09 riastradh

Here's the tail of another bconly, no-fortify build -- this one did seem to make it past bignum.c, which may confirm my hypothesis about xform.rkt getting confused by the macro expansion of memmove:

bc/racketcgc -O info'@'compiler/cm -l- setup --boot setup-go.rkt bc/compiled --tag ++out bc/gc2/xform-mod.rkt --depends --cpp cc" "-E" "-Ibc" "-Ibc/src" "-Ibc/include" "-Iversion" "-Irktio" "-Ibc/rktio" "-Ibc/phase2" "-O2" "-g" "-pthread" "-I/home/riastradh/pkgsrc/current/pkg/include" "-I/home/riastradh/pkgsrc/current/pkg/include/ncurses" "-I/usr/include" "-I/home/riastradh/pkgsrc/current/pkg/include/freetype2" "-I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0" "-I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0" "-I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include" "-I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz" "-I/home/riastradh/pkgsrc/current/pkg/include" "-I/home/riastradh/pkgsrc/current/pkg/include/ncurses" "-I/usr/include" "-I/home/riastradh/pkgsrc/current/pkg/include/freetype2" "-I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0" "-I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0" "-I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include" "-I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz" "-I/home/riastradh/pkgsrc/current/pkg/include" "-DUSE_SENORA_GC --keep-lines -o ++out bc/xsrc/bignum.c bc/src/bignum.c
cc -I/home/riastradh/pkgsrc/current/pkg/include -I/home/riastradh/pkgsrc/current/pkg/include/ncurses -I/usr/include -I/home/riastradh/pkgsrc/current/pkg/include/freetype2 -I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0 -I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0 -I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include -I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz -I/home/riastradh/pkgsrc/current/pkg/include -Ibc -Ibc/rktio -Irktio -Ibc/include -Iversion -Ibc/src -Ibc/phase2 -O2 -g -pthread -I/home/riastradh/pkgsrc/current/pkg/include -I/home/riastradh/pkgsrc/current/pkg/include/ncurses -I/usr/include -I/home/riastradh/pkgsrc/current/pkg/include/freetype2 -I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0 -I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0 -I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include -I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz -I/home/riastradh/pkgsrc/current/pkg/include -I/home/riastradh/pkgsrc/current/pkg/include/ncurses -I/usr/include -I/home/riastradh/pkgsrc/current/pkg/include/freetype2 -I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0 -I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0 -I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include -I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz -I/home/riastradh/pkgsrc/current/pkg/include -DUSE_SENORA_GC -o bc/xsrc/bignum.o -c bc/xsrc/bignum.c
bc/racketcgc -O info'@'compiler/cm -l- setup --boot setup-go.rkt bc/compiled --tag ++out bc/gc2/xform-mod.rkt --depends --cpp cc" "-E" "-Ibc" "-Ibc/src" "-Ibc/include" "-Iversion" "-Irktio" "-Ibc/rktio" "-Ibc/phase2" "-O2" "-g" "-pthread" "-I/home/riastradh/pkgsrc/current/pkg/include" "-I/home/riastradh/pkgsrc/current/pkg/include/ncurses" "-I/usr/include" "-I/home/riastradh/pkgsrc/current/pkg/include/freetype2" "-I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0" "-I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0" "-I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include" "-I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz" "-I/home/riastradh/pkgsrc/current/pkg/include" "-I/home/riastradh/pkgsrc/current/pkg/include/ncurses" "-I/usr/include" "-I/home/riastradh/pkgsrc/current/pkg/include/freetype2" "-I/home/riastradh/pkgsrc/current/pkg/include/glib-2.0" "-I/home/riastradh/pkgsrc/current/pkg/include/gio-unix-2.0" "-I/home/riastradh/pkgsrc/current/pkg/lib/glib-2.0/include" "-I/home/riastradh/pkgsrc/current/pkg/include/harfbuzz" "-I/home/riastradh/pkgsrc/current/pkg/include" "-DUSE_SENORA_GC --keep-lines -o ++out bc/xsrc/bool.c bc/src/bool.c
failed
 in xform
 in build-one
 in loop
 in module->hash
gmake: *** [Makefile:18: all] Error 1

riastradh avatar Sep 01 '23 13:09 riastradh

This certainly sounds like a bug, but is there a particular reason you're building --enable-bconly? If you're trying to bootstrap Racket CS, as a workaround, you can do with the CGC build directly without going through 3M.

LiberalArtist avatar Sep 03 '23 01:09 LiberalArtist

This certainly sounds like a bug, but is there a particular reason you're building --enable-bconly?

Not particularly, someone had suggested to me that it was necessary, so I tried it first. When I hit this, I tried disabling it and made progress, so I guess it wasn't necessary!

riastradh avatar Sep 03 '23 10:09 riastradh

I've updated xform in 00945ab5d6f43c2679b85a144fe6d80b873d97f4, and now BC builds for me on NetBSD with -D_FORTIFY_SOURCE=2. The xform approach is definitely sketchy, though, and it's among the reasons that BC will eventually be phased out completely in favor of CS. Unless someone particularly needs BC, I recommend avoiding it.

I would not able to provoke a problem turning -D_FORTIFY_SOURCE=2 off. Probably I'm missing some other ingredient, but maybe it's also ok to just chalk this up to BC being a problem.

mflatt avatar Sep 03 '23 16:09 mflatt