From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#20862: 25.0.50; 32-bit Emacs configured --with-wide-int miscompiles CL Date: Wed, 24 Jun 2015 20:31:10 -0700 Organization: UCLA Computer Science Department Message-ID: <558B75FE.3010806@cs.ucla.edu> References: <83k2uxhye8.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050707070307010400090409" X-Trace: ger.gmane.org 1435203764 15036 80.91.229.3 (25 Jun 2015 03:42:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Jun 2015 03:42:44 +0000 (UTC) Cc: 20862@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 25 05:42:33 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z7y3b-0001Wu-BH for geb-bug-gnu-emacs@m.gmane.org; Thu, 25 Jun 2015 05:42:31 +0200 Original-Received: from localhost ([::1]:53781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7xtg-0001rV-Qh for geb-bug-gnu-emacs@m.gmane.org; Wed, 24 Jun 2015 23:32:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7xtc-0001qz-Ic for bug-gnu-emacs@gnu.org; Wed, 24 Jun 2015 23:32:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7xtS-0005Ij-QG for bug-gnu-emacs@gnu.org; Wed, 24 Jun 2015 23:32:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:55375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7xtS-0005IZ-MH for bug-gnu-emacs@gnu.org; Wed, 24 Jun 2015 23:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Z7xtR-0003hf-Sm for bug-gnu-emacs@gnu.org; Wed, 24 Jun 2015 23:32:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <83k2uxhye8.fsf@gnu.org> Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 25 Jun 2015 03:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20862 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20862-submit@debbugs.gnu.org id=B20862.143520308514195 (code B ref 20862); Thu, 25 Jun 2015 03:32:01 +0000 Original-Received: (at 20862) by debbugs.gnu.org; 25 Jun 2015 03:31:25 +0000 Original-Received: from localhost ([127.0.0.1]:56821 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z7xsn-0003gq-9v for submit@debbugs.gnu.org; Wed, 24 Jun 2015 23:31:24 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:60762) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z7xsj-0003gY-Dj for 20862@debbugs.gnu.org; Wed, 24 Jun 2015 23:31:19 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id BDCE7160835; Wed, 24 Jun 2015 20:31:11 -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 WTs-o0wB86SB; Wed, 24 Jun 2015 20:31:10 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 96A17160820; Wed, 24 Jun 2015 20:31:10 -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 udy49GOcROpY; Wed, 24 Jun 2015 20:31:10 -0700 (PDT) Original-Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 62F2E1601CB; Wed, 24 Jun 2015 20:31:10 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:104323 Archived-At: This is a multi-part message in MIME format. --------------050707070307010400090409 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for reporting that. It appears to be a bug in the garbage collector, and is likely to be hard to reproduce. I couldn't reproduce it, but I did a 'make bootstrap' on Fedora x86-64 (configured with --with-wide-int and compiled with gcc -m32 so it's really x86), and got a core dump in a completely different area that (of course!) went away when I compiled without optimization. Rather than try to debug it directly, I thought about what might have caused the problem, and re-audited the garbage collector with the recent Qnil==0 changes in mind. This did uncover a bug, and the attached patch (which we will need anyway) allowed me to do a "make bootstrap" successfully in the same configuration. I installed this into the master as commit 93f4f67ba93b78e8b31e498e8ce7bce4c8298b76; please give it a try in your setup when you have the time. --------------050707070307010400090409 Content-Type: text/x-diff; name="0001-Fix-GC-bugs-with-wide-int-and-Qnil-0.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-GC-bugs-with-wide-int-and-Qnil-0.patch" >From 2bc416753ea9dbdeb27719957076ceb909886bd1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 24 Jun 2015 20:10:03 -0700 Subject: [PATCH] Fix GC bugs --with-wide-int and Qnil == 0 Use the same alignment for the !USE_LSB_TAG case as for the more-typical USE_LSB_TAG case. The attempt to support arbitrary alignments with !USE_LSB_TAG had subtle bugs in garbage collection once we changed the representation of symbols so that Qnil == 0. Problem reported by Eli Zaretskii (Bug#20862). * src/alloc.c (XMALLOC_HEADER_ALIGNMENT) [XMALLOC_OVERRUN_CHECK]: * src/alloc.c (vector_alignment, union aligned_Lisp_Symbol) (union aligned_Lisp_Misc, maybe_lisp_pointer, pure_alloc): Use same alignment for !USE_LSB_TAG as for USE_LSB_TAG. * src/alloc.c (POINTERS_MIGHT_HIDE_IN_OBJECTS): Remove. This optimization in the !USE_LSB_TAG case is no longer valid when symbols are represented via offsets. Change the only use to assume that pointers might hide in objects. * src/lisp.h (alignas) [!USE_LSB_TAG]: Require support in this case, too. (TAG_SYMOFFSET, XSYMBOL) [!USE_LSB_TAG]: Do not shift the offset. This is OK, because the !USE_LSB_TAG case now applies only when Lisp_Object is wider than void *, so there's no longer any need to shift the offset. Not shifting the offset means that symbol representations have the same alignment as pointers, which the GC assumes. --- src/alloc.c | 59 ++++++++++------------------------------------------------- src/lisp.h | 11 ++--------- 2 files changed, 12 insertions(+), 58 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index a956e95..c9bdcc2 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -528,12 +528,8 @@ buffer_memory_full (ptrdiff_t nbytes) alignment that Emacs needs for C types and for USE_LSB_TAG. */ #define XMALLOC_BASE_ALIGNMENT alignof (max_align_t) -#if USE_LSB_TAG -# define XMALLOC_HEADER_ALIGNMENT \ - COMMON_MULTIPLE (GCALIGNMENT, XMALLOC_BASE_ALIGNMENT) -#else -# define XMALLOC_HEADER_ALIGNMENT XMALLOC_BASE_ALIGNMENT -#endif +#define XMALLOC_HEADER_ALIGNMENT \ + COMMON_MULTIPLE (GCALIGNMENT, XMALLOC_BASE_ALIGNMENT) #define XMALLOC_OVERRUN_SIZE_SIZE \ (((XMALLOC_OVERRUN_CHECK_SIZE + sizeof (size_t) \ + XMALLOC_HEADER_ALIGNMENT - 1) \ @@ -2730,7 +2726,7 @@ enum { /* Alignment of struct Lisp_Vector objects. */ vector_alignment = COMMON_MULTIPLE (ALIGNOF_STRUCT_LISP_VECTOR, - USE_LSB_TAG ? GCALIGNMENT : 1), + GCALIGNMENT), /* Vector size requests are a multiple of this. */ roundup_size = COMMON_MULTIPLE (vector_alignment, word_size) @@ -3299,15 +3295,13 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT ***********************************************************************/ /* Like struct Lisp_Symbol, but padded so that the size is a multiple - of the required alignment if LSB tags are used. */ + of the required alignment. */ union aligned_Lisp_Symbol { struct Lisp_Symbol s; -#if USE_LSB_TAG unsigned char c[(sizeof (struct Lisp_Symbol) + GCALIGNMENT - 1) & -GCALIGNMENT]; -#endif }; /* Each symbol_block is just under 1020 bytes long, since malloc @@ -3411,15 +3405,13 @@ Its value is void, and its function definition and property list are nil. */) ***********************************************************************/ /* Like union Lisp_Misc, but padded so that its size is a multiple of - the required alignment when LSB tags are used. */ + the required alignment. */ union aligned_Lisp_Misc { union Lisp_Misc m; -#if USE_LSB_TAG unsigned char c[(sizeof (union Lisp_Misc) + GCALIGNMENT - 1) & -GCALIGNMENT]; -#endif }; /* Allocation of markers and other objects that share that structure. @@ -4628,13 +4620,13 @@ mark_maybe_object (Lisp_Object obj) } /* Return true if P can point to Lisp data, and false otherwise. - USE_LSB_TAG needs Lisp data to be aligned on multiples of GCALIGNMENT. - Otherwise, assume that Lisp data is aligned on even addresses. */ + Symbols are implemented via offsets not pointers, but the offsets + are also multiples of GCALIGNMENT. */ static bool maybe_lisp_pointer (void *p) { - return !((intptr_t) p % (USE_LSB_TAG ? GCALIGNMENT : 2)); + return (uintptr_t) p % GCALIGNMENT == 0; } /* If P points to Lisp data, mark that as live if it isn't already @@ -4722,27 +4714,6 @@ mark_maybe_pointer (void *p) miss objects if __alignof__ were used. */ #define GC_POINTER_ALIGNMENT alignof (void *) -/* Define POINTERS_MIGHT_HIDE_IN_OBJECTS to 1 if marking via C pointers does - not suffice, which is the typical case. A host where a Lisp_Object is - wider than a pointer might allocate a Lisp_Object in non-adjacent halves. - If USE_LSB_TAG, the bottom half is not a valid pointer, but it should - suffice to widen it to to a Lisp_Object and check it that way. */ -#if USE_LSB_TAG || VAL_MAX < UINTPTR_MAX -# if !USE_LSB_TAG && VAL_MAX < UINTPTR_MAX >> GCTYPEBITS - /* If tag bits straddle pointer-word boundaries, neither mark_maybe_pointer - nor mark_maybe_object can follow the pointers. This should not occur on - any practical porting target. */ -# error "MSB type bits straddle pointer-word boundaries" -# endif - /* Marking via C pointers does not suffice, because Lisp_Objects contain - pointer words that hold pointers ORed with type bits. */ -# define POINTERS_MIGHT_HIDE_IN_OBJECTS 1 -#else - /* Marking via C pointers suffices, because Lisp_Objects contain pointer - words that hold unmodified pointers. */ -# define POINTERS_MIGHT_HIDE_IN_OBJECTS 0 -#endif - /* Mark Lisp objects referenced from the address range START+OFFSET..END or END+OFFSET..START. */ @@ -4788,8 +4759,7 @@ mark_memory (void *start, void *end) { void *p = *(void **) ((char *) pp + i); mark_maybe_pointer (p); - if (POINTERS_MIGHT_HIDE_IN_OBJECTS) - mark_maybe_object (XIL ((intptr_t) p)); + mark_maybe_object (XIL ((intptr_t) p)); } } @@ -5148,22 +5118,13 @@ static void * pure_alloc (size_t size, int type) { void *result; -#if USE_LSB_TAG - size_t alignment = GCALIGNMENT; -#else - size_t alignment = alignof (EMACS_INT); - - /* Give Lisp_Floats an extra alignment. */ - if (type == Lisp_Float) - alignment = alignof (struct Lisp_Float); -#endif again: if (type >= 0) { /* Allocate space for a Lisp object from the beginning of the free space with taking account of alignment. */ - result = ALIGN (purebeg + pure_bytes_used_lisp, alignment); + result = ALIGN (purebeg + pure_bytes_used_lisp, GCALIGNMENT); pure_bytes_used_lisp = ((char *)result - (char *)purebeg) + size; } else diff --git a/src/lisp.h b/src/lisp.h index 198f116..c3289c9 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -278,10 +278,7 @@ error !; #endif #ifndef alignas -# define alignas(alignment) /* empty */ -# if USE_LSB_TAG -# error "USE_LSB_TAG requires alignas" -# endif +# error "alignas not defined" #endif #ifdef HAVE_STRUCT_ATTRIBUTE_ALIGNED @@ -731,9 +728,7 @@ struct Lisp_Symbol /* Yield an integer that contains a symbol tag along with OFFSET. OFFSET should be the offset in bytes from 'lispsym' to the symbol. */ -#define TAG_SYMOFFSET(offset) \ - TAG_PTR (Lisp_Symbol, \ - ((uintptr_t) (offset) >> (USE_LSB_TAG ? 0 : GCTYPEBITS))) +#define TAG_SYMOFFSET(offset) TAG_PTR (Lisp_Symbol, offset) /* XLI_BUILTIN_LISPSYM (iQwhatever) is equivalent to XLI (builtin_lisp_symbol (Qwhatever)), @@ -899,8 +894,6 @@ INLINE struct Lisp_Symbol * XSYMBOL (Lisp_Object a) { uintptr_t i = (uintptr_t) XUNTAG (a, Lisp_Symbol); - if (! USE_LSB_TAG) - i <<= GCTYPEBITS; void *p = (char *) lispsym + i; return p; } -- 2.1.0 --------------050707070307010400090409--