mailing list of musl libc
 help / color / mirror / code / Atom feed
From: John Regan <saxindustries@gmail.com>
To: musl@lists.openwall.com
Subject: Question about setting argv[0] when manually using dynamic linker
Date: Tue, 16 May 2017 20:38:56 -0400	[thread overview]
Message-ID: <CACBMf30_2GBzDxnLyKzm7MUJZu7-xy-SNw5eBT=xDiC-N+PQOw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1273 bytes --]

Hi there - I was wondering if it's possible to somehow set argv[0] when
calling the dynamic linker to load a program.

The reason I want to do this (in case there's a better way) - I was looking
into compiling programs with musl libc, and distributing the binaries with
the needed libc.so file, so I could have a directory structure like:

/bin
|  app
/lib
|  libc.so
|  some_other_lib.so

I can set the rpath to $ORIGIN/../lib so the whole folder is relocatable,
but as far as i know, there's no equivalent concept for setting the dynamic
linker with a path that's relative to the binary.

My current idea is to have a wrapper script, so my structure would be
something like:

/bin
|  app.bin <- actual binary
|  app
/lib
|  libc.so
|  some_other_lib.so

The 'app' script could find the actual, absolute path to itself and figure
out where libc.so is, ending with a line like

exec /path/to/libc.so /path/to/app.bin arg1 arg2 etc

I'd like to retain whatever was actually typed on the command line (in this
case, set argv[0] to "app"), since many apps look at argv[0] to change
behavior, ie - gzip vs gunzip.

I tried seeing if there was some switch I could pass to the linker, etc -
as far as I can tell, there's no easy way to do this.

Thanks in advance!!

-John Regan

[-- Attachment #2: Type: text/html, Size: 3013 bytes --]

             reply	other threads:[~2017-05-17  0:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-17  0:38 John Regan [this message]
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
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='CACBMf30_2GBzDxnLyKzm7MUJZu7-xy-SNw5eBT=xDiC-N+PQOw@mail.gmail.com' \
    --to=saxindustries@gmail.com \
    --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).