From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Brown Newsgroups: gmane.emacs.bugs Subject: bug#9273: 23.3; malloc initialization should (sometimes) happen at runtime Date: Tue, 09 Aug 2011 16:09:48 -0400 Message-ID: <4E41940C.2010605@cornell.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1312920670 5273 80.91.229.12 (9 Aug 2011 20:11:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 9 Aug 2011 20:11:10 +0000 (UTC) To: 9273@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 09 22:11:06 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Qqsdl-0007UQ-Dn for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Aug 2011 22:11:05 +0200 Original-Received: from localhost ([::1]:43304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqsdk-0006E7-FP for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Aug 2011 16:11:04 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:46147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqsdd-0006Ds-Ab for bug-gnu-emacs@gnu.org; Tue, 09 Aug 2011 16:11:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QqsdZ-00088j-EP for bug-gnu-emacs@gnu.org; Tue, 09 Aug 2011 16:10:57 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36581) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QqsdZ-00088f-BY for bug-gnu-emacs@gnu.org; Tue, 09 Aug 2011 16:10:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Qqseg-0008BY-DU; Tue, 09 Aug 2011 16:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ken Brown Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 09 Aug 2011 20:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 9273 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.131292067331385 (code B ref -1); Tue, 09 Aug 2011 20:12:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Aug 2011 20:11:13 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qqsds-0008A9-3p for submit@debbugs.gnu.org; Tue, 09 Aug 2011 16:11:12 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qqsdn-00089z-Ex for submit@debbugs.gnu.org; Tue, 09 Aug 2011 16:11:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qqsce-0007yl-TV for submit@debbugs.gnu.org; Tue, 09 Aug 2011 16:09:57 -0400 Original-Received: from lists.gnu.org ([140.186.70.17]:59238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqsce-0007yh-S1 for submit@debbugs.gnu.org; Tue, 09 Aug 2011 16:09:56 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:45967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqscd-00066j-Ci for bug-gnu-emacs@gnu.org; Tue, 09 Aug 2011 16:09:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qqscb-0007yA-Po for bug-gnu-emacs@gnu.org; Tue, 09 Aug 2011 16:09:55 -0400 Original-Received: from granite1.mail.cornell.edu ([128.253.83.141]:57630 helo=authusersmtp.mail.cornell.edu) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqscb-0007xc-MU for bug-gnu-emacs@gnu.org; Tue, 09 Aug 2011 16:09:53 -0400 Original-Received: from [128.84.234.236] (dhcp236.math.cornell.edu [128.84.234.236]) (authenticated bits=0) by authusersmtp.mail.cornell.edu (8.14.4/8.12.10) with ESMTP id p79K9mMx003421 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 9 Aug 2011 16:09:48 -0400 (EDT) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 X-detected-operating-system: by eggs.gnu.org: Solaris 9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Tue, 09 Aug 2011 16:12:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) 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:49968 Archived-At: The code in src/gmalloc.c makes assumptions about how a system maintains its memory that are not necessarily valid. In particular, they will not be valid on Cygwin starting with version 1.7.10 (which will almost certainly be released before emacs 24.1). The problem is that malloc initialization is done by temacs, and the results are dumped into emacs. This includes the setting __malloc_initialized = 1, so no malloc initialization is done when emacs is run. But the dumped value of _heapbase, while appropriate for temacs, may not point to the beginning of the runtime heap for emacs. This causes all code that uses the BLOCK and ADDRESS macros to be invalid. Here's what happens on Cygwin. temacs (on Cygwin) uses a static buffer as its heap and a function bss_sbrk that simulates sbrk. (See src/sheap.c.) The data in this buffer, including malloc information, are then dumped into emacs.exe as initialized data. But when the dumped emacs is run, it uses Cygwin's sbrk, which allocates memory on a heap that won't (as of Cygwin 1.7.10) be contiguous with the static heap. The saved value of _heapbase, which points into the static heap, is never changed, but it will mess up later calculations as soon as sbrk is called for the first time. All of this is described in detail on the Cygwin mailing list in the thread starting at http://cygwin.com/ml/cygwin/2011-08/msg00153.html See especially http://cygwin.com/ml/cygwin/2011-08/msg00193.html which contains a gdb session illustrating the problem. The context for that session is that, as a result of the problem I'm reporting, morecore_nolock went into an infinite loop. I attached gdb to that looping process. Maybe the solution is for emacs to do malloc initialization, including the assignment of _heapbase, every time it starts, at least on systems that use gmalloc.c. I made one naive attempt to do this, but it didn't work (and it was Cygwin specific). Namely, I made unexec (for Cygwin) set _malloc_initialized = 0 before dumping. The resulting emacs aborted as soon as it was started. I haven't figured out what went wrong, but I'm not sure that's the right answer anyway. Ken