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

From: Andrea Corallo <[email-masked]>
Date: Thu, 08 Jun 2023 10:02:22 -0400

Eli Zaretskii <[email-masked]> writes:

>> From: Arash Esbati <[email-masked]>
>> Cc: [email-masked],  [email-masked]
>> Date: Thu, 08 Jun 2023 12:21:11 +0200
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> > Did you say that the problem goes away if you configure without
>> > native-compilation?
>> 
>> Yes, no problems when --without-native-compilation is passed to
>> configure.
>> 
>> > If so, let's wait for Andrea to fix the problems with that on master,
>> > and try again.
>> 
>> I tried the latest master (a902156068), and the issue remains.
>> 
>> > Or did you also see similar problems on the emacs-29 branch?
>> 
>> Yes, issue remains with 0eba9cf651.
>
> Andrea, can you suggest some ideas for what to try/test, or
> alternatively how to prepare a concise test/reproducer for the GCC
> folks?  AFAIU, GCC 13.1 does work on GNU/Linux

I'm giving it a try mow to be sure.

> to produce a working
> Emacs with native-compilation, so this is probably Windows-specific.

I'd personally start producing an Emacs made only of bytecode but with
native compiler capabilies.  To achieve this one can hack the Makefile
removing the native code specific parts, something like the very much
untested attached.

diff --git a/lisp/Makefile.in b/lisp/Makefile.in
index 1e0935f565f..635dd7d1450 100644
--- a/lisp/Makefile.in
+++ b/lisp/Makefile.in
@@ -278,23 +278,9 @@ TAGS:
 THEFILE = no-such-file
 .PHONY: $(THEFILE)c
 $(THEFILE)c:
-ifeq ($(HAVE_NATIVE_COMP),yes)
-	$(AM_V_ELC)$(emacs) $(BYTE_COMPILE_FLAGS) \
-		-l comp -f byte-compile-refresh-preloaded \
-		-f batch-byte+native-compile $(THEFILE)
-else
 	$(AM_V_ELC)$(emacs) $(BYTE_COMPILE_FLAGS) \
 		-l bytecomp -f byte-compile-refresh-preloaded \
 		-f batch-byte-compile $(THEFILE)
-endif
-
-ifeq ($(HAVE_NATIVE_COMP),yes)
-.PHONY: $(THEFILE)n
-$(THEFILE)n:
-	$(AM_V_ELN)$(emacs) $(BYTE_COMPILE_FLAGS) \
-		-l comp -f byte-compile-refresh-preloaded \
-		--eval '(batch-native-compile t)' $(THEFILE)
-endif
 
 # Files MUST be compiled one by one. If we compile several files in a
 # row (i.e., in the same instance of Emacs) we can't make sure that
@@ -323,11 +309,6 @@ .el.elc:
 	-l comp -f batch-byte-compile $<
 	TZ=UTC0 touch -t 197001010000 $@
 else
-.el.elc:
-	$(AM_V_ELC)$(emacs) $(BYTE_COMPILE_FLAGS) \
-	-l comp -f batch-byte+native-compile $<
-endif
-else
 .el.elc:
 	$(AM_V_ELC)$(emacs) $(BYTE_COMPILE_FLAGS) -f batch-byte-compile $<
 endif

I'd also nil `native-comp-jit-compilation' in the early init.

After that one should still be able to run the native compiler testsuite
with say:

./src/emacs -batch -l ert -l test/src/comp-tests.el -f ert-run-tests-batch-and-exit

We want probably start running first all tests but the bootstrap one and
if they pass run this as well.  At this point probably start reasoning
depending on the output.

Best Regards

  Andrea