From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11327 Path: news.gmane.org!.POSTED!not-for-mail From: John Regan Newsgroups: gmane.linux.lib.musl.general Subject: Question about setting argv[0] when manually using dynamic linker Date: Tue, 16 May 2017 20:38:56 -0400 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a1146cc1071cb23054fad83d2" X-Trace: blaine.gmane.org 1494985274 26023 195.159.176.226 (17 May 2017 01:41:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 May 2017 01:41:14 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11342-gllmg-musl=m.gmane.org@lists.openwall.com Wed May 17 03:41:08 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dAnxb-0006eJ-RF for gllmg-musl@m.gmane.org; Wed, 17 May 2017 03:41:07 +0200 Original-Received: (qmail 15852 invoked by uid 550); 17 May 2017 01:41:10 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 20463 invoked from network); 17 May 2017 00:39:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=c5JldTdxbhVbRufz3Wbbihg8fD8zYilb7WFEEP5OKTE=; b=k4K/Yc9mcCijnSvdMNf8CoiyTJ+8D3SEGbBEmXYhb1RsnREigywwz/Ieppuc5czRis 5mPIvQo2VxBB0w8SoPCH6/gv93g3lyUOIjbGF8yq4TFIDbNLlBC+nVdIQsAnnpuvcpmw XGyE/xWNmovYDccPKijWDKjYDT0lf+Whw3Z93hpvLhpc9Vq9eIyGuNJmI1CRI83MFDcZ qbhBkH1ZJ3vHZThFXYlJmBnfY7jkPgek9U5iev6B23Zd7tUtzyemYI3f4b/W95Q2XgzD o5yYpv/dsdFg5KKAjPfMG985w1gmy4waGnpiM6wLr8uBjBwYOoHbnUk/osQkOsxsmkFw 73UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=c5JldTdxbhVbRufz3Wbbihg8fD8zYilb7WFEEP5OKTE=; b=CuTrdkW84Egx9adI0bKvNSUAYuApaDp5X1NB0EGonf1Wl6Ccm8mtZ41agF5iObmwoT +nnHWb+EKRSN7AYtL+ISiTgeRPPrSLYh8xVU5GSTKWdCah55C6UyHJSf5XSdN7dbNvix 5rII0rdPiRkLRTe1LbC1Q8lduKrJ/ooNZBXakzRk6jN1weiJxFZgg3/s02q55Nn+3TpF 1rDk2bo08l2OUm8FB3j8lKiVvNDwqyOraaj1onULCevASYgmwUGumVEKGNJUqzM1mHU2 xSJor4bUKOD4Ig+1u1twwhUkRM4rpQtT/0YzvV8VTCRoOYbb8ViIdHxzX4whIXbRQael 7QUw== X-Gm-Message-State: AODbwcAFcMLVQa+atU19VxMn8g2NMzLWdF44u9xz3pSytmA7y1bpuzsG TMwblTfllyp81WrZECx0sqSYVfjGdQ== X-Received: by 10.55.15.143 with SMTP id 15mr635130qkp.44.1494981536761; Tue, 16 May 2017 17:38:56 -0700 (PDT) Xref: news.gmane.org gmane.linux.lib.musl.general:11327 Archived-At: --001a1146cc1071cb23054fad83d2 Content-Type: text/plain; charset="UTF-8" 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 --001a1146cc1071cb23054fad83d2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi there - I was wonde= ring if it's possible to somehow set argv[0] when calling the dynamic l= inker 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
| = =C2=A0app
/lib<= /div>
| =C2=A0libc.so
<= div>| =C2=A0some_other_lib.so

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

<= /div>
My current idea is to have a = wrapper script, so my structure would be something like:
<= font face=3D"monospace, monospace">
/bin
| =C2=A0app.bin <- actual binary
| =C2=A0app
/lib
| =C2=A0libc= .so
| =C2=A0some_other= _lib.so

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

exec /path/to/li= bc.so /path/to/app.bin arg1 arg2 etc

I&= #39;d like to retain whatever was actually typed on the command line (in th= is case, set argv[0] to "app"), since many apps look at argv[0] t= o 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
--001a1146cc1071cb23054fad83d2--