Subject: Re: bug#57789: Emacs 28.1 clone build with native compilation crashes on s390x

From: Rob Browning <[email-masked]>
Date: Wed, 14 Sep 2022 15:19:24 -0500

Eli Zaretskii <[email-masked]> writes:

> Please run the crashing command under GDB, and when it segfaults,
> produce the C-level and Lisp-level backtrace, and post them here.

Starting from scratch with the emacs-28.1 commit I can reproduce the
failure when building via

  ./configure --prefix=/home/rlb/opt/emacs-tmp --with-native-compilation

It crashes with the same segfault repeatably, i.e. if you run make
again, it crashes again on the previously mentioned "... -l comp -f
batch-byte+native-compile international/titdic-cnv.el" invocation.  That
crash output is attached below.

After adjusting the Makefile.in invocation so I could run it with gdb in
exactly the same environment once it's failing on that command, I
captured the backtrace and included it below.

With respect to the Lisp-level backtrace, I imagined you probably meant
an xbacktrace?  If so (and assuming I'm guessing right about how I
should do that), I haven't figured out how to arrange sourcing the
src/.gdbinit from the src/Makefile.in command.  I'm likely doing
something wrong, but it doesn't seem to want to load the file.

It looked like it might be because there were no debug symbols, so I
tried adding a CFLAGS=-g3 to the end of the ./configure, but that caused
the crash to disappear entirely.

Finally (and this was just a random guess based on previous experiences,
particularly with programs like guile that play (normal, traditional)
tricks with pointers/coercions/etc.) I noticed that emacs doesn't
specify -fno-strict-aliasing, and unless all the C code has been written
with that in mind, I assume that might open a window allowing the
optimizer to introduce undesirable changes.  So I added a
CFLAGS=-fno-strict-aliasing to the end of the ./configure command, and
then the build and tests worked fine (twice in a row):

  ./configure --prefix=/home/rlb/opt/emacs-tmp --with-native-compilation \
    CFLAGS=-fno-strict-aliasing

Of course that's not remotely conclusive, but if all of the C code
wasn't written with strict-aliasing in mind, then I wondered if it might
make sense to consider adding -fno-strict-aliasing as a default option.

Also, even if that ends up being desirable, I'm not sure it'll be
sufficient.  That is, I suspect I might want to run the full build/check
with -fno-strict-aliasing in a loop for a bit to make sure the clean
build/check is reliable, since I think I may have seen some test crashes
(not the build crash) on one earlier run with that option, but I'm not
sure that was a clean attempt.

The make crash:

