From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#35711: emacs crashes on m68k after d2f1971dd5 Date: Mon, 13 May 2019 12:47:44 -0700 Organization: UCLA Computer Science Department Message-ID: <98a8bb69-486e-20b2-891d-65015bab9579@cs.ucla.edu> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2D50F141F2CFCC6D985A890D" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="132722"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 Cc: Andreas Schwab , Michael Karcher To: John Paul Adrian Glaubitz , 35711@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 13 21:57:10 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hQH4N-000YOo-SJ for geb-bug-gnu-emacs@m.gmane.org; Mon, 13 May 2019 21:57:08 +0200 Original-Received: from localhost ([127.0.0.1]:34257 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQH4M-0003fT-Uo for geb-bug-gnu-emacs@m.gmane.org; Mon, 13 May 2019 15:57:06 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:38969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQH3m-0002pf-Q3 for bug-gnu-emacs@gnu.org; Mon, 13 May 2019 15:56:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQGva-0008EA-KU for bug-gnu-emacs@gnu.org; Mon, 13 May 2019 15:48:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:32780) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQGva-0008E2-Eu for bug-gnu-emacs@gnu.org; Mon, 13 May 2019 15:48:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hQGva-0007Y9-4l for bug-gnu-emacs@gnu.org; Mon, 13 May 2019 15:48:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 13 May 2019 19:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35711 X-GNU-PR-Package: emacs Original-Received: via spool by 35711-submit@debbugs.gnu.org id=B35711.155777687629011 (code B ref 35711); Mon, 13 May 2019 19:48:02 +0000 Original-Received: (at 35711) by debbugs.gnu.org; 13 May 2019 19:47:56 +0000 Original-Received: from localhost ([127.0.0.1]:46324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQGvU-0007Xq-AS for submit@debbugs.gnu.org; Mon, 13 May 2019 15:47:56 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:35220) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hQGvQ-0007XY-DW for 35711@debbugs.gnu.org; Mon, 13 May 2019 15:47:54 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2206A161A2B; Mon, 13 May 2019 12:47:46 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id arrDcM7mXDeQ; Mon, 13 May 2019 12:47:45 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E6608161A30; Mon, 13 May 2019 12:47:44 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id PtvMLpigSmWm; Mon, 13 May 2019 12:47:44 -0700 (PDT) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id C24FE161A19; Mon, 13 May 2019 12:47:44 -0700 (PDT) Openpgp: preference=signencrypt Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiHlmLC+ KaHLeCLF5ZI2vKm3HEeCTtlOg7xZEONgwzL+fdKo+D6SoC8RRxJKs8a3sVfI4t6CnrQzvJbB n6gxdgCu5i29J1QCYrCYvql2UyFPAK+do99/1jOXT4m2836j1wARAQABzSBQYXVsIEVnZ2Vy dCA8ZWdnZXJ0QGNzLnVjbGEuZWR1PsLBfgQTAQIAKAUCTIByZAIbAwUJEswDAAYLCQgHAwIG FQgCCQoLBBYCAwECH In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:159204 Archived-At: This is a multi-part message in MIME format. --------------2D50F141F2CFCC6D985A890D Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Thanks for the bug report. Please try the attached, more-general patch, which I've installed on master. I suppose I should backport it to the emacs-26 branch if it works for you. --------------2D50F141F2CFCC6D985A890D Content-Type: text/x-patch; name="0001-Fix-broken-build-on-m68k.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-broken-build-on-m68k.patch" >From 5190acc14f58d5f96887b1d9b6981aa1c48ced6f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 13 May 2019 12:43:13 -0700 Subject: [PATCH] Fix broken build on m68k The GCC + valgrind fix caused the m68k build to fail (Bug#35711). Simplify string allocation a bit to make similar problems less likely in the future. * src/alloc.c (sdata, SDATA_NBYTES, SDATA_DATA) [GC_CHECK_STRING_BYTES]: Use the same implementation as with !GC_CHECK_STRING_BYTES, as the special case is no longer needed. (SDATA_ALIGN): New constant. (SDATA_SIZE): Remove this macro, replacing with ... (sdata_size): ... this new function. All uses changed. Properly account for sizes and alignments even in the m68k case, and even if GC_CHECK_STRING_BYTES is not defined. --- src/alloc.c | 77 +++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 948a0e8a2d..af4adb3856 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1447,9 +1447,7 @@ mark_interval_tree (INTERVAL i) #define LARGE_STRING_BYTES 1024 -/* The SDATA typedef is a struct or union describing string memory - sub-allocated from an sblock. This is where the contents of Lisp - strings are stored. */ +/* The layout of a nonnull string. */ struct sdata { @@ -1468,13 +1466,8 @@ struct sdata unsigned char data[FLEXIBLE_ARRAY_MEMBER]; }; -#ifdef GC_CHECK_STRING_BYTES - -typedef struct sdata sdata; -#define SDATA_NBYTES(S) (S)->nbytes -#define SDATA_DATA(S) (S)->data - -#else +/* A union describing string memory sub-allocated from an sblock. + This is where the contents of Lisp strings are stored. */ typedef union { @@ -1502,8 +1495,6 @@ typedef union #define SDATA_NBYTES(S) (S)->n.nbytes #define SDATA_DATA(S) ((struct sdata *) (S))->data -#endif /* not GC_CHECK_STRING_BYTES */ - enum { SDATA_DATA_OFFSET = offsetof (struct sdata, data) }; /* Structure describing a block of memory which is sub-allocated to @@ -1586,31 +1577,20 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] = # define GC_STRING_OVERRUN_COOKIE_SIZE 0 #endif -/* Value is the size of an sdata structure large enough to hold NBYTES - bytes of string data. The value returned includes a terminating - NUL byte, the size of the sdata structure, and padding. */ - -#ifdef GC_CHECK_STRING_BYTES - -#define SDATA_SIZE(NBYTES) FLEXSIZEOF (struct sdata, data, (NBYTES) + 1) +/* Return the size of an sdata structure large enough to hold N bytes + of string data. This counts the sdata structure, the N bytes, a + terminating NUL byte, and alignment padding. */ -#else /* not GC_CHECK_STRING_BYTES */ - -/* The 'max' reserves space for the nbytes union member even when NBYTES + 1 is - less than the size of that member. The 'max' is not needed when - SDATA_DATA_OFFSET is a multiple of FLEXALIGNOF (struct sdata), - because then the alignment code reserves enough space. */ - -#define SDATA_SIZE(NBYTES) \ - ((SDATA_DATA_OFFSET \ - + (SDATA_DATA_OFFSET % FLEXALIGNOF (struct sdata) == 0 \ - ? NBYTES \ - : max (NBYTES, FLEXALIGNOF (struct sdata) - 1)) \ - + 1 \ - + FLEXALIGNOF (struct sdata) - 1) \ - & ~(FLEXALIGNOF (struct sdata) - 1)) - -#endif /* not GC_CHECK_STRING_BYTES */ +static ptrdiff_t +sdata_size (ptrdiff_t n) +{ + /* Reserve space for the nbytes union member even when N + 1 is less + than the size of that member. */ + ptrdiff_t unaligned_size = max (SDATA_DATA_OFFSET + n + 1, + sizeof (sdata)); + int sdata_align = max (FLEXALIGNOF (struct sdata), alignof (sdata)); + return (unaligned_size + sdata_align - 1) & ~(sdata_align - 1); +} /* Extra bytes to allocate for each string. */ #define GC_STRING_EXTRA GC_STRING_OVERRUN_COOKIE_SIZE @@ -1664,21 +1644,14 @@ string_bytes (struct Lisp_String *s) static void check_sblock (struct sblock *b) { - sdata *from, *end, *from_end; - - end = b->next_free; + sdata *end = b->next_free; - for (from = b->data; from < end; from = from_end) + for (sdata *from = b->data; from < end; ) { - /* Compute the next FROM here because copying below may - overwrite data we need to compute it. */ - ptrdiff_t nbytes; - - /* Check that the string size recorded in the string is the - same as the one recorded in the sdata structure. */ - nbytes = SDATA_SIZE (from->string ? string_bytes (from->string) - : SDATA_NBYTES (from)); - from_end = (sdata *) ((char *) from + nbytes + GC_STRING_EXTRA); + ptrdiff_t nbytes = sdata_size (from->string + ? string_bytes (from->string) + : SDATA_NBYTES (from)); + from = (sdata *) ((char *) from + nbytes + GC_STRING_EXTRA); } } @@ -1810,14 +1783,14 @@ allocate_string_data (struct Lisp_String *s, { sdata *data, *old_data; struct sblock *b; - ptrdiff_t needed, old_nbytes; + ptrdiff_t old_nbytes; if (STRING_BYTES_MAX < nbytes) string_overflow (); /* Determine the number of bytes needed to store NBYTES bytes of string data. */ - needed = SDATA_SIZE (nbytes); + ptrdiff_t needed = sdata_size (nbytes); if (s->u.s.data) { old_data = SDATA_OF_STRING (s); @@ -2068,7 +2041,7 @@ compact_small_strings (void) nbytes = s ? STRING_BYTES (s) : SDATA_NBYTES (from); eassert (nbytes <= LARGE_STRING_BYTES); - ptrdiff_t size = SDATA_SIZE (nbytes); + ptrdiff_t size = sdata_size (nbytes); sdata *from_end = (sdata *) ((char *) from + size + GC_STRING_EXTRA); -- 2.21.0 --------------2D50F141F2CFCC6D985A890D--