Browse Source

Some cleanups needed for things to compile and work as expected
with the new build system...
-Erik

Eric Andersen 23 years ago
parent
commit
df6add6279
8 changed files with 162 additions and 99 deletions
  1. 4 4
      Makefile
  2. 8 8
      extra/gcc-uClibc/Makefile
  3. 5 5
      ldso/config.h
  4. 44 5
      ldso/ldso/dl-elf.c
  5. 44 5
      ldso/ldso/readelflib1.c
  6. 3 2
      ldso/util/Makefile
  7. 2 2
      ldso/util/ldconfig.c
  8. 52 68
      ldso/util/ldd.c

+ 4 - 4
Makefile

@@ -209,10 +209,10 @@ ifeq ($(LDSO_PRESENT),$(TARGET_ARCH))
 	install -m 755 lib/ld-uClibc-0.9.5.so $(DEVEL_PREFIX)/lib
 	install -m 755 ldso/util/ldd $(DEVEL_PREFIX)/bin
 	install -m 755 ldso/util/ldconfig $(DEVEL_PREFIX)/bin
-	install -d $(PREFIX)/bin
-	ln -fs $(DEVEL_PREFIX)/bin/ldd $(PREFIX)/bin/$(TARGET_ARCH)-uclibc-ldd
-	install -d $(PREFIX)/sbin
-	ln -fs $(DEVEL_PREFIX)/sbin/ldconfig $(PREFIX)/sbin/$(TARGET_ARCH)-uclibc-ldconfig
+	install -d $(TARGET_PREFIX)/bin
+	ln -fs $(DEVEL_PREFIX)/bin/ldd $(TARGET_PREFIX)/bin/$(TARGET_ARCH)-uclibc-ldd
+	install -d $(TARGET_PREFIX)/sbin
+	ln -fs $(DEVEL_PREFIX)/sbin/ldconfig $(TARGET_PREFIX)/sbin/$(TARGET_ARCH)-uclibc-ldconfig
 endif
 endif
 

+ 8 - 8
extra/gcc-uClibc/Makefile

@@ -32,17 +32,17 @@ ld-uClibc:
 
 install: all
 	install -d $(DEVEL_PREFIX)/bin;
-	install -d $(PREFIX)/bin;
-	install -m 755 $(TARGET_ARCH)-uclibc-gcc $(PREFIX)/bin/
-	install -m 755 $(TARGET_ARCH)-uclibc-ld $(PREFIX)/bin/
-	ln -fs $(TARGET_ARCH)-uclibc-gcc $(PREFIX)/bin/$(TARGET_ARCH)-uclibc-cc
-	ln -fs $(PREFIX)/bin/$(TARGET_ARCH)-uclibc-gcc $(DEVEL_PREFIX)/bin/gcc
-	ln -fs $(PREFIX)/bin/$(TARGET_ARCH)-uclibc-gcc $(DEVEL_PREFIX)/bin/cc
-	ln -fs $(PREFIX)/bin/$(TARGET_ARCH)-uclibc-ld $(DEVEL_PREFIX)/bin/ld
+	install -d $(DEVEL_PREFIX)/usr/bin;
+	install -m 755 $(TARGET_ARCH)-uclibc-gcc $(DEVEL_PREFIX)/usr/bin/
+	install -m 755 $(TARGET_ARCH)-uclibc-ld $(DEVEL_PREFIX)/usr/bin/
+	ln -fs $(TARGET_ARCH)-uclibc-gcc $(DEVEL_PREFIX)/usr/bin/$(TARGET_ARCH)-uclibc-cc
+	ln -fs $(DEVEL_PREFIX)/usr/bin/$(TARGET_ARCH)-uclibc-gcc $(DEVEL_PREFIX)/bin/gcc
+	ln -fs $(DEVEL_PREFIX)/usr/bin/$(TARGET_ARCH)-uclibc-gcc $(DEVEL_PREFIX)/bin/cc
+	ln -fs $(DEVEL_PREFIX)/usr/bin/$(TARGET_ARCH)-uclibc-ld $(DEVEL_PREFIX)/bin/ld
 	for app in addr2line ar as cpp gasp nm objcopy \
 	    objdump ranlib size strings strip; do \
 	  ln -fs `which $(CROSS)$${app}` $(DEVEL_PREFIX)/bin/$${app}; \
-	  ln -fs `which $(CROSS)$${app}` $(PREFIX)/bin/$(TARGET_ARCH)-uclibc-$${app}; \
+	  ln -fs `which $(CROSS)$${app}` $(DEVEL_PREFIX)/usr/bin/$(TARGET_ARCH)-uclibc-$${app}; \
 	done
 
 clean:

+ 5 - 5
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"

+ 44 - 5
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)

+ 44 - 5
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)

+ 3 - 2
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 $@

+ 2 - 2
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)

+ 52 - 68
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);
 	}
 }