unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ali Bahrami <ali_gnu2@emvision.com>
To: Eli Zaretskii <eliz@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Finding the dump (redux)
Date: Mon, 19 Apr 2021 09:43:46 -0600	[thread overview]
Message-ID: <6e7934e4-7aed-423d-256b-671823f2ec49@emvision.com> (raw)
In-Reply-To: <83o8eas613.fsf@gnu.org>

On 4/19/21 8:28 AM, Eli Zaretskii wrote:
>> From: Stefan Monnier <monnier@iro.umontreal.ca>
>> Cc: Eli Zaretskii <eliz@gnu.org>,  emacs-devel@gnu.org
>> Date: Mon, 19 Apr 2021 09:26:57 -0400
>>
>> That reminds me: I think ideally, we should see the pdmp files as the
>> executables and the temacs file as a runtime library (after all,
>> a single temacs file can be used with several different pdmp files).
>>
>> If we could find a nice&portable way to turn the pdmp files into
>> executables, then that would be The Right Way.
> 
> I'd rather we didn't mess with binary files and didn't produce
> executables except by running the system linker on object files
> created by some system compiler.  Otherwise we will slip back towards
> the kind of problems we had with unexec.
> 

    I almost floated this yesterday in my reply, but I
dropped it, as things were already getting long, and that
discussion didn't need another digression. However,
I think I see a way to get this data into the binary
itself without doing anything clever with linking, and
only using vanilla C. I saw someone else allude to this
idea here before, so I make no claim to invention, but
let me sketch it out and see if you think it might be viable.

The idea is to get the pdump data into the executable, not
by unexec-like methods, but as a simple C array, compiled
by the C compiler, and linked into emacs like a normal
object. Since we have to build emacs before we generate the
pdump data, this needs 2 stages, much like the temacs/emacs
division as it existed in the unexec days.

Imagine that emacs has an array for this, and a variable
giving the size of the array. A size of 0 means that there
is no pdump content. When emacs starts, it still looks at
the command line option, or for a pdmp file sitting next to
the executable, but failing that, it will fall back to the
array, if present, for its pdump content.

Start with a stub C file containing these variables:

     unsigned char default_pdmp_data[1];
     const size_t  default_pdmp_data_size = 0;

Build temacs with that stub, and then run temacs to
generate a pdmp file, as it does today. temacs will
see that default_pdmp_data[] is empty, and will ignore it.

Then, use a script, or even temacs itself, to generate
a source file that creates a version of default_pdmp_data[]
initialized with the pdmp data from the generated file, and
with a non-zero value for default_pdmp_data_size giving the
size.

And finally, relink emacs once more, using the generated
object in place of the stub.

I notice that there are actually multiple mappings from
todays pdmp file in the process, so the above is probably
over-simplified, and perhaps we need more than one such
array. I'm sure a pdump-knowledgable person would know
what to do about it:

     ali@rtld% pmap `pgrep emacs` | grep pdmp
     00007FE834C00000   7088K rw-----  /usr/lib/emacs/27.2/x86_64-pc-solaris2.11/emacs-gtk.pdmp
     00007FE8352EC000    120K -------  /usr/lib/emacs/27.2/x86_64-pc-solaris2.11/emacs-gtk.pdmp
     00007FE83530A000   3188K rw-----  /usr/lib/emacs/27.2/x86_64-pc-solaris2.11/emacs-gtk.pdmp

(I'm not sure what to make of the mapping with no
access bits set).

I'll guess it also changes the fingerprint, between the
2 stages, but perhaps that's OK, since there's no need
for a fingerprint validation if the data is held in the binary,
or perhaps there's an easy way to finesse that. Perhaps the
fingerprint from temacs gets propagated to the final emacs,
instead of being recomputed?

The overall point of the above is that it only uses
basic C, so it should be robust and portable. Since
we already know that we can read and use the pdump data,
it should work in the same way when seen in an in-memory
array, rather than mapped from a data file.

- Ali



  parent reply	other threads:[~2021-04-19 15:43 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15 19:38 Finding the dump (redux) Ali Bahrami
2021-04-17 18:45 ` Eli Zaretskii
2021-04-18  0:15   ` Ali Bahrami
2021-04-18  7:55     ` Eli Zaretskii
2021-04-18  8:18       ` Andreas Schwab
2021-04-18 16:05         ` Glenn Morris
2021-04-19  4:53         ` Richard Stallman
2021-04-19  8:35           ` Andreas Schwab
2021-04-19 13:00             ` Eli Zaretskii
2021-04-19 13:04             ` Ali Bahrami
2021-04-19 13:14               ` Eli Zaretskii
2021-04-19 13:34                 ` Stefan Kangas
2021-04-19 14:39                   ` Eli Zaretskii
2021-04-19 15:41                     ` Ali Bahrami
2021-04-19 15:58                       ` Eli Zaretskii
2021-04-19 16:08                         ` Ali Bahrami
2021-04-19 17:09                           ` Eli Zaretskii
2021-04-19  4:01       ` Ali Bahrami
2021-04-19 13:26         ` Stefan Monnier
2021-04-19 14:28           ` Eli Zaretskii
2021-04-19 14:50             ` Stefan Monnier
2021-04-19 15:43             ` Ali Bahrami [this message]
2021-04-19 16:06               ` Eli Zaretskii
2021-04-19 16:39                 ` Ali Bahrami
2021-04-19 17:19                   ` Eli Zaretskii
2021-04-19 18:03                     ` Ali Bahrami

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=6e7934e4-7aed-423d-256b-671823f2ec49@emvision.com \
    --to=ali_gnu2@emvision.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).