make[2]: Entering directory '/home/rlb/emacs/lisp'
EMACSLOADPATH= '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp --eval '(setq load-prefer-newer t)'  \
-l comp -f batch-byte+native-compile international/titdic-cnv.el
Fatal error 11: Segmentation fault
Backtrace:
../src/bootstrap-emacs(+0x15deb6)[0x2aa293ddeb6]
../src/bootstrap-emacs(+0x4efc4)[0x2aa292cefc4]
../src/bootstrap-emacs(+0x4f1fe)[0x2aa292cf1fe]
../src/bootstrap-emacs(+0x15c240)[0x2aa293dc240]
../src/bootstrap-emacs(+0x15c2d2)[0x2aa293dc2d2]
../src/bootstrap-emacs(+0x6a47d8)[0x2aa299247d8]
../src/bootstrap-emacs(+0x1a7fa8)[0x2aa29427fa8]
../src/bootstrap-emacs(+0x1a8ee6)[0x2aa29428ee6]
../src/bootstrap-emacs(+0x1a8ee6)[0x2aa29428ee6]
../src/bootstrap-emacs(+0x1a8ee6)[0x2aa29428ee6]
../src/bootstrap-emacs(+0x1a7c3e)[0x2aa29427c3e]
../src/bootstrap-emacs(+0x1a9094)[0x2aa29429094]
../src/bootstrap-emacs(Ffuncall+0x2de)[0x2aa2944a2ee]
../src/bootstrap-emacs(+0x1ca42c)[0x2aa2944a42c]
../src/bootstrap-emacs(+0x1f0c72)[0x2aa29470c72]
../src/bootstrap-emacs(+0x1f7fb0)[0x2aa29477fb0]
../src/bootstrap-emacs(+0x1f8474)[0x2aa29478474]
../src/bootstrap-emacs(eval_sub+0x5e4)[0x2aa2944cdfc]
../src/bootstrap-emacs(+0x1ce488)[0x2aa2944e488]
../src/bootstrap-emacs(eval_sub+0x532)[0x2aa2944cd4a]
../src/bootstrap-emacs(+0x1ce488)[0x2aa2944e488]
../src/bootstrap-emacs(eval_sub+0x532)[0x2aa2944cd4a]
../src/bootstrap-emacs(+0x1ce8cc)[0x2aa2944e8cc]
../src/bootstrap-emacs(eval_sub+0x532)[0x2aa2944cd4a]
../src/bootstrap-emacs(+0x1ce488)[0x2aa2944e488]
../src/bootstrap-emacs(eval_sub+0x532)[0x2aa2944cd4a]
../src/bootstrap-emacs(+0x1cd824)[0x2aa2944d824]
../src/bootstrap-emacs(eval_sub+0x532)[0x2aa2944cd4a]
../src/bootstrap-emacs(+0x1cdc2e)[0x2aa2944dc2e]
../src/bootstrap-emacs(Ffuncall+0x1f2)[0x2aa2944a202]
../src/bootstrap-emacs(+0x1ca4b0)[0x2aa2944a4b0]
../src/bootstrap-emacs(+0x1f90e4)[0x2aa294790e4]
../src/bootstrap-emacs(+0x1f9462)[0x2aa29479462]
../src/bootstrap-emacs(+0x1c9ef0)[0x2aa29449ef0]
../src/bootstrap-emacs(Ffuncall+0x182)[0x2aa2944a192]
/home/rlb/emacs/native-lisp/28.2-87d45215/comp-7672a6ed-ac6bcf4e.eln(F636f6d702d2d6e61746976652d636f6d70696c65_comp__native_compile_0+0x804)[0x3ff91d6b0d4]
../src/bootstrap-emacs(Ffuncall+0x23e)[0x2aa2944a24e]
/home/rlb/emacs/native-lisp/28.2-87d45215/comp-7672a6ed-ac6bcf4e.eln(F62617463682d6e61746976652d636f6d70696c65_batch_native_compile_0+0x1d2)[0x3ff91d6c592]
../src/bootstrap-emacs(Ffuncall+0x23e)[0x2aa2944a24e]
/home/rlb/emacs/native-lisp/28.2-87d45215/comp-7672a6ed-ac6bcf4e.eln(F62617463682d627974652b6e61746976652d636f6d70696c65_batch_bytenative_compile_0+0x108)[0x3ff91d6c728]
../src/bootstrap-emacs(Ffuncall+0x23e)[0x2aa2944a24e]
...
make[2]: *** [Makefile:321: international/titdic-cnv.elc] Segmentation fault
make[2]: Leaving directory '/home/rlb/emacs/lisp'
make[1]: *** [Makefile:845: ../lisp/loaddefs.el] Error 2
make[1]: Leaving directory '/home/rlb/emacs/src'
make: *** [Makefile:449: src] Error 2

The gdb backtrace:

Program received signal SIGSEGV, Segmentation fault.
mark_object (arg=<optimized out>) at alloc.c:6809
6809            if (symbol_marked_p (ptr))
(gdb) backtrace
#0  mark_object (arg=<optimized out>) at alloc.c:6809
#1  0x000002aa001a8ee6 in mark_objects (n=<optimized out>, obj=0x2aa00ac54a8) at alloc.c:6607
#2  mark_vectorlike (header=0x2aa00ac54a0) at alloc.c:6382
#3  0x000002aa001a8ee6 in mark_objects (n=<optimized out>, obj=0x2aa007f4ca8) at alloc.c:6607
#4  mark_vectorlike (header=0x2aa007f4ca0) at alloc.c:6382
#5  0x000002aa001a8ee6 in mark_objects (n=<optimized out>, obj=0x2aa007c3b10) at alloc.c:6607
#6  mark_vectorlike (header=0x2aa007c3b08) at alloc.c:6382
#7  0x000002aa001a7c3e in visit_static_gc_roots (visitor=...) at alloc.c:5926
#8  0x000002aa001a9094 in garbage_collect () at alloc.c:6132
#9  0x000002aa001a9d0c in maybe_garbage_collect () at alloc.c:6045
#10 0x000002aa001ca2ee in maybe_gc () at lisp.h:5142
#11 Ffuncall (nargs=nargs@entry=3, args=args@entry=0x3ffffffa6a0) at eval.c:3007
#12 0x000002aa001ca42c in call2 (fn=fn@entry=0x155f3675830, arg1=arg1@entry=0x2aa00a75e43, arg2=arg2@entry=0x0) at eval.c:2890
#13 0x000002aa001f0c72 in readevalloop_eager_expand_eval (val=val@entry=0x2aa00a75e43, macroexpand=macroexpand@entry=0x155f3675830) at lread.c:2133
#14 0x000002aa001f7fb0 in readevalloop (readcharfun=readcharfun@entry=0x2aa00aa27b5, infile0=<optimized out>, 
    infile0@entry=0x0, sourcename=sourcename@entry=0x2aa00a7fff4, printflag=printflag@entry=false, unibyte=unibyte@entry=0x0, readfun=0x0, start=0x0, end=<optimized out>) at lread.c:2324
