summaryrefslogtreecommitdiff
path: root/ldso
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-07-17 00:52:04 +0000
committerEric Andersen <andersen@codepoet.org>2001-07-17 00:52:04 +0000
commitdf6add6279d3ad5b92b143f8781bec329f8c659c (patch)
tree610ff10f4967583f69d30d4d8f5a893951569621 /ldso
parent3bb075634b78b854510807448b8939d98830a4d7 (diff)
Some cleanups needed for things to compile and work as expected
with the new build system... -Erik
Diffstat (limited to 'ldso')
-rw-r--r--ldso/config.h10
-rw-r--r--ldso/ldso/dl-elf.c49
-rw-r--r--ldso/ldso/readelflib1.c49
-rw-r--r--ldso/util/Makefile5
-rw-r--r--ldso/util/ldconfig.c4
-rw-r--r--ldso/util/ldd.c120
6 files changed, 150 insertions, 87 deletions
diff --git a/ldso/config.h b/ldso/config.h
index 3dbf0cdfa..256bab271 100644
--- a/ldso/config.h
+++ b/ldso/config.h
@@ -5,11 +5,11 @@
# define LDSO_PRELOAD "../util/ld.so.preload"
# define LDDSTUB "../util/lddstub"
#else
-# define LDSO_IMAGE UCLIBC_ROOT_DIR "/lib/ld.so"
-# define LDSO_CONF UCLIBC_ROOT_DIR "/etc/ld.so.conf"
-# define LDSO_CACHE UCLIBC_ROOT_DIR "/etc/ld.so.cache"
-# define LDSO_PRELOAD UCLIBC_ROOT_DIR "/etc/ld.so.preload"
-# define LDDSTUB UCLIBC_ROOT_DIR "/usr/lib/lddstub"
+# define LDSO_IMAGE UCLIBC_PREFIX "/lib/ld.so"
+# define LDSO_CONF UCLIBC_PREFIX "/etc/ld.so.conf"
+# define LDSO_CACHE UCLIBC_PREFIX "/etc/ld.so.cache"
+# define LDSO_PRELOAD UCLIBC_PREFIX "/etc/ld.so.preload"
+# define LDDSTUB UCLIBC_PREFIX "/usr/lib/lddstub"
#endif
#define LDD_ARGV0 "__LDD_ARGV0"
diff --git a/ldso/ldso/dl-elf.c b/ldso/ldso/dl-elf.c
index 2276d4a9f..fa84dde52 100644
--- a/ldso/ldso/dl-elf.c
+++ b/ldso/ldso/dl-elf.c
@@ -248,8 +248,8 @@ struct elf_resolve *_dl_load_shared_library(int secure,
}
#endif
- /* Check in <install-dir>/usr/lib */
- pnt1 = UCLIBC_ROOT_DIR "/usr/lib/";
+ /* Check in <prefix>/usr/lib */
+ pnt1 = UCLIBC_PREFIX "/usr/lib/";
pnt = mylibname;
while (*pnt1)
*pnt++ = *pnt1++;
@@ -261,8 +261,8 @@ struct elf_resolve *_dl_load_shared_library(int secure,
if (tpnt1)
return tpnt1;
- /* Check in <install-dir>/lib */
- pnt1 = UCLIBC_ROOT_DIR "/lib/";
+ /* Check in <prefix>/lib */
+ pnt1 = UCLIBC_PREFIX "/lib/";
pnt = mylibname;
while (*pnt1)
*pnt++ = *pnt1++;
@@ -274,7 +274,20 @@ struct elf_resolve *_dl_load_shared_library(int secure,
if (tpnt1)
return tpnt1;
- /* Bummer. Nothing so far. Check in <builddir>/lib */
+ /* Bummer. Nothing so far. Try <devel-dir>/lib */
+ pnt1 = UCLIBC_DEVEL_PREFIX "/lib/";
+ pnt = mylibname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ pnt1 = libname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ *pnt++ = 0;
+ tpnt1 = _dl_load_elf_shared_library(secure, mylibname, 0);
+ if (tpnt1)
+ return tpnt1;
+
+ /* Still nothing... Ok, try <builddir>/lib */
pnt1 = UCLIBC_BUILD_DIR "/lib/";
pnt = mylibname;
while (*pnt1)
@@ -287,6 +300,32 @@ struct elf_resolve *_dl_load_shared_library(int secure,
if (tpnt1)
return tpnt1;
+ /* Wow. Still nothing. Try /usr/lib */
+ pnt1 = "/usr/lib/";
+ pnt = mylibname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ pnt1 = libname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ *pnt++ = 0;
+ tpnt1 = _dl_load_elf_shared_library(secure, mylibname, 0);
+ if (tpnt1)
+ return tpnt1;
+
+ /* This is our last hope before giving up -- Try /lib */
+ pnt1 = "/lib/";
+ pnt = mylibname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ pnt1 = libname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ *pnt++ = 0;
+ tpnt1 = _dl_load_elf_shared_library(secure, mylibname, 0);
+ if (tpnt1)
+ return tpnt1;
+
goof:
/* Well, we shot our wad on that one. All we can do now is punt */
if (_dl_internal_error_number)
diff --git a/ldso/ldso/readelflib1.c b/ldso/ldso/readelflib1.c
index 2276d4a9f..fa84dde52 100644
--- a/ldso/ldso/readelflib1.c
+++ b/ldso/ldso/readelflib1.c
@@ -248,8 +248,8 @@ struct elf_resolve *_dl_load_shared_library(int secure,
}
#endif
- /* Check in <install-dir>/usr/lib */
- pnt1 = UCLIBC_ROOT_DIR "/usr/lib/";
+ /* Check in <prefix>/usr/lib */
+ pnt1 = UCLIBC_PREFIX "/usr/lib/";
pnt = mylibname;
while (*pnt1)
*pnt++ = *pnt1++;
@@ -261,8 +261,8 @@ struct elf_resolve *_dl_load_shared_library(int secure,
if (tpnt1)
return tpnt1;
- /* Check in <install-dir>/lib */
- pnt1 = UCLIBC_ROOT_DIR "/lib/";
+ /* Check in <prefix>/lib */
+ pnt1 = UCLIBC_PREFIX "/lib/";
pnt = mylibname;
while (*pnt1)
*pnt++ = *pnt1++;
@@ -274,7 +274,20 @@ struct elf_resolve *_dl_load_shared_library(int secure,
if (tpnt1)
return tpnt1;
- /* Bummer. Nothing so far. Check in <builddir>/lib */
+ /* Bummer. Nothing so far. Try <devel-dir>/lib */
+ pnt1 = UCLIBC_DEVEL_PREFIX "/lib/";
+ pnt = mylibname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ pnt1 = libname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ *pnt++ = 0;
+ tpnt1 = _dl_load_elf_shared_library(secure, mylibname, 0);
+ if (tpnt1)
+ return tpnt1;
+
+ /* Still nothing... Ok, try <builddir>/lib */
pnt1 = UCLIBC_BUILD_DIR "/lib/";
pnt = mylibname;
while (*pnt1)
@@ -287,6 +300,32 @@ struct elf_resolve *_dl_load_shared_library(int secure,
if (tpnt1)
return tpnt1;
+ /* Wow. Still nothing. Try /usr/lib */
+ pnt1 = "/usr/lib/";
+ pnt = mylibname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ pnt1 = libname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ *pnt++ = 0;
+ tpnt1 = _dl_load_elf_shared_library(secure, mylibname, 0);
+ if (tpnt1)
+ return tpnt1;
+
+ /* This is our last hope before giving up -- Try /lib */
+ pnt1 = "/lib/";
+ pnt = mylibname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ pnt1 = libname;
+ while (*pnt1)
+ *pnt++ = *pnt1++;
+ *pnt++ = 0;
+ tpnt1 = _dl_load_elf_shared_library(secure, mylibname, 0);
+ if (tpnt1)
+ return tpnt1;
+
goof:
/* Well, we shot our wad on that one. All we can do now is punt */
if (_dl_internal_error_number)
diff --git a/ldso/util/Makefile b/ldso/util/Makefile
index f1485d50e..a5eb9ad6c 100644
--- a/ldso/util/Makefile
+++ b/ldso/util/Makefile
@@ -8,7 +8,7 @@ readsoname.o: readsoname.c readsoname2.c
$(STRIPTOOL) -x -R .note -R .comment $*.o
ldconfig.o: ldconfig.c
- $(TARGET_CC) $(TARGET_CFLAGS) -DUCLIBC_ROOT_DIR=\"$(DEVEL_PREFIX)\" \
+ $(TARGET_CC) $(TARGET_CFLAGS) -DUCLIBC_PREFIX=\"$(PREFIX)\" \
-c $< -o $@
$(STRIPTOOL) -x -R .note -R .comment $*.o
@@ -21,7 +21,8 @@ ldconfig: ldconfig.o readsoname.o
$(STRIPTOOL) -x -R .note -R .comment $@
ldd: ldd.c
- $(TARGET_CC) $(TARGET_CFLAGS) -DUCLIBC_ROOT_DIR=\"$(DEVEL_PREFIX)\" \
+ $(TARGET_CC) $(TARGET_CFLAGS) -DUCLIBC_PREFIX=\"$(PREFIX)\" \
+ -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \
-DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR); pwd)\" \
-static ldd.c -o $@
$(STRIPTOOL) -x -R .note -R .comment $@
diff --git a/ldso/util/ldconfig.c b/ldso/util/ldconfig.c
index 8ea344043..054b82a93 100644
--- a/ldso/util/ldconfig.c
+++ b/ldso/util/ldconfig.c
@@ -683,8 +683,8 @@ int main(int argc, char **argv)
free(extpath);
}
- scan_dir(UCLIBC_ROOT_DIR "/usr/lib");
- scan_dir(UCLIBC_ROOT_DIR "/lib");
+ scan_dir(UCLIBC_PREFIX "/usr/lib");
+ scan_dir(UCLIBC_PREFIX "/lib");
}
if (!nocache)
diff --git a/ldso/util/ldd.c b/ldso/util/ldd.c
index 0224b0c29..eb530f4bb 100644
--- a/ldso/util/ldd.c
+++ b/ldso/util/ldd.c
@@ -100,76 +100,42 @@ int check_elf_header(Elf32_Ehdr const *const ehdr)
return 0;
}
-char * last_char_is(const char *s, int c)
+/* This function must exactly match that in uClibc/ldso/util/ldd.c */
+static void search_for_named_library(char *name, char *result, const char *path_list)
{
- char *sret;
- if (!s)
- return NULL;
- sret = (char *)s+strlen(s)-1;
- if (sret>=s && *sret == c) {
- return sret;
- } else {
- return NULL;
- }
-}
-
-extern char *concat_path_file(const char *path, const char *filename)
-{
- char *outbuf;
- char *lc;
-
- if (!path)
- path="";
- lc = last_char_is(path, '/');
- if (filename[0] == '/')
- filename++;
- outbuf = malloc(strlen(path)+strlen(filename)+1+(lc==NULL));
- if (!outbuf) {
- fprintf(stderr, "out of memory\n");
- exit(EXIT_FAILURE);
- }
- sprintf(outbuf, "%s%s%s", path, (lc==NULL)? "/" : "", filename);
-
- return outbuf;
-}
-
-char *do_which(char *name, char *path_list)
-{
- char *path_n;
- char *path_tmp;
+ int i, count = 0;
+ char *path, *path_n;
struct stat filestat;
- int i, count=1;
-
- if (!path_list) {
- fprintf(stderr, "yipe!\n");
- exit(EXIT_FAILURE);
- }
/* We need a writable copy of this string */
- path_tmp = strdup(path_list);
- if (!path_tmp) {
- fprintf(stderr, "yipe!\n");
+ path = strdup(path_list);
+ if (!path) {
+ fprintf(stderr, "Out of memory!\n");
exit(EXIT_FAILURE);
}
/* Replace colons with zeros in path_parsed and count them */
- for(i=strlen(path_tmp); i > 0; i--)
- if (path_tmp[i]==':') {
- path_tmp[i]=0;
+ for(i=strlen(path); i > 0; i--) {
+ if (path[i]==':') {
+ path[i]=0;
count++;
}
+ }
- path_n = path_tmp;
+ path_n = path;
+ *result = '\0';
for (i = 0; i < count; i++) {
- char *buf;
- buf = concat_path_file(path_n, name);
- if (stat (buf, &filestat) == 0 && filestat.st_mode & S_IRUSR) {
- return(buf);
+ strcat(result, path_n);
+ strcat(result, "/");
+ strcat(result, name);
+ if (stat (result, &filestat) == 0 && filestat.st_mode & S_IRUSR) {
+ free(path);
+ return;
}
- free(buf);
path_n += (strlen(path_n) + 1);
}
- return NULL;
+ free(path);
+ *result = '\0';
}
void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int is_suid, struct library *lib)
@@ -177,6 +143,8 @@ void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int
char *buf;
char *path;
struct stat filestat;
+
+
lib->path = "not found";
@@ -186,18 +154,25 @@ void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int
return;
}
+ /* We need some elbow room here. Make some room...*/
+ buf = malloc(1024);
+ if (!buf) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(EXIT_FAILURE);
+ }
+
/* This function must match the behavior of _dl_load_shared_library
* in readelflib1.c or things won't work out as expected... */
- /* The ABI specifies that RPATH is searched before LD_*_PATH or the
- * default path (such as /usr/lib). So first, lets check the rpath
- * directories */
+ /* The ABI specifies that RPATH is searched first, so do that now. */
path = (char *)elf_find_dynamic(DT_RPATH, dynamic, ehdr, 0);
if (path) {
- buf = do_which(lib->name, path);
- if (buf) {
+ search_for_named_library(lib->name, buf, path);
+ if (*buf != '\0') {
lib->path = buf;
return;
+ } else {
+ free(buf);
}
}
@@ -209,20 +184,29 @@ void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int
else
path = getenv("LD_LIBRARY_PATH");
if (path) {
- buf = do_which(lib->name, path);
- if (buf) {
+ search_for_named_library(lib->name, buf, path);
+ if (*buf != '\0') {
lib->path = buf;
return;
+ } else {
+ free(buf);
}
}
- /* Fixme -- add code to check the Cache here */
-
-
- buf = do_which(lib->name, UCLIBC_ROOT_DIR "/usr/lib/:" UCLIBC_ROOT_DIR
- "/lib/:" UCLIBC_BUILD_DIR "/lib/:/usr/lib:/lib");
- if (buf) {
+ /* FIXME -- add code to check the Cache here */
+
+ /* Lastly, search the standard list of paths for the library */
+ path = UCLIBC_PREFIX "/usr/lib:"
+ UCLIBC_PREFIX "/lib:"
+ UCLIBC_DEVEL_PREFIX "/lib:"
+ UCLIBC_BUILD_DIR "/lib:"
+ "/usr/lib:"
+ "/lib";
+ search_for_named_library(lib->name, buf, path);
+ if (*buf != '\0') {
lib->path = buf;
+ } else {
+ free(buf);
}
}