From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9067 Path: news.gmane.org!not-for-mail From: N Jain Newsgroups: gmane.linux.lib.musl.general Subject: Re: dynamic linker command line invocation Date: Thu, 7 Jan 2016 18:29:48 -0500 Message-ID: References: <20160104205920.GW238@brightrain.aerifal.cx> <20160105173200.GZ238@brightrain.aerifal.cx> <20160105182326.GB238@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7ba9821cb9084f0528c6d843 X-Trace: ger.gmane.org 1452209405 31860 80.91.229.3 (7 Jan 2016 23:30:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 7 Jan 2016 23:30:05 +0000 (UTC) To: musl@lists.openwall.com, Rich Felker Original-X-From: musl-return-9080-gllmg-musl=m.gmane.org@lists.openwall.com Fri Jan 08 00:30:04 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1aHK0J-0005v8-Di for gllmg-musl@m.gmane.org; Fri, 08 Jan 2016 00:30:03 +0100 Original-Received: (qmail 23810 invoked by uid 550); 7 Jan 2016 23:30:01 -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 23787 invoked from network); 7 Jan 2016 23:30:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=JuHHDixQQS1RGOK4YhMdURuNcqCmi/VXDQVq/4FH9S0=; b=akjOvA4Jc9GEKhhIjFX+t7WgHOdcggeFEpPJp2F/stLxTaeLTsXCXuMSEgJs3xwdyO VyP9vn4YhcNkkvKDk1TdvsuTrW256WGqQmurXdgbqWwC6D60Lsf9JUsQGIUzZY7ynD2+ fsiLF7Y+6TJHHeyHIUOgJuRUVMGNm+fl65wC3imz9fKEZLpyfVefTJ0m6K/oI8j9waNM qeNxHpX+wAW0MfOGSo6Yr5TVkyo1NQTywBCsGa9MveGeDkG67mTdWezzRc5Yu7ZhMJRY GqcbQkEvPd+0PzgZDS2qTckV8I7LnoQEO0bLuiDBMECQxX1+3bBCWwj46TnbLYdMnpNx yWxA== X-Received: by 10.60.174.232 with SMTP id bv8mr73169163oec.46.1452209388191; Thu, 07 Jan 2016 15:29:48 -0800 (PST) In-Reply-To: <20160105182326.GB238@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:9067 Archived-At: --047d7ba9821cb9084f0528c6d843 Content-Type: text/plain; charset=UTF-8 Hi Rich, Thanks I am able to get my dynamic linker loaded into memory but facing issue during application load at __dls3 function. I am getting following print from MUSL - "musl libc Version 1.1.10 Dynamic Program Loader Usage: hello.elf [options] [--] pathname--2--" Not sure why my application is not getting loaded in below code __dls3 function ? char *ldname = argv[0]; size_t l = strlen(ldname); *ldname is the application elf which I want to load "hello.elf"* if (l >= 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode = 1; *I am not sure why "ldd" string is compared here ?* argv++; *I don't pass any options ? Do I need to pass some option value ?* while (argv[0] && argv[0][0]=='-' && argv[0][1]=='-') { char *opt = argv[0]+2; *argv++ = (void *)-1; if (!*opt) { break; } else if (!memcmp(opt, "list", 5)) { ldd_mode = 1; } else if (!memcmp(opt, "library-path", 12)) { if (opt[12]=='=') env_path = opt+13; else if (opt[12]) *argv = 0; else if (*argv) env_path = *argv++; } else if (!memcmp(opt, "preload", 7)) { if (opt[7]=='=') env_preload = opt+8; else if (opt[7]) *argv = 0; else if (*argv) env_preload = *argv++; } else { argv[0] = 0; } } *I see the argv[0] is set to 0 so I am not able to see my application loaded ?* Thanks, NJ On Tue, Jan 5, 2016 at 1:23 PM, Rich Felker wrote: > On Tue, Jan 05, 2016 at 01:00:37PM -0500, N Jain wrote: > > > You never answered whether > > > you were setting up the aux vector right, but if not, that's > > > definitely going to cause problems. > > > > I am not setting any aux vectors. I only pass argv = "app.elf" and argc > = 1 > > to dynamic linker. > > What and where I need to set "aux" vectors ? Any pointers will help.. > > The ELF entry point ABI is that the initial stack pointer points to an > array of word-sized cells containing: > > argc argv[0] argv[1] ... argv[argc-1] argv[argc](=0) anviron[0] > environ[1] ... 0 auxv[0].key auxv[0].val auxv[1].key auxv[1].val ... 0 > > The auxv items are key,val pairs where the key is one of the AT_* > constants from elf.h and the value is either an integer or pointer > (depending on which key it's for). At the very least you should be > passing: > > AT_PHDR - points to the start of elf program headers > AT_PHENT - size of each program header > AT_PHNUM - number of program headers > > If you load both the main program and "interpreter" (dynamic linker) > from the kernel, then these values should be for the main program's > headers, and in addition you need to pass: > > AT_BASE - load address of the "interpreter" (dynamic linker) > AT_ENTRY - entry point address of the main program, from its header > > On the other hand, if you only load the dynamic linker (treating it as > the main program), then the program header auxv entries should hold > the right values for the dynamic linker. > > Rich > --047d7ba9821cb9084f0528c6d843 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Rich,

= Thanks I am able to get my dynamic linker loaded into memory but facing iss= ue during application load at=C2=A0__dls3 function.
I am getting following print from MUSL -

"musl libc
Version 1.1.10
Dynamic Program Loader
Usage: hello.elf [options] [--] pathname--2--"

Not sure why my application is no= t getting loaded in below code __dls3 function ?

= char *ldname =3D argv[0];
size_t l =3D strlen(ldname);

= ldname is the application elf which I want to load "hello.elf"=
if (l &g= t;=3D 3 && !strcmp(ldname+l-3, "ldd")) ldd_mode =3D 1;
I am not sure why "= ldd" string is compared here ?
argv++;
I don't pass any option= s ? Do I need to pass some option value ?
while (argv[0] && argv[0][0]=3D=3D= '-' && argv[0][1]=3D=3D'-') {
char *opt =3D argv[0]+2;
*argv++ =3D (void *)= -1;
if (!*op= t) {
break;=
} else if (= !memcmp(opt, "list", 5)) {
ldd_mode =3D 1;
} else if (!memcmp(opt, "library-path&q= uot;, 12)) {
if (opt[12]=3D=3D'=3D') env_path =3D opt+13;
else if (opt[12]) *argv =3D 0;<= /div>
else if (*a= rgv) env_path =3D *argv++;
} else if (!memcmp(opt, "preload", 7)) {
if (opt[7]=3D=3D'= ;=3D') env_preload =3D opt+8;
else if (opt[7]) *argv =3D 0;
else if (*argv) env_preload =3D = *argv++;
} e= lse {
argv[= 0] =3D 0;
}<= /div>
}
<= b>I see the argv[0] is set to 0 so I am not able to see my application load= ed ?

Thanks,
NJ
<= /div>

On Tue= , Jan 5, 2016 at 1:23 PM, Rich Felker <dalias@libc.org> wrote:=
On Tue, Jan 05, 2016 at= 01:00:37PM -0500, N Jain wrote:
> > You never answered whether
> > you were setting up the aux vector right, but if not, that's<= br> > > definitely going to cause problems.
>
> I am not setting any aux vectors. I only pass argv =3D "app.elf&q= uot; and argc =3D 1
> to dynamic linker.
> What and where I need to set "aux" vectors ? Any pointers wi= ll help..

The ELF entry point ABI is that the initial stack pointer points to = an
array of word-sized cells containing:

argc argv[0] argv[1] ... argv[argc-1] argv[argc](=3D0) anviron[0]
environ[1] ... 0 auxv[0].key auxv[0].val auxv[1].key auxv[1].val ... 0

The auxv items are key,val pairs where the key is one of the AT_*
constants from elf.h and the value is either an integer or pointer
(depending on which key it's for). At the very least you should be
passing:

AT_PHDR - points to the start of elf program headers
AT_PHENT - size of each program header
AT_PHNUM - number of program headers

If you load both the main program and "interpreter" (dynamic link= er)
from the kernel, then these values should be for the main program's
headers, and in addition you need to pass:

AT_BASE - load address of the "interpreter" (dynamic linker)
AT_ENTRY - entry point address of the main program, from its header

On the other hand, if you only load the dynamic linker (treating it as
the main program), then the program header auxv entries should hold
the right values for the dynamic linker.

Rich

--047d7ba9821cb9084f0528c6d843--