From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#2507: 23.0.91; Stripping emacs.exe on MS-Windows produces an invalid program Date: Sun, 07 Apr 2013 19:44:28 +0300 Message-ID: <83bo9qcmtv.fsf@gnu.org> References: <83y604n6t3.fsf@gnu.org> <83sjqcn5wr.fsf@gnu.org> <877h7mz2nv.fsf@gnu.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1365353146 2059 80.91.229.3 (7 Apr 2013 16:45:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 7 Apr 2013 16:45:46 +0000 (UTC) Cc: lekktu@gmail.com, larsi@gnus.org, 2507@debbugs.gnu.org To: Jason Rumney Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Apr 07 18:45:48 2013 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 1UOsix-0005yc-L5 for geb-bug-gnu-emacs@m.gmane.org; Sun, 07 Apr 2013 18:45:47 +0200 Original-Received: from localhost ([::1]:41658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOsix-0000pw-AL for geb-bug-gnu-emacs@m.gmane.org; Sun, 07 Apr 2013 12:45:47 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:60268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOsip-0000pe-9i for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2013 12:45:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UOsil-0006vW-Qr for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2013 12:45:39 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOsil-0006vJ-MS for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2013 12:45:35 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UOsm6-0000az-Eu for bug-gnu-emacs@gnu.org; Sun, 07 Apr 2013 12:49:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 07 Apr 2013 16:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 2507 X-GNU-PR-Package: emacs,w32 X-GNU-PR-Keywords: Original-Received: via spool by 2507-submit@debbugs.gnu.org id=B2507.13653532872218 (code B ref 2507); Sun, 07 Apr 2013 16:49:02 +0000 Original-Received: (at 2507) by debbugs.gnu.org; 7 Apr 2013 16:48:07 +0000 Original-Received: from localhost ([127.0.0.1]:38639 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UOsl9-0000Zg-Nl for submit@debbugs.gnu.org; Sun, 07 Apr 2013 12:48:07 -0400 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:36272) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UOsl2-0000ZB-HK for 2507@debbugs.gnu.org; Sun, 07 Apr 2013 12:48:01 -0400 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0MKW00J0093MUW00@a-mtaout22.012.net.il> for 2507@debbugs.gnu.org; Sun, 07 Apr 2013 19:44:21 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MKW00JE295WKM70@a-mtaout22.012.net.il>; Sun, 07 Apr 2013 19:44:21 +0300 (IDT) In-reply-to: <877h7mz2nv.fsf@gnu.org> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.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:73239 Archived-At: > From: Jason Rumney > Date: Wed, 13 Jul 2011 22:16:36 +0800 > Cc: Juanma Barranquero , > Lars Magne Ingebrigtsen , 2507@debbugs.gnu.org > > If you build without debug info in the first place, it does work, at > around the same size. Also if you strip temacs before dumping, it > works. The problem is only in stripping a dumped binary that had > debug info to start with. It seems the strip command removes some info > that Emacs needs to reconstruct the heap from the dumped image. That is correct. I looked into this some more. The problem is that we add an extra section to the Emacs executable (by running addsection), which serves as the static heap. Here's the report from "objdump -h": temacs.exe: file format pei-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0032e604 01001000 01001000 00001000 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA 1 .data 0020aea0 01330000 01330000 00330000 2**4 CONTENTS, ALLOC, LOAD, DATA 2 .rdata 000dc57c 0153b000 0153b000 0053b000 2**4 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .bss 0005c410 01618000 01618000 00000000 2**4 ALLOC 4 .idata 000036f4 01675000 01675000 00618000 2**2 CONTENTS, ALLOC, LOAD, DATA 5 .rsrc 0000d5f0 01679000 01679000 0061c000 2**2 CONTENTS, ALLOC, LOAD, DATA 6 .debug_aranges 00000ce0 01687000 01687000 0062a000 2**0 CONTENTS, READONLY, DEBUGGING 7 .debug_pubnames 00011b5a 01688000 01688000 0062b000 2**0 CONTENTS, READONLY, DEBUGGING 8 .debug_info 003992b0 0169a000 0169a000 0063d000 2**0 CONTENTS, READONLY, DEBUGGING 9 .debug_abbrev 0001181b 01a34000 01a34000 009d7000 2**0 CONTENTS, READONLY, DEBUGGING 10 .debug_line 0003f37e 01a46000 01a46000 009e9000 2**0 CONTENTS, READONLY, DEBUGGING 11 .debug_frame 0001b6b8 01a86000 01a86000 00a29000 2**0 CONTENTS, READONLY, DEBUGGING 12 .debug_str 0000d3bb 01aa2000 01aa2000 00a45000 2**0 CONTENTS, READONLY, DEBUGGING 13 .debug_macinfo 01b54308 01ab0000 01ab0000 00a53000 2**0 CONTENTS, READONLY, DEBUGGING 14 EMHEAP 01b00000 03605000 03605000 00000000 2**2 ALLOC The last section, EMHEAP, is the one we add. Now look what happens after stripping: temacs.exe: file format pei-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0032e604 01001000 01001000 00000400 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA 1 .data 0020aea0 01330000 01330000 0032ec00 2**4 CONTENTS, ALLOC, LOAD, DATA 2 .rdata 000dc57c 0153b000 0153b000 00539c00 2**4 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .bss 0005c410 01618000 01618000 00000000 2**4 ALLOC 4 .idata 000036f4 01675000 01675000 00616200 2**2 CONTENTS, ALLOC, LOAD, DATA 5 .rsrc 0000d5f0 01679000 01679000 00619a00 2**2 CONTENTS, ALLOC, LOAD, DATA 6 EMHEAP 01b00000 03605000 03605000 00000000 2**2 ALLOC The debug sections are gone, but the VMA and LMA of EMHEAP were left intact. By contrast, if we strip temacs.bin _before_ running addsection, and run addsection on the stripped temacs.bin, we get this: temacs.exe: file format pei-i386 Sections: Idx Name Size VMA LMA File off Algn 0 .text 0032e604 01001000 01001000 00001000 2**4 CONTENTS, ALLOC, LOAD, READONLY, CODE, DATA 1 .data 0020aea0 01330000 01330000 00330000 2**4 CONTENTS, ALLOC, LOAD, DATA 2 .rdata 000dc57c 0153b000 0153b000 0053b000 2**4 CONTENTS, ALLOC, LOAD, READONLY, DATA 3 .bss 0005c410 01618000 01618000 00000000 2**4 ALLOC 4 .idata 000036f4 01675000 01675000 00618000 2**2 CONTENTS, ALLOC, LOAD, DATA 5 .rsrc 0000d5f0 01679000 01679000 0061c000 2**2 CONTENTS, ALLOC, LOAD, DATA 6 EMHEAP 01b00000 01687000 01687000 00000000 2**2 ALLOC Now EMHEAP's VMA and LMA follow the section before it. So I think the kind of workaround mentioned in http://debbugs.gnu.org/cgi/bugreport.cgi?bug=2507#10 above, or some variant thereof, is the right way of producing a stripped emacs.exe. That is, link with -s (or strip temacs.bin after it is produced), and then run addsection to produce temacs.exe and finally loadup+dump into emacs.exe. An alternative is to add code to addsection.c so that it could adjust the EMHEAP section's VMA and LMA after emacs.exe was stripped. No, I'm not volunteering ;-) P.S. I tried to adjust the VMA/LMA with objcopy, but the result is not reliable: sometimes works, sometimes crashes. So more than just address adjustment is needed.