summaryrefslogtreecommitdiff
path: root/libexec/ld.so
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2000-09-17 17:50:58 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2000-09-17 17:50:58 +0000
commitab6dfee5bd566ceab3f3454f91a6a00c9ea5104b (patch)
tree96d99ce730d3ac579f9fecdd8e69048e54a4422a /libexec/ld.so
parent58cc392834945db9576ff91a4e74733f16ca1c2a (diff)
activate ldd, and indent some ld.so messages to make it easier to see what is going on
Diffstat (limited to 'libexec/ld.so')
-rw-r--r--libexec/ld.so/Makefile4
-rw-r--r--libexec/ld.so/dlfcn.c25
-rw-r--r--libexec/ld.so/ldd/Makefile9
-rw-r--r--libexec/ld.so/ldd/ldd.172
-rw-r--r--libexec/ld.so/ldd/ldd.c259
-rw-r--r--libexec/ld.so/loader.c5
6 files changed, 362 insertions, 12 deletions
diff --git a/libexec/ld.so/Makefile b/libexec/ld.so/Makefile
index 8d545561c85..3410535349f 100644
--- a/libexec/ld.so/Makefile
+++ b/libexec/ld.so/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.2 2000/09/08 04:23:45 rahnds Exp $
+# $OpenBSD: Makefile,v 1.3 2000/09/17 17:50:57 deraadt Exp $
-SUBDIR=libdl ldconfig
+SUBDIR=libdl ldconfig ldd
#CFLAGS =
.if (${MACHINE_ARCH} == "powerpc")
CFLAGS += -fpic -msoft-float
diff --git a/libexec/ld.so/dlfcn.c b/libexec/ld.so/dlfcn.c
index 4d4832d8e8b..f51a3bab83a 100644
--- a/libexec/ld.so/dlfcn.c
+++ b/libexec/ld.so/dlfcn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dlfcn.c,v 1.1 2000/06/13 03:33:58 rahnds Exp $ */
+/* $OpenBSD: dlfcn.c,v 1.2 2000/09/17 17:50:57 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -35,6 +35,7 @@
#define _DYN_LOADER
#include <sys/types.h>
+#include <nlist.h>
#include <link.h>
#include <dlfcn.h>
@@ -48,6 +49,7 @@ void _dl_show_objects(void);
static int _dl_real_close(void *handle);
static void _dl_unload_deps(elf_object_t *object);
+extern char *_dl_debug;
void *
dlopen(const char *libname, int how)
@@ -56,6 +58,9 @@ dlopen(const char *libname, int how)
elf_object_t *dynobj;
Elf32_Dyn *dynp;
+ if (_dl_debug) {
+ _dl_printf("loading: %s\n", libname);
+ }
object = _dl_load_shlib(libname, _dl_objects, OBJTYPE_DLO);
if(object == 0) {
return((void *)0);
@@ -97,12 +102,14 @@ dlopen(const char *libname, int how)
_dl_rtld(object);
_dl_call_init(object);
+#ifdef __mips__
if(_dl_debug_map->r_brk) {
_dl_debug_map->r_state = RT_ADD;
(*((void (*)())_dl_debug_map->r_brk))();
_dl_debug_map->r_state = RT_CONSISTENT;
(*((void (*)())_dl_debug_map->r_brk))();
}
+#endif /* __mips__ */
return((void *)object);
}
@@ -113,7 +120,7 @@ dlsym(void *handle, const char *name)
elf_object_t *object;
elf_object_t *dynobj;
void *retval;
- Elf32_Sym *sym = 0;
+ const Elf32_Sym *sym = 0;
object = (elf_object_t *)handle;
dynobj = _dl_objects;
@@ -125,7 +132,7 @@ dlsym(void *handle, const char *name)
return(0);
}
- retval = (void *)_dl_find_symbol(name, object, &sym, 1);
+ retval = (void *)_dl_find_symbol(name, object, &sym, 1, 1);
if(retval) {
retval += sym->st_value;
}
@@ -139,9 +146,12 @@ int
dlctl(void *handle, int command, void *data)
{
switch(command) {
+
+#ifdef __mips__
case DL_DUMP_MAP:
_dl_show_objects();
return(0);
+#endif /* __mips__ */
default:
_dl_errno = DL_INVALID_CTL;
@@ -157,12 +167,14 @@ dlclose(void *handle)
retval = _dl_real_close(handle);
+#ifdef __mips__
if(_dl_debug_map->r_brk) {
_dl_debug_map->r_state = RT_DELETE;
(*((void (*)())_dl_debug_map->r_brk))();
_dl_debug_map->r_state = RT_CONSISTENT;
(*((void (*)())_dl_debug_map->r_brk))();
}
+#endif /* __mips__ */
return(retval);
}
@@ -248,19 +260,16 @@ void
_dl_show_objects()
{
elf_object_t *object;
- elf_object_t *depobj;
- elf_object_t *tmpobj;
static char *otyp[] = {
"none", "rtld", "exe ", "rlib", "dlib"
};
object = _dl_objects;
- _dl_printf("Currently loaded modules:\n");
- _dl_printf("Start End Type Ref Name\n");
+ _dl_printf("\tStart End Type Ref Name\n");
while(object) {
- _dl_printf("%X %X %s %d %s\n", object->load_addr,
+ _dl_printf("\t%X %X %s %d %s\n", object->load_addr,
object->load_size, otyp[object->obj_type],
object->refcount, object->load_name);
object = object->next;
diff --git a/libexec/ld.so/ldd/Makefile b/libexec/ld.so/ldd/Makefile
new file mode 100644
index 00000000000..b0ed6f7af69
--- /dev/null
+++ b/libexec/ld.so/ldd/Makefile
@@ -0,0 +1,9 @@
+# $OpenBSD: Makefile,v 1.1 2000/09/17 17:50:57 deraadt Exp $
+
+PROG= ldd
+SRCS= ldd.c
+MAN= ldd.1
+
+BINDIR= /usr/bin
+
+.include <bsd.prog.mk>
diff --git a/libexec/ld.so/ldd/ldd.1 b/libexec/ld.so/ldd/ldd.1
new file mode 100644
index 00000000000..d6621f3e613
--- /dev/null
+++ b/libexec/ld.so/ldd/ldd.1
@@ -0,0 +1,72 @@
+.\" $OpenBSD: ldd.1,v 1.1 2000/09/17 17:50:57 deraadt Exp $
+.\"
+.\" Copyright (c) 1996 Per Fogelstrom
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed under OpenBSD by
+.\" Per Fogelstrom.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"
+.Dd October 4, 1996
+.Dt LDD 1
+.Os
+.Sh NAME
+.Nm ldd
+.Nd list dynamic object dependencies
+.Sh SYNOPSIS
+.Nm ldd
+.Op Fl x
+.Ar program
+.Sh DESCRIPTION
+.Nm ldd
+displays the shared objects needed to run
+.Ar program.
+.Nm ldd
+uses the
+.Nm DT_NEEDED
+tags to determine what dynamic objects are required. To list the objects
+.Nm ldd
+sets the environment variable
+.Nm LD_TRACE_LOADED_OBJECTS
+and then execs
+.Ar program Ns .
+.Pp
+If
+.Nm ldd
+is invoked with the
+.Nm -x
+flag, the tags from
+.Ar program
+are listed without using current ldconfig configuration.
+.Sh SEE ALSO
+.Xr ldconfig 8 ,
+.Xr ld.so 8
+.Sh DIAGNOSTICS
+Exit status 0 if no error. Exit status 1 if arg error. Exit status 2 if
+.Ar program
+can't be read. If
+.Nm ldd
+fails to open the program file a message is printed.
diff --git a/libexec/ld.so/ldd/ldd.c b/libexec/ld.so/ldd/ldd.c
new file mode 100644
index 00000000000..9c0720c0a47
--- /dev/null
+++ b/libexec/ld.so/ldd/ldd.c
@@ -0,0 +1,259 @@
+/* $OpenBSD: ldd.c,v 1.1 2000/09/17 17:50:57 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1993 Paul Kranenburg
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Paul Kranenburg.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/*
+ * Copyright (c) 1996 Per Fogelstrom
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed under OpenBSD by
+ * Per Fogelstrom.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+
+/* readsoname() adapted from Eric Youngdale's readelf program */
+
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <err.h>
+#include <fcntl.h>
+#include <elf_abi.h>
+
+int readsoneeded(FILE *f, int flag);
+
+void
+usage()
+{
+ extern char *__progname;
+
+ fprintf(stderr, "Usage: %s <filename> ...\n", __progname);
+ exit(1);
+}
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ FILE *fp;
+ int lflag = 0;
+ int rval;
+ int c;
+
+ while ((c = getopt(argc, argv, "l")) != EOF) {
+ switch (c) {
+ case 'l':
+ lflag = 1;
+ break;
+ default:
+ usage();
+ /*NOTREACHED*/
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc <= 0) {
+ usage();
+ /*NOTREACHED*/
+ }
+
+ if (setenv("LD_TRACE_LOADED_OBJECTS", "1", 1) == -1)
+ errx(1, "cannot setenv LD_TRACE_LOADED_OBJECTS");
+
+ rval = 0;
+ while (argc--) {
+ int fd;
+ int status;
+
+ if (lflag) {
+ if ((fp = fopen(*argv, "r")) == NULL) {
+ warn("%s", *argv);
+ rval |= 1;
+ argv++;
+ continue;
+ }
+ readsoneeded(fp, 0);
+ fclose(fp);
+ continue;
+ }
+ printf("%s:\n", *argv);
+ fflush(stdout);
+
+ switch (fork()) {
+ case -1:
+ err(1, "fork");
+ break;
+ default:
+ if (wait(&status) <= 0) {
+ warn("wait");
+ rval |= 1;
+ } else if (WIFSIGNALED(status)) {
+ fprintf(stderr, "%s: signal %d\n",
+ *argv, WTERMSIG(status));
+ rval |= 1;
+ } else if (WIFEXITED(status) && WEXITSTATUS(status)) {
+ fprintf(stderr, "%s: exit status %d\n",
+ *argv, WEXITSTATUS(status));
+ rval |= 1;
+ }
+ break;
+ case 0:
+ rval |= execl(*argv, *argv, NULL) != 0;
+ perror(*argv);
+ _exit(1);
+ }
+ argv++;
+ }
+
+ return (rval ? 1 : 0);
+}
+
+int
+readsoneeded(FILE *infile, int dyncheck)
+{
+ Elf32_Ehdr *epnt;
+ Elf32_Phdr *ppnt;
+ int i;
+ int isdynamic = 0;
+ char *header;
+ unsigned int dynamic_addr = 0;
+ unsigned int dynamic_size = 0;
+ int strtab_val = 0;
+ int soname_val = 0;
+ int loadaddr = -1;
+ int loadbase = 0;
+ Elf32_Dyn *dpnt;
+ struct stat st;
+ char *res = NULL;
+
+ if (fstat(fileno(infile), &st))
+ return -1L;
+ header = mmap(0, st.st_size, PROT_READ, MAP_SHARED, fileno(infile), 0);
+ if (header == (caddr_t)-1)
+ return -1;
+
+ epnt = (Elf32_Ehdr *)header;
+ if ((int)(epnt+1) > (int)(header + st.st_size))
+ goto skip;
+
+ ppnt = (Elf32_Phdr *)&header[epnt->e_phoff];
+ if ((int)ppnt < (int)header ||
+ (int)(ppnt+epnt->e_phnum) > (int)(header + st.st_size))
+ goto skip;
+
+ for (i = 0; i < epnt->e_phnum; i++) {
+ if (loadaddr == -1 && ppnt->p_vaddr != 0)
+ loadaddr = (ppnt->p_vaddr & 0xfffff000) -
+ (ppnt->p_offset & 0xfffff000);
+ if (ppnt->p_type == 2) {
+ dynamic_addr = ppnt->p_offset;
+ dynamic_size = ppnt->p_filesz;
+ }
+ ppnt++;
+ }
+
+ dpnt = (Elf32_Dyn *) &header[dynamic_addr];
+ dynamic_size = dynamic_size / sizeof(Elf32_Dyn);
+ if ((int)dpnt < (int)header ||
+ (int)(dpnt+dynamic_size) > (int)(header + st.st_size))
+ goto skip;
+
+ while (dpnt->d_tag != DT_NULL) {
+ if (dpnt->d_tag == DT_STRTAB)
+ strtab_val = dpnt->d_un.d_val;
+#define DT_MIPS_BASE_ADDRESS 0x70000006 /* XXX */
+ if (dpnt->d_tag == DT_MIPS_BASE_ADDRESS)
+ loadbase = dpnt->d_un.d_val;
+ dpnt++;
+ }
+
+ if (!strtab_val)
+ goto skip;
+
+ dpnt = (Elf32_Dyn *) &header[dynamic_addr];
+ while (dpnt->d_tag != DT_NULL) {
+ if (dpnt->d_tag == DT_NEEDED) {
+ isdynamic = 1;
+ if (dyncheck)
+ break;
+ soname_val = dpnt->d_un.d_val;
+ if (soname_val != 0 &&
+ soname_val + strtab_val - loadbase >= 0 &&
+ soname_val + strtab_val - loadbase < st.st_size)
+ printf("%s\n",
+ header - loadbase + soname_val + strtab_val);
+ }
+ dpnt++;
+ }
+
+skip:
+ munmap(header, st.st_size);
+
+ return isdynamic;
+}
+
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c
index 5d059d15782..4ea71d1a903 100644
--- a/libexec/ld.so/loader.c
+++ b/libexec/ld.so/loader.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: loader.c,v 1.2 2000/09/11 02:36:37 rahnds Exp $ */
+/* $OpenBSD: loader.c,v 1.3 2000/09/17 17:50:57 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -287,7 +287,8 @@ _dl_boot(const char **argv, const char **envp, const int loff,
if(_dl_debug || _dl_traceld) {
void _dl_show_objects(); /* remove -Wall warning */
_dl_show_objects();
- _dl_printf("dynamic loading done.\n");
+ if (_dl_debug)
+ _dl_printf("dynamic loading done.\n");
}
_dl_unmaphints();
if (_dl_traceld) {