#15 0x000002aa001f8474 in Feval_buffer (buffer=<optimized out>, printflag=0x0, filename=0x2aa00a7fff4, unibyte=0x0, do_allow_print=<optimized out>) at lread.c:2397
#16 0x000002aa001ccdfc in eval_sub (form=<optimized out>) at eval.c:2512
#17 0x000002aa001ce488 in Fprogn (body=0x0) at eval.c:465
#18 Flet (args=0x3b) at eval.c:1051
#19 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#20 0x000002aa001ce488 in Fprogn (body=0x0) at eval.c:465
#21 Flet (args=0x36) at eval.c:1051
#22 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#23 0x000002aa001ce8cc in Funwind_protect (args=0x3fff3cf7f0b) at lisp.h:1420
#24 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#25 0x000002aa001ce488 in Fprogn (body=0x3fff3cf7d6b) at eval.c:465
#26 Flet (args=0x2d) at eval.c:1051
#27 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#28 0x000002aa001cd824 in Fprogn (body=0x0) at eval.c:465
#29 Fif (args=<optimized out>) at eval.c:421
#30 Fif (args=<optimized out>) at eval.c:407
#31 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#32 0x000002aa001cdc2e in Fprogn (body=0x0) at eval.c:465
#33 funcall_lambda (fun=0x3fff3cf7c9b, nargs=nargs@entry=4, arg_vector=arg_vector@entry=0x3ffffffb650) at eval.c:3305
#34 0x000002aa001ca202 in Ffuncall (nargs=nargs@entry=5, args=args@entry=0x3ffffffb648) at eval.c:3039
#35 0x000002aa001ca4b0 in call4 (fn=<optimized out>, arg1=arg1@entry=0x2aa00a7fff4, arg2=arg2@entry=0x2aa00a7fff4, arg3=arg3@entry=0x0, arg4=arg4@entry=0x30) at eval.c:2905
#36 0x000002aa001f90e4 in Fload (file=file@entry=0x3fff362bcbc, noerror=noerror@entry=0x0, nomessage=nomessage@entry=0x30, nosuffix=nosuffix@entry=0x0, must_suffix=<optimized out>, 
    must_suffix@entry=0x30) at lread.c:1473
#37 0x000002aa001f9462 in save_match_data_load (file=0x3fff362bcbc, noerror=noerror@entry=0x0, nomessage=nomessage@entry=0x30, nosuffix=nosuffix@entry=0x0, must_suffix=must_suffix@entry=0x30)
    at lread.c:1629
