unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Pieter van Oostrum <pieter-l@vanoostrum.org>
Cc: 39962@debbugs.gnu.org, Paul Eggert <eggert@cs.ucla.edu>
Subject: bug#39962: 27.0.90; Crash in Emacs 27.0.90
Date: Thu, 12 Mar 2020 20:00:13 +0000	[thread overview]
Message-ID: <CAOqdjBfumTOOWEZsEbDUkwSD7_KPQg_a1EXx+=1djn9JQuVUAg@mail.gmail.com> (raw)
In-Reply-To: <lxlfo5saq1.fsf@cochabamba.vanoostrum.org>

[-- Attachment #1: Type: text/plain, Size: 3261 bytes --]

On Thu, Mar 12, 2020 at 6:13 PM Pieter van Oostrum
<pieter-l@vanoostrum.org> wrote:
> > My guess is 0x7ffeef270000 is your stack's guard page... Can you print
> > $rsp to confirm?
>
> Sorry, because of the erratic behaviour of GDB I killed that one. I have a new segfault in the GC. It is a long stack trace, so it could be a stack overflow. And, by the way, I had the two brakpoints set for the assignments to marker->charpos that Eli suggested, but they were not triggered. I have dumped a part of the stack trace below.

Thanks! I believe that solves it.

That indeed looks like a stack overflow.

Here's some speculation about what I think is happening:

We're seeing deep recursion in the garbage collector. If you look at
the tag bits of the objects marked by mark_object, you'll notice the
sequence is

symbol - cons - vectorlike - vectorlike - symbol - cons - vectorlike -
vectorlike - ...

That means there are thousands of symbols referring to values which
again contain symbols, and so on.

I suspect this code in vm-summary.el, or similar code, at least:

(defun vm-make-message ()
  "Create a new blank message struct."
  (let ((mvec (make-vector 5 nil))
    sym)
    (vm-set-softdata-of mvec (make-vector vm-softdata-vector-length nil))
    (vm-set-location-data-of
     mvec (make-vector vm-location-data-vector-length nil))
    (vm-set-mirror-data-of
     mvec (make-vector vm-mirror-data-vector-length nil))
    (vm-set-message-id-number-of mvec (int-to-string vm-message-id-number))
    (vm-increment vm-message-id-number)
    (vm-set-buffer-of mvec (current-buffer))
    ;; We use an uninterned symbol here as a level of indirection
    ;; from a purely self-referential structure.  This is
    ;; necessary so that Emacs debugger can be used on this
    ;; program.
    (setq sym (make-symbol "<<>>"))
    (set sym mvec)
    (vm-set-real-message-sym-of mvec sym)
    (vm-set-mirrored-message-sym-of mvec sym)
    ;; Another uninterned symbol for the virtual messages list.
    (setq sym (make-symbol "<v>"))
    (set sym nil)
    (vm-set-virtual-messages-sym-of mvec sym)
    ;; Another uninterned symbol for the reverse link
    ;; into the message list.
    (setq sym (make-symbol "<--"))
    (vm-set-reverse-link-sym-of mvec sym)
    mvec ))

Essentially, that code is building a singly-linked list of message
vectors, but the links go via symbols rather than directly to the next
message. The garbage collector isn't written for that case, and
recurses rather than iterating, causing the stack overflow.

The first attachment to this message is an Elisp file which does the
same thing, by creating thousands of symbols. On GNU/Linux, with
fairly default standard stack size settings, I get a segfault after
some 85,000 symbols have been created.

The second attachment is a patch which is
1. untested
2. a dirty workaround
3. not intended for inclusion in the master branch
4. not intended for inclusion in the emacs-27 branch.

It's possible this patch will work around the problem and result in a
different bug, or, less optimistically, fix this bug. With the patch,
I'm able to make it through the first 2^20 iterations of
symbol-crash.el without a segfault.

[-- Attachment #2: symbol-crash.el --]
[-- Type: text/x-emacs-lisp, Size: 222 bytes --]

(let* ((sym (make-symbol ""))
       (osym sym))
  (dotimes (i 1000000000)
    (set sym (make-symbol ""))
    (setq sym (symbol-value sym))
    (message "%d" i)
    (when (= 0 (logand i (1+ i)))
      (garbage-collect))))

[-- Attachment #3: 0001-recurse-into-symbol-values-rather-than-along-the-sym.patch --]
[-- Type: text/x-patch, Size: 1513 bytes --]

From d562402198a0341e5a1bbfff4f0e8ea0df63d484 Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
Date: Thu, 12 Mar 2020 19:47:10 +0000
Subject: [PATCH] recurse into symbol values rather than along the symbol chain
 when GCing

---
 src/alloc.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index 1c6b664b22..0db9620f3e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6581,9 +6581,19 @@ #define CHECK_ALLOCATED_AND_LIVE_SYMBOL()	((void) 0)
 	eassert (valid_lisp_object_p (ptr->u.s.function));
 	mark_object (ptr->u.s.function);
 	mark_object (ptr->u.s.plist);
+	if (!PURE_P (XSTRING (ptr->u.s.name)))
+          set_string_marked (XSTRING (ptr->u.s.name));
+        mark_interval_tree (string_intervals (ptr->u.s.name));
 	switch (ptr->u.s.redirect)
 	  {
-	  case SYMBOL_PLAINVAL: mark_object (SYMBOL_VAL (ptr)); break;
+	  case SYMBOL_PLAINVAL:
+	    if (!ptr->u.s.next)
+	      {
+		obj = SYMBOL_VAL (ptr);
+		goto loop;
+	      }
+	    mark_object (SYMBOL_VAL (ptr));
+	    break;
 	  case SYMBOL_VARALIAS:
 	    {
 	      Lisp_Object tem;
@@ -6602,9 +6612,6 @@ #define CHECK_ALLOCATED_AND_LIVE_SYMBOL()	((void) 0)
 	    break;
 	  default: emacs_abort ();
 	  }
-	if (!PURE_P (XSTRING (ptr->u.s.name)))
-          set_string_marked (XSTRING (ptr->u.s.name));
-        mark_interval_tree (string_intervals (ptr->u.s.name));
 	/* Inner loop to mark next symbol in this bucket, if any.  */
 	po = ptr = ptr->u.s.next;
 	if (ptr)
-- 
2.25.1


  reply	other threads:[~2020-03-12 20:00 UTC|newest]

Thread overview: 119+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-06 23:55 bug#39962: 27.0.90; Crash in Emacs 27.0.90 Pieter van Oostrum
2020-03-07  7:48 ` Eli Zaretskii
2020-03-07  8:40   ` Pieter van Oostrum
2020-03-07  8:41   ` Pieter van Oostrum
2020-03-07 10:51     ` Eli Zaretskii
2020-03-07 11:06   ` Pieter van Oostrum
2020-03-07 13:10     ` Eli Zaretskii
2020-03-07 15:06       ` Pieter van Oostrum
2020-03-07 15:17         ` Eli Zaretskii
2020-03-07 15:49           ` Pieter van Oostrum
2020-03-07 16:07             ` Eli Zaretskii
2020-03-07 17:21               ` Pieter van Oostrum
2020-03-07 18:01                 ` Eli Zaretskii
2020-03-07 19:14                   ` Pieter van Oostrum
2020-03-07 19:21                     ` Eli Zaretskii
2020-03-07 22:07                       ` Pieter van Oostrum
2020-03-09  4:00     ` Pip Cet
2020-03-08  7:42 ` Paul Eggert
2020-03-08  9:34   ` Pieter van Oostrum
2020-03-08 10:05     ` Paul Eggert
2020-03-08 21:37       ` Pieter van Oostrum
2020-03-08 21:58         ` Pieter van Oostrum
2020-03-08 22:34         ` Paul Eggert
2020-03-08 23:58           ` Pieter van Oostrum
2020-03-09  0:01             ` Paul Eggert
2020-03-09 13:26               ` Pieter van Oostrum
2020-03-09 17:10                 ` Eli Zaretskii
2020-03-09 19:48                   ` Pieter van Oostrum
2020-03-10 13:37                     ` Pieter van Oostrum
2020-03-09 19:51                   ` Paul Eggert
2020-03-09 21:32                     ` Pieter van Oostrum
2020-03-10 10:52                       ` Pieter van Oostrum
2020-03-10 14:19                         ` Pip Cet
2020-03-10 16:36                           ` Pieter van Oostrum
2020-03-11 14:32                             ` Pip Cet
2020-03-11 15:16                               ` Pieter van Oostrum
2020-03-11 15:43                                 ` Pip Cet
2020-03-11 15:51                                   ` Paul Eggert
2020-03-11 16:21                                     ` Eli Zaretskii
2020-03-11 17:52                                   ` Eli Zaretskii
2020-03-11 18:53                                     ` Pip Cet
2020-03-11 19:34                                       ` Eli Zaretskii
2020-03-12 10:32                                         ` Pip Cet
2020-03-12 15:23                                           ` Eli Zaretskii
2020-03-12 20:36                                             ` Pip Cet
2020-03-13  9:39                                               ` Eli Zaretskii
2020-03-13 13:56                                                 ` Pip Cet
2020-03-13 16:30                                                   ` Eli Zaretskii
2020-03-14  9:02                                                     ` Pip Cet
2020-03-14 15:39                                                       ` Pip Cet
2020-03-14 16:00                                                         ` Paul Eggert
2020-03-14 16:15                                                           ` Pip Cet
2020-03-14 16:57                                                             ` Eli Zaretskii
2020-03-14 18:34                                                               ` Pip Cet
2020-03-14 19:09                                                                 ` Paul Eggert
2020-03-14 20:10                                                                   ` Eli Zaretskii
2020-03-15 12:12                                                                     ` Pip Cet
2020-03-15 14:53                                                                       ` Eli Zaretskii
2020-03-15 12:09                                                                   ` Pip Cet
2020-03-15 14:50                                                                     ` Eli Zaretskii
2020-03-16 16:31                                                     ` Stefan Monnier
2020-03-11 20:03                                   ` Pieter van Oostrum
2020-03-12 13:55                                     ` Pip Cet
2020-03-12 18:13                                       ` Pieter van Oostrum
2020-03-12 20:00                                         ` Pip Cet [this message]
2020-03-13  8:09                                           ` Eli Zaretskii
2020-03-13  8:39                                             ` Pip Cet
2020-03-13  9:19                                               ` Eli Zaretskii
2020-03-13 17:43                                                 ` Pieter van Oostrum
2020-03-14  3:38                                                 ` Richard Stallman
2020-03-14  8:37                                                   ` Eli Zaretskii
2020-03-14  9:16                                                     ` Pip Cet
2020-03-14 15:34                                                       ` Pip Cet
2020-03-13 17:42                                             ` Pieter van Oostrum
2020-03-13 19:34                                               ` Eli Zaretskii
2020-03-13 21:35                                                 ` Pieter van Oostrum
2020-03-14  8:08                                                   ` Eli Zaretskii
2020-03-14 21:32                                                     ` Pieter van Oostrum
2020-03-15 19:49                                                       ` Pieter van Oostrum
2020-03-15 19:57                                                         ` Eli Zaretskii
2020-03-15 23:26                                                           ` Pieter van Oostrum
2020-03-16 10:44                                                             ` Pieter van Oostrum
2020-03-16 15:07                                                               ` Eli Zaretskii
2020-03-16 15:33                                                               ` Pip Cet
2020-03-16 17:19                                                                 ` Pip Cet
2020-03-17  3:29                                                                   ` Pieter van Oostrum
2020-03-17  4:54                                                                     ` Pip Cet
2020-03-17  5:20                                                                       ` Pip Cet
2020-03-17  8:45                                                                         ` Pieter van Oostrum
2020-03-17 13:54                                                                           ` Pip Cet
2020-03-17 15:27                                                                             ` Pieter van Oostrum
2020-03-17 20:16                                                                               ` Pip Cet
2020-03-17 23:32                                                                                 ` Pieter van Oostrum
2020-03-18 15:05                                                                                   ` Eli Zaretskii
2020-03-19 13:23                                                                                     ` Pieter van Oostrum
2020-03-19 13:57                                                                                       ` Pip Cet
2020-03-21 21:22                                                                                         ` Pieter van Oostrum
2020-03-22 14:21                                                                                           ` Eli Zaretskii
2020-03-22 15:48                                                                                           ` Pip Cet
2020-03-23 19:34                                                                                             ` Pip Cet
2020-03-17  8:40                                                                       ` Pieter van Oostrum
2020-03-17 15:33                                                                     ` Eli Zaretskii
2020-03-17 20:59                                                                       ` Paul Eggert
2020-03-18  6:17                                                                         ` Pip Cet
2020-03-18  9:22                                                                           ` Robert Pluim
2020-03-18 11:38                                                                             ` Pieter van Oostrum
2020-03-18 11:57                                                                               ` Paul Eggert
2020-03-18 14:08                                                                               ` Pip Cet
2020-03-19 19:17                                                                                 ` Pieter van Oostrum
2020-03-19 19:31                                                                                   ` Pip Cet
2020-03-19 21:30                                                                                     ` Pieter van Oostrum
2020-03-18 14:08                                                                           ` Eli Zaretskii
2020-03-16 18:36                                                                 ` Pieter van Oostrum
2020-03-13  7:58                                         ` Eli Zaretskii
2020-03-10 15:10                         ` Eli Zaretskii
2020-03-10 18:23                           ` Pieter van Oostrum
2020-03-11  8:22                         ` Paul Eggert
2022-04-30 12:38 ` Lars Ingebrigtsen
2022-05-29 13:19   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOqdjBfumTOOWEZsEbDUkwSD7_KPQg_a1EXx+=1djn9JQuVUAg@mail.gmail.com' \
    --to=pipcet@gmail.com \
    --cc=39962@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=pieter-l@vanoostrum.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).