emacs-devel
[Top][All Lists]
Advanced

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

Re: scratch/comp-static-data 5aa3db2f11: comp: Add support for compiling


From: vibhavp
Subject: Re: scratch/comp-static-data 5aa3db2f11: comp: Add support for compiling elisp constants into static data.
Date: Sun, 20 Nov 2022 22:07:12 +0530
User-agent: Evolution 3.46.1

On Sun, 2022-11-20 at 09:37 +0200, Eli Zaretskii wrote:
> > From: Richard Stallman <rms@gnu.org>
> > Cc: vibhavp@gmail.com, akrl@sdf.org, luangruo@yahoo.com,
> >         emacs-devel@gnu.org
> > Date: Sat, 19 Nov 2022 20:15:33 -0500
> > 
> >   > I'm not aware of any aspect of the change which would cause
> > crashes in
> >   > these cases.
> > 
> > It is possible I misunderstood what the change was for.  The
> > message
> > seemed to say that it would put the values of variables defined
> > with
> > `defconst' into read-only memory.  If there are cases in which that
> > affects the program's execution, I expect it will cause a failure
> > of
> > some sort in those same cases.
> 
> I'd need to understand what does "read-only memory" mean in this
> context.
> Does the code use some memory-protection capabilities to enforce
> that?  Or
> does it do something else?
> 
> Vibhav, please chime in and help us understand what the code does.

Hi Eli, Richard,

The follow elisp snipper is an example of code that when compiled under
this branch, crashes Emacs:
;; -*- lexical-binding: t; -*-
(defun fault-function ()
  (let ((a [1 2 3]))
    (aset a 0 5)
    a))

(fault-function)

I've attached the psuedo-C output produced by libgccjit below.
While compiling `fault-function', comp emits the data for `a' as
follows:

static const struct comp_Lisp_Vector_3  __attribute__((aligned(8)))
lisp_data_3 = (struct comp_Lisp_Vector_3) {.header=(long long)-
9223372036854775805, .contents=(struct Lisp_X *[3]) {(struct Lisp_X
*)0x6, (struct Lisp_X *)0xa, (struct Lisp_X *)0xe}};

Therefore, `lisp_data_3' gets stored in .rodata (or .data.rel.ro),
which causes the call to `aset' to trigger a SIGSEGV. This behaviour is
documented by the Elisp reference manual, which states that self-
evaluating forms are immutable, and changing then can read to
crashes/undefined behaviour
(https://www.gnu.org/software/emacs/manual/html_node/elisp/Self_002dEvaluating-Forms.html
).
The idea behind this patch is to replace the runtime initialization of
lisp objects in the original bytecode constant vector with static
variables, compiled into the eln itself. For now, it is able to do so
for strings (without text properties), bare symbols in `lispsym',
floats, vectors (and other psuedovectors in the future), and conses.
Objects that require runtime initialization (for instance, interned
symbols) are still created by calling their respective initialization
functions, and are not able to be stored as consts.

Best,
Vibhav
-- 
Vibhav Pant
vibhavp@gmail.com
GPG: 7ED1 D48C 513C A024 BE3A  785F E3FB 28CB 6AB5 9598

Attachment: crash-898ac2ed-6cd79c5a.c
Description: Text Data

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

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