summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-03-18 10:53:56 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2011-12-23 15:49:01 +0100
commitb1aea0b3872b246cf17f04d5442a94e39e45203e (patch)
tree36d495755fc8609bf338cb4d1a99955793ab6398
parent6864dfeef979985f9f173b842034183476b95583 (diff)
downloaduClibc-alpine-b1aea0b3872b246cf17f04d5442a94e39e45203e.tar.bz2
uClibc-alpine-b1aea0b3872b246cf17f04d5442a94e39e45203e.tar.xz
ldso: limited support for $ORIGIN in rpath
Handle it if it's in the beginning of the rpath entry as it should be. Posted to uclibc ml: http://old.nabble.com/-PATCH-1-3--ldso%3A-limited-support-for-$ORIGIN-in-rpath-td31181219.html Signed-off-by: Timo Teräs <timo.teras@iki.fi> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
-rw-r--r--ldso/ldso/dl-elf.c80
-rw-r--r--ldso/ldso/ldso.c18
2 files changed, 59 insertions, 39 deletions
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
index 09b3aaf01..558176a55 100644
--- a/ldso/ldso/dl-elf.c
+++ b/ldso/ldso/dl-elf.c
@@ -133,53 +133,60 @@ _dl_protect_relro (struct elf_resolve *l)
* in uClibc/ldso/util/ldd.c */
static struct elf_resolve *
search_for_named_library(const char *name, int secure, const char *path_list,
- struct dyn_elf **rpnt)
+ struct dyn_elf **rpnt, const char *origin)
{
- char *path, *path_n, *mylibname;
+ char *mylibname;
+ const char *p, *pn;
struct elf_resolve *tpnt;
- int done;
+ int plen;
if (path_list==NULL)
return NULL;
- /* We need a writable copy of this string, but we don't
- * need this allocated permanently since we don't want
- * to leak memory, so use alloca to put path on the stack */
- done = _dl_strlen(path_list);
- path = alloca(done + 1);
-
/* another bit of local storage */
mylibname = alloca(2050);
- _dl_memcpy(path, path_list, done+1);
-
/* Unlike ldd.c, don't bother to eliminate double //s */
/* Replace colons with zeros in path_list */
/* : at the beginning or end of path maps to CWD */
/* :: anywhere maps CWD */
/* "" maps to CWD */
- done = 0;
- path_n = path;
- do {
- if (*path == 0) {
- *path = ':';
- done = 1;
- }
- if (*path == ':') {
- *path = 0;
- if (*path_n)
- _dl_strcpy(mylibname, path_n);
- else
- _dl_strcpy(mylibname, "."); /* Assume current dir if empty path */
- _dl_strcat(mylibname, "/");
- _dl_strcat(mylibname, name);
- if ((tpnt = _dl_load_elf_shared_library(secure, rpnt, mylibname)) != NULL)
- return tpnt;
- path_n = path+1;
+ for (p = path_list; p != NULL; p = pn) {
+ pn = _dl_strchr(p + 1, ':');
+ if (pn != NULL) {
+ plen = pn - p;
+ pn++;
+ } else
+ plen = _dl_strlen(p);
+
+ if (plen >= 7 && _dl_memcmp(p, "$ORIGIN", 7) == 0) {
+ int olen;
+ if (secure && plen != 7)
+ continue;
+ if (origin == NULL)
+ continue;
+ for (olen = _dl_strlen(origin) - 1; olen >= 0 && origin[olen] != '/'; olen--)
+ ;
+ if (olen <= 0)
+ continue;
+ _dl_memcpy(&mylibname[0], origin, olen);
+ _dl_memcpy(&mylibname[olen], p + 7, plen - 7);
+ mylibname[olen + plen - 7] = 0;
+ } else if (plen != 0) {
+ _dl_memcpy(mylibname, p, plen);
+ mylibname[plen] = 0;
+ } else {
+ _dl_strcpy(mylibname, ".");
}
- path++;
- } while (!done);
+ _dl_strcat(mylibname, "/");
+ _dl_strcat(mylibname, name);
+
+ tpnt = _dl_load_elf_shared_library(secure, rpnt, mylibname);
+ if (tpnt != NULL)
+ return tpnt;
+ }
+
return NULL;
}
@@ -231,7 +238,8 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
if (pnt) {
pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
_dl_if_debug_dprint("\tsearching RPATH='%s'\n", pnt);
- if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt)) != NULL)
+ if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt,
+ tpnt->libname)) != NULL)
return tpnt1;
}
#endif
@@ -239,7 +247,7 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
/* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
if (_dl_library_path) {
_dl_if_debug_dprint("\tsearching LD_LIBRARY_PATH='%s'\n", _dl_library_path);
- if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path, rpnt)) != NULL)
+ if ((tpnt1 = search_for_named_library(libname, secure, _dl_library_path, rpnt, NULL)) != NULL)
{
return tpnt1;
}
@@ -253,7 +261,7 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
if (pnt) {
pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
_dl_if_debug_dprint("\tsearching RUNPATH='%s'\n", pnt);
- if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt)) != NULL)
+ if ((tpnt1 = search_for_named_library(libname, secure, pnt, rpnt, NULL)) != NULL)
return tpnt1;
}
#endif
@@ -287,7 +295,7 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
/* Look for libraries wherever the shared library loader
* was installed */
_dl_if_debug_dprint("\tsearching ldso dir='%s'\n", _dl_ldsopath);
- tpnt1 = search_for_named_library(libname, secure, _dl_ldsopath, rpnt);
+ tpnt1 = search_for_named_library(libname, secure, _dl_ldsopath, rpnt, NULL);
if (tpnt1 != NULL)
return tpnt1;
@@ -300,7 +308,7 @@ struct elf_resolve *_dl_load_shared_library(int secure, struct dyn_elf **rpnt,
#ifndef __LDSO_CACHE_SUPPORT__
":" UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib"
#endif
- , rpnt);
+ , rpnt, NULL);
if (tpnt1 != NULL)
return tpnt1;
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index 3585cb7e3..df16b4fb7 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -268,6 +268,20 @@ static void __attribute__ ((destructor)) __attribute_used__ _dl_fini(void)
}
}
+static void _dl_setup_progname(const char *argv0)
+{
+ char image[PATH_MAX];
+ ssize_t s;
+
+ s = _dl_readlink("/proc/self/exe", image, sizeof(image));
+ if (s > 0 && image[0] == '/') {
+ image[s] = 0;
+ _dl_progname = _dl_strdup(image);
+ } else if (argv0) {
+ _dl_progname = argv0;
+ }
+}
+
void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp,
char **argv
@@ -317,9 +331,7 @@ void _dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
* been fixed up by now. Still no function calls outside of this
* library, since the dynamic resolver is not yet ready.
*/
- if (argv[0]) {
- _dl_progname = argv[0];
- }
+ _dl_setup_progname(argv[0]);
if (_start == (void *) auxvt[AT_ENTRY].a_un.a_val) {
_dl_dprintf(_dl_debug_file, "Standalone execution is not supported yet\n");