Use AT_SUN_EXECPATH instead of argv[0] for the executable name. This needs
kernel support, which is not there yet, thus $ORIGIN is broken at this time. This is ok, nothing uses it yet.
This commit is contained in:
parent
244d23f931
commit
40cfdb5e3a
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: expand.c,v 1.2 2007/05/18 21:46:39 christos Exp $ */
|
||||
/* $NetBSD: expand.c,v 1.3 2007/09/20 14:14:25 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 The NetBSD Foundation, Inc.
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: expand.c,v 1.2 2007/05/18 21:46:39 christos Exp $");
|
||||
__RCSID("$NetBSD: expand.c,v 1.3 2007/09/20 14:14:25 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <ctype.h>
|
||||
@ -75,7 +75,7 @@ static int mib[3][2] = {
|
||||
};
|
||||
|
||||
static size_t
|
||||
expand(char *buf, const char *av, int what, size_t bl)
|
||||
expand(char *buf, const char *execname, int what, size_t bl)
|
||||
{
|
||||
const char *p, *ep;
|
||||
char *bp = buf;
|
||||
@ -88,11 +88,11 @@ expand(char *buf, const char *av, int what, size_t bl)
|
||||
return 0;
|
||||
|
||||
case 2: /* ORIGIN */
|
||||
ep = strrchr(p = av, '/');
|
||||
if (ep == NULL) {
|
||||
p = ".";
|
||||
ep = p + 1;
|
||||
}
|
||||
xprintf("execname %p\n", execname);
|
||||
if (execname == NULL)
|
||||
xerr(1, "execname not specified in AUX vector");
|
||||
if ((ep = strrchr(p = execname, '/')) == NULL)
|
||||
xerr(1, "bad execname `%s' in AUX vector", execname);
|
||||
break;
|
||||
|
||||
case 3: /* OSNAME */
|
||||
@ -117,8 +117,8 @@ expand(char *buf, const char *av, int what, size_t bl)
|
||||
|
||||
|
||||
size_t
|
||||
_rtld_expand_path(char *buf, size_t bufsize, const char *av, const char *bp,
|
||||
const char *ep)
|
||||
_rtld_expand_path(char *buf, size_t bufsize, const char *execname,
|
||||
const char *bp, const char *ep)
|
||||
{
|
||||
size_t i, ds = bufsize;
|
||||
char *dp = buf;
|
||||
@ -142,7 +142,7 @@ _rtld_expand_path(char *buf, size_t bufsize, const char *av, const char *bp,
|
||||
continue;
|
||||
|
||||
if (strncmp(bltn[i].name, p, s) == 0) {
|
||||
size_t ls = expand(dp, av, i, ds);
|
||||
size_t ls = expand(dp, execname, i, ds);
|
||||
if (ls >= ds)
|
||||
return bufsize;
|
||||
ds -= ls;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: headers.c,v 1.21 2007/05/18 21:44:08 christos Exp $ */
|
||||
/* $NetBSD: headers.c,v 1.22 2007/09/20 14:14:25 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 John D. Polstra.
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: headers.c,v 1.21 2007/05/18 21:44:08 christos Exp $");
|
||||
__RCSID("$NetBSD: headers.c,v 1.22 2007/09/20 14:14:25 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
@ -63,7 +63,7 @@ __RCSID("$NetBSD: headers.c,v 1.21 2007/05/18 21:44:08 christos Exp $");
|
||||
* information in its Obj_Entry structure.
|
||||
*/
|
||||
void
|
||||
_rtld_digest_dynamic(const char *argv0, Obj_Entry *obj)
|
||||
_rtld_digest_dynamic(const char *execname, Obj_Entry *obj)
|
||||
{
|
||||
Elf_Dyn *dynp;
|
||||
Needed_Entry **needed_tail = &obj->needed;
|
||||
@ -269,7 +269,7 @@ _rtld_digest_dynamic(const char *argv0, Obj_Entry *obj)
|
||||
#endif
|
||||
|
||||
if (dyn_rpath != NULL) {
|
||||
_rtld_add_paths(argv0, &obj->rpaths, obj->strtab +
|
||||
_rtld_add_paths(execname, &obj->rpaths, obj->strtab +
|
||||
dyn_rpath->d_un.d_val);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: paths.c,v 1.34 2007/05/18 21:44:08 christos Exp $ */
|
||||
/* $NetBSD: paths.c,v 1.35 2007/09/20 14:14:25 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 Matt Thomas <matt@3am-software.com>
|
||||
@ -30,7 +30,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: paths.c,v 1.34 2007/05/18 21:44:08 christos Exp $");
|
||||
__RCSID("$NetBSD: paths.c,v 1.35 2007/09/20 14:14:25 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
@ -171,13 +171,14 @@ _rtld_find_path(Search_Path *path, const char *pathstr, size_t pathlen)
|
||||
|
||||
static Search_Path **
|
||||
_rtld_append_path(Search_Path **head_p, Search_Path **path_p,
|
||||
const char *argv0, const char *bp, const char *ep)
|
||||
const char *execname, const char *bp, const char *ep)
|
||||
{
|
||||
Search_Path *path;
|
||||
char epath[MAXPATHLEN];
|
||||
size_t len;
|
||||
|
||||
if ((len = _rtld_expand_path(epath, sizeof(epath), argv0, bp, ep)) == 0)
|
||||
len = _rtld_expand_path(epath, sizeof(epath), execname, bp, ep);
|
||||
if (len == 0)
|
||||
return path_p;
|
||||
|
||||
if (_rtld_find_path(*head_p, bp, ep - bp) != NULL)
|
||||
@ -195,7 +196,7 @@ _rtld_append_path(Search_Path **head_p, Search_Path **path_p,
|
||||
}
|
||||
|
||||
void
|
||||
_rtld_add_paths(const char *argv0, Search_Path **path_p, const char *pathstr)
|
||||
_rtld_add_paths(const char *execname, Search_Path **path_p, const char *pathstr)
|
||||
{
|
||||
Search_Path **head_p = path_p;
|
||||
|
||||
@ -217,7 +218,7 @@ _rtld_add_paths(const char *argv0, Search_Path **path_p, const char *pathstr)
|
||||
if (ep == NULL)
|
||||
ep = &pathstr[strlen(pathstr)];
|
||||
|
||||
path_p = _rtld_append_path(head_p, path_p, argv0, bp, ep);
|
||||
path_p = _rtld_append_path(head_p, path_p, execname, bp, ep);
|
||||
|
||||
if (ep[0] == '\0')
|
||||
break;
|
||||
@ -332,7 +333,7 @@ cleanup:
|
||||
}
|
||||
|
||||
void
|
||||
_rtld_process_hints(const char *argv0, Search_Path **path_p,
|
||||
_rtld_process_hints(const char *execname, Search_Path **path_p,
|
||||
Library_Xform **lib_p, const char *fname)
|
||||
{
|
||||
int fd;
|
||||
@ -379,7 +380,7 @@ _rtld_process_hints(const char *argv0, Search_Path **path_p,
|
||||
*/
|
||||
while (b[-1] == ' ' || b[-1] == '\t')
|
||||
b--;
|
||||
path_p = _rtld_append_path(head_p, path_p, argv0,
|
||||
path_p = _rtld_append_path(head_p, path_p, execname,
|
||||
ptr, b);
|
||||
} else
|
||||
_rtld_process_mapping(lib_p, ptr, b);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: rtld.c,v 1.113 2007/05/18 21:44:08 christos Exp $ */
|
||||
/* $NetBSD: rtld.c,v 1.114 2007/09/20 14:14:26 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 John D. Polstra.
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: rtld.c,v 1.113 2007/05/18 21:44:08 christos Exp $");
|
||||
__RCSID("$NetBSD: rtld.c,v 1.114 2007/09/20 14:14:26 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
@ -148,7 +148,7 @@ _rtld_call_init_functions(Obj_Entry *first)
|
||||
* define __HAVE_FUNCTION_DESCRIPTORS
|
||||
*/
|
||||
static void
|
||||
_rtld_init(caddr_t mapbase, caddr_t relocbase, const char *argv0)
|
||||
_rtld_init(caddr_t mapbase, caddr_t relocbase, const char *execname)
|
||||
{
|
||||
|
||||
/* Conjure up an Obj_Entry structure for the dynamic linker. */
|
||||
@ -174,7 +174,8 @@ _rtld_init(caddr_t mapbase, caddr_t relocbase, const char *argv0)
|
||||
assert(!_rtld_objself.textrel);
|
||||
#endif
|
||||
|
||||
_rtld_add_paths(argv0, &_rtld_default_paths, RTLD_DEFAULT_LIBRARY_PATH);
|
||||
_rtld_add_paths(execname, &_rtld_default_paths,
|
||||
RTLD_DEFAULT_LIBRARY_PATH);
|
||||
|
||||
/*
|
||||
* Set up the _rtld_objlist pointer, so that rtld symbols can be found.
|
||||
@ -230,6 +231,7 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
|
||||
bool bind_now = 0;
|
||||
const char *ld_bind_now;
|
||||
const char **argv;
|
||||
const char *execname;
|
||||
long argc;
|
||||
const char **real___progname;
|
||||
const Obj_Entry **real___mainprog_obj;
|
||||
@ -273,6 +275,8 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
|
||||
pAUX_euid = pAUX_ruid = pAUX_egid = pAUX_rgid = NULL;
|
||||
pAUX_pagesz = NULL;
|
||||
|
||||
execname = NULL;
|
||||
|
||||
/* Digest the auxiliary vector. */
|
||||
for (auxp = aux; auxp->a_type != AT_NULL; ++auxp) {
|
||||
switch (auxp->a_type) {
|
||||
@ -307,6 +311,11 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
|
||||
case AT_RGID:
|
||||
pAUX_rgid = auxp;
|
||||
break;
|
||||
#endif
|
||||
#ifdef AT_SUN_EXECNAME
|
||||
case AT_SUN_EXECNAME:
|
||||
execname = (const char *)(const void *)auxp->a_v;
|
||||
break;
|
||||
#endif
|
||||
case AT_PAGESZ:
|
||||
pAUX_pagesz = auxp;
|
||||
@ -321,7 +330,7 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
|
||||
}
|
||||
assert(pAUX_pagesz != NULL);
|
||||
_rtld_pagesz = (int)pAUX_pagesz->a_v;
|
||||
_rtld_init((caddr_t)pAUX_base->a_v, (caddr_t)relocbase, argv[0]);
|
||||
_rtld_init((caddr_t)pAUX_base->a_v, (caddr_t)relocbase, execname);
|
||||
|
||||
__progname = _rtld_objself.path;
|
||||
environ = env;
|
||||
@ -343,12 +352,13 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
|
||||
if (ld_debug != NULL && *ld_debug != '\0')
|
||||
debug = 1;
|
||||
#endif
|
||||
_rtld_add_paths(argv[0], &_rtld_paths, getenv("LD_LIBRARY_PATH"));
|
||||
_rtld_add_paths(execname, &_rtld_paths,
|
||||
getenv("LD_LIBRARY_PATH"));
|
||||
} else {
|
||||
unsetenv("LD_DEBUG");
|
||||
unsetenv("LD_LIBRARY_PATH");
|
||||
}
|
||||
_rtld_process_hints(argv[0], &_rtld_paths, &_rtld_xforms,
|
||||
_rtld_process_hints(execname, &_rtld_paths, &_rtld_xforms,
|
||||
_PATH_LD_HINTS);
|
||||
dbg(("dynamic linker is initialized, mapbase=%p, relocbase=%p",
|
||||
_rtld_objself.mapbase, _rtld_objself.relocbase));
|
||||
@ -398,7 +408,7 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
|
||||
_rtld_objself.path = xstrdup(_rtld_objmain->interp);
|
||||
dbg(("actual dynamic linker is %s", _rtld_objself.path));
|
||||
|
||||
_rtld_digest_dynamic(argv[0], _rtld_objmain);
|
||||
_rtld_digest_dynamic(execname, _rtld_objmain);
|
||||
|
||||
/* Link the main program into the list of objects. */
|
||||
*_rtld_objtail = _rtld_objmain;
|
||||
|
Loading…
Reference in New Issue
Block a user