From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11331 Path: news.gmane.org!.POSTED!not-for-mail From: mzpqnxow Newsgroups: gmane.linux.lib.musl.general Subject: Re: Question about setting argv[0] when manually using dynamic linker Date: Wed, 17 May 2017 11:00:35 +0000 Message-ID: References: <20170517070115.GL6320@example.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a114a6a9441eaf8054fb6330b" X-Trace: blaine.gmane.org 1495018865 2541 195.159.176.226 (17 May 2017 11:01:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 May 2017 11:01:05 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-11346-gllmg-musl=m.gmane.org@lists.openwall.com Wed May 17 13:00:58 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 1dAwhM-0000TS-TA for gllmg-musl@m.gmane.org; Wed, 17 May 2017 13:00:57 +0200 Original-Received: (qmail 26358 invoked by uid 550); 17 May 2017 11:00:59 -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 26337 invoked from network); 17 May 2017 11:00:58 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mzpqnxow-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=m2ikoonvAQQHLWyvIYrGgZwFU6ubBehaye/LyoqakQY=; b=zTIAvApppqPubtpeehogh9PGrYyDJ7HSGGHga9egHVXelC2tE8WU0KaVsR9QL4h48U LFzrl1I5FyhSElhKaUk+nmWF+AzAr19bk6X9ml914uAacHzGpQ9gfJZBFjiGz89qnwGB Aq/tNEP5F057OKI3p9I0ar1KpggMgbzaHfR6YRF6jdM2i392NQbzoIqTb9Mvp4r2CU+V Tie3fmKyXFWKPkcU9ixxli2NCX3Hw4GSMZxThrcx481LieQaRgI6/OaqRhFhxvtyYv0b qEYTHdsfbLr41lQJbnLSRPOYrnh6D2rvIvUQGxjlOnDIsvHOqDXv0/RhaIdyF8C1ZULb 5c2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=m2ikoonvAQQHLWyvIYrGgZwFU6ubBehaye/LyoqakQY=; b=dG1S1ItPezP/XAS/CmDvaN5Rqt/oAwxUEEHwi5ZDkQ+9p43XjwCzQ+yzO5xMydtnHD rFsdItl0RbMgqyVYjYxmZ/fvxtU54vKRwBwgq210vf9i2griORuLDzspVTwfmjuRJoUn ArPjyxxUxBLyA/YevnmsV59NyDx2LcuV20l0a5Zt+ObKnGZOkQXcUSzJdyA6CWAetj/r eMBGlb2mTZzysLp8f3EQ6DY5hmTa7pdboxP5xm+uiAt+wdr30xb/OmZat++yLYEQ+Jso 7LJeMuwpsNYZxJgvuzQ0s4BoBy+J3U1EYG7Uvftn2zHm0pKFfuwCPumLESBG00L6iGYY hgDw== X-Gm-Message-State: AODbwcC22gpYkqLfIJSSqT0+d457KB0EshZ9s6aTw+0eHIqRyJHW47uI jEzjc9OBs9SN0AXqqMIQA+BBfhAXvWGsXHU= X-Received: by 10.55.81.139 with SMTP id f133mr2512506qkb.125.1495018846128; Wed, 17 May 2017 04:00:46 -0700 (PDT) In-Reply-To: <20170517070115.GL6320@example.net> Xref: news.gmane.org gmane.linux.lib.musl.general:11331 Archived-At: --001a114a6a9441eaf8054fb6330b Content-Type: text/plain; charset="UTF-8" Is there any reason you want to avoid simply statically linking the program(s) so that it needs no libc or other shared objects at all? Or did I misunderstand what you're trying to do? On Wed, May 17, 2017 at 05:05 wrote: > On Tue, May 16, 2017 at 08:38:56PM -0400, John Regan wrote: > > Hi there - I was wondering if it's possible to somehow set argv[0] when > > calling the dynamic linker to load a program. > ... > > 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. > > Set argv[0] to whatever you need when you exec*() the dynamic loader, > which is straightforward with a binary wrapper (not with a shell). > > A binary wrapper also adds less overhead then going through a shell. > > There is imho hardly any incentive to put such functionalty into the > loader. I say this even though we are dependent here on such tricks, > to work around programs which insist on guessing things when not asked to. > > Regards, > Rune > > --001a114a6a9441eaf8054fb6330b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Is there any reason you want to avoid simply statically linking the pr= ogram(s) so that it needs no libc or other shared objects at all?

Or did I misunderstand what you're trying to do?
<= div>
On Wed, May 17, 2017 at = 05:05 <u-uy74@aetey.se> wrote:=
On Tue, May 16, 2017 at 08:38:56PM= -0400, John Regan wrote:
> Hi there - I was wondering if it's possible to somehow set argv[0]= when
> calling the dynamic linker to load a program.
=C2=A0...
> 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, et= c -
> as far as I can tell, there's no easy way to do this.

Set argv[0] to whatever you need when you exec*() the dynamic loader,
which is straightforward with a binary wrapper (not with a shell).

A binary wrapper also adds less overhead then going through a shell.

There is imho hardly any incentive to put such functionalty into the
loader. I say this even though we are dependent here on such tricks,
to work around programs which insist on guessing things when not asked to.<= br>
Regards,
Rune

--001a114a6a9441eaf8054fb6330b--