#38 0x000002aa001c9ef0 in Fautoload_do_load (fundef=0x3fff362bc4b, funname=funname@entry=0x155f2f7a340, macro_only=macro_only@entry=0x0) at eval.c:2295
#39 0x000002aa001ca192 in Ffuncall (nargs=2, args=0x3ffffffbba0) at eval.c:3042
#40 0x000003fff306b0d4 in F636f6d702d2d6e61746976652d636f6d70696c65_comp__native_compile_0 () at /home/rlb/emacs/native-lisp/28.2-87d45215/comp-7672a6ed-ac6bcf4e.eln
#41 0x000002aa001ca24e in Ffuncall (nargs=<optimized out>, args=<optimized out>) at lisp.h:2110
#42 0x000003fff306c592 in F62617463682d6e61746976652d636f6d70696c65_batch_native_compile_0 () at /home/rlb/emacs/native-lisp/28.2-87d45215/comp-7672a6ed-ac6bcf4e.eln
#43 0x000002aa001ca24e in Ffuncall (nargs=<optimized out>, args=<optimized out>) at lisp.h:2110
#44 0x000003fff306c728 in F62617463682d627974652b6e61746976652d636f6d70696c65_batch_bytenative_compile_0 () at /home/rlb/emacs/native-lisp/28.2-87d45215/comp-7672a6ed-ac6bcf4e.eln
#45 0x000002aa001ca24e in Ffuncall (nargs=<optimized out>, args=<optimized out>) at lisp.h:2110
#46 0x000002aa001ccfc4 in eval_sub (form=<optimized out>) at eval.c:2470
#47 0x000002aa001cd824 in Fprogn (body=0x0) at eval.c:465
#48 Fif (args=<optimized out>) at eval.c:421
#49 Fif (args=<optimized out>) at eval.c:407
#50 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#51 0x000002aa001cd8cc in Fprogn (body=0x0) at eval.c:465
#52 Fcond (args=<optimized out>) at eval.c:445
#53 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#54 0x000002aa001ce732 in Fprogn (body=0x3fff36e1b43) at eval.c:465
#55 FletX (args=0x3fff36e1b03) at eval.c:983
#56 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#57 0x000002aa001cd6ae in Fprogn (body=0x0) at eval.c:465
#58 prog_ignore (body=<optimized out>) at eval.c:476
#59 Fwhile (args=<optimized out>) at eval.c:1072
#60 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#61 0x000002aa001ce732 in Fprogn (body=0x0) at eval.c:465
#62 FletX (args=0x3fff36e1a83) at eval.c:983
#63 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#64 0x000002aa001cd1d6 in Fprogn (body=0x0) at eval.c:465
#65 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#66 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#67 0x000002aa001ce488 in Fprogn (body=0x0) at eval.c:465
#68 Flet (args=0x12) at eval.c:1051
#69 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#70 0x000002aa001ce488 in Fprogn (body=0x3fff35d3a73) at eval.c:465
#71 Flet (args=0xe) at eval.c:1051
#72 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#73 0x000002aa001cdc2e in Fprogn (body=0x0) at eval.c:465
#74 funcall_lambda (fun=0x3fff35d39e3, fun@entry=0x3fff35d39d3, nargs=nargs@entry=1, arg_vector=arg_vector@entry=0x3ffffffd280) at eval.c:3305
#75 0x000002aa001cdf10 in apply_lambda (fun=fun@entry=0x3fff35d39d3, args=<optimized out>, count=2929176661299, count@entry=15) at eval.c:3172
#76 0x000002aa001cc9d0 in eval_sub (form=<optimized out>) at eval.c:2575
#77 0x000002aa001ce488 in Fprogn (body=0x3fff37a209b) at eval.c:465
#78 Flet (args=0x8) at eval.c:1051
#79 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#80 0x000002aa001cdc2e in Fprogn (body=0x0) at eval.c:465
#81 funcall_lambda (fun=0x3fff37a1e7b, fun@entry=0x3fff37a1e6b, nargs=nargs@entry=0, arg_vector=arg_vector@entry=0x3ffffffd740) at eval.c:3305
#82 0x000002aa001cdf10 in apply_lambda (fun=fun@entry=0x3fff37a1e6b, args=<optimized out>, count=2929176221524, count@entry=11) at eval.c:3172
#83 0x000002aa001cc9d0 in eval_sub (form=<optimized out>) at eval.c:2575
#84 0x000002aa001ce8cc in Funwind_protect (args=0x3fff380e7a3) at lisp.h:1420
#85 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#86 0x000002aa001ce488 in Fprogn (body=0x0) at eval.c:465
#87 Flet (args=0x3ffffffe658) at eval.c:1051
#88 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#89 0x000002aa001cd824 in Fprogn (body=0x3fff380e233) at eval.c:465
#90 Fif (args=<optimized out>) at eval.c:421
#91 Fif (args=<optimized out>) at eval.c:407
#92 0x000002aa001ccd4a in eval_sub (form=<optimized out>) at eval.c:2451
#93 0x000002aa001cdc2e in Fprogn (body=0x0) at eval.c:465
#94 funcall_lambda (fun=0x3fff380e0e3, fun@entry=0x3fff380e0d3, nargs=nargs@entry=0, arg_vector=arg_vector@entry=0x3ffffffdf88) at eval.c:3305
#95 0x000002aa001cdf10 in apply_lambda (fun=fun@entry=0x3fff380e0d3, args=<optimized out>, count=4398046502696, count@entry=4) at eval.c:3172
#96 0x000002aa001cc9d0 in eval_sub (form=form@entry=0x3fff3f3ef1b) at eval.c:2575
#97 0x000002aa001cee52 in Feval (form=0x3fff3f3ef1b, lexical=<optimized out>) at eval.c:2327
#98 0x000002aa001c8fb6 in internal_condition_case (bfun=bfun@entry=0x2aa00142860 <top_level_2>, handlers=handlers@entry=0x90, hfun=hfun@entry=0x2aa00148ca8 <cmd_error>) at eval.c:1450
#99 0x000002aa001435d2 in top_level_1 (ignore=ignore@entry=0x0) at keyboard.c:1150
#100 0x000002aa001c8ed4 in internal_catch (tag=tag@entry=0xe850, func=func@entry=0x2aa001435a0 <top_level_1>, arg=arg@entry=0x0) at eval.c:1181
#101 0x000002aa001427e0 in command_loop () at keyboard.c:1110
#102 0x000002aa001487bc in recursive_edit_1 () at keyboard.c:720
#103 0x000002aa00148bcc in Frecursive_edit () at keyboard.c:803
#104 0x000002aa00051d7a in main (argc=<optimized out>, argv=0x3ffffffea28) at emacs.c:2358

Thanks
-- 
Rob Browning
rlb @defaultvalue.org and @debian.org
GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A
GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4