From unknown Wed Jun 18 00:23:07 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#22085 <22085@debbugs.gnu.org> To: bug#22085 <22085@debbugs.gnu.org> Subject: Status: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization Reply-To: bug#22085 <22085@debbugs.gnu.org> Date: Wed, 18 Jun 2025 07:23:07 +0000 retitle 22085 25.0.50; src/gmalloc.c hit by gcc >=3D 5 optimization=20 reassign 22085 emacs submitter 22085 Wolfgang Jenkner severity 22085 normal tag 22085 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 03 12:54:06 2015 Received: (at submit) by debbugs.gnu.org; 3 Dec 2015 17:54:06 +0000 Received: from localhost ([127.0.0.1]:37730 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a4Y4z-0001jI-DV for submit@debbugs.gnu.org; Thu, 03 Dec 2015 12:54:05 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58726) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a4Y4f-0001ic-Rr for submit@debbugs.gnu.org; Thu, 03 Dec 2015 12:54:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a4Y4b-0005lJ-Af for submit@debbugs.gnu.org; Thu, 03 Dec 2015 12:53:45 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:35390) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4Y4b-0005lA-7D for submit@debbugs.gnu.org; Thu, 03 Dec 2015 12:53:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4Y4V-00011d-Ap for bug-gnu-emacs@gnu.org; Thu, 03 Dec 2015 12:53:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a4Y4R-0005fN-4S for bug-gnu-emacs@gnu.org; Thu, 03 Dec 2015 12:53:35 -0500 Received: from b2bfep12.mx.upcmail.net ([62.179.121.57]:51490) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4Y4Q-0005cB-QS for bug-gnu-emacs@gnu.org; Thu, 03 Dec 2015 12:53:31 -0500 Received: from edge12.upcmail.net ([192.168.13.82]) by b2bfep12.mx.upcmail.net (InterMail vM.8.01.05.18 201-2260-151-151-20140610) with ESMTP id <20151203175326.LDYS16586.b2bfep12-int.chello.at@edge12.upcmail.net> for ; Thu, 3 Dec 2015 18:53:26 +0100 Received: from iznogoud.viz ([91.119.234.240]) by edge12.upcmail.net with edge id p5tS1r0035BsVPf0C5tSAE; Thu, 03 Dec 2015 18:53:26 +0100 X-SourceIP: 91.119.234.240 Received: from wolfgang by iznogoud.viz with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1a4Y4L-0000Uo-Pb for bug-gnu-emacs@gnu.org; Thu, 03 Dec 2015 18:53:25 +0100 From: Wolfgang Jenkner To: bug-gnu-emacs@gnu.org Subject: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization X-Debbugs-CC: John Marino Date: Thu, 03 Dec 2015 18:53:25 +0100 Message-ID: <854mfzzaei.fsf@iznogoud.viz> User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) --=-=-= Content-Type: text/plain On systems which use src/gmalloc.c but don't define HYBRID_MALLOC that file defines global replacements for malloc and other memory management functions. Strictly speaking, this results in undefined behaviour according to ISO C11 (wg14 n1570 draft) 7.1.3 and 7.22.3. But it used to work. However, with recent gcc versions and the default optimization level (-O2), most of the definition of calloc is replaced with a call to calloc (which the linker resolves to a call to that same calloc). Chances are temacs crashes because some library calls calloc. This happens with the gcc 5.2.0 release and also with the 6.0.0 20151108 snapshot. Please find below a self-contained test program which shows the problem (try gcc5 -Wall -g -O2 callocopt.c -o callocopt && ./callocopt 666, and then with -O instead of -O2, or even with -O2 -fno-optimize-strlen). For comparison purposes, I note that, meanwhile, the issue has also surfaced here http://permalink.gmane.org/gmane.os.freebsd.devel.cvs.src/210733 Back to the problem with gmalloc.c, I'd suggest the simple toolchain-independent work-around given in the patch below. A real fix is to use hybrid malloc. --=-=-= Content-Type: text/x-csrc Content-Disposition: attachment; filename=callocopt.c Content-Description: Test program #include #include #include #include #include void * calloc (size_t bytes, size_t size) { void *result; static int cnt; if (cnt++) { fprintf(stderr, "Been there, done that.\n"); abort(); } result = malloc(bytes); if (result) return memset(result, 0, bytes); return result; } int main (int argc, char *argv[]) { if (argc != 2) return (1); size_t bytes = strtoul(argv[1], NULL, 10); return (calloc(bytes, 1) ? 42 : 0); } --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-src-gmalloc.c-Always-define-gmalloc-and-friends.patch Content-Description: gcc 5 optimization work-around for gmalloc >From 91a5b2c6f46db7f6882fb1bf514209f45802732e Mon Sep 17 00:00:00 2001 From: Wolfgang Jenkner Date: Mon, 16 Nov 2015 13:15:00 +0100 Subject: [PATCH 1/5] * src/gmalloc.c: Always define gmalloc and friends. This is a work-around to prevent the compiler from using semantic knowledge about malloc for optimization purposes. E.g., newer gcc with -O2 replaces most of calloc's definition by a call to calloc. --- src/gmalloc.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/gmalloc.c b/src/gmalloc.c index a88f4ab..90a52a1 100644 --- a/src/gmalloc.c +++ b/src/gmalloc.c @@ -60,7 +60,6 @@ extern void emacs_abort (void); which HYBRID_MACRO is defined. Any other platform that wants to define it will have to define the macros DUMPED and ALLOCATED_BEFORE_DUMPING, defined below for Cygwin. */ -#ifdef HYBRID_MALLOC #undef malloc #undef realloc #undef calloc @@ -70,7 +69,6 @@ extern void emacs_abort (void); #define calloc gcalloc #define aligned_alloc galigned_alloc #define free gfree -#endif /* HYBRID_MALLOC */ #ifdef CYGWIN extern void *bss_sbrk (ptrdiff_t size); @@ -1711,13 +1709,13 @@ valloc (size_t size) return aligned_alloc (pagesize, size); } -#ifdef HYBRID_MALLOC #undef malloc #undef realloc #undef calloc #undef aligned_alloc #undef free +#ifdef HYBRID_MALLOC /* Declare system malloc and friends. */ extern void *malloc (size_t size); extern void *realloc (void *ptr, size_t size); @@ -1816,6 +1814,38 @@ hybrid_get_current_dir_name (void) } #endif +#else /* ! HYBRID_MALLOC */ + +void * +malloc (size_t size) +{ + return gmalloc (size); +} + +void * +calloc (size_t nmemb, size_t size) +{ + return gcalloc (nmemb, size); +} + +void +free (void *ptr) +{ + gfree (ptr); +} + +void * +aligned_alloc (size_t alignment, size_t size) +{ + return galigned_alloc (alignment, size); +} + +void * +realloc (void *ptr, size_t size) +{ + return grealloc (ptr, size); +} + #endif /* HYBRID_MALLOC */ #ifdef GC_MCHECK -- 2.6.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 03 13:05:52 2015 Received: (at 22085) by debbugs.gnu.org; 3 Dec 2015 18:05:52 +0000 Received: from localhost ([127.0.0.1]:37743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a4YGN-00021f-SW for submit@debbugs.gnu.org; Thu, 03 Dec 2015 13:05:52 -0500 Received: from b2bqsv11.mx.upcmail.net ([62.179.121.55]:51239) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a4YG3-00020q-Is for 22085@debbugs.gnu.org; Thu, 03 Dec 2015 13:05:50 -0500 Received: from edge12.upcmail.net ([192.168.13.82]) by b2bqsv11.mx.upcmail.net (InterMail vM.8.01.05.11 201-2260-151-128-20120928) with ESMTP id <20151203180528.IOTD22374.b2bqsv11-int.chello.at@edge12.upcmail.net> for <22085@debbugs.gnu.org>; Thu, 3 Dec 2015 19:05:28 +0100 Received: from iznogoud.viz ([91.119.234.240]) by edge12.upcmail.net with edge id p65T1r01a5BsVPf0C65UBx; Thu, 03 Dec 2015 19:05:28 +0100 X-SourceIP: 91.119.234.240 Received: from wolfgang by iznogoud.viz with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1a4YFz-0000WK-P0; Thu, 03 Dec 2015 19:05:27 +0100 From: Wolfgang Jenkner To: 22085@debbugs.gnu.org Subject: Re: bug#22085: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization References: <854mfzzaei.fsf@iznogoud.viz> Date: Thu, 03 Dec 2015 19:05:27 +0100 In-Reply-To: <854mfzzaei.fsf@iznogoud.viz> (Wolfgang Jenkner's message of "Thu, 03 Dec 2015 18:53:25 +0100") Message-ID: <85lh9bxva0.fsf@iznogoud.viz> User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 22085 Cc: John Marino X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On Thu, Dec 03 2015, Wolfgang Jenkner wrote: > A real fix is to use hybrid malloc. For which, please see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22086 From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 03 13:24:31 2015 Received: (at control) by debbugs.gnu.org; 3 Dec 2015 18:24:31 +0000 Received: from localhost ([127.0.0.1]:37759 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a4YYR-0002nH-42 for submit@debbugs.gnu.org; Thu, 03 Dec 2015 13:24:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50244) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a4YYP-0002n7-RQ for control@debbugs.gnu.org; Thu, 03 Dec 2015 13:24:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a4YYP-0007eS-7v for control@debbugs.gnu.org; Thu, 03 Dec 2015 13:24:29 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:39372) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4YYP-0007eM-4J for control@debbugs.gnu.org; Thu, 03 Dec 2015 13:24:29 -0500 Received: from rgm by fencepost.gnu.org with local (Exim 4.82) (envelope-from ) id 1a4YYO-0001kT-6R for control@debbugs.gnu.org; Thu, 03 Dec 2015 13:24:28 -0500 Subject: control message for bug 19759 To: X-Mailer: mail (GNU Mailutils 2.99.98) Message-Id: From: Glenn Morris Date: Thu, 03 Dec 2015 13:24:28 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) block 19759 by 22085 From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 03 14:14:12 2015 Received: (at control) by debbugs.gnu.org; 3 Dec 2015 19:14:12 +0000 Received: from localhost ([127.0.0.1]:37786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a4ZKW-0007Eo-By for submit@debbugs.gnu.org; Thu, 03 Dec 2015 14:14:12 -0500 Received: from b2bfep13.mx.upcmail.net ([62.179.121.58]:43552) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1a4ZKB-0007Dx-No for control@debbugs.gnu.org; Thu, 03 Dec 2015 14:14:10 -0500 Received: from edge12.upcmail.net ([192.168.13.82]) by b2bfep13.mx.upcmail.net (InterMail vM.8.01.05.18 201-2260-151-151-20140610) with ESMTP id <20151203191350.MQDV21170.b2bfep13-int.chello.at@edge12.upcmail.net> for ; Thu, 3 Dec 2015 20:13:50 +0100 Received: from iznogoud.viz ([91.119.234.240]) by edge12.upcmail.net with edge id p7Dl1r00c5BsVPf0C7DmCJ; Thu, 03 Dec 2015 20:13:46 +0100 X-SourceIP: 91.119.234.240 Received: from wolfgang by iznogoud.viz with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1a4ZK5-0000YR-IQ for control@debbugs.gnu.org; Thu, 03 Dec 2015 20:13:45 +0100 From: Wolfgang Jenkner To: control@debbugs.gnu.org Subject: There's a patch here... Date: Thu, 03 Dec 2015 20:13:45 +0100 Message-ID: <85h9jzxs46.fsf@iznogoud.viz> User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) tags 22085 + patch quit From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 26 15:16:02 2015 Received: (at 22085-done) by debbugs.gnu.org; 26 Dec 2015 20:16:02 +0000 Received: from localhost ([127.0.0.1]:42165 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aCvFy-0007IV-76 for submit@debbugs.gnu.org; Sat, 26 Dec 2015 15:16:02 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:33462) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aCvFw-0007Hz-SQ for 22085-done@debbugs.gnu.org; Sat, 26 Dec 2015 15:16:01 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2B28E1607C4; Sat, 26 Dec 2015 12:15:55 -0800 (PST) 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 clSmn0w1g3tG; Sat, 26 Dec 2015 12:15:54 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 69A49160CC0; Sat, 26 Dec 2015 12:15:54 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu 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 xeJ9pbsKPyZG; Sat, 26 Dec 2015 12:15:54 -0800 (PST) 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 4A9CF1607C4; Sat, 26 Dec 2015 12:15:54 -0800 (PST) To: Wolfgang Jenkner From: Paul Eggert Subject: Re: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization Organization: UCLA Computer Science Department Message-ID: <567EF57A.20806@cs.ucla.edu> Date: Sat, 26 Dec 2015 12:15:54 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 22085-done Cc: 22085-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Thanks for the fix; I have applied this patch to the emacs-25 branch and am closing Bug#22085. The companion Bug#22086 will require more thinking, and I plan to follow up there. From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 26 17:37:37 2015 Received: (at 22085) by debbugs.gnu.org; 26 Dec 2015 22:37:37 +0000 Received: from localhost ([127.0.0.1]:42260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aCxSz-0005Z8-Fo for submit@debbugs.gnu.org; Sat, 26 Dec 2015 17:37:37 -0500 Received: from b2bfep13.mx.upcmail.net ([62.179.121.58]:42789) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aCxSx-0005Ys-Ed for 22085@debbugs.gnu.org; Sat, 26 Dec 2015 17:37:36 -0500 Received: from edge12.upcmail.net ([192.168.13.82]) by b2bfep13.mx.upcmail.net (InterMail vM.8.01.05.18 201-2260-151-151-20140610) with ESMTP id <20151226223728.NKDF31131.b2bfep13-int.chello.at@edge12.upcmail.net> for <22085@debbugs.gnu.org>; Sat, 26 Dec 2015 23:37:28 +0100 Received: from iznogoud.viz ([91.119.137.116]) by edge12.upcmail.net with edge id yNdT1r00T2Wrhgj0CNdUDt; Sat, 26 Dec 2015 23:37:28 +0100 X-SourceIP: 91.119.137.116 Received: from wolfgang by iznogoud.viz with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1aCxSp-0000Ep-Kd; Sat, 26 Dec 2015 23:37:27 +0100 From: Wolfgang Jenkner To: 22085@debbugs.gnu.org Subject: Re: bug#22085: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization References: <854mfzzaei.fsf@iznogoud.viz> <567EF57A.20806@cs.ucla.edu> Date: Sat, 26 Dec 2015 23:37:27 +0100 In-Reply-To: <567EF57A.20806@cs.ucla.edu> (Paul Eggert's message of "Sat, 26 Dec 2015 12:15:54 -0800") Message-ID: <85si2osuoo.fsf@iznogoud.viz> User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 22085 Cc: eggert@cs.ucla.edu X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On Sat, Dec 26 2015, Paul Eggert wrote: > Thanks for the fix; I have applied this patch to the emacs-25 branch > and am closing Bug#22085. The companion Bug#22086 will require more > thinking, and I plan to follow up there. I just wanted to wait until your plan for bug#22086 becomes more concrete (I do have push access), but thanks anyway (I'm actually surprised that you are willing to live with this work-around for a little while :-) From unknown Wed Jun 18 00:23:07 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 24 Jan 2016 12:24:12 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator