emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] [WIP] Port feature/native-comp to Windows.


From: Nicolas Bértolo
Subject: Re: [PATCH] [WIP] Port feature/native-comp to Windows.
Date: Sun, 10 May 2020 16:02:11 -0300

> This is known in advance.  We already have that knowledge in Emacs,
> see HAVE__SETJMP and HAVE_SIGSETJMP used in lisp.h.

> I don't yet understand why we need the _name_ of the setjmp function.
> How will this name be used?

I think it is a good idea to show how the information is used:
This is the function that generates a function call to `setjmp`.

static gcc_jit_rvalue *
emit_setjmp (gcc_jit_rvalue *buf)
{
#ifndef _WIN32
  gcc_jit_rvalue *args[] = {buf};
  return emit_call (intern_c_string (STR (SETJMP_NAME)), comp.int_type, 1, args,
                   false);
#else
  /* _setjmp (buf, __builtin_frame_address (0)) */
  gcc_jit_rvalue *args[2];

  args[0] = gcc_jit_context_new_rvalue_from_int (comp.ctxt,
comp.unsigned_type, 0);

  args[1] = gcc_jit_context_new_call(comp.ctxt,
                                     NULL,
                                     comp.setjmp_ctx_func,
                                     1, args);
  args[0] = buf;
  return emit_call (intern_c_string (STR (SETJMP_NAME)), comp.int_type, 2, args,
                    false);
#endif
}

In Windows we issue a call to _setjmp with a jmp_buf as first parameter and the
result of calling __builtin_frame_address(0) as second argument.

This handles the case where setjmp.h defines setjmp like this:
#define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0))

The rest of the cases need to be added by hand to this function or we need to
find a way to get autoconf to generate this function.

We need the name of the setjmp function because it is used in two places:
- The freloc table needs to store a pointer to it, and to do it it needs the
name the macro is hiding.
- The emit_call function maps strings to fields in the freloc table.

> Then why do we need to tell libgccjit where the GCC installation
> lives?  AFAIU from what you are saying, libgccjit already knows that.
> What am I missing?

Because libgccjit tries to find the GCC installation in the path it was given
when `configure` was called. I thinking about redistributing a "stub GCC
installation" alongside Emacs.

> The gcc executable is always on PATH, only the auxiliary programs
> (cc1.exe etc.) aren't.  Otherwise you couldn't compile programs in
> arbitrary directories.

What about users that don't have `gcc` in PATH? We are back to the solution that
adds it to PATH before creating the compilation process.

> Then I don't understand why it needs any help at all.  When I invoke
> gcc to compile a program, I don't tell it anything about where the
> installation lives, gcc finds that all by itself.  Why is libgccjit
> different?

Because I was thinking about the case in which GCC is not in PATH because the
user does not have a Mingw installation. In that case we need to help libgccjit
find the stub GCC installtion.

> Same GCC version as what other version? the one used to compile Emacs
itself, perhaps?

> What is the definition of "the appropriate GCC version" in this
> context?  E.g., does it have to be exactly the same version as the one
> used to build Emacs itself?  Or does it mean something else?

The GCC that comes from the source tree that libgccjit was built from.

Lets say Emacs was built with libgccjit 9.2 and the user has GCC 10.0.0
installed: it would be a very bad idea to use the local installation, AFAIU.
In fact, libgccjit will not even try and it'll fail.
Andrea knows the internals of libgccjit way better than me: I am I right?

> How will this work in practice?  Are you suggesting that we include
> part of the GCC installation in the Emacs binary zip file?  If so, we
> will have to provide also the humongous GCC source tarball on the same
> site, to comply with the GPL.  That is doable, of course, but very
> inconvenient.  We should try to find a better way.

This is what I was proposing indeed. The strict version requirement seems to get
in the way of using the system GCC (If there is one. I hadn't thought about the
GPL requirement.

El dom., 10 may. 2020 a las 15:22, Eli Zaretskii (<address@hidden>) escribió:
>
> > From: Nicolas Bértolo <address@hidden>
> > Date: Sun, 10 May 2020 14:50:52 -0300
> > Cc: Andrea Corallo <address@hidden>, address@hidden
> >
> > > What information do we need, exactly?
> >
> > We need:
> > - The name of the setjmp function.
> > - Whether it needs a second parameter, in that case:
> >    - It can be a gcc builtin, a function call or a NULL constant.
> >    - If it is a function call or a builtin it may need a parameter.
> >      This is a NULL constant in all cases I have seen.
>
> This is known in advance.  We already have that knowledge in Emacs,
> see HAVE__SETJMP and HAVE_SIGSETJMP used in lisp.h.
>
> I don't yet understand why we need the _name_ of the setjmp function.
> How will this name be used?
>
> > > What is the definition of " where the gcc installation lives"?  What
> > > files does libgccjit need from that place, and how does it look for
> > > those files?
> >
> > libgccjit implements generates an assembler file. This is done without any 
> > calls
> > to any external program. Then it calls a gcc entry point to finish the 
> > process.
> > This calls the same functions that the `gcc` program uses to identify where 
> > it
> > was installed. In particular, it uses constants defined at libgccjit build 
> > time
> > (the compiler version, the directories where it was installed, etc.). It 
> > uses
> > that information plus some environment variables: GCC_EXEC_PREFIX, 
> > LIBRARY_PATH,
> > maybe others, to find where the gcc support files are installed: the support
> > binaries, libgcc. This is what I meant by "where the gcc installation 
> > lives".
> >
> > This logic runs inside the Emacs process that is performing the compilation
> > process, but it is the same code that would run in a `gcc -print-*` IIUC.
> >
> > > IIUC what is needed, it should be relatively easy to glean this
> > > information from the output of "gcc -print-file-name=" and its ilk.
> >
> > libgccjit runs the exact same code as gcc would. So this would not help.
>
> Then why do we need to tell libgccjit where the GCC installation
> lives?  AFAIU from what you are saying, libgccjit already knows that.
> What am I missing?
>
> > Moreover, how would Emacs find gcc? We would need to add it to PATH.
>
> The gcc executable is always on PATH, only the auxiliary programs
> (cc1.exe etc.) aren't.  Otherwise you couldn't compile programs in
> arbitrary directories.
>
> > > Using the above-mentioned -print-* options to GCC should accomplish
> > > the same tasks, because they ask GCC to reveal the places where it
> > > finds its auxiliary binaries and support libraries.  Isn't it enough
> > > to find out the absolute file names of each such file/program, and
> > > tell libgccjit to use that absolute file name, instead of using -B?
> >
> > I do not think that is possible. libgccjit likes to find the files it needs 
> > as
> > if it was a gcc instance.
>
> Then I don't understand why it needs any help at all.  When I invoke
> gcc to compile a program, I don't tell it anything about where the
> installation lives, gcc finds that all by itself.  Why is libgccjit
> different?
>
> > > I'd like to avoid that: it's a nuisance to have to copy files that
> > > way, and users could legitimately have more than one GCC version
> > > installed and available at the same time.
> >
> > AFAIU, we need to use the same GCC version, that is what libgccjit looks 
> > for.
>
> Same GCC version as what other version? the one used to compile Emacs
> itself, perhaps?
>
> > Using support libraries from different GCC versions may cause weird bugs.
>
> Then we are already in trouble, because libgcc comes with each GCC
> version and is slightly different from other versions (although it's
> supposed to be compatible), and libmingwex and libmingw32 come with
> MinGW distribution which is independent of GCC -- users can upgrade
> their MinGW installation at will.
>
> I don't think using libraries from a different GCC version is going to
> cause problems, assuming the newer library is binary-compatible to the
> old one (if it isn't, the DLL will have a different name, like
> libgcc_s_dw2-2.dll vs libgcc_s_dw2-1.dll).
>
> > > That assumes that Emacs is configured and built on the same system
> > > where it is used.  That assumption is mostly false for Windows, where
> > > many users simply download and install precompiled binaries, or build
> > > on one system and then use on several different ones.  We should try
> > > to find a way of getting this information at run time, not at
> > > configure time.  And it shouldn't be hard: we can use at run time the
> > > same GCC options as the configure script would do.  This should be
> > > done once, and the result stored in some FOO-directory variable for
> > > use when Lisp should be compiled.
> >
> > This would mean that users would have to download the appropriate GCC 
> > version if
> > they want to use native lisp compilation
>
> What is the definition of "the appropriate GCC version" in this
> context?  E.g., does it have to be exactly the same version as the one
> used to build Emacs itself?  Or does it mean something else?
>
> > By copying the support files into the installation dir we ensure
> > that Emacs finds the correct files and it works out of the box for
> > users that download a ZIP file.
>
> How will this work in practice?  Are you suggesting that we include
> part of the GCC installation in the Emacs binary zip file?  If so, we
> will have to provide also the humongous GCC source tarball on the same
> site, to comply with the GPL.  That is doable, of course, but very
> inconvenient.  We should try to find a better way.
>
> But this is still too early, I think we first need to understand
> exactly what files does libgccjit need to find during compilation and
> how.  (Well, I guess _I_ need to understand that; apologies for not
> being more familiar with these details of the native-comp branch, and
> wasting your time on looking into this and describing the findings.
> maybe someone else who knows more about this could chime in and make
> the progress faster and less tedious.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]