unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Spencer Baugh via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 73318@debbugs.gnu.org, larsi@gnus.org, acorallo@gnu.org,
	schwab@linux-m68k.org, shipmints@gmail.com
Subject: bug#73318: 31.0.50; with-native-compilation=aot breaks exec -a emacs
Date: Fri, 04 Oct 2024 12:51:59 -0400	[thread overview]
Message-ID: <ieriku7zu8g.fsf@janestreet.com> (raw)
In-Reply-To: <86iku8x95w.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 04 Oct 2024 16:57:47 +0300")

Eli Zaretskii <eliz@gnu.org> writes:
>> From: Spencer Baugh <sbaugh@janestreet.com>
>> Cc: 73318@debbugs.gnu.org,  larsi@gnus.org,  acorallo@gnu.org,
>>    schwab@linux-m68k.org,  shipmints@gmail.com
>> Date: Fri, 04 Oct 2024 09:22:08 -0400
>> 
>> > The specific issue with finding the pdumper file more reliably is
>> > solved in Emacs 30 in the way Andreas suggested, but it has no effect
>> > on the problem which you describe, with finding the preloaded *.eln
>> > files.
>> 
>> Ah, interesting.  So Emacs 30 falls back on looking up the pdmp in
>> PATH_EXEC, a path compiled into the Emacs binary.
>> 
>> Should we perhaps do the same for the native-lisp directory?
>
> We already do, sort of.  We just rely on the search for the pdumper
> file to supply us with the answer.  See below.
>
>> If we can't find it in other ways, look it up relative to a path
>> compiled into the Emacs binary?  I don't know if that should be
>> PATH_EXEC or some other path.
>> 
>> That would work on my system.  Then we wouldn't need to use
>> /proc/self/exe at all.
>> 
>> Might that be the best solution?
>
> It isn't that easy.  We need to support 2 possible locations for the
> preloaded *.eln files: in the source tree and in the installation
> tree.  You now want us to look in yet a third place.  Take a look at
> dump_do_dump_relocation where we look for the *.eln files.  What you
> suggest is to add a third place to that code.

Yes.  I suggest that if installation_state == INSTALLED, and we fail to
find an eln file in emacs_execdir, we fall back to look in PATH_EXEC (or
some other path compiled into the Emacs binary).

But it occurs to me that there's another possible solution.  We already
have a robust way to find the pdump.  My Emacs finds the pdump and loads
it just fine.  Maybe we could look for the eln files relative to the
pdump?

So the two solutions that seem possible right now are:

A. If we fail to find an eln file relative to the Emacs executable, fall
   back to PATH_EXEC (or something similar)

B. Always look for eln files at a path relative to the pdmp, instead of
   relative to the Emacs executable.

>> >> >   . what if /proc/self/exe is unreadable? AFAIK, on some systems you
>> >> >     need special privileges to follow its symlink
>> >> >   . what if /proc/self/exe points to a file name that is a symlink, or
>> >> >     some of its leading directories are symlinks?
>> >> >   . what if Emacs is invoked via a script which is in the correct
>> >> >     installation directory, but the actual binary the script invokes
>> >> >     is not in the expected location relative to the native-lisp/
>> >> >     directory where we have the preloaded *.eln files?
>> >> >
>> >> > The existing code handles all these cases, and some others.  We could
>> >> > perhaps _add_ the use of /proc/self/exe to what we have, but we'd need
>> >> > to be sure that it doesn't break for the above situations.
>> >
>> > I'm still waiting for some answers to these.
>> 
>> If we use /proc/self/exe, I'm fine with it being a fallback if all other
>> mechanisms fail.  That should make these cases still work fine, right?
>
> To use /proc/self/exe as fallback, we need to somehow reject the Emacs
> "executable" found in your case.  Because otherwise fallbacks are only
> used if the previous attempts fail, and the attempt to find atgv[0]
> along PATH does not fail in your case, it just finds the "wrong" file.

True, so maybe /proc/self/exe is not a good solution.

>> > Why cannot you modify the script for all the commands to include the
>> > leading directories in executable-name?  That is all that is needed
>> > for Emacs to find its *.eln files.
>> 
>> See the motivation that I quoted above:
>> 
>>  For context, I believe the reason why we pass `-a` is to make the prog
>>  more identifiable when users try to find it in the output of
>>  `ps`. That still sounds like the right thing to do in the majority of
>>  the cases.
>> 
>> Including the leading directories would make them show up in the output
>> of "ps", which is uglier.
>
> "Uglier" is in the eyes of the beholder.  The important thing is that
> it solves the problem without any other changes, and will then use
> code which was tested and validated by many users.
>
>> I realize this might not seem like an important justification, but it
>> works for every other program we run, and has worked for decades.  And
>> other distributors might be doing this too, so I think it's reasonable
>> to make Emacs robust to this by having it fall back to looking up
>> native-lisp in something like PATH_EXEC.
>
> I disagree that this is reasonable, and what you suggest is not
> possible/practical anyway.
>
>> But now I think we maybe don't need to use /proc/self/exe at all, and
>> can just have Emacs fall back on something like PATH_EXEC when it fails
>> to find the native lisp files.
>
> See above.  If you insist to go this much more complicated way, we'll
> need to modify the code in dump_do_dump_relocation to use PATH_EXEC,
> and deal with possible false positives.

Yes, I am willing to put in the effort to do that.





  parent reply	other threads:[~2024-10-04 16:51 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-17 15:18 bug#73318: 31.0.50; with-native-compilation=aot breaks exec -a emacs Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-17 15:40 ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-17 17:47 ` Eli Zaretskii
2024-09-17 18:14   ` Ship Mints
2024-09-17 19:07     ` Eli Zaretskii
2024-09-17 19:22       ` Ship Mints
2024-09-17 19:31         ` Eli Zaretskii
2024-09-17 22:31           ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-17 22:45             ` Ship Mints
2024-09-18 13:11             ` Eli Zaretskii
2024-09-19  3:09               ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-19 12:54                 ` Ship Mints
2024-09-19 13:44                   ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-19 13:51                     ` Ship Mints
2024-09-19 15:45                       ` Eli Zaretskii
2024-10-04 12:09               ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-04 12:51                 ` Eli Zaretskii
2024-10-04 13:22                   ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-04 13:57                     ` Eli Zaretskii
2024-10-04 14:02                       ` shipmints
2024-10-04 16:51                       ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-10-04 19:09                         ` Eli Zaretskii
2024-10-07 14:18                           ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-07 18:44                             ` Eli Zaretskii
2024-10-07 20:16                               ` Spencer Baugh via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-10-08 11:47                                 ` Eli Zaretskii
2024-10-08 12:16                                   ` Eli Zaretskii
2024-10-04 19:16                         ` Eli Zaretskii
2024-10-08 23:35                     ` Stefan Kangas
2024-10-09 12:13                       ` 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=ieriku7zu8g.fsf@janestreet.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=73318@debbugs.gnu.org \
    --cc=acorallo@gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    --cc=sbaugh@janestreet.com \
    --cc=schwab@linux-m68k.org \
    --cc=shipmints@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).