diff options
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | ldso/include/dl-elf.h | 3 | ||||
-rw-r--r-- | ldso/include/ld_elf.h | 3 | ||||
-rw-r--r-- | ldso/util/Makefile | 64 | ||||
-rw-r--r-- | ldso/util/ldconfig.c | 103 | ||||
-rw-r--r-- | ldso/util/readsoname.c | 6 |
6 files changed, 90 insertions, 102 deletions
@@ -346,16 +346,13 @@ endif install_target_utils: ifeq ($(strip $(HAVE_SHARED)),y) - @$(MAKE) -C ldso/util ldd.target readelf.target #ldconfig.target + @$(MAKE) -C ldso/util ldd.target ldconfig.target #readelf.target + install -d $(PREFIX)$(TARGET_PREFIX)/etc; + install -d $(PREFIX)$(TARGET_PREFIX)/sbin; install -d $(PREFIX)$(TARGET_PREFIX)/usr/bin; install -m 755 ldso/util/ldd.target $(PREFIX)$(TARGET_PREFIX)/usr/bin/ldd - install -m 755 ldso/util/readelf.target $(PREFIX)$(TARGET_PREFIX)/usr/bin/readelf - @if [ -x ldso/util/ldconfig.target ] ; then \ - set -x -e; \ - install -d $(PREFIX)$(TARGET_PREFIX)/etc; \ - install -d $(PREFIX)$(TARGET_PREFIX)/sbin; \ - install -m 755 ldso/util/ldconfig.target $(PREFIX)$(TARGET_PREFIX)/sbin/ldconfig; \ - fi; + install -m 755 ldso/util/ldconfig.target $(PREFIX)$(TARGET_PREFIX)/sbin/ldconfig; + #install -m 755 ldso/util/readelf.target $(PREFIX)$(TARGET_PREFIX)/usr/bin/readelf; endif ifeq ($(strip $(UCLIBC_HAS_LOCALE)),y) @$(MAKE) -C libc/misc/wchar iconv.target diff --git a/ldso/include/dl-elf.h b/ldso/include/dl-elf.h index 992a608b1..db9ee9556 100644 --- a/ldso/include/dl-elf.h +++ b/ldso/include/dl-elf.h @@ -19,9 +19,10 @@ #define LIB_ANY -1 #define LIB_DLL 0 #define LIB_ELF 1 +#define LIB_ELF64 0x80 #define LIB_ELF_LIBC5 2 #define LIB_ELF_LIBC6 3 -#define LIB_ELF64 0x80 +#define LIB_ELF_LIBC0 4 /* Forward declarations for stuff defined in ld_hash.h */ struct dyn_elf; diff --git a/ldso/include/ld_elf.h b/ldso/include/ld_elf.h index 992a608b1..db9ee9556 100644 --- a/ldso/include/ld_elf.h +++ b/ldso/include/ld_elf.h @@ -19,9 +19,10 @@ #define LIB_ANY -1 #define LIB_DLL 0 #define LIB_ELF 1 +#define LIB_ELF64 0x80 #define LIB_ELF_LIBC5 2 #define LIB_ELF_LIBC6 3 -#define LIB_ELF64 0x80 +#define LIB_ELF_LIBC0 4 /* Forward declarations for stuff defined in ld_hash.h */ struct dyn_elf; diff --git a/ldso/util/Makefile b/ldso/util/Makefile index 4765fd2e3..87e69b4ea 100644 --- a/ldso/util/Makefile +++ b/ldso/util/Makefile @@ -24,59 +24,77 @@ TOPDIR=../../ include $(TOPDIR)Rules.mak TARGET_CC = $(TOPDIR)extra/gcc-uClibc/$(TARGET_ARCH)-uclibc-gcc -TARGETS = ldd +TARGETS = ldd ldconfig ifeq ($(OSTYPE),linux) TARGETS += readelf endif -ifneq ($(strip $(LIBRARY_CACHE)),) -TARGETS += ldconfig -endif -all: $(TARGETS) +#ifneq ($(strip $(LIBRARY_CACHE)),) +#TARGETS += ldconfig +#endif ifeq ($(strip $(LDSO_LDD_SUPPORT)),y) -XXFLAGS=-D__LDSO_LDD_SUPPORT +XXFLAGS = -D__LDSO_LDD_SUPPORT endif +all: $(TARGETS) + headers: ln -fs $(TOPDIR)include/elf.h -readelf: headers readelf.c - $(HOSTCC) $(HOSTCFLAGS) -I . readelf.c -o $@ +readelf: readelf.c + $(HOSTCC) $(HOSTCFLAGS) -I. -I../include $^ -o $@ strip -x -R .note -R .comment $@ readelf.target: readelf.c - $(TARGET_CC) $(CFLAGS) -Wl,-s readelf.c -o $@ + $(TARGET_CC) $(CFLAGS) -Wl,-s $^ -o $@ $(STRIPTOOL) -x -R .note -R .comment $@ -readsoname.o: headers readsoname.c readsoname2.c - $(HOSTCC) $(HOSTCFLAGS) -I . -c $< -o $@ - strip -x -R .note -R .comment $*.o - -ldconfig.o: headers ldconfig.c - $(HOSTCC) $(HOSTCFLAGS) -I . \ - -DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" -c $< -o $@ +readsoname.o: readsoname.c readsoname2.c + $(HOSTCC) $(HOSTCFLAGS) -I. -I../include -c $< -o $@ strip -x -R .note -R .comment $*.o -ldconfig: headers ldconfig.o readsoname.o - $(HOSTCC) $(HOSTCFLAGS) $^ -o $@ +#ldconfig.o: ldconfig.c +# $(HOSTCC) $(HOSTCFLAGS) -I. -I../include \ +# -DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" -c $< -o $@ +# strip -x -R .note -R .comment $*.o + +#ldconfig: ldconfig.o readsoname.o +# $(HOSTCC) $(HOSTCFLAGS) $^ -o $@ +# strip -x -R .note -R .comment $@ + +ldconfig: ldconfig.c readsoname.c + $(HOSTCC) $(HOSTCFLAGS) $(XXFLAGS) -DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ + -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \ + -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR) && pwd)\" \ + -DUCLIBC_LDSO=\"$(UCLIBC_LDSO)\" -I. -I../include \ + $^ -o $@ strip -x -R .note -R .comment $@ -ldd: headers ldd.c +ldconfig.target: ldconfig.c readsoname.c + $(TARGET_CC) $(CFLAGS) $(XXFLAGS) -Wl,-s -DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ + -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \ + -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR) && pwd)\" \ + -DUCLIBC_LDSO=\"$(UCLIBC_LDSO)\" -I. -I../include \ + $^ -o $@ + $(STRIPTOOL) -x -R .note -R .comment $@ + +ldd: ldd.c $(HOSTCC) $(HOSTCFLAGS) $(XXFLAGS) -DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \ -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR) && pwd)\" \ - -DUCLIBC_LDSO=\"$(UCLIBC_LDSO)\" -I . \ - ldd.c -o $@ + -DUCLIBC_LDSO=\"$(UCLIBC_LDSO)\" -I. -I../include \ + $^ -o $@ strip -x -R .note -R .comment $@ -ldd.target: ldd.c +ldd.target: ldd.c $(TARGET_CC) $(CFLAGS) $(XXFLAGS) -Wl,-s -DUCLIBC_TARGET_PREFIX=\"$(TARGET_PREFIX)\" \ -DUCLIBC_DEVEL_PREFIX=\"$(DEVEL_PREFIX)\" \ -DUCLIBC_BUILD_DIR=\"$(shell cd $(TOPDIR) && pwd)\" \ -DUCLIBC_LDSO=\"$(UCLIBC_LDSO)\" \ - ldd.c -o $@ + $^ -o $@ $(STRIPTOOL) -x -R .note -R .comment $@ clean: rm -f $(TARGETS) *.o *~ core *.target elf.h +readelf.c readsoname.c ldconfig.c ldd.c: headers diff --git a/ldso/util/ldconfig.c b/ldso/util/ldconfig.c index f90cb073f..e971f5aa1 100644 --- a/ldso/util/ldconfig.c +++ b/ldso/util/ldconfig.c @@ -33,11 +33,12 @@ #include <dirent.h> #include <unistd.h> #include <link.h> -#include <sys/stat.h> #include <fcntl.h> -#include <sys/mman.h> +#include <err.h> #include <errno.h> -#include <ldso.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <ld_elf.h> #include "readsoname.h" struct exec @@ -66,10 +67,6 @@ struct exec #define QMAGIC 0314 /* Code indicating core file. */ #define CMAGIC 0421 -#ifdef __GNUC__ -void warn(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); -void error(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); -#endif char *___strtok = NULL; @@ -100,46 +97,11 @@ void cache_print(void); void cache_dolib(const char *dir, const char *so, int libtype); void cache_write(void); -void warn(const char *fmt, ...) -{ - va_list ap; - - if (verbose < 0) - return; - - fflush(stdout); /* don't mix output and error messages */ - fprintf(stderr, "%s: warning: ", prog); - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - fprintf(stderr, "\n"); - - return; -} - -void error(const char *fmt, ...) -{ - va_list ap; - - fflush(stdout); /* don't mix output and error messages */ - fprintf(stderr, "%s: ", prog); - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - - fprintf(stderr, "\n"); - - exit(EXIT_FATAL); -} - void *xmalloc(size_t size) { void *ptr; if ((ptr = malloc(size)) == NULL) - error("out of memory"); + err(EXIT_FATAL,"out of memory"); return ptr; } @@ -147,7 +109,7 @@ char *xstrdup(const char *str) { char *ptr; if ((ptr = strdup(str)) == NULL) - error("out of memory"); + err(EXIT_FATAL,"out of memory"); return ptr; } @@ -470,8 +432,10 @@ void scan_dir(const char *name) { if (!lp->islink) link_shlib(name, lp->name, lp->so); +#ifdef USE_CACHE if (!nocache) cache_dolib(name, lp->so, lp->libtype); +#endif } /* always try to clean up after ourselves */ @@ -520,11 +484,10 @@ char *get_extpath(void) void usage(void) { fprintf(stderr, - "ldconfig - update shared library symlinks\n" - "\n" - "usage: ldconfig [-DvqnNX] [-f conf] [-C cache] [-r root] dir ...\n" + "ldconfig - updates symlinks for shared libraries\n\n" + "Usage: ldconfig [-DvqnNX] [-f conf] [-C cache] [-r root] dir ...\n" " ldconfig -l [-Dv] lib ...\n" - " ldconfig -p\n" + " ldconfig -p\n\nOptions:\n" "\t-D:\t\tdebug mode, don't update links\n" "\t-v:\t\tverbose mode, print things as we go\n" "\t-q:\t\tquiet mode, don't print warnings\n" @@ -537,9 +500,7 @@ void usage(void) "\t-C cache:\tuse cache instead of %s\n" "\t-r root :\tfirst, do a chroot to the indicated directory\n" "\tdir ... :\tdirectories to process\n" - "\tlib ... :\tlibraries to link\n" - "\n" - "Copyright 1994-2000 David Engel and Mitch D'Souza\n", + "\tlib ... :\tlibraries to link\n\n", LDSO_CONF, LDSO_CACHE ); exit(EXIT_FATAL); @@ -610,9 +571,9 @@ int main(int argc, char **argv) if (chroot_dir && *chroot_dir) { if (chroot(chroot_dir) < 0) - error("couldn't chroot to %s (%s)", chroot_dir, strerror(errno)); + err(EXIT_FATAL,"couldn't chroot to %s (%s)", chroot_dir, strerror(errno)); if (chdir("/") < 0) - error("couldn't chdir to / (%s)", strerror(errno)); + err(EXIT_FATAL,"couldn't chdir to / (%s)", strerror(errno)); } /* allow me to introduce myself, hi, my name is ... */ @@ -622,7 +583,11 @@ int main(int argc, char **argv) if (printcache) { /* print the cache -- don't you trust me? */ +#ifdef USE_CACHE cache_print(); +#else + warnx("Cache support disabled\n"); +#endif exit(EXIT_OK); } else if (libmode) @@ -649,7 +614,7 @@ int main(int argc, char **argv) /* we'd better do a little bit of checking */ if ((so = is_shlib(dir, cp, &libtype, &islink, LIB_ANY)) == NULL) - error("%s%s%s is not a shared library", dir, + err(EXIT_FATAL,"%s%s%s is not a shared library", dir, (*dir && strcmp(dir, "/")) ? "/" : "", cp); /* so far, so good, maybe he knows what he's doing */ @@ -687,13 +652,16 @@ int main(int argc, char **argv) scan_dir(UCLIBC_TARGET_PREFIX "/lib"); } +#ifdef USE_CACHE if (!nocache) cache_write(); +#endif } exit(EXIT_OK); } +#ifdef USE_CACHE typedef struct liblist { int flags; @@ -761,13 +729,13 @@ void cache_write(void) sprintf(tempfile, "%s~", cachefile); if (unlink(tempfile) && errno != ENOENT) - error("can't unlink %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't unlink %s (%s)", tempfile, strerror(errno)); if ((cachefd = creat(tempfile, 0644)) < 0) - error("can't create %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't create %s (%s)", tempfile, strerror(errno)); if (write(cachefd, &magic, sizeof (header_t)) != sizeof (header_t)) - error("can't write %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't write %s (%s)", tempfile, strerror(errno)); for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next) { @@ -777,27 +745,27 @@ void cache_write(void) stroffset += strlen(cur_lib->libname) + 1; if (write(cachefd, cur_lib, sizeof (libentry_t)) != sizeof (libentry_t)) - error("can't write %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't write %s (%s)", tempfile, strerror(errno)); } for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next) { if (write(cachefd, cur_lib->soname, strlen(cur_lib->soname) + 1) != strlen(cur_lib->soname) + 1) - error("can't write %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't write %s (%s)", tempfile, strerror(errno)); if (write(cachefd, cur_lib->libname, strlen(cur_lib->libname) + 1) != strlen(cur_lib->libname) + 1) - error("can't write %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't write %s (%s)", tempfile, strerror(errno)); } if (close(cachefd)) - error("can't close %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't close %s (%s)", tempfile, strerror(errno)); if (chmod(tempfile, 0644)) - error("can't chmod %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't chmod %s (%s)", tempfile, strerror(errno)); if (rename(tempfile, cachefile)) - error("can't rename %s (%s)", tempfile, strerror(errno)); + err(EXIT_FATAL,"can't rename %s (%s)", tempfile, strerror(errno)); } void cache_print(void) @@ -810,16 +778,16 @@ void cache_print(void) libentry_t *libent; if (stat(cachefile, &st) || (fd = open(cachefile, O_RDONLY))<0) - error("can't read %s (%s)", cachefile, strerror(errno)); + err(EXIT_FATAL,"can't read %s (%s)", cachefile, strerror(errno)); if ((c = mmap(0,st.st_size, PROT_READ, MAP_SHARED ,fd, 0)) == (caddr_t)-1) - error("can't map %s (%s)", cachefile, strerror(errno)); + err(EXIT_FATAL,"can't map %s (%s)", cachefile, strerror(errno)); close(fd); if (memcmp(((header_t *)c)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN)) - error("%s cache corrupt", cachefile); + err(EXIT_FATAL,"%s cache corrupt", cachefile); if (memcmp(((header_t *)c)->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN)) - error("wrong cache version - expected %s", LDSO_CACHE_VER); + err(EXIT_FATAL,"wrong cache version - expected %s", LDSO_CACHE_VER); header = (header_t *)c; libent = (libentry_t *)(c + sizeof (header_t)); @@ -853,4 +821,5 @@ void cache_print(void) munmap (c,st.st_size); } +#endif diff --git a/ldso/util/readsoname.c b/ldso/util/readsoname.c index 2b3f8353f..12c2428f2 100644 --- a/ldso/util/readsoname.c +++ b/ldso/util/readsoname.c @@ -7,8 +7,7 @@ #include <link.h> #include <unistd.h> #include <sys/types.h> -#include "elf.h" -#include "../config.h" +#include <ld_elf.h> #include "readsoname.h" void warn(char *fmt, ...); @@ -21,6 +20,9 @@ struct needed_tab }; struct needed_tab needed_tab[] = { + { "libc.so.0", LIB_ELF_LIBC0 }, + { "libm.so.0", LIB_ELF_LIBC0 }, + { "libdl.so.0", LIB_ELF_LIBC0 }, { "libc.so.5", LIB_ELF_LIBC5 }, { "libm.so.5", LIB_ELF_LIBC5 }, { "libdl.so.1", LIB_ELF_LIBC5 }, |