GNU bug report logs - #22085
25.0.50; src/gmalloc.c hit by gcc >= 5 optimization

Previous Next

Package: emacs;

Reported by: Wolfgang Jenkner <wjenkner <at> inode.at>

Date: Thu, 3 Dec 2015 17:55:02 UTC

Severity: normal

Tags: patch

Found in version 25.0.50

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22085 in the body.
You can then email your comments to 22085 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to marino <at> FreeBSD.org, bug-gnu-emacs <at> gnu.org:
bug#22085; Package emacs. (Thu, 03 Dec 2015 17:55:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Wolfgang Jenkner <wjenkner <at> inode.at>:
New bug report received and forwarded. Copy sent to marino <at> FreeBSD.org, bug-gnu-emacs <at> gnu.org. (Thu, 03 Dec 2015 17:55:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Wolfgang Jenkner <wjenkner <at> inode.at>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization 
Date: Thu, 03 Dec 2015 18:53:25 +0100
[Message part 1 (text/plain, inline)]
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.

[callocopt.c (text/x-csrc, attachment)]
[0001-src-gmalloc.c-Always-define-gmalloc-and-friends.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#22085; Package emacs. (Thu, 03 Dec 2015 18:06:02 GMT) Full text and rfc822 format available.

Message #8 received at 22085 <at> debbugs.gnu.org (full text, mbox):

From: Wolfgang Jenkner <wjenkner <at> inode.at>
To: 22085 <at> debbugs.gnu.org
Cc: John Marino <marino <at> FreeBSD.org>
Subject: Re: bug#22085: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization
Date: Thu, 03 Dec 2015 19:05:27 +0100
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




Added indication that bug 22085 blocks19759 Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 03 Dec 2015 18:25:04 GMT) Full text and rfc822 format available.

Added tag(s) patch. Request was from Wolfgang Jenkner <wjenkner <at> inode.at> to control <at> debbugs.gnu.org. (Thu, 03 Dec 2015 19:15:02 GMT) Full text and rfc822 format available.

Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sat, 26 Dec 2015 20:17:01 GMT) Full text and rfc822 format available.

Notification sent to Wolfgang Jenkner <wjenkner <at> inode.at>:
bug acknowledged by developer. (Sat, 26 Dec 2015 20:17:01 GMT) Full text and rfc822 format available.

Message #17 received at 22085-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Wolfgang Jenkner <wjenkner <at> inode.at>
Cc: 22085-done <at> debbugs.gnu.org
Subject: Re: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization
Date: Sat, 26 Dec 2015 12:15:54 -0800
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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#22085; Package emacs. (Sat, 26 Dec 2015 22:38:02 GMT) Full text and rfc822 format available.

Message #20 received at 22085 <at> debbugs.gnu.org (full text, mbox):

From: Wolfgang Jenkner <wjenkner <at> inode.at>
To: 22085 <at> debbugs.gnu.org
Cc: eggert <at> cs.ucla.edu
Subject: Re: bug#22085: 25.0.50; src/gmalloc.c hit by gcc >= 5 optimization
Date: Sat, 26 Dec 2015 23:37:27 +0100
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 :-)




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 24 Jan 2016 12:24:12 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 146 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.