Subject: Re: bug#45303: #45303 [feature/native-comp] building error on Windows

From: Pal Gloss <[email-masked]>
Date: Mon, 21 Dec 2020 11:10:15 +0100

> There are still problems related to the usage of Fdirectory_files and
> internal_condition_case_5 I think. At least, I get a crash after the
> bootstrap is dumped (? see attached build log)
>
> Debugger entered--Lisp error: (wrong-type-argument wholenump t)

Despite 2526032ea954671aa48a6ad6d924df2941a8364a, this error still happens:
Qt and Qnil should be swapped (see sed script at the bottom of the mail
inside my build commands or the git diff in the build log).

> >> With 407fb16583 I think '-lgccjit' should be unnecessary on Windows now, is it?
> >
> > It is still needed, see my previous mail. But adding -lgccjit allows the build
> > to proceed but crashes later on.
>
> Hopefully this is fixed now by 3bb2fd0c58?

Not quite: -lgccjit was still needed for strsignal.  Note that the strsignal is a
double problem:
1. Because configure can link the test program with the call to strsignal because
   libgccjit exports it (though Eli argues it shouldn't and I've reported an issue
   to the mingw64-packages repository), no special provision is made to include a
   header defining the function.  Hence, during compilation, there are several
   warnings that gcc assumes that strsignal returns an int and has to cast it to
   const char*.
2. Because -lgccjit is not added to LIBGCCJIT (it is supposed to be loaded
   dynamically, if I understood it right), strsignal is not found at linking time.

So, even when hacking the LIBGCCJIT to contain -lgccjit in src/Makefile, I'm just
allowing the linking to succeed, but probably risk a crash because the linked
function strsignal does not match the implicit definition assumed by gcc (?).

In the end, I've applied (see sed script at the bottom of the mail
inside my build commands or the git diff in the build log) AndyM's suggestion
(https://debbugs.gnu.org/cgi/bugreport.cgi?bug=45303#83) to nt/mingw-cfg.site.
After this change, there are no nativecomp related warnings nor errors during
the build if I still include -lz in LIBGCCJIT in src/Makefile.  Regarding my
change to nt/mingw-cfg.sites, be aware that I know even less about the
configuration process than AndyM (I would not have known about
nt/mingw-cfg.sites) and he says:
> Adding "ac_cv_func_strsignal=no" in nt/mingw-cfg.site appears to
> suppress this problem, but I don't know if that is the right fix.

TLDR for 2526032ea954671aa48a6ad6d924df2941a8364a:
- swap Qt and Qnil in src/comp.c
- fix the strsignal problem, then only -lz is needed

Kind regards,
--
Pal Gloss

#+begin_src shell :exports code
  (
      PROCESSORS_TO_USE="3"
      EMACS_VERSION="emacs-native-comp"
      cd ../emacs
      rm -rf ../build
      gcc --version
      git restore .
      sed -i -e '${ a # force strsignal from gnulib to be used (cf https://debbugs.gnu.org/cgi/bugreport.cgi?bug=45303#83)
                    a ac_cv_func_strsignal=no
                 }' \
          nt/mingw-cfg.site
      sed -i -e '/^[^a-z]* *Qt, Qnil, return_nil);$/ {
                   s;.*;/* Fix argument order to avoid "error (wrong-type-argument wholenump t)" */;
                   a Qnil, Qt, return_nil);
                 }' \
          src/comp.c
      echo "Starting point is $(git rev-parse HEAD) with the following changes:"
      git status
      git diff
      ./autogen.sh
      mkdir -p ../build
      cd ../build
      ../emacs/configure \
          --with-xml2 \
          --without-pop \
          --prefix="/home/cramaph1/$EMACS_VERSION/dest" \
          --without-compress-install \
          --without-dbus \
          --with-nativecomp \
          --with-modules 'CFLAGS=-O2 -g3'
      # fix
      # (1) linker errors by tuning LIBGCCJIT making sure the correct libraries are added to the linker command
      sed -i -e 's/^LIBGCCJIT = *$/LIBGCCJIT = -lz/' \
          src/Makefile
      make -j"$PROCESSORS_TO_USE"
      make install
  ) 2>&1 | tee /tmp/emacs-$(git rev-parse HEAD)-patch_mingw.site-patch_comp.c-lz.log