Subject: bug#63365: 30.0.50; GCC 13.1 breaks building Emacs with native-compilation

From: Eli Zaretskii <[email-masked]>
Date: Mon, 08 May 2023 18:13:06 +0300

> From: Arash Esbati <[email-masked]>
> Cc: Andrea Corallo <[email-masked]>,  [email-masked]
> Date: Mon, 08 May 2023 16:36:57 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > These addresses are not useful anywhere but on your system.  So either
> > run this command under GDB and post a human-readable source-level
> > backtrace,
> 
> Thank.  I tried that, i.e.,
> 
>   $ ./autogen.sh
>   $ ./configure --with-native-compilation
>   $ gdb
>   $ (gdb) make
> 
> But backtrace in gdb returns nothing (nothing on stack IIRC).  Do I have
> to do something else?

Yes, of course.  The GDB command "make" doesn't run anything under the
debugger, it is just a conveniency for rebuilding a program without
exiting GDB.

What you need is to run Emacs under GDB while it (Emacs) executes the
command which crashes.  To find out what is that crashing command, you
should say:

  $ make V=1

(note: "make", not "make -jN"!).  Then wait for the crash.  The
(longish) command shown by Make immediately before the crash is the
command that you want; copy it into the clipboard, and then do

  $ cd  /path/to/emacs/src
  $ gdb ./emacs.exe
  ...
  (gdb) cd ../lisp
  (gdb) run <paste here the crashing command you copied>

and wait for the crash.  Then:

  (gdb) thread 1
  (gdb) bt

Note: the command you copy into the clipboard may need massaging
before you can paste it to the GDB prompt: remove any stray newlines
and backslashes that escape newlines etc.  Use some editor for that:
either (an older) Emacs or even Notepad.

> > or at least convert the above list of addresses to a list of file
> > names, function names, and line numbers as explained in the node
> > "Crashing" of the Emacs user manual.
> 
> The recipe from the manual[1] doesn't work since:
> 
>   $ sed -n 's/.*\[\(.*\)]$/\1/p' lisp/emacs_backtrace.txt
> 
> prints nothing on addresses like:
> 
>   00007ff67feca12e
>   00007ff67fd98be1
>   00007ff67fdb9601
> 
> Am I missing something?

The recipe goes like this:

  sed -n 's/.*\[\(.*\)]$/\1/p' BACKTRACE | addr2line -C -f -i -p -e BINDIR/EMACS-BINARY

(It is broken in the manual into two lines, because the line is long,
but it is a single long command that runs Sed and pipes its output
into addr2line, a program that comes with GNU Binutils.)

> Another observation after reading etc/DEBUG: The build is successful if
> I follow the advice there and do:
> 
>   $ ./configure --with-native-compilation  CFLAGS='-O0 -g3'
> 
> Does this make sense?

It probably means this is a GCC bug that rears its ugly head when you
compile with optimizations.

Can you show a full C compilation command of one of the C source
files?  Like this:

  $ cd /path/to/emacs/src
  $ make data.o -W data.c V=1

I'd like to see all of the compiler's command-line options your build
uses.