mailing list of musl libc
 help / color / mirror / code / Atom feed
From: u-uy74@aetey.se
To: musl@lists.openwall.com
Subject: Re: Question about setting argv[0] when manually using dynamic linker
Date: Sun, 9 Jul 2017 11:23:23 +0200	[thread overview]
Message-ID: <20170709092322.GA27260@example.net> (raw)
In-Reply-To: <20170704205811.GN1627@brightrain.aerifal.cx>

On Tue, Jul 04, 2017 at 04:58:11PM -0400, Rich Felker wrote:
> On Sun, Jul 02, 2017 at 07:36:19PM +0200, u-uy74@aetey.se wrote:
> > On Wed, May 17, 2017 at 12:24:28PM -0400, Rich Felker wrote:
> > > Perhaps adding an option like --argv0=foo would be
> > > appropriate.
> > 
> > Is this option being considered to introduce?

> Yes, adding it.

Thanks again, it makes some "unsolvable" cases work as needed.

OTOH when applying this in practice, I noticed that a slightly
different behaviour would be very handy: if the linker could
supply its own argv[0] as the one for the program to run.

This would fit nicely into the framework where we already set argv[0]
anyway, in the same way for both statically and dynamically linked
programs. (The only exception so far would be a hypothetical need to
pass on the value "ldd" as argv[0], then --argv0=ldd would save the day)

Otherwise we have to set the dynloader --argv0 argument per binary
which is of course possible but remarkably less convenient,
among others because this setting is dynloader-specific, while
otherwise our tools are libc- and dynamic vs static agnostic.

IOW as long as the loader itself does not rely on its argv[0]
too much, plainly passing on argv[0] is a very practical means to
handle the programs like busybox and gcc transparently.

What about always passing on the loader argv[0] unless --argv0 is present?
This will not matter for programs which do not analyze argv[0]
and will not make it worse for programs which do.

--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1388,7 +1388,7 @@
                kernel_mapped_dso(&app);
        } else {
                int fd;
-               char *ldname = argv[0];
+               char *ldname = replace_argv0 = argv[0];
                size_t l = strlen(ldname);
                if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1;
                argv++;

or even

--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1322,7 +1322,7 @@
        size_t aux[AUX_CNT], *auxv;
        size_t i;
        char *env_preload=0;
-       char *replace_argv0=0;
+       char *replace_argv0=argv[0];
        size_t vdso_base;
        int argc = *sp;
        char **argv = (void *)(sp+1);
@@ -1567,7 +1567,7 @@
        debug.state = 0;
        _dl_debug_state();

-       if (replace_argv0) argv[0] = replace_argv0;
+       argv[0] = replace_argv0;

        errno = 0;
 

Otherwise may be something like this:

--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1409,6 +1409,7 @@
                                else if (*argv) env_preload = *argv++;
                        } else if (!memcmp(opt, "argv0", 5)) {
                                if (opt[5]=='=') replace_argv0 = opt+6;
+                               else if (opt[5]=='^') replace_argv0 = ldname;
                                else if (opt[5]) *argv = 0;
                                else if (*argv) replace_argv0 = *argv++;
                        } else {

to instead introduce an extra --argv0^ option ?

Regards,
Rune



  parent reply	other threads:[~2017-07-09  9:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-17  0:38 John Regan
2017-05-17  9:01 ` u-uy74
2017-05-17 11:00   ` mzpqnxow
2017-05-17 16:07     ` mzpqnxow
2017-05-17 16:16       ` John Regan
2017-05-17 16:24         ` Rich Felker
2017-05-17 19:07           ` u-uy74
2017-05-17 19:16             ` John Regan
2017-05-17 21:10               ` u-uy74
2017-05-17 21:15               ` mzpqnxow
2017-05-17 21:22                 ` John Regan
2017-07-02 17:36           ` u-uy74
2017-07-04 20:58             ` Rich Felker
2017-07-05  6:01               ` u-uy74
2017-07-09  9:23               ` u-uy74 [this message]
2017-07-09 12:23                 ` Rich Felker
2017-07-09 14:04                   ` u-uy74

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170709092322.GA27260@example.net \
    --to=u-uy74@aetey.se \
    --cc=musl@lists.openwall.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.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).