From: Eli Zaretskii <eliz@gnu.org>
To: Jason Rumney <jasonr@gnu.org>
Cc: lekktu@gmail.com, larsi@gnus.org, 2507@debbugs.gnu.org
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 [thread overview]
Message-ID: <83bo9qcmtv.fsf@gnu.org> (raw)
In-Reply-To: <877h7mz2nv.fsf@gnu.org>
> From: Jason Rumney <jasonr@gnu.org>
> Date: Wed, 13 Jul 2011 22:16:36 +0800
> Cc: Juanma Barranquero <lekktu@gmail.com>,
> Lars Magne Ingebrigtsen <larsi@gnus.org>, 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.
next prev parent reply other threads:[~2013-04-07 16:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-28 11:01 bug#2507: 23.0.91; Stripping emacs.exe on MS-Windows produces an invalid program Eli Zaretskii
2009-02-28 12:14 ` Eli Zaretskii
2009-03-01 6:01 ` Harald Maier
2009-03-01 17:15 ` Eli Zaretskii
2009-03-02 11:55 ` Juanma Barranquero
2009-03-02 19:05 ` Eli Zaretskii
2011-07-11 13:53 ` Lars Magne Ingebrigtsen
2011-07-11 14:12 ` Juanma Barranquero
2011-07-11 16:03 ` Eli Zaretskii
2011-07-11 16:09 ` Lars Magne Ingebrigtsen
2011-07-11 16:22 ` Eli Zaretskii
2011-07-11 19:36 ` Juanma Barranquero
2011-07-12 4:56 ` Stefan Monnier
2011-07-12 11:03 ` Juanma Barranquero
2011-07-13 14:16 ` Jason Rumney
2013-04-07 16:44 ` Eli Zaretskii [this message]
2014-06-04 18:42 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=83bo9qcmtv.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=2507@debbugs.gnu.org \
--cc=jasonr@gnu.org \
--cc=larsi@gnus.org \
--cc=lekktu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).