summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ld.so/alpha/archdep.h4
-rw-r--r--libexec/ld.so/alpha/ldasm.S12
-rw-r--r--libexec/ld.so/alpha/rtld_machine.c33
-rw-r--r--libexec/ld.so/dlfcn.c55
-rw-r--r--libexec/ld.so/ldconfig/ld.h11
-rw-r--r--libexec/ld.so/ldconfig/ldconfig.c19
-rw-r--r--libexec/ld.so/ldconfig/shlib.c12
-rw-r--r--libexec/ld.so/ldd/ldd.c27
-rw-r--r--libexec/ld.so/libdl/libdl.c10
-rw-r--r--libexec/ld.so/library.c124
-rw-r--r--libexec/ld.so/loader.c90
-rw-r--r--libexec/ld.so/mips/archdep.h4
-rw-r--r--libexec/ld.so/mips/ldasm.S6
-rw-r--r--libexec/ld.so/mips/rtld_machine.c61
-rw-r--r--libexec/ld.so/mips/syscall.h329
-rw-r--r--libexec/ld.so/powerpc/archdep.h31
-rw-r--r--libexec/ld.so/powerpc/ldasm.S20
-rw-r--r--libexec/ld.so/powerpc/rtld_machine.c236
-rw-r--r--libexec/ld.so/powerpc/syscall.h45
-rw-r--r--libexec/ld.so/resolve.c72
-rw-r--r--libexec/ld.so/resolve.h4
-rw-r--r--libexec/ld.so/sod.c21
-rw-r--r--libexec/ld.so/sparc64/archdep.h6
-rw-r--r--libexec/ld.so/sparc64/ldasm.S29
-rw-r--r--libexec/ld.so/sparc64/rtld_machine.c69
-rw-r--r--libexec/ld.so/strdup.c7
-rw-r--r--libexec/ld.so/util.c11
-rw-r--r--libexec/ld.so/util.h32
28 files changed, 656 insertions, 724 deletions
diff --git a/libexec/ld.so/alpha/archdep.h b/libexec/ld.so/alpha/archdep.h
index 999d5877d09..8ec8942cd6d 100644
--- a/libexec/ld.so/alpha/archdep.h
+++ b/libexec/ld.so/alpha/archdep.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: archdep.h,v 1.5 2002/02/21 23:17:53 drahn Exp $ */
+/* $OpenBSD: archdep.h,v 1.6 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
diff --git a/libexec/ld.so/alpha/ldasm.S b/libexec/ld.so/alpha/ldasm.S
index 5fea7c60807..1d09ca23489 100644
--- a/libexec/ld.so/alpha/ldasm.S
+++ b/libexec/ld.so/alpha/ldasm.S
@@ -1,8 +1,8 @@
-/* $OpenBSD: ldasm.S,v 1.5 2002/03/17 00:22:04 art Exp $ */
+/* $OpenBSD: ldasm.S,v 1.6 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 2001 Niklas Hallqvist
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -78,8 +78,8 @@ L1:
lda t0, _GLOBAL_OFFSET_TABLE_
addq t0, t2, t0
lda t1, _DYNAMIC
- addq t1, t2, t1
-L2: cmpult t0, t1, t3
+ addq t1, t2, t1
+L2: cmpult t0, t1, t3
beq t3, L3
ldq t3, 0(t0)
addq t3, t2, t3
@@ -203,7 +203,7 @@ END(_dl_bind_start)
* In reality these are not leaves, but they are stubs which does not need
* further register saving.
*/
-
+
LEAF_NOPROFILE(_dl_exit, 1)
ldiq v0, SYS_exit
call_pal PAL_OSF1_callsys
@@ -235,7 +235,7 @@ LEAF_NOPROFILE(_dl_read, 3)
ldiq v0, SYS_read
call_pal PAL_OSF1_callsys
RET
-END(_dl_exit)
+END(_dl_read)
LEAF_NOPROFILE(_dl_mmap, 6)
lda sp, -8(sp)
diff --git a/libexec/ld.so/alpha/rtld_machine.c b/libexec/ld.so/alpha/rtld_machine.c
index bec720d9f21..7019f80a6a7 100644
--- a/libexec/ld.so/alpha/rtld_machine.c
+++ b/libexec/ld.so/alpha/rtld_machine.c
@@ -1,10 +1,10 @@
-/* $OpenBSD: rtld_machine.c,v 1.8 2001/06/26 18:43:06 art Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.9 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
* Copyright (c) 2001 Niklas Hallqvist
* Copyright (c) 2001 Artur Grabowski
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -75,9 +75,8 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz)
numrela = object->Dyn.info[relasz] / sizeof(Elf64_Rela);
relas = (Elf64_Rela *)(object->Dyn.info[rel]);
- if ((object->status & STAT_RELOC_DONE) || !relas) {
+ if ((object->status & STAT_RELOC_DONE) || !relas)
return(0);
- }
/*
* unprotect some segments if we need it.
@@ -88,7 +87,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz)
for (llist = object->load_list; llist != NULL; llist = llist->next) {
if (!(llist->prot & PROT_WRITE)) {
_dl_mprotect(llist->start, llist->size,
- llist->prot|PROT_WRITE);
+ llist->prot|PROT_WRITE);
}
}
}
@@ -101,9 +100,9 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz)
r_addr = (Elf64_Addr *)(relas->r_offset + loff);
- if (ELF64_R_SYM(relas->r_info) == 0xffffffff) {
+ if (ELF64_R_SYM(relas->r_info) == 0xffffffff)
continue;
- }
+
sym = object->dyn.symtab;
sym += ELF64_R_SYM(relas->r_info);
@@ -126,14 +125,13 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz)
Elf_Addr tmp;
#if 0
_dl_printf("unaligned RELATIVE: %p type: %d %s 0x%lx -> 0x%lx\n", r_addr,
-ELF_R_TYPE(relas->r_info), object->load_name, *r_addr, *r_addr+loff);
+ ELF_R_TYPE(relas->r_info), object->load_name, *r_addr, *r_addr+loff);
#endif
_dl_bcopy(r_addr, &tmp, sizeof(Elf_Addr));
tmp += loff;
_dl_bcopy(&tmp, r_addr, sizeof(Elf_Addr));
- } else {
+ } else
*r_addr += loff;
- }
break;
case R_TYPE(JMP_SLOT):
ooff = _dl_find_symbol(symn, _dl_objects, &this, 0, 1);
@@ -151,15 +149,15 @@ ELF_R_TYPE(relas->r_info), object->load_name, *r_addr, *r_addr+loff);
break;
default:
_dl_printf("%s:"
- " %s: unsupported relocation '%s' %d at %lx\n",
- _dl_progname, object->load_name, symn,
- ELF64_R_TYPE(relas->r_info), r_addr );
+ " %s: unsupported relocation '%s' %d at %lx\n",
+ _dl_progname, object->load_name, symn,
+ ELF64_R_TYPE(relas->r_info), r_addr );
_dl_exit(1);
}
continue;
resolve_failed:
_dl_printf("%s: %s :can't resolve reference '%s'\n",
- _dl_progname, object->load_name, symn);
+ _dl_progname, object->load_name, symn);
fails++;
}
__asm __volatile("imb" : : : "memory");
@@ -167,13 +165,11 @@ resolve_failed:
/* reprotect the unprotected segments */
if ((rel == DT_REL || rel == DT_RELA)) {
for (llist = object->load_list; llist != NULL; llist = llist->next) {
- if (!(llist->prot & PROT_WRITE)) {
+ if (!(llist->prot & PROT_WRITE))
_dl_mprotect(llist->start, llist->size,
- llist->prot);
- }
+ llist->prot);
}
}
-
return (fails);
}
@@ -201,7 +197,6 @@ _dl_bind(elf_object_t *object, Elf_Word reloff)
*((int *)0) = 0; /* XXX */
}
*addr = ooff + this->st_value + rela->r_addend;
-
return (void *)*addr;
}
diff --git a/libexec/ld.so/dlfcn.c b/libexec/ld.so/dlfcn.c
index 3451600b5a8..60c5fcccf54 100644
--- a/libexec/ld.so/dlfcn.c
+++ b/libexec/ld.so/dlfcn.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: dlfcn.c,v 1.14 2002/03/17 04:50:57 drahn Exp $ */
+/* $OpenBSD: dlfcn.c,v 1.15 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -57,19 +57,17 @@ dlopen(const char *libname, int how)
elf_object_t *dynobj;
Elf_Dyn *dynp;
- if (libname == NULL) {
+ if (libname == NULL)
return _dl_objects;
- }
+
DL_DEB(("dlopen: loading: %s\n", libname));
object = _dl_load_shlib(libname, _dl_objects, OBJTYPE_DLO);
- if (object == 0) {
+ if (object == 0)
return((void *)0);
- }
- if (object->refcount > 1) {
+ if (object->refcount > 1)
return((void *)object); /* Already loaded */
- }
/*
* Check for 'needed' objects. For each 'needed' object we
@@ -86,14 +84,14 @@ dlopen(const char *libname, int how)
const char *libname;
elf_object_t *depobj;
- if (dynp->d_tag != DT_NEEDED) {
+ if (dynp->d_tag != DT_NEEDED)
continue;
- }
+
libname = dynobj->dyn.strtab + dynp->d_un.d_val;
depobj = _dl_load_shlib(libname, dynobj, OBJTYPE_LIB);
- if (!depobj) {
+ if (!depobj)
_dl_exit(4);
- }
+
tmpobj->dep_next = _dl_malloc(sizeof(elf_object_t));
tmpobj->dep_next->next = depobj;
tmpobj = tmpobj->dep_next;
@@ -104,13 +102,12 @@ dlopen(const char *libname, int how)
_dl_rtld(object);
_dl_call_init(object);
- if(_dl_debug_map->r_brk) {
+ 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))();
}
-
return((void *)object);
}
@@ -124,21 +121,19 @@ dlsym(void *handle, const char *name)
object = (elf_object_t *)handle;
dynobj = _dl_objects;
- while (dynobj && dynobj != object) {
+ while (dynobj && dynobj != object)
dynobj = dynobj->next;
- }
+
if (!dynobj || object != dynobj) {
_dl_errno = DL_INVALID_HANDLE;
return(0);
}
retval = (void *)_dl_find_symbol(name, object, &sym, 1, 1);
- if (sym != NULL) {
+ if (sym != NULL)
retval += sym->st_value;
- } else {
+ else
_dl_errno = DL_NO_SYMBOL;
- }
-
return (retval);
}
@@ -165,9 +160,9 @@ dlclose(void *handle)
{
int retval;
- if (handle == _dl_objects) {
+ if (handle == _dl_objects)
return 0;
- }
+
retval = _dl_real_close(handle);
if (_dl_debug_map->r_brk) {
@@ -176,7 +171,6 @@ dlclose(void *handle)
_dl_debug_map->r_state = RT_CONSISTENT;
(*((void (*)())_dl_debug_map->r_brk))();
}
-
return (retval);
}
@@ -188,18 +182,17 @@ _dl_real_close(void *handle)
object = (elf_object_t *)handle;
dynobj = _dl_objects;
- while (dynobj && dynobj != object) {
+ while (dynobj && dynobj != object)
dynobj = dynobj->next;
- }
+
if (!dynobj || object != dynobj) {
_dl_errno = DL_INVALID_HANDLE;
return (1);
}
if (object->refcount == 1) {
- if (dynobj->dep_next) {
+ if (dynobj->dep_next)
_dl_unload_deps(dynobj);
- }
}
_dl_unload_shlib(object);
@@ -218,9 +211,8 @@ _dl_unload_deps(elf_object_t *object)
depobj = object->dep_next;
while (depobj) {
if (depobj->next->refcount == 1) { /* This object will go away */
- if (depobj->next->dep_next) {
+ if (depobj->next->dep_next)
_dl_unload_deps(depobj->next);
- }
_dl_unload_shlib(depobj->next);
}
depobj = depobj->dep_next;
@@ -288,9 +280,8 @@ _dl_show_objects()
break;
}
_dl_printf("\t%X %X %s %d %s\n", object->load_addr,
- object->load_addr + object->load_size,
- objtypename, object->refcount,
- object->load_name);
+ object->load_addr + object->load_size,
+ objtypename, object->refcount, object->load_name);
object = object->next;
}
}
diff --git a/libexec/ld.so/ldconfig/ld.h b/libexec/ld.so/ldconfig/ld.h
index 30abc5c7bba..1d60f0b6f64 100644
--- a/libexec/ld.so/ldconfig/ld.h
+++ b/libexec/ld.so/ldconfig/ld.h
@@ -1,6 +1,6 @@
-/* $OpenBSD: ld.h,v 1.5 2002/05/24 00:25:42 ericj Exp $ */
+/* $OpenBSD: ld.h,v 1.6 2002/05/24 03:44:37 deraadt Exp $ */
/*
- * Header file to make code compatible with ELF version
+ * Header file to make code compatible with ELF version
* ldconfig was taken from the a.out ld.
*/
#include <link.h>
@@ -12,4 +12,11 @@ void *xmalloc(size_t);
void *xrealloc(void *, size_t);
char *concat(const char *, const char *, const char *);
+void add_search_dir(char *name);
+void std_search_path(void);
+void add_search_path(char *path);
+void remove_search_dir(char *name);
+int getdewey(int dewey[], char *cp);
+int cmpndewey(int d1[], int n1, int d2[], int n2);
+
#define PAGSIZ __LDPGSZ
diff --git a/libexec/ld.so/ldconfig/ldconfig.c b/libexec/ld.so/ldconfig/ldconfig.c
index 06cc9268f12..cd0c111e2d9 100644
--- a/libexec/ld.so/ldconfig/ldconfig.c
+++ b/libexec/ld.so/ldconfig/ldconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldconfig.c,v 1.8 2002/05/22 06:35:44 deraadt Exp $ */
+/* $OpenBSD: ldconfig.c,v 1.9 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1993,1995 Paul Kranenburg
@@ -114,8 +114,8 @@ char *argv[];
verbose = 1;
break;
default:
- (void)fprintf(stderr,
- "usage: %s [-RUmrsv] [dir ...]\n", __progname);
+ fprintf(stderr,
+ "usage: %s [-RUmrsv] [dir ...]\n", __progname);
exit(1);
break;
}
@@ -221,7 +221,6 @@ int silent;
ndewey = getdewey(dewey, cp + 4);
enter(dir, dp->d_name, name, dewey, ndewey);
}
-
return 0;
}
@@ -242,8 +241,8 @@ int dewey[], ndewey;
/* Update this entry with higher versioned lib */
if (verbose)
printf("Updating lib%s.%d.%d to %s/%s\n",
- shp->name, shp->major, shp->minor,
- dir, file);
+ shp->name, shp->major, shp->minor,
+ dir, file);
free(shp->name);
shp->name = xstrdup(name);
@@ -332,7 +331,7 @@ buildhints()
if (verbose)
printf("Totals: entries %d, buckets %ld, string size %d\n",
- nhints, hdr.hh_nbucket, strtab_sz);
+ nhints, hdr.hh_nbucket, strtab_sz);
/* Allocate buckets and string table */
blist = (struct hints_bucket *)xmalloc(n);
@@ -347,8 +346,8 @@ buildhints()
for (shp = shlib_head; shp; shp = shp->next) {
struct hints_bucket *bp;
- bp = blist +
- (hinthash(shp->name, shp->major, shp->minor) % hdr.hh_nbucket);
+ bp = blist + (hinthash(shp->name, shp->major, shp->minor) %
+ hdr.hh_nbucket);
if (bp->hi_pathx) {
int i;
@@ -525,7 +524,7 @@ listhints()
for (i = 0, shp = shlib_head; shp; i++, shp = shp->next)
printf("\t%d:-l%s.%d.%d => %s\n",
- i, shp->name, shp->major, shp->minor, shp->path);
+ i, shp->name, shp->major, shp->minor, shp->path);
return;
}
diff --git a/libexec/ld.so/ldconfig/shlib.c b/libexec/ld.so/ldconfig/shlib.c
index 690e722b931..12d4ef57414 100644
--- a/libexec/ld.so/ldconfig/shlib.c
+++ b/libexec/ld.so/ldconfig/shlib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: shlib.c,v 1.4 2002/05/22 06:35:44 deraadt Exp $ */
+/* $OpenBSD: shlib.c,v 1.5 2002/05/24 03:44:37 deraadt Exp $ */
/* $NetBSD: shlib.c,v 1.13 1998/04/04 01:00:29 fvdl Exp $ */
/*
@@ -154,7 +154,7 @@ char *path;
}
void
-std_search_path()
+std_search_path(void)
{
int i, n;
@@ -172,8 +172,8 @@ std_search_path()
int
getdewey(dewey, cp)
-int dewey[];
-char *cp;
+ int dewey[];
+ char *cp;
{
int i, n;
@@ -266,7 +266,7 @@ int do_dot_a;
for (i = 0; i < n_search_dirs; i++) {
DIR *dd = opendir(search_dirs[i]);
struct dirent *dp;
- char *path = NULL;
+ char *path = NULL;
if (dd == NULL)
continue;
@@ -297,7 +297,7 @@ int do_dot_a;
continue;
if (n != 1 && minor != -1 && tmp[1] < minor)
continue;
- }
+ }
if (cmpndewey(tmp, n, dewey, ndewey) <= 0)
continue;
diff --git a/libexec/ld.so/ldd/ldd.c b/libexec/ld.so/ldd/ldd.c
index 2c43fdbad48..6e505f7205b 100644
--- a/libexec/ld.so/ldd/ldd.c
+++ b/libexec/ld.so/ldd/ldd.c
@@ -1,19 +1,19 @@
-/* $OpenBSD: ldd.c,v 1.8 2002/02/20 03:56:48 jason Exp $ */
+/* $OpenBSD: ldd.c,v 1.9 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 2001 Artur Grabowski <art@openbsd.org>
- * All rights reserved.
+ * All rights reserved.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * 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.
+ * 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. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
+ * derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
@@ -24,7 +24,7 @@
* 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.
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
@@ -94,7 +94,6 @@ doit(char *name)
{
Elf_Ehdr ehdr;
Elf_Phdr *phdr;
- char *buf;
int fd, i, size, status;
printf("%s:\n", name);
@@ -165,5 +164,3 @@ doit(char *name)
return 0;
}
-
-
diff --git a/libexec/ld.so/libdl/libdl.c b/libexec/ld.so/libdl/libdl.c
index c794002c2d2..4373307e187 100644
--- a/libexec/ld.so/libdl/libdl.c
+++ b/libexec/ld.so/libdl/libdl.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: libdl.c,v 1.1 2000/06/13 03:34:09 rahnds Exp $ */
+/* $OpenBSD: libdl.c,v 1.2 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -45,33 +45,39 @@ void *dlsym(void *handle, const char *name) __attribute__((weak));
int dlctl(void *handle, int command, void *data) __attribute__((weak));
int dlclose(void *handle)__attribute__((weak));
const char * dlerror() __attribute__((weak));
+#include <stdio.h>
void *
dlopen(const char *libname, int how)
{
printf("ERROR! libdl incorrectly linked!\n");
+ return NULL;
}
void *
dlsym(void *handle, const char *name)
{
printf("ERROR! libdl incorrectly linked!\n");
+ return NULL;
}
int
dlctl(void *handle, int command, void *data)
{
printf("ERROR! libdl incorrectly linked!\n");
+ return 0;
}
int
dlclose(void *handle)
{
printf("ERROR! libdl incorrectly linked!\n");
+ return 0;
}
const char *
dlerror()
{
printf("ERROR! libdl incorrectly linked!\n");
+ return "ERROR! libdl incorrectly linked!\n";
}
diff --git a/libexec/ld.so/library.c b/libexec/ld.so/library.c
index 72dd02012bc..5d3195568d5 100644
--- a/libexec/ld.so/library.c
+++ b/libexec/ld.so/library.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: library.c,v 1.10 2001/09/22 04:33:36 drahn Exp $ */
+/* $OpenBSD: library.c,v 1.11 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -49,9 +49,9 @@
(((X) & PF_W) ? PROT_WRITE : 0) | \
(((X) & PF_X) ? PROT_EXEC : 0))
-elf_object_t * _dl_tryload_shlib(const char *libname, int type);
-void _dl_build_sod(const char *name, struct sod *sodp);
-char * _dl_findhint(char *name, int major, int minor, char *prefered_path);
+elf_object_t *_dl_tryload_shlib(const char *libname, int type);
+void _dl_build_sod(const char *name, struct sod *sodp);
+char *_dl_findhint(char *name, int major, int minor, char *prefered_path);
/*
* Load a shared object. Search order is:
@@ -72,7 +72,7 @@ _dl_load_shlib(const char *libname, elf_object_t *parent, int type)
struct sod sodp;
char *hint;
- if(_dl_strchr(libname, '/')) {
+ if (_dl_strchr(libname, '/')) {
object = _dl_tryload_shlib(libname, type);
return(object);
}
@@ -81,27 +81,26 @@ _dl_load_shlib(const char *libname, elf_object_t *parent, int type)
* No '/' in name. Scan the known places, LD_LIBRARY_PATH first.
*/
pp = _dl_libpath;
- while(pp) {
+ while (pp) {
const char *ln = libname;
path = lp;
- while(path < lp + PATH_MAX && *pp && *pp != ':' && *pp != ';') {
+ while (path < lp + PATH_MAX && *pp && *pp != ':' && *pp != ';')
*path++ = *pp++;
- }
- if(path != lp && *(path - 1) != '/') { /* Insert '/' */
+ /* Insert '/' */
+ if (path != lp && *(path - 1) != '/')
*path++ = '/';
- }
- while(path < lp + PATH_MAX && (*path++ = *ln++)) {};
- if(path < lp + PATH_MAX) {
+
+ while (path < lp + PATH_MAX && (*path++ = *ln++))
+ ;
+ if (path < lp + PATH_MAX) {
object = _dl_tryload_shlib(lp, type);
- if(object) {
+ if (object)
return(object);
- }
}
- if(*pp) { /* Try curdir if ':' at end */
+ if (*pp) { /* Try curdir if ':' at end */
pp++;
- }
- else {
+ } else {
pp = 0;
}
}
@@ -110,38 +109,35 @@ _dl_load_shlib(const char *libname, elf_object_t *parent, int type)
* Check DT_RPATH.
*/
pp = parent->dyn.rpath;
- while(pp) {
+ while (pp) {
const char *ln = libname;
path = lp;
- while(path < lp + PATH_MAX && *pp && *pp != ':') {
+ while (path < lp + PATH_MAX && *pp && *pp != ':')
*path++ = *pp++;
- }
- if(*(path - 1) != '/') {/* Make sure '/' after dir path */
+ /* Make sure '/' after dir path */
+ if (*(path - 1) != '/')
*path++ = '/';
- }
- while(path < lp + PATH_MAX && (*path++ = *ln++)) {};
- if(path < lp + PATH_MAX) {
+
+ while (path < lp + PATH_MAX && (*path++ = *ln++))
+ ;
+ if (path < lp + PATH_MAX) {
object = _dl_tryload_shlib(lp, type);
- if(object) {
+ if (object)
return(object);
- }
}
- if(*pp) { /* Try curdir if ':' at end */
+ if (*pp) { /* Try curdir if ':' at end */
pp++;
- }
- else {
+ } else {
pp = 0;
}
}
_dl_build_sod(libname, &sodp);
if ((hint = _dl_findhint((char *)sodp.sod_name, sodp.sod_major,
- sodp.sod_minor, NULL)) != NULL)
- {
+ sodp.sod_minor, NULL)) != NULL) {
object = _dl_tryload_shlib(hint, type);
return(object);
-
}
@@ -151,10 +147,11 @@ _dl_load_shlib(const char *libname, elf_object_t *parent, int type)
_dl_strcpy(lp, "/usr/lib/");
path = lp + sizeof("/usr/lib/") - 1;
- while(path < lp + PATH_MAX && (*path++ = *libname++)) {};
- if(path < lp + PATH_MAX) {
+ while (path < lp + PATH_MAX && (*path++ = *libname++))
+ ;
+ if (path < lp + PATH_MAX) {
object = _dl_tryload_shlib(lp, type);
- if(object) {
+ if (object) {
return(object);
}
}
@@ -167,7 +164,7 @@ _dl_load_list_free(load_list_t *load_list)
{
load_list_t *next;
- while(load_list != NULL) {
+ while (load_list != NULL) {
next = load_list->next;
_dl_free(load_list);
load_list = next;
@@ -177,7 +174,7 @@ _dl_load_list_free(load_list_t *load_list)
void
_dl_unload_shlib(elf_object_t *object)
{
- if(--object->refcount == 0) {
+ if (--object->refcount == 0) {
_dl_load_list_free(object->load_list);
_dl_munmap((void *)object->load_addr, object->load_size);
_dl_remove_object(object);
@@ -190,7 +187,7 @@ _dl_tryload_shlib(const char *libname, int type)
{
int libfile;
int i;
- char hbuf[4096];
+ char hbuf[4096];
Elf_Ehdr *ehdr;
Elf_Phdr *phdp;
Elf_Dyn *dynp = 0;
@@ -203,20 +200,20 @@ _dl_tryload_shlib(const char *libname, int type)
load_list_t *next_load, *load_list = NULL;
object = _dl_lookup_object(libname);
- if(object) {
+ if (object) {
object->refcount++;
return(object); /* Already loaded */
}
libfile = _dl_open(libname, O_RDONLY);
- if(libfile < 0) {
+ if (libfile < 0) {
_dl_errno = DL_CANT_OPEN;
return(0);
}
_dl_read(libfile, hbuf, sizeof(hbuf));
ehdr = (Elf_Ehdr *)hbuf;
- if(_dl_strncmp(ehdr->e_ident, ELFMAG, SELFMAG) ||
+ if (_dl_strncmp(ehdr->e_ident, ELFMAG, SELFMAG) ||
ehdr->e_type != ET_DYN || ehdr->e_machine != MACHID) {
_dl_close(libfile);
_dl_errno = DL_NOT_ELF;
@@ -229,13 +226,13 @@ _dl_tryload_shlib(const char *libname, int type)
*/
phdp = (Elf_Phdr *)(hbuf + ehdr->e_phoff);
- for(i = 0; i < ehdr->e_phnum; i++, phdp++) {
- switch(phdp->p_type) {
+ for (i = 0; i < ehdr->e_phnum; i++, phdp++) {
+ switch (phdp->p_type) {
case PT_LOAD:
- if(phdp->p_vaddr < minva) {
+ if (phdp->p_vaddr < minva) {
minva = phdp->p_vaddr;
}
- if(phdp->p_vaddr + phdp->p_memsz > maxva) {
+ if (phdp->p_vaddr + phdp->p_memsz > maxva) {
maxva = phdp->p_vaddr + phdp->p_memsz;
}
break;
@@ -257,9 +254,9 @@ _dl_tryload_shlib(const char *libname, int type)
*/
libaddr = (Elf_Addr)_dl_mmap(0, maxva - minva, PROT_NONE,
MAP_PRIVATE|MAP_ANON, -1, 0);
- if(_dl_check_error(libaddr)) {
+ if (_dl_check_error(libaddr)) {
_dl_printf("%s: rtld mmap failed mapping %s.\n",
- _dl_progname, libname);
+ _dl_progname, libname);
_dl_close(libfile);
_dl_errno = DL_CANT_MMAP;
return(0);
@@ -268,24 +265,24 @@ _dl_tryload_shlib(const char *libname, int type)
loff = libaddr - minva;
phdp = (Elf_Phdr *)(hbuf + ehdr->e_phoff);
- for(i = 0; i < ehdr->e_phnum; i++, phdp++) {
- if(phdp->p_type == PT_LOAD) {
+ for (i = 0; i < ehdr->e_phnum; i++, phdp++) {
+ if (phdp->p_type == PT_LOAD) {
int res;
char *start = (char *)(phdp->p_vaddr & ~align) + loff;
int size = (phdp->p_vaddr & align) + phdp->p_filesz;
res = _dl_mmap(start, size, PFLAGS(phdp->p_flags),
- MAP_FIXED|MAP_PRIVATE, libfile,
- phdp->p_offset & ~align);
+ MAP_FIXED|MAP_PRIVATE, libfile,
+ phdp->p_offset & ~align);
next_load = (load_list_t *)_dl_malloc(
- sizeof(load_list_t));
+ sizeof(load_list_t));
next_load->next = load_list;
load_list = next_load;
next_load->start = start;
next_load->size = size;
next_load->prot = PFLAGS(phdp->p_flags);
- if(_dl_check_error(res)) {
+ if (_dl_check_error(res)) {
_dl_printf("%s: rtld mmap failed mapping %s.\n",
- _dl_progname, libname);
+ _dl_progname, libname);
_dl_close(libfile);
_dl_errno = DL_CANT_MMAP;
_dl_munmap((void *)libaddr, maxva - minva);
@@ -293,20 +290,19 @@ _dl_tryload_shlib(const char *libname, int type)
return(0);
}
if (phdp->p_flags & PF_W) {
- if(size & align) {
+ if (size & align)
_dl_memset(start + size, 0,
- _dl_pagesz - (size & align));
- }
+ _dl_pagesz - (size & align));
start = start + ((size + align) & ~align);
size = size - (phdp->p_vaddr & align);
size = phdp->p_memsz - size;
res = _dl_mmap(start, size,
- PFLAGS(phdp->p_flags),
- MAP_FIXED|MAP_PRIVATE|MAP_ANON,
- -1, 0);
- if(_dl_check_error(res)) {
+ PFLAGS(phdp->p_flags),
+ MAP_FIXED|MAP_PRIVATE|MAP_ANON,
+ -1, 0);
+ if (_dl_check_error(res)) {
_dl_printf("%s: rtld mmap failed mapping %s.\n",
- _dl_progname, libname);
+ _dl_progname, libname);
_dl_close(libfile);
_dl_errno = DL_CANT_MMAP;
_dl_munmap((void *)libaddr, maxva - minva);
@@ -320,7 +316,7 @@ _dl_tryload_shlib(const char *libname, int type)
dynp = (Elf_Dyn *)((unsigned long)dynp + loff);
object = _dl_add_object(libname, dynp, 0, type, libaddr, loff);
- if(object) {
+ if (object) {
object->load_size = maxva - minva; /*XXX*/
object->load_list = load_list;
} else {
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c
index 66f28e8c7a2..2dc60778e7f 100644
--- a/libexec/ld.so/loader.c
+++ b/libexec/ld.so/loader.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: loader.c,v 1.28 2002/03/31 21:56:58 drahn Exp $ */
+/* $OpenBSD: loader.c,v 1.29 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -70,26 +70,22 @@ _dl_debug_state(void)
/*
* Routine to walk thru all of the objects except the first (main executable).
*/
-
void
_dl_run_dtors(elf_object_t *object)
{
DL_DEB(("doing dtors: [%s]\n", object->load_name));
- if (object->dyn.fini) {
+ if (object->dyn.fini)
(*object->dyn.fini)();
- }
- if (object->next) {
+ if (object->next)
_dl_run_dtors(object->next);
- }
}
void
_dl_dtors(void)
{
DL_DEB(("doing dtors\n"));
- if (_dl_objects->next) {
+ if (_dl_objects->next)
_dl_run_dtors(_dl_objects->next);
- }
}
/*
@@ -121,11 +117,11 @@ _dl_boot(const char **argv, const char **envp, const long loff,
_dl_debug = _dl_getenv("LD_DEBUG", envp);
_dl_progname = argv[0];
- if (dl_data[AUX_pagesz] != 0) {
+ if (dl_data[AUX_pagesz] != 0)
_dl_pagesz = dl_data[AUX_pagesz];
- } else {
+ else
_dl_pagesz = 4096;
- }
+
DL_DEB(("rtld loading: '%s'\n", _dl_progname));
/*
@@ -133,12 +129,10 @@ _dl_boot(const char **argv, const char **envp, const long loff,
* a suid program without credentials high enough.
*/
if (_dl_issetugid()) { /* Zap paths if s[ug]id... */
- if (_dl_preload) {
+ if (_dl_preload)
*_dl_preload = '\0';
- }
- if (_dl_libpath) {
+ if (_dl_libpath)
*_dl_libpath = '\0';
- }
}
/*
@@ -151,9 +145,8 @@ _dl_boot(const char **argv, const char **envp, const long loff,
(Elf_Dyn *)phdp->p_vaddr, dl_data, OBJTYPE_EXE,
0, 0);
}
- if (phdp->p_type == PT_INTERP) {
+ if (phdp->p_type == PT_INTERP)
us = _dl_strdup((char *)phdp->p_vaddr);
- }
phdp++;
}
@@ -175,7 +168,7 @@ _dl_boot(const char **argv, const char **envp, const long loff,
DL_DEB(("needs: '%s'\n", libname));
if (_dl_load_shlib(libname, dynobj, OBJTYPE_LIB) == 0) {
_dl_printf("%s: can't load library '%s'\n",
- _dl_progname, libname);
+ _dl_progname, libname);
_dl_exit(4);
}
}
@@ -194,19 +187,17 @@ _dl_boot(const char **argv, const char **envp, const long loff,
* Everything should be in place now for doing the relocation
* and binding. Call _dl_rtld to do the job. Fingers crossed.
*/
-
_dl_rtld(_dl_objects);
/*
- * The first object is the executable itself,
+ * The first object is the executable itself,
* it is responsible for running it's own ctors/dtors
* thus do NOT run the ctors for the executable, all of
* the shared libraries which follow.
* Do not run init code if run from ldd.
*/
- if ((_dl_traceld == NULL) && (_dl_objects->next != NULL)) {
+ if ((_dl_traceld == NULL) && (_dl_objects->next != NULL))
_dl_call_init(_dl_objects->next);
- }
/*
* Schedule a routine to be run at shutdown, by using atexit.
@@ -262,9 +253,8 @@ _dl_boot(const char **argv, const char **envp, const long loff,
_dl_show_objects();
DL_DEB(("dynamic loading done.\n"));
}
- if (_dl_traceld) {
+ if (_dl_traceld)
_dl_exit(0);
- }
DL_DEB(("entry point: 0x%lx\n", dl_data[AUX_entry]));
/*
@@ -294,7 +284,8 @@ _dl_boot_bind(const long sp, long loff, Elf_Dyn *dynamicp, long *dl_data)
argv = (char **)stack;
envp = &argv[argc + 1];
stack = (long *)envp;
- while(*stack++ != NULL) {};
+ while (*stack++ != NULL)
+ ;
/*
* Zero out dl_data.
@@ -332,11 +323,11 @@ _dl_boot_bind(const long sp, long loff, Elf_Dyn *dynamicp, long *dl_data)
dynp = (Elf_Dyn *)((long)_DYNAMIC + loff);
#endif
while (dynp != NULL && dynp->d_tag != DT_NULL) {
- if (dynp->d_tag < DT_LOPROC) {
+ if (dynp->d_tag < DT_LOPROC)
dynld.Dyn.info[dynp->d_tag] = dynp->d_un.d_val;
- } else if (dynp->d_tag >= DT_LOPROC && dynp->d_tag < DT_LOPROC + DT_NUM) {
- dynld.Dyn.info[dynp->d_tag + DT_NUM - DT_LOPROC] = dynp->d_un.d_val;
- }
+ else if (dynp->d_tag >= DT_LOPROC && dynp->d_tag < DT_LOPROC + DT_NUM)
+ dynld.Dyn.info[dynp->d_tag + DT_NUM - DT_LOPROC] =
+ dynp->d_un.d_val;
if (dynp->d_tag == DT_TEXTREL)
dynld.dyn.textrel = 1;
dynp++;
@@ -352,7 +343,8 @@ _dl_boot_bind(const long sp, long loff, Elf_Dyn *dynamicp, long *dl_data)
{
int i, val;
/* must be code, not pic data */
- int table[20];
+ int table[20];
+
i = 0;
table[i++] = DT_PLTGOT;
table[i++] = DT_HASH;
@@ -397,8 +389,8 @@ _dl_boot_bind(const long sp, long loff, Elf_Dyn *dynamicp, long *dl_data)
/* cannot printf in this function */
_dl_wrstderr("Dynamic loader failure: self bootstrapping impossible.\n");
_dl_wrstderr("Undefined symbol: ");
- _dl_wrstderr((char *)dynld.dyn.strtab
- + sp->st_name);
+ _dl_wrstderr((char *)dynld.dyn.strtab +
+ sp->st_name);
#endif
_dl_exit(5);
}
@@ -447,9 +439,7 @@ _dl_boot_bind(const long sp, long loff, Elf_Dyn *dynamicp, long *dl_data)
}
ra = (Elf_Addr *)(rp->r_offset + loff);
-
RELOC_RELA(rp, sp, ra, loff);
-
rp++;
}
}
@@ -463,20 +453,18 @@ _dl_boot_bind(const long sp, long loff, Elf_Dyn *dynamicp, long *dl_data)
void
_dl_rtld(elf_object_t *object)
{
- if (object->next) {
+ if (object->next)
_dl_rtld(object->next);
- }
/*
* Do relocation information first, then GOT.
*/
_dl_md_reloc(object, DT_REL, DT_RELSZ);
_dl_md_reloc(object, DT_RELA, DT_RELASZ);
- if (_dl_bindnow || object->dyn.bind_now) { /* XXX Perhaps more checking ? */
+ if (_dl_bindnow || object->dyn.bind_now) /* XXX Perhaps more checking ? */
_dl_md_reloc_got(object, 0);
- } else {
+ else
_dl_md_reloc_got(object, 1);
- }
object->status |= STAT_RELOC_DONE;
}
@@ -486,18 +474,15 @@ _dl_call_init(elf_object_t *object)
Elf_Addr ooff;
const Elf_Sym *sym;
- if (object->next) {
+ if (object->next)
_dl_call_init(object->next);
- }
- if (object->status & STAT_INIT_DONE) {
+ if (object->status & STAT_INIT_DONE)
return;
- }
#ifndef __mips__
- if(object->dyn.init) {
+ if (object->dyn.init)
(*object->dyn.init)();
- }
/*
* XXX We perform relocation of DTOR/CTOR. This is a ld bug problem
* XXX that should be fixed.
@@ -506,17 +491,15 @@ _dl_call_init(elf_object_t *object)
ooff = _dl_find_symbol("__CTOR_LIST__", object, &sym, 1, 1);
if (sym != NULL) {
int i = *(int *)(sym->st_value + ooff);
- while(i--) {
+ while (i--)
*(int *)(sym->st_value + ooff + 4 + 4 * i) += ooff;
- }
}
sym = NULL;
ooff = _dl_find_symbol("__DTOR_LIST__", object, &sym, 1, 1);
if (sym != NULL) {
int i = *(int *)(sym->st_value + ooff);
- while(i--) {
+ while (i--)
*(int *)(sym->st_value + ooff + 4 + 4 * i) += ooff;
- }
}
/*
@@ -531,9 +514,8 @@ _dl_call_init(elf_object_t *object)
(*(void(*)(void))(sym->st_value + ooff))();
}
#if 0 /*XXX*/
- if (object->dyn.init) {
+ if (object->dyn.init)
(*object->dyn.init)();
- }
#endif
#endif /* __mips__ */
object->status |= STAT_INIT_DONE;
@@ -551,10 +533,8 @@ _dl_getenv(const char *var, const char **env)
vp++;
ep++;
}
- if (*vp == '\0' && *ep++ == '=') {
+ if (*vp == '\0' && *ep++ == '=')
return((char *)ep);
- }
}
-
return(0);
}
diff --git a/libexec/ld.so/mips/archdep.h b/libexec/ld.so/mips/archdep.h
index e5d8c41e612..f25c00f51dd 100644
--- a/libexec/ld.so/mips/archdep.h
+++ b/libexec/ld.so/mips/archdep.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: archdep.h,v 1.2 2002/02/21 23:17:53 drahn Exp $ */
+/* $OpenBSD: archdep.h,v 1.3 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
diff --git a/libexec/ld.so/mips/ldasm.S b/libexec/ld.so/mips/ldasm.S
index a39428f61fd..e4216d38b7f 100644
--- a/libexec/ld.so/mips/ldasm.S
+++ b/libexec/ld.so/mips/ldasm.S
@@ -1,8 +1,8 @@
-/* $OpenBSD: ldasm.S,v 1.1 2000/06/13 03:34:13 rahnds Exp $ */
+/* $OpenBSD: ldasm.S,v 1.2 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -49,7 +49,7 @@ LEAF(_dl_start) /* Not really LEAF, but we simplify */
move t9, v0 # Entry address from _dl_boot.
j t9 # Go execute the 'real' program.
-
+
END(_dl_start)
diff --git a/libexec/ld.so/mips/rtld_machine.c b/libexec/ld.so/mips/rtld_machine.c
index cd6416390ce..8e57fe3f4b2 100644
--- a/libexec/ld.so/mips/rtld_machine.c
+++ b/libexec/ld.so/mips/rtld_machine.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: rtld_machine.c,v 1.1 2000/06/13 03:34:15 rahnds Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.2 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -55,46 +55,43 @@ _dl_md_reloc(elf_object_t *object, int rel, int relsz)
numrel = object->Dyn.info[relsz] / sizeof(Elf32_Rel);
relocs = (Elf32_Rel *)(object->Dyn.info[rel]);
- if((object->status & STAT_RELOC_DONE) || !relocs) {
+ if ((object->status & STAT_RELOC_DONE) || !relocs) {
return(0);
}
- for(i = 0; i < numrel; i++, relocs++) {
+ for (i = 0; i < numrel; i++, relocs++) {
Elf32_Addr r_addr = relocs->r_offset + loff;
Elf32_Addr ooff;
const Elf32_Sym *sym, *this;
const char *symn;
- if(ELF32_R_SYM(relocs->r_info) == 0xffffff) {
+ if (ELF32_R_SYM(relocs->r_info) == 0xffffff)
continue;
- }
sym = object->dyn.symtab;
sym += ELF32_R_SYM(relocs->r_info);
this = sym;
symn = object->dyn.strtab + sym->st_name;
- if(ELF32_R_SYM(relocs->r_info) &&
+ if (ELF32_R_SYM(relocs->r_info) &&
!(ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
ELF32_ST_TYPE (sym->st_info) == STT_NOTYPE)) {
-
- ooff = _dl_find_symbol(symn, _dl_objects, &this, 0);
- if(!this && ELF32_ST_BIND(sym->st_info) == STB_GLOBAL) {
+ ooff = _dl_find_symbol(symn, _dl_objects, &this, 0, 1);
+ if (!this && ELF32_ST_BIND(sym->st_info) == STB_GLOBAL) {
_dl_printf("%s: can't resolve reference '%s'\n",
- _dl_progname, symn);
+ _dl_progname, symn);
fails++;
}
}
- switch(ELF32_R_TYPE(relocs->r_info)) {
+ switch (ELF32_R_TYPE(relocs->r_info)) {
case R_MIPS_REL32:
- if(ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
+ if (ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
(ELF32_ST_TYPE(sym->st_info) == STT_SECTION ||
ELF32_ST_TYPE(sym->st_info) == STT_NOTYPE) ) {
*(u_int32_t *)r_addr += loff;
- }
- else if(this) {
+ } else if (this) {
*(u_int32_t *)r_addr += this->st_value + ooff;
}
break;
@@ -138,7 +135,7 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
gotp = object->dyn.pltgot;
n = object->Dyn.info[DT_MIPS_LOCAL_GOTNO - DT_LOPROC + DT_NUM];
- if(object->status & STAT_GOT_DONE) {
+ if (object->status & STAT_GOT_DONE) {
return;
}
@@ -146,19 +143,19 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
* Set up pointers for run time (lazy) resolving.
*/
gotp[0] = (int)_dl_rt_resolve;
- if(gotp[1] & 0x80000000) {
+ if (gotp[1] & 0x80000000) {
gotp[1] = (int)object | 0x80000000;
}
/*
* First do all local references.
*/
- for(i = ((gotp[1] & 0x80000000) ? 2 : 1); i < n; i++) {
+ for (i = ((gotp[1] & 0x80000000) ? 2 : 1); i < n; i++) {
gotp[i] += loff;
}
gotp += n;
-
+
symp = object->dyn.symtab;
symp += object->Dyn.info[DT_MIPS_GOTSYM - DT_LOPROC + DT_NUM];
n = object->Dyn.info[DT_MIPS_SYMTABNO - DT_LOPROC + DT_NUM] -
@@ -168,35 +165,31 @@ _dl_md_reloc_got(elf_object_t *object, int lazy)
* Then do all global references according to the ABI.
* Quickstart is not yet implemented.
*/
- while(n--) {
- if(symp->st_shndx == SHN_UNDEF &&
+ while (n--) {
+ if (symp->st_shndx == SHN_UNDEF &&
ELF32_ST_TYPE(symp->st_info) == STT_FUNC) {
_dl_printf("undef: %s = %X\n", strt + symp->st_name, symp->st_value);
- if(symp->st_value == 0 || !lazy) {
+ if (symp->st_value == 0 || !lazy) {
this = 0;
ooff = _dl_find_symbol(strt + symp->st_name,
- _dl_objects, &this, 0);
- if(this) {
+ _dl_objects, &this, 0, 1);
+ if (this) {
*gotp = this->st_value + ooff;
}
- }
- else {
+ } else {
*gotp = symp->st_value + ooff;
}
- }
- else if(symp->st_shndx == SHN_COMMON ||
+ } else if (symp->st_shndx == SHN_COMMON ||
symp->st_shndx == SHN_UNDEF) {
this = 0;
ooff = _dl_find_symbol(strt + symp->st_name,
- _dl_objects, &this, 0);
- if(this) {
+ _dl_objects, &this, 0, 1);
+ if (this) {
*gotp = this->st_value + ooff;
}
- }
- else if(ELF32_ST_TYPE(symp->st_info) == STT_FUNC) {
+ } else if (ELF32_ST_TYPE(symp->st_info) == STT_FUNC) {
*gotp += loff;
- }
- else { /* XXX ??? */ /* Resolve all others immediatly */
+ } else { /* XXX ??? */ /* Resolve all others immediatly */
*gotp = symp->st_value + loff;
}
gotp++;
diff --git a/libexec/ld.so/mips/syscall.h b/libexec/ld.so/mips/syscall.h
index dd92915c265..baff785e39c 100644
--- a/libexec/ld.so/mips/syscall.h
+++ b/libexec/ld.so/mips/syscall.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: syscall.h,v 1.2 2002/02/21 23:17:53 drahn Exp $ */
+/* $OpenBSD: syscall.h,v 1.3 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -44,7 +44,7 @@
#define _dl_MAX_ERRNO 4096
#endif
#define _dl_check_error(__res) \
- ((int) __res < 0 && (int) __res >= -_dl_MAX_ERRNO)
+ ((int) __res < 0 && (int) __res >= -_dl_MAX_ERRNO)
/*
* Inlined system call functions that can be used before
@@ -53,196 +53,207 @@
extern inline int
_dl_exit (int status)
-{
- register int __status __asm__ ("$2");
- __asm__ volatile ("move $4,%2\n\t"
- "syscall"
- : "=r" (__status)
- : "0" (SYS_exit), "r" (status)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- while(1);
-}
+{
+ register int __status __asm__ ("$2");
+
+ __asm__ volatile ("move $4,%2\n\t"
+ "syscall"
+ : "=r" (__status)
+ : "0" (SYS_exit), "r" (status)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ while (1)
+ ;
+}
extern inline int
_dl_open (const char* addr, unsigned int flags)
-{
- register int status __asm__ ("$2");
- __asm__ volatile ("move $4,%2\n\t"
- "move $5,%3\n\t"
- "syscall\n\t"
- "beq $7,$0,1f\n\t"
- "li $2,-1\n\t"
- "1:"
- : "=r" (status)
- : "0" (SYS_open), "r" (addr), "r" (flags)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- return status;
-}
+{
+ register int status __asm__ ("$2");
+
+ __asm__ volatile ("move $4,%2\n\t"
+ "move $5,%3\n\t"
+ "syscall\n\t"
+ "beq $7,$0,1f\n\t"
+ "li $2,-1\n\t"
+ "1:"
+ : "=r" (status)
+ : "0" (SYS_open), "r" (addr), "r" (flags)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ return status;
+}
extern inline int
_dl_close (int fd)
-{
- register int status __asm__ ("$2");
- __asm__ volatile ("move $4,%2\n\t"
- "syscall\n\t"
- "beq $7,$0,1f\n\t"
- "li $2,-1\n\t"
- "1:"
- : "=r" (status)
- : "0" (SYS_close), "r" (fd)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- return status;
-}
+{
+ register int status __asm__ ("$2");
+
+ __asm__ volatile ("move $4,%2\n\t"
+ "syscall\n\t"
+ "beq $7,$0,1f\n\t"
+ "li $2,-1\n\t"
+ "1:"
+ : "=r" (status)
+ : "0" (SYS_close), "r" (fd)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ return status;
+}
extern inline int
_dl_write (int fd, const char* buf, int len)
-{
- register int status __asm__ ("$2");
- __asm__ volatile ("move $4,%2\n\t"
- "move $5,%3\n\t"
- "move $6,%4\n\t"
- "syscall\n\t"
- "beq $7,$0,1f\n\t"
- "li $2,-1\n\t"
- "1:"
- : "=r" (status)
- : "0" (SYS_write), "r" (fd), "r" (buf), "r" (len)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- return status;
-}
+{
+ register int status __asm__ ("$2");
+
+ __asm__ volatile ("move $4,%2\n\t"
+ "move $5,%3\n\t"
+ "move $6,%4\n\t"
+ "syscall\n\t"
+ "beq $7,$0,1f\n\t"
+ "li $2,-1\n\t"
+ "1:"
+ : "=r" (status)
+ : "0" (SYS_write), "r" (fd), "r" (buf), "r" (len)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ return status;
+}
extern inline int
_dl_read (int fd, const char* buf, int len)
-{
- register int status __asm__ ("$2");
- __asm__ volatile ("move $4,%2\n\t"
- "move $5,%3\n\t"
- "move $6,%4\n\t"
- "syscall\n\t"
- "beq $7,$0,1f\n\t"
- "li $2,-1\n\t"
- "1:"
- : "=r" (status)
- : "0" (SYS_read), "r" (fd), "r" (buf), "r" (len)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- return status;
-}
+{
+ register int status __asm__ ("$2");
+
+ __asm__ volatile ("move $4,%2\n\t"
+ "move $5,%3\n\t"
+ "move $6,%4\n\t"
+ "syscall\n\t"
+ "beq $7,$0,1f\n\t"
+ "li $2,-1\n\t"
+ "1:"
+ : "=r" (status)
+ : "0" (SYS_read), "r" (fd), "r" (buf), "r" (len)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ return status;
+}
extern inline int
_dl_mmap (void *addr, unsigned int size, unsigned int prot,
- unsigned int flags, int fd, unsigned int f_offset)
-{
- register int malloc_buffer __asm__ ("$2");
- __asm__ volatile ("addiu $29,-40\n\t"
- "move $6,%2\n\t"
- "move $7,%3\n\t"
- "sw %4,16($29)\n\t"
- "sw %5,20($29)\n\t"
+ unsigned int flags, int fd, unsigned int f_offset)
+{
+ register int malloc_buffer __asm__ ("$2");
+
+ __asm__ volatile ("addiu $29,-40\n\t"
+ "move $6,%2\n\t"
+ "move $7,%3\n\t"
+ "sw %4,16($29)\n\t"
+ "sw %5,20($29)\n\t"
#ifdef MIPSEL
- "li $4,197\n\t"
- "li $5,0\n\t"
- "sw %6,24($29)\n\t"
- "sw $0,28($29)\n\t"
- "sw %7,32($29)\n\t"
- "sw $0,36($29)\n\t"
+ "li $4,197\n\t"
+ "li $5,0\n\t"
+ "sw %6,24($29)\n\t"
+ "sw $0,28($29)\n\t"
+ "sw %7,32($29)\n\t"
+ "sw $0,36($29)\n\t"
#endif
#ifdef MIPSEB
- "li $4,0\n\t"
- "li $5,197\n\t"
- "sw %6,24($29)\n\t"
- "sw $0,28($29)\n\t"
- "sw $0,32($29)\n\t"
- "sw %7,36($29)\n\t"
+ "li $4,0\n\t"
+ "li $5,197\n\t"
+ "sw %6,24($29)\n\t"
+ "sw $0,28($29)\n\t"
+ "sw $0,32($29)\n\t"
+ "sw %7,36($29)\n\t"
#endif
- "syscall\n\t"
- "addiu $29,40"
- : "=r" (malloc_buffer)
- : "0" (SYS___syscall), "r" (addr), "r" (size), "r" (prot),
- "r" (flags), "r" (fd), "r" (f_offset)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- return malloc_buffer;
-}
+ "syscall\n\t"
+ "addiu $29,40"
+ : "=r" (malloc_buffer)
+ : "0" (SYS___syscall), "r" (addr), "r" (size), "r" (prot),
+ "r" (flags), "r" (fd), "r" (f_offset)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ return malloc_buffer;
+}
extern inline int
_dl_munmap (const void* addr, unsigned int len)
-{
- register int status __asm__ ("$2");
- __asm__ volatile ("move $4,%2\n\t"
- "move $5,%3\n\t"
- "syscall\n\t"
- "beq $7,$0,1f\n\t"
- "li $2,-1\n\t"
- "1:"
- : "=r" (status)
- : "0" (SYS_munmap), "r" (addr), "r" (len)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- return status;
-}
+{
+ register int status __asm__ ("$2");
+
+ __asm__ volatile ("move $4,%2\n\t"
+ "move $5,%3\n\t"
+ "syscall\n\t"
+ "beq $7,$0,1f\n\t"
+ "li $2,-1\n\t"
+ "1:"
+ : "=r" (status)
+ : "0" (SYS_munmap), "r" (addr), "r" (len)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ return status;
+}
extern inline int
_dl_mprotect (const void *addr, int size, int prot)
-{
- register int status __asm__ ("$2");
- __asm__ volatile ("move $4,%2\n\t"
- "move $5,%3\n\t"
- "move $6,%4\n\t"
- "syscall"
- : "=r" (status)
- : "0" (SYS_mprotect), "r" (addr), "r" (size), "r" (prot)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- return status;
-}
+{
+ register int status __asm__ ("$2");
+
+ __asm__ volatile ("move $4,%2\n\t"
+ "move $5,%3\n\t"
+ "move $6,%4\n\t"
+ "syscall"
+ : "=r" (status)
+ : "0" (SYS_mprotect), "r" (addr), "r" (size), "r" (prot)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ return status;
+}
#ifdef USE_CACHE
extern inline int
_dl_stat (const char *addr, struct stat *sb)
-{
- register int status __asm__ ("$2");
- __asm__ volatile ("move $4,%2\n\t"
- "move $5,%3\n\t"
- "syscall"
- : "=r" (status)
- : "0" (SYS_stat), "r" (addr), "r" (sb)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- return status;
-}
+{
+ register int status __asm__ ("$2");
-#endif
+ __asm__ volatile ("move $4,%2\n\t"
+ "move $5,%3\n\t"
+ "syscall"
+ : "=r" (status)
+ : "0" (SYS_stat), "r" (addr), "r" (sb)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ return status;
+}
-/* Not an actual syscall, but we need something in assembly to say
- whether this is OK or not. */
+#endif
+/*
+ * Not an actual syscall, but we need something in assembly to say
+ * whether this is OK or not.
+ */
extern inline int
_dl_suid_ok (void)
{
- unsigned int uid, euid, gid, egid;
-
- __asm__ volatile ("move $2,%1; syscall; move %0,$2"
- : "=r" (uid) : "r" (SYS_getuid)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- __asm__ volatile ("move $2,%1; syscall; move %0,$2"
- : "=r" (euid) : "r" (SYS_geteuid)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- __asm__ volatile ("move $2,%1; syscall; move %0,$2"
- : "=r" (gid) : "r" (SYS_getgid)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
- __asm__ volatile ("move $2,%1; syscall; move %0,$2"
- : "=r" (egid) : "r" (SYS_getegid)
- : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
- "$10","$11","$12","$13","$14","$15","$24","$25");
-
- return (uid == euid && gid == egid);
+ unsigned int uid, euid, gid, egid;
+
+ __asm__ volatile ("move $2,%1; syscall; move %0,$2"
+ : "=r" (uid) : "r" (SYS_getuid)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ __asm__ volatile ("move $2,%1; syscall; move %0,$2"
+ : "=r" (euid) : "r" (SYS_geteuid)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ __asm__ volatile ("move $2,%1; syscall; move %0,$2"
+ : "=r" (gid) : "r" (SYS_getgid)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+ __asm__ volatile ("move $2,%1; syscall; move %0,$2"
+ : "=r" (egid) : "r" (SYS_getegid)
+ : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9",
+ "$10","$11","$12","$13","$14","$15","$24","$25");
+
+ return (uid == euid && gid == egid);
}
#endif /*__DL_SYSCALL_H__*/
diff --git a/libexec/ld.so/powerpc/archdep.h b/libexec/ld.so/powerpc/archdep.h
index d544e286524..c813c70a985 100644
--- a/libexec/ld.so/powerpc/archdep.h
+++ b/libexec/ld.so/powerpc/archdep.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: archdep.h,v 1.5 2002/04/29 15:52:30 drahn Exp $ */
+/* $OpenBSD: archdep.h,v 1.6 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -49,7 +49,7 @@
/* HACK */
#define DT_PROCNUM 0
-#ifndef DT_BIND_NOW
+#ifndef DT_BIND_NOW
#define DT_BIND_NOW 0
#endif
@@ -71,24 +71,23 @@ _dl_dcbf(Elf32_Addr *addr)
static inline void
RELOC_RELA(Elf32_Rela *r, const Elf32_Sym *s, Elf32_Addr *p, unsigned long v)
{
- if(ELF32_R_TYPE(r->r_info) == RELOC_RELATIVE) {
+ if (ELF32_R_TYPE(r->r_info) == RELOC_RELATIVE) {
*p = v + r->r_addend;
- } else if(ELF32_R_TYPE(r->r_info) == RELOC_JMP_SLOT) {
+ } else if (ELF32_R_TYPE(r->r_info) == RELOC_JMP_SLOT) {
Elf32_Addr val = v + s->st_value + r->r_addend -
- (Elf32_Addr)(p);
- if (((val & 0xfe000000) != 0) &&
- ((val & 0xfe000000) != 0xfe000000))
- {
- /* invalid offset */
- _dl_exit(20);
- }
- val &= ~0xfc000000;
+ (Elf32_Addr)(p);
+ if (((val & 0xfe000000) != 0) &&
+ ((val & 0xfe000000) != 0xfe000000)) {
+ /* invalid offset */
+ _dl_exit(20);
+ }
+ val &= ~0xfc000000;
val |= 0x48000000;
- *p = val;
+ *p = val;
_dl_dcbf(p);
- } else if(ELF32_R_TYPE((r)->r_info) == RELOC_GLOB_DAT) {
+ } else if (ELF32_R_TYPE((r)->r_info) == RELOC_GLOB_DAT) {
*p = v + s->st_value + r->r_addend;
- } else {
+ } else {
/* XXX - printf might not work here, but we give it a shot. */
_dl_printf("Unknown bootstrap relocation.\n");
_dl_exit(6);
diff --git a/libexec/ld.so/powerpc/ldasm.S b/libexec/ld.so/powerpc/ldasm.S
index 6b2542315be..e7e929825bd 100644
--- a/libexec/ld.so/powerpc/ldasm.S
+++ b/libexec/ld.so/powerpc/ldasm.S
@@ -1,8 +1,8 @@
-/* $OpenBSD: ldasm.S,v 1.2 2001/09/24 21:35:09 drahn Exp $ */
+/* $OpenBSD: ldasm.S,v 1.3 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -45,7 +45,7 @@
#include <machine/asm.h>
-ENTRY(_dl_start)
+ENTRY(_dl_start)
mr 19, 1
stwu 1, (-16 -((AUX_entry+3)*4))(1) # Some space.
@@ -60,7 +60,7 @@ ENTRY(_dl_start)
.local .L___offset_sym
.type .L___offset_sym,@function
- bl 1f
+ bl 1f
.L___offset_sym:
# this instruction never gets executed but can be used
# to find the virtual address where the page is loaded.
@@ -81,7 +81,7 @@ ENTRY(_dl_start)
*/
add 28, 18, 5
- li 0, 0
+ li 0, 0
dcbf 5, 18
sync
isync
@@ -92,7 +92,7 @@ ENTRY(_dl_start)
isync
addi 28, 28, 4
- mr 29, 28
+ mr 29, 28
lwz 30, 0(28) # this loads the first entry of the GOT
# thus forcing it to be paged in when
@@ -104,8 +104,8 @@ ENTRY(_dl_start)
mflr 28
- lwz 4, .L___offset_sym@got(28)
- mr 6, 4 # make copy of register for debugging
+ lwz 4, .L___offset_sym@got(28)
+ mr 6, 4 # make copy of register for debugging
/* This cheats and calculates the address of _DYNAMIC
* the same way that the GLOBAL_OFFSET_TABLE was calcuated
@@ -134,7 +134,7 @@ ENTRY(_dl_start)
bl _dl_boot@local
- mtctr 3 # put return value into ctr to execute
+ mtctr 3 # put return value into ctr to execute
# get back the squirreled away the arguments for main
mr 3, 20
@@ -145,7 +145,7 @@ ENTRY(_dl_start)
mtlr 27
lwz 1, 0(1) # Restore stack pointer.
- bctr # Go execute the 'real' program.
+ bctr # Go execute the 'real' program.
.globl _dl_rt_resolve
.data
diff --git a/libexec/ld.so/powerpc/rtld_machine.c b/libexec/ld.so/powerpc/rtld_machine.c
index 172a9ccea81..1354b90393a 100644
--- a/libexec/ld.so/powerpc/rtld_machine.c
+++ b/libexec/ld.so/powerpc/rtld_machine.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: rtld_machine.c,v 1.5 2001/08/05 15:31:35 drahn Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.6 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -47,13 +47,11 @@
void
_dl_bcopy(void *src, void *dest, int size)
{
- unsigned char *psrc, *pdest;
+ unsigned char *psrc = src, *pdest = dest;
int i;
- psrc = src;
- pdest = dest;
- for (i = 0; i < size; i++) {
+
+ for (i = 0; i < size; i++)
pdest[i] = psrc[i];
- }
}
int
@@ -69,7 +67,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz)
Elf32_Addr *pltcall;
Elf32_Addr *plttable;
- Elf32_Addr * first_rela;
+ Elf32_Addr *first_rela;
loff = object->load_offs;
numrela = object->Dyn.info[relasz] / sizeof(Elf32_Rela);
@@ -80,37 +78,35 @@ _dl_printf("object relocation size %x, numrela %x\n",
object->Dyn.info[relasz], numrela);
#endif
- if((object->status & STAT_RELOC_DONE) || !relas) {
+ if ((object->status & STAT_RELOC_DONE) || !relas)
return(0);
- }
+
/* for plt relocation usage */
if (object->Dyn.info[DT_JMPREL] != 0) {
/* resolver stub not set up */
Elf32_Addr val;
first_rela = (Elf32_Addr *)
- (((Elf32_Rela *)(object->Dyn.info[DT_JMPREL]))->r_offset
- + loff);
+ (((Elf32_Rela *)(object->Dyn.info[DT_JMPREL]))->r_offset +
+ loff);
/* Need to construct table to do jumps */
pltcall = (Elf32_Addr *)(first_rela) - 12;
#ifdef DL_PRINTF_DEBUG
-_dl_printf("creating pltcall at %x\n", pltcall);
-_dl_printf("md_reloc( jumprel %x\n", first_rela );
+ _dl_printf("creating pltcall at %x\n", pltcall);
+ _dl_printf("md_reloc(jumprel %x\n", first_rela);
#endif
plttable = (Elf32_Addr *)
- ((Elf32_Addr)first_rela) + (2 *
- (object->Dyn.info[DT_PLTRELSZ]/sizeof(Elf32_Rela))
- );
+ ((Elf32_Addr)first_rela) + (2 *
+ (object->Dyn.info[DT_PLTRELSZ]/sizeof(Elf32_Rela)));
#ifdef DL_PRINTF_DEBUG
-_dl_printf("md_reloc: plttbl size %x\n",
- (object->Dyn.info[DT_PLTRELSZ]/sizeof(Elf32_Rela))
-);
-_dl_printf("md_reloc: plttable %x\n", plttable);
+ _dl_printf("md_reloc: plttbl size %x\n",
+ (object->Dyn.info[DT_PLTRELSZ]/sizeof(Elf32_Rela)));
+ _dl_printf("md_reloc: plttable %x\n", plttable);
#endif
pltcall[-1]= 0x504c5400; /* PLT tag :-) */
val = ((Elf32_Addr)plttable >> 16) +
- (((Elf32_Addr)plttable & 0x00008000) >> 15);
+ (((Elf32_Addr)plttable & 0x00008000) >> 15);
pltcall[0] = 0x3d6b0000 | val; /* addis r11,r11,.PLTtable@ha*/
val = (Elf32_Addr)plttable & 0x0000ffff;
pltcall[1] = 0x816b0000 | val; /* lwz r11,plttable@l(r11) */
@@ -128,79 +124,73 @@ _dl_printf("md_reloc: plttable %x\n", plttable);
* relocation restore protection.
*/
load_list = object->load_list;
- while(load_list != NULL) {
+ while (load_list != NULL) {
_dl_mprotect(load_list->start, load_list->size,
- load_list->prot|PROT_WRITE);
+ load_list->prot|PROT_WRITE);
load_list = load_list->next;
}
- for(i = 0; i < numrela; i++, relas++) {
+ for (i = 0; i < numrela; i++, relas++) {
Elf32_Addr *r_addr = (Elf32_Addr *)(relas->r_offset + loff);
Elf32_Addr ooff;
const Elf32_Sym *sym, *this;
const char *symn;
- if(ELF32_R_SYM(relas->r_info) == 0xffffff) {
+ if (ELF32_R_SYM(relas->r_info) == 0xffffff)
continue;
- }
sym = object->dyn.symtab;
sym += ELF32_R_SYM(relas->r_info);
this = sym;
symn = object->dyn.strtab + sym->st_name;
- if(ELF32_R_SYM(relas->r_info) &&
- !(ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
- ELF32_ST_TYPE (sym->st_info) == STT_NOTYPE)) {
-
+ if (ELF32_R_SYM(relas->r_info) &&
+ !(ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
+ ELF32_ST_TYPE (sym->st_info) == STT_NOTYPE)) {
ooff = _dl_find_symbol(symn, _dl_objects, &this, 0, 0);
- if(!this && ELF32_ST_BIND(sym->st_info) == STB_GLOBAL) {
- _dl_printf("%s:"
- " %s :can't resolve reference '%s'\n",
- _dl_progname, object->load_name,
- symn);
+ if (!this && ELF32_ST_BIND(sym->st_info) == STB_GLOBAL) {
+ _dl_printf("%s: %s :can't resolve reference '%s'\n",
+ _dl_progname, object->load_name, symn);
fails++;
}
-
}
- switch(ELF32_R_TYPE(relas->r_info)) {
+ switch (ELF32_R_TYPE(relas->r_info)) {
#if 1
case RELOC_32:
- if(ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
+ if (ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
(ELF32_ST_TYPE(sym->st_info) == STT_SECTION ||
ELF32_ST_TYPE(sym->st_info) == STT_NOTYPE) ) {
*r_addr = ooff + relas->r_addend;
} else {
*r_addr = ooff + this->st_value +
- relas->r_addend;
+ relas->r_addend;
}
break;
#endif
case RELOC_RELATIVE:
- if(ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
+ if (ELF32_ST_BIND(sym->st_info) == STB_LOCAL &&
(ELF32_ST_TYPE(sym->st_info) == STT_SECTION ||
ELF32_ST_TYPE(sym->st_info) == STT_NOTYPE) ) {
*r_addr = loff + relas->r_addend;
#ifdef DL_PRINTF_DEBUG
_dl_printf("rel1 r_addr %x val %x loff %x ooff %x addend %x\n", r_addr,
-loff + relas->r_addend, loff, ooff, relas->r_addend);
+ loff + relas->r_addend, loff, ooff, relas->r_addend);
#endif
} else {
*r_addr = loff + this->st_value +
- relas->r_addend;
+ relas->r_addend;
}
break;
case RELOC_JMP_SLOT:
{
Elf32_Addr val = ooff + this->st_value +
- relas->r_addend - (Elf32_Addr)r_addr;
- if (!(((val & 0xfe000000) == 0x00000000) ||
- ((val & 0xfe000000) == 0xfe000000)))
- {
+ relas->r_addend - (Elf32_Addr)r_addr;
+ if (!(((val & 0xfe000000) == 0x00000000) ||
+ ((val & 0xfe000000) == 0xfe000000))) {
int index;
#ifdef DL_PRINTF_DEBUG
_dl_printf(" ooff %x, sym val %x, addend %x"
@@ -212,27 +202,25 @@ _dl_printf(" ooff %x, sym val %x, addend %x"
index = (r_addr - first_rela) >> 1;
if (index > (2 << 14)) {
-
/* addis r11,r11,.PLTtable@ha*/
val = (index*4 >> 16) +
- ((index*4 & 0x00008000) >> 15);
+ ((index*4 & 0x00008000) >> 15);
r_addr[0] = 0x3d600000 | val;
val = (Elf32_Addr)pltcall -
- (Elf32_Addr)&r_addr[2];
- r_addr[1] = 0x396b0000 | val;
+ (Elf32_Addr)&r_addr[2];
+ r_addr[1] = 0x396b0000 | val;
val &= ~0xfc000000;
val |= 0x48000000;
r_addr[2] = val;
-
} else {
#ifdef DL_PRINTF_DEBUG
- _dl_printf(" index %d, pltcall %x r_addr %x\n",
- index, pltcall, r_addr);
+_dl_printf(" index %d, pltcall %x r_addr %x\n",
+ index, pltcall, r_addr);
#endif
r_addr[0] = 0x39600000 | (index * 4);
val = (Elf32_Addr)pltcall -
- (Elf32_Addr)&r_addr[1];
+ (Elf32_Addr)&r_addr[1];
val &= ~0xfc000000;
val |= 0x48000000;
r_addr[1] = val;
@@ -241,18 +229,18 @@ _dl_printf(" ooff %x, sym val %x, addend %x"
_dl_dcbf(r_addr);
_dl_dcbf(&r_addr[2]);
val= ooff + this->st_value +
- relas->r_addend;
+ relas->r_addend;
#ifdef DL_PRINTF_DEBUG
- _dl_printf(" symn [%s] val 0x%x\n", symn, val);
+_dl_printf(" symn [%s] val 0x%x\n", symn, val);
#endif
plttable[index] = val;
} else {
- /* if the offset is small enough,
+ /* if the offset is small enough,
* branch directy to the dest
*/
val &= ~0xfc000000;
val |= 0x48000000;
- *r_addr = val;
+ *r_addr = val;
_dl_dcbf(r_addr);
}
}
@@ -264,144 +252,140 @@ _dl_printf(" ooff %x, sym val %x, addend %x"
#if 1
/* should not be supported ??? */
case RELOC_REL24:
- {
+ {
Elf32_Addr val = ooff + this->st_value +
- relas->r_addend - (Elf32_Addr)r_addr;
- if ((val & 0xfe000000 != 0) &&
- (val & 0xfe000000 != 0xfe000000)) {
+ relas->r_addend - (Elf32_Addr)r_addr;
+ if (((val & 0xfe000000) != 0) &&
+ ((val & 0xfe000000) != 0xfe000000)) {
/* invalid offset */
_dl_exit(20);
}
val &= ~0xfc000003;
val |= (*r_addr & 0xfc000003);
- *r_addr = val;
+ *r_addr = val;
_dl_dcbf(r_addr);
- }
+ }
break;
#endif
#if 1
case RELOC_16_LO:
- {
+ {
Elf32_Addr val;
val = loff + relas->r_addend;
*(Elf32_Half *)r_addr = val;
_dl_dcbf(r_addr);
- }
+ }
break;
#endif
#if 1
case RELOC_16_HI:
- {
+ {
Elf32_Addr val;
val = loff + relas->r_addend;
*(Elf32_Half *)r_addr = (val >> 16);
_dl_dcbf(r_addr);
- }
+ }
break;
#endif
#if 1
case RELOC_16_HA:
- {
+ {
Elf32_Addr val;
val = loff + relas->r_addend;
*(Elf32_Half *)r_addr = ((val + 0x8000) >> 16);
_dl_dcbf(r_addr);
- }
+ }
break;
-#endif
+#endif
case RELOC_REL14_TAKEN:
/* val |= 1 << (31-10) XXX? */
case RELOC_REL14:
case RELOC_REL14_NTAKEN:
- {
+ {
Elf32_Addr val = ooff + this->st_value +
- relas->r_addend - (Elf32_Addr)r_addr;
+ relas->r_addend - (Elf32_Addr)r_addr;
if (((val & 0xffff8000) != 0) &&
- ((val & 0xffff8000) != 0xffff8000))
- {
+ ((val & 0xffff8000) != 0xffff8000)) {
/* invalid offset */
_dl_exit(20);
}
val &= ~0xffff0003;
val |= (*r_addr & 0xffff0003);
- *r_addr = val;
+ *r_addr = val;
#ifdef DL_PRINTF_DEBUG
- _dl_printf("rel 14 %x val %x\n",
- r_addr, val);
+ _dl_printf("rel 14 %x val %x\n", r_addr, val);
#endif
-
+
_dl_dcbf(r_addr);
- }
+ }
break;
case RELOC_COPY:
#ifdef DL_PRINTF_DEBUG
_dl_printf("copy r_addr %x, sym %x [%s] size %d val %x\n",
- r_addr, sym, symn, sym->st_size,
- (ooff + this->st_value+
- relas->r_addend)
-
- );
+ r_addr, sym, symn, sym->st_size,
+ (ooff + this->st_value+
+ relas->r_addend));
#endif
-{
- /* we need to find a symbol, that is not in the current object,
- * start looking at the beginning of the list, searching all objects
- * but _not_ the current object, first one found wins.
- */
- elf_object_t *cobj;
- const Elf32_Sym *cpysrc = NULL;
- Elf32_Addr src_loff;
- int size;
- for (cobj = _dl_objects;
- cobj != NULL && cpysrc == NULL;
- cobj = cobj->next)
- {
- if (object != cobj) {
-
- /* only look in this object */
- src_loff = _dl_find_symbol(symn, cobj,
- &cpysrc, 1, 1);
- }
- }
- if (cpysrc == NULL) {
- _dl_printf("symbol not found [%s] \n", symn);
- } else {
- size = sym->st_size;
- if (sym->st_size != cpysrc->st_size) {
- _dl_printf("symbols size differ [%s] \n", symn);
- size = sym->st_size < cpysrc->st_size ?
- sym->st_size : cpysrc->st_size;
- }
+ {
+ /*
+ * we need to find a symbol, that is not in the current
+ * object, start looking at the beginning of the list,
+ * searching all objects but _not_ the current object,
+ * first one found wins.
+ */
+ elf_object_t *cobj;
+ const Elf32_Sym *cpysrc = NULL;
+ Elf32_Addr src_loff;
+ int size;
+ for (cobj = _dl_objects; cobj != NULL && cpysrc == NULL;
+ cobj = cobj->next) {
+ if (object != cobj) {
+ /* only look in this object */
+ src_loff = _dl_find_symbol(symn, cobj,
+ &cpysrc, 1, 1);
+ }
+ }
+ if (cpysrc == NULL) {
+ _dl_printf("symbol not found [%s] \n", symn);
+ } else {
+ size = sym->st_size;
+ if (sym->st_size != cpysrc->st_size) {
+ _dl_printf("symbols size differ [%s] \n",
+ symn);
+ size = sym->st_size < cpysrc->st_size ?
+ sym->st_size : cpysrc->st_size;
+ }
#ifdef DL_PRINTF_DEBUG
-_dl_printf(" found other symbol at %x size %d\n",
- src_loff + cpysrc->st_value, cpysrc->st_size);
+_dl_printf(" found other symbol at %x size %d\n",
+ src_loff + cpysrc->st_value, cpysrc->st_size);
#endif
- _dl_bcopy((void *)(src_loff + cpysrc->st_value),
- (void *)(ooff + this->st_value+ relas->r_addend),
- size);
- }
-}
+ _dl_bcopy((void *)(src_loff + cpysrc->st_value),
+ (void *)(ooff + this->st_value+ relas->r_addend),
+ size);
+ }
+ }
break;
case RELOC_NONE:
break;
default:
_dl_printf("%s:"
- " %s: unsupported relocation '%s' %d at %x\n",
- _dl_progname, object->load_name, symn,
- ELF32_R_TYPE(relas->r_info), r_addr );
+ " %s: unsupported relocation '%s' %d at %x\n",
+ _dl_progname, object->load_name, symn,
+ ELF32_R_TYPE(relas->r_info), r_addr );
_dl_exit(1);
}
}
object->status |= STAT_RELOC_DONE;
load_list = object->load_list;
- while(load_list != NULL) {
+ while (load_list != NULL) {
_dl_mprotect(load_list->start, load_list->size, load_list->prot);
load_list = load_list->next;
}
diff --git a/libexec/ld.so/powerpc/syscall.h b/libexec/ld.so/powerpc/syscall.h
index d539e591e65..6cdf53e20b5 100644
--- a/libexec/ld.so/powerpc/syscall.h
+++ b/libexec/ld.so/powerpc/syscall.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: syscall.h,v 1.5 2002/03/17 00:22:04 art Exp $ */
+/* $OpenBSD: syscall.h,v 1.6 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -53,19 +53,20 @@
static inline int
_dl_exit (int status)
-{
+{
register int __status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"mr 3,%2\n\t"
"sc"
: "=r" (__status)
: "r" (SYS_exit), "r" (status) : "0", "3");
- while(1);
-}
+ while (1)
+ ;
+}
static inline int
_dl_open (const char* addr, unsigned int flags)
-{
+{
register int status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"mr 3,%2\n\t"
@@ -79,11 +80,11 @@ _dl_open (const char* addr, unsigned int flags)
: "r" (SYS_open), "r" (addr), "r" (flags)
: "0", "3", "4" );
return status;
-}
+}
static inline int
_dl_close (int fd)
-{
+{
register int status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"mr 3,%2\n\t"
@@ -96,11 +97,11 @@ _dl_close (int fd)
: "r" (SYS_close), "r" (fd)
: "0", "3");
return status;
-}
+}
static inline int
_dl_write (int fd, const char* buf, int len)
-{
+{
register int status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"mr 3,%2\n\t"
@@ -115,11 +116,11 @@ _dl_write (int fd, const char* buf, int len)
: "r" (SYS_write), "r" (fd), "r" (buf), "r" (len)
: "0", "3", "4", "5" );
return status;
-}
+}
static inline int
_dl_read (int fd, const char* buf, int len)
-{
+{
register int status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"mr 3,%2\n\t"
@@ -134,7 +135,7 @@ _dl_read (int fd, const char* buf, int len)
: "r" (SYS_read), "r" (fd), "r" (buf), "r" (len)
: "0", "3", "4", "5");
return status;
-}
+}
#define STRINGIFY(x) #x
#define XSTRINGIFY(x) STRINGIFY(x)
@@ -153,14 +154,14 @@ __asm__(".align 2\n\t"
static int
_dl_mmap (void *addr, unsigned int len, unsigned int prot,
unsigned int flags, int fd, off_t offset)
-{
+{
return((int)_dl__syscall((quad_t)SYS_mmap, addr, len, prot,
flags, fd, 0, offset));
}
static inline int
_dl_munmap (const void* addr, unsigned int len)
-{
+{
register int status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"mr 3,%2\n\t"
@@ -174,11 +175,11 @@ _dl_munmap (const void* addr, unsigned int len)
: "r" (SYS_munmap), "r" (addr), "r" (len)
: "0", "3", "4");
return status;
-}
+}
static inline int
_dl_mprotect (const void *addr, int size, int prot)
-{
+{
register int status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"mr 3,%2\n\t"
@@ -193,12 +194,12 @@ _dl_mprotect (const void *addr, int size, int prot)
: "r" (SYS_mprotect), "r" (addr), "r" (size), "r" (prot)
: "0", "3", "4", "5");
return status;
-}
+}
#ifdef USE_CACHE
static inline int
_dl_stat (const char *addr, struct stat *sb)
-{
+{
register int status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"mr 3,%2\n\t"
@@ -212,13 +213,13 @@ _dl_stat (const char *addr, struct stat *sb)
: "r" (SYS_stat), "r" (addr), "r" (sb)
: "0", "3", "4");
return status;
-}
+}
#endif
static inline int
_dl_issetugid()
-{
+{
register int status __asm__ ("3");
__asm__ volatile ("mr 0,%1\n\t"
"sc\n\t"
@@ -230,6 +231,6 @@ _dl_issetugid()
: "r" (SYS_issetugid)
: "0", "3");
return status;
-}
+}
#include <elf_abi.h>
#endif /*__DL_SYSCALL_H__*/
diff --git a/libexec/ld.so/resolve.c b/libexec/ld.so/resolve.c
index ad3fb94dedf..b608495aa59 100644
--- a/libexec/ld.so/resolve.c
+++ b/libexec/ld.so/resolve.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: resolve.c,v 1.7 2002/03/17 04:46:53 drahn Exp $ */
+/* $OpenBSD: resolve.c,v 1.8 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -57,7 +57,7 @@ _dl_add_object(const char *objname, Elf_Dyn *dynp, const u_long *dl_data,
elf_object_t *object;
#if 0
_dl_printf("objname [%s], dynp %p, dl_data %p, objtype %x laddr %lx, loff %lx\n",
- objname, dynp, dl_data, objtype, laddr, loff);
+ objname, dynp, dl_data, objtype, laddr, loff);
#endif
object = _dl_malloc(sizeof(elf_object_t));
@@ -93,27 +93,27 @@ d_un.d_val;
* Now relocate all pointer to dynamic info, but only
* the ones which has pointer values.
*/
- if(object->Dyn.info[DT_PLTGOT])
+ if (object->Dyn.info[DT_PLTGOT])
object->Dyn.info[DT_PLTGOT] += loff;
- if(object->Dyn.info[DT_HASH])
+ if (object->Dyn.info[DT_HASH])
object->Dyn.info[DT_HASH] += loff;
- if(object->Dyn.info[DT_STRTAB])
+ if (object->Dyn.info[DT_STRTAB])
object->Dyn.info[DT_STRTAB] += loff;
- if(object->Dyn.info[DT_SYMTAB])
+ if (object->Dyn.info[DT_SYMTAB])
object->Dyn.info[DT_SYMTAB] += loff;
- if(object->Dyn.info[DT_RELA])
+ if (object->Dyn.info[DT_RELA])
object->Dyn.info[DT_RELA] += loff;
- if(object->Dyn.info[DT_SONAME])
+ if (object->Dyn.info[DT_SONAME])
object->Dyn.info[DT_SONAME] += loff;
- if(object->Dyn.info[DT_RPATH])
+ if (object->Dyn.info[DT_RPATH])
object->Dyn.info[DT_RPATH] += object->Dyn.info[DT_STRTAB];
- if(object->Dyn.info[DT_REL])
+ if (object->Dyn.info[DT_REL])
object->Dyn.info[DT_REL] += loff;
- if(object->Dyn.info[DT_INIT])
+ if (object->Dyn.info[DT_INIT])
object->Dyn.info[DT_INIT] += loff;
- if(object->Dyn.info[DT_FINI])
+ if (object->Dyn.info[DT_FINI])
object->Dyn.info[DT_FINI] += loff;
- if(object->Dyn.info[DT_JMPREL])
+ if (object->Dyn.info[DT_JMPREL])
object->Dyn.info[DT_JMPREL] += loff;
if (object->Dyn.info[DT_HASH] != 0) {
@@ -134,27 +134,25 @@ d_un.d_val;
object->load_offs = loff;
object->load_name = _dl_strdup(objname);
object->refcount = 1;
-
return(object);
}
-
void
_dl_remove_object(elf_object_t *object)
{
elf_object_t *depobj;
object->prev->next = object->next;
- if(object->next) {
+ if (object->next)
object->next->prev = object->prev;
- }
- if (_dl_last_object == object) {
+
+ if (_dl_last_object == object)
_dl_last_object = object->prev;
- }
- if(object->load_name) {
+
+ if (object->load_name)
_dl_free(object->load_name);
- }
- while((depobj = object->dep_next)) {
+
+ while ((depobj = object->dep_next)) {
object->dep_next = object->dep_next->dep_next;
_dl_free(depobj);
}
@@ -168,10 +166,9 @@ _dl_lookup_object(const char *name)
elf_object_t *object;
object = _dl_objects;
- while(object) {
- if(_dl_strcmp(name, object->load_name) == 0) {
+ while (object) {
+ if (_dl_strcmp(name, object->load_name) == 0)
return(object);
- }
object = object->next;
}
return(0);
@@ -191,41 +188,33 @@ _dl_find_symbol(const char *name, elf_object_t *startlook,
while (*p) {
unsigned long g;
h = (h << 4) + *p++;
- if((g = h & 0xf0000000)) {
+ if ((g = h & 0xf0000000)) {
h ^= g >> 24;
}
h &= ~g;
}
for (object = startlook; object; object = (myself ? 0 : object->next)) {
- const Elf_Sym *symt;
- const char *strt;
+ const Elf_Sym *symt = object->dyn.symtab;
+ const char *strt = object->dyn.strtab;
long si;
- symt = object->dyn.symtab;
- strt = object->dyn.strtab;
-
-
for (si = object->buckets[h % object->nbuckets];
si != STN_UNDEF; si = object->chains[si]) {
const Elf_Sym *sym = symt + si;
if (sym->st_value == 0 ||
- sym->st_shndx == SHN_UNDEF) {
+ sym->st_shndx == SHN_UNDEF)
continue;
- }
if (ELF_ST_TYPE(sym->st_info) != STT_NOTYPE &&
ELF_ST_TYPE(sym->st_info) != STT_OBJECT &&
- ELF_ST_TYPE(sym->st_info) != STT_FUNC) {
+ ELF_ST_TYPE(sym->st_info) != STT_FUNC)
continue;
- }
-
if (sym != *ref &&
- _dl_strcmp(strt + sym->st_name, name)) {
+ _dl_strcmp(strt + sym->st_name, name))
continue;
- }
if (ELF_ST_BIND(sym->st_info) == STB_GLOBAL) {
*ref = sym;
@@ -243,10 +232,9 @@ _dl_find_symbol(const char *name, elf_object_t *startlook,
*ref &&
ELF_ST_BIND((*ref)->st_info) != STB_WEAK) {
_dl_printf("%s: undefined symbol '%s'\n",
- _dl_progname, name);
+ _dl_progname, name);
}
}
*ref = weak_sym;
return(weak_offs);
}
-
diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h
index 0d06bfb482a..bad0cc391af 100644
--- a/libexec/ld.so/resolve.h
+++ b/libexec/ld.so/resolve.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: resolve.h,v 1.8 2002/03/17 00:22:04 art Exp $ */
+/* $OpenBSD: resolve.h,v 1.9 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
diff --git a/libexec/ld.so/sod.c b/libexec/ld.so/sod.c
index e29f1fec1ed..8bd1ab81b00 100644
--- a/libexec/ld.so/sod.c
+++ b/libexec/ld.so/sod.c
@@ -1,5 +1,6 @@
-/* $OpenBSD: sod.c,v 1.8 2002/02/21 23:17:53 drahn Exp $ */
-/*
+/* $OpenBSD: sod.c,v 1.9 2002/05/24 03:44:37 deraadt Exp $ */
+
+/*
* Copyright (c) 1993 Paul Kranenburg
* All rights reserved.
*
@@ -172,9 +173,8 @@ _dl_maphints()
if (hheader->hh_ehints > hsize) {
if ((caddr_t)_dl_mmap(addr+hsize, hheader->hh_ehints - hsize,
- PROT_READ, MAP_PRIVATE|MAP_FIXED,
- hfd, hsize) != (caddr_t)(addr+hsize)) {
-
+ PROT_READ, MAP_PRIVATE|MAP_FIXED,
+ hfd, hsize) != (caddr_t)(addr+hsize)) {
_dl_munmap((caddr_t)hheader, hsize);
_dl_close(hfd);
hheader = (struct hints_header *)-1;
@@ -203,14 +203,12 @@ _dl_findhint(name, major, minor, prefered_path)
* hints, if previous attempts failed hheader is -1 and we
* do not wish to retry it.
*/
- if (hheader == NULL) {
+ if (hheader == NULL)
_dl_maphints();
- }
/* if it failed to map, return failure */
- if (!(HINTS_VALID)) {
+ if (!(HINTS_VALID))
return NULL;
- }
bp = hbuckets + (_dl_hinthash(name, major, minor) % hheader->hh_nbucket);
@@ -233,10 +231,9 @@ _dl_findhint(name, major, minor, prefered_path)
(bp->hi_ndewey < 2 || bp->hi_minor >= minor)) {
if (prefered_path == NULL ||
strncmp(prefered_path,
- hstrtab + bp->hi_pathx,
- _dl_strlen(prefered_path)) == 0) {
+ hstrtab + bp->hi_pathx,
+ _dl_strlen(prefered_path)) == 0)
return hstrtab + bp->hi_pathx;
- }
}
}
diff --git a/libexec/ld.so/sparc64/archdep.h b/libexec/ld.so/sparc64/archdep.h
index 29477a75c80..6ced3ab80b3 100644
--- a/libexec/ld.so/sparc64/archdep.h
+++ b/libexec/ld.so/sparc64/archdep.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: archdep.h,v 1.7 2002/04/24 21:58:15 drahn Exp $ */
+/* $OpenBSD: archdep.h,v 1.8 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -52,7 +52,7 @@
static inline long
_dl_mmap(void *addr, unsigned int len, unsigned int prot,
unsigned int flags, int fd, off_t offset)
-{
+{
return(_dl___syscall((quad_t)SYS_mmap, addr, len, prot,
flags, fd, 0, offset));
}
diff --git a/libexec/ld.so/sparc64/ldasm.S b/libexec/ld.so/sparc64/ldasm.S
index a466cb5b260..201b4074a9c 100644
--- a/libexec/ld.so/sparc64/ldasm.S
+++ b/libexec/ld.so/sparc64/ldasm.S
@@ -1,6 +1,6 @@
-/* $OpenBSD: ldasm.S,v 1.9 2002/03/17 00:22:04 art Exp $ */
+/* $OpenBSD: ldasm.S,v 1.10 2002/05/24 03:44:38 deraadt Exp $ */
/* $NetBSD: rtld_start.S,v 1.5 2001/08/14 22:17:48 eeh Exp $ */
-
+
/*
* Copyright (c) 2001 Jason L. Wright (jason@thought.net)
* All rights reserved.
@@ -83,11 +83,11 @@
* _rtld() expects the stack pointer to point to two longwords for argument
* return followed by argc, etc. We need to create a pointer to
* &argc + 16 and pass that in. The return args will be in those locations.
- *
+ *
* NB: We are violating the ELF spec by passing a pointer to the ps strings in
- * %g1 instead of a termination routine.
+ * %g1 instead of a termination routine.
*/
-
+
/* Offset of ARGC from bottom of stack */
#define ARGC (16*8)
/* XXX - DL_DATA_SIZE should be (9*8), but I can't think right now. */
@@ -140,7 +140,7 @@ _dl_start:
*
* The first two entries of PLT2 contain the xword object pointer.
*
- * These routines are called with two longword arguments,
+ * These routines are called with two longword arguments,
* x and y. To calculate the address of the entry,
* _dl_bind_start_1(x, y) does:
*
@@ -156,7 +156,7 @@ _dl_start:
*/
/* NOTE: _dl_bind_start_0 is untested. Hence the debug stuff */
-
+
.section ".text"
.align 4
.global _dl_bind_start_0
@@ -166,7 +166,7 @@ _dl_bind_start_0: # (x, y)
call _dl_bind_start_0_stub
ldx [%o1 + (10*4)], %l7
mov %o0, %o1
-
+
call _dl_bind
mov %l7, %o0
#else
@@ -178,7 +178,7 @@ _dl_bind_start_0: # (x, y)
sdivx %l0, 5120, %l1 /* Calculate i/5120 */
ldx [%o1 + (10*4)], %o0 /* Load object pointer from PLT2 */
sub %l0, %l1, %l2 /* And i%5120 */
-
+
/* Let the division churn for a bit. */
sdivx %l2, 14, %l4 /* (i%5120)/24 */
@@ -190,29 +190,28 @@ _dl_bind_start_0: # (x, y)
sethi %hi(32768), %l6
add %l3, %l4, %l5 /* %l5 = (i/5120)*160 + (i%5120)/24; */
add %l5, %l6, %l5
-
+
call _dl_bind /* Call _dl_bind(obj, offset) */
mov %l5, %o1
jmp %o0 /* return value == function address */
restore /* Dump our stack frame */
-#endif
-
+#endif
+
.section ".text"
.align 4
.global _dl_bind_start_1
.type _dl_bind_start_1,@function
_dl_bind_start_1: # (x, y)
srax %o0, 15, %o2 /* %o0 is the index to our PLT slot */
-
+
ldx [%o1 + 8], %o0 /* The object pointer is at [%o1 + 8] */
-
+
call _dl_bind /* Call _dl_bind(obj, offset) */
mov %o2, %o1
jmp %o0 /* return value == function address */
restore /* Dump our stack frame */
-
.section ".text"
.align 4
diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c
index 3bbe447f264..328566fbd7f 100644
--- a/libexec/ld.so/sparc64/rtld_machine.c
+++ b/libexec/ld.so/sparc64/rtld_machine.c
@@ -1,10 +1,10 @@
-/* $OpenBSD: rtld_machine.c,v 1.11 2002/03/15 14:52:39 drahn Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.12 2002/05/24 03:44:38 deraadt Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
* Copyright (c) 2001 Niklas Hallqvist
* Copyright (c) 2001 Artur Grabowski
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -85,14 +85,12 @@
void
_dl_bcopy(const void *src, void *dest, int size)
{
- const unsigned char *psrc;
- unsigned char *pdest;
+ const unsigned char *psrc = src;
+ unsigned char *pdest = dest;
int i;
- psrc = src;
- pdest = dest;
- for (i = 0; i < size; i++) {
+
+ for (i = 0; i < size; i++)
pdest[i] = psrc[i];
- }
}
/*
@@ -116,7 +114,7 @@ _dl_bcopy(const void *src, void *dest, int size)
#define _RF_B 0x08000000 /* Load address relative */
#define _RF_U 0x04000000 /* Unaligned */
#define _RF_SZ(s) (((s) & 0xff) << 8) /* memory target size */
-#define _RF_RS(s) ( (s) & 0xff) /* right shift */
+#define _RF_RS(s) ((s) & 0xff) /* right shift */
static int reloc_target_flags[] = {
0, /* NONE */
_RF_S|_RF_A| _RF_SZ(8) | _RF_RS(0), /* RELOC_8 */
@@ -194,7 +192,7 @@ static long reloc_target_bitmask[] = {
_BM(22), _BM(22), /* HI22, _22 */
_BM(13), _BM(10), /* RELOC_13, _LO10 */
_BM(10), _BM(13), _BM(22), /* GOT10, GOT13, GOT22 */
- _BM(10), _BM(22), /* _PC10, _PC22 */
+ _BM(10), _BM(22), /* _PC10, _PC22 */
_BM(30), 0, /* _WPLT30, _COPY */
_BM(32), _BM(32), _BM(32), /* _GLOB_DAT, JMP_SLOT, _RELATIVE */
_BM(32), _BM(32), /* _UA32, PLT32 */
@@ -231,19 +229,17 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz)
numrela = object->Dyn.info[relasz] / sizeof(Elf64_Rela);
relas = (Elf64_Rela *)(object->Dyn.info[rel]);
- if ((object->status & STAT_RELOC_DONE) || !relas) {
+ if ((object->status & STAT_RELOC_DONE) || !relas)
return(0);
- }
/*
* unprotect some segments if we need it.
*/
if ((rel == DT_REL || rel == DT_RELA)) {
for (llist = object->load_list; llist != NULL; llist = llist->next) {
- if (!(llist->prot & PROT_WRITE)) {
+ if (!(llist->prot & PROT_WRITE))
_dl_mprotect(llist->start, llist->size,
- llist->prot|PROT_WRITE);
- }
+ llist->prot|PROT_WRITE);
}
}
@@ -282,7 +278,7 @@ _dl_md_reloc(elf_object_t *object, int rel, int relasz)
&this, 0, 1);
if (this == NULL) {
resolve_failed:
- _dl_printf("%s: %s :can't resolve "
+ _dl_printf("%s: %s: can't resolve "
"reference '%s'\n",
_dl_progname, object->load_name,
symn);
@@ -329,13 +325,10 @@ resolve_failed:
continue;
}
- if (RELOC_PC_RELATIVE(type)) {
+ if (RELOC_PC_RELATIVE(type))
value -= (Elf_Addr)where;
- }
-
- if (RELOC_BASE_RELATIVE(type)) {
+ if (RELOC_BASE_RELATIVE(type))
value += loff;
- }
mask = RELOC_VALUE_BITMASK(type);
value >>= RELOC_VALUE_RIGHTSHIFT(type);
@@ -346,7 +339,7 @@ resolve_failed:
Elf_Addr tmp = 0;
char *ptr = (char *)where;
int i, size = RELOC_TARGET_SIZE(type)/8;
-
+
/* Read it in one byte at a time. */
for (i=0; i<size; i++)
tmp = (tmp << 8) | ptr[i];
@@ -371,10 +364,9 @@ resolve_failed:
/* reprotect the unprotected segments */
if ((rel == DT_REL || rel == DT_RELA)) {
for (llist = object->load_list; llist != NULL; llist = llist->next) {
- if (!(llist->prot & PROT_WRITE)) {
+ if (!(llist->prot & PROT_WRITE))
_dl_mprotect(llist->start, llist->size,
- llist->prot);
- }
+ llist->prot);
}
}
@@ -442,7 +434,7 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
ptr[0] = value;
} else if (offset <= (1L<<20) && offset >= -(1L<<20)) {
- /*
+ /*
* We're within 1MB -- we can use a direct branch insn.
*
* We can generate this pattern:
@@ -460,7 +452,7 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
where[1] = BAA | ((offset >> 2) &0x3fffff);
__asm __volatile("iflush %0+4" : : "r" (where));
} else if (value >= 0 && value < (1L<<32)) {
- /*
+ /*
* We're withing 32-bits of address zero.
*
* The resulting code in the jump slot is:
@@ -481,7 +473,7 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
__asm __volatile("iflush %0+4" : : "r" (where));
} else if (value <= 0 && value > -(1L<<32)) {
- /*
+ /*
* We're withing 32-bits of address -1.
*
* The resulting code in the jump slot is:
@@ -504,8 +496,8 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
__asm __volatile("iflush %0+4" : : "r" (where));
} else if (offset <= (1L<<32) && offset >= -((1L<<32) - 4)) {
- /*
- * We're withing 32-bits -- we can use a direct call insn
+ /*
+ * We're withing 32-bits -- we can use a direct call insn
*
* The resulting code in the jump slot is:
*
@@ -527,7 +519,7 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
__asm __volatile("iflush %0+4" : : "r" (where));
} else if (offset >= 0 && offset < (1L<<44)) {
- /*
+ /*
* We're withing 44 bits. We can generate this pattern:
*
* The resulting code in the jump slot is:
@@ -535,8 +527,8 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
* sethi %hi(. - .PLT0), %g1
* sethi %h44(addr), %g1
* or %g1, %m44(addr), %g1
- * sllx %g1, 12, %g1
- * jmp %g1+%l44(addr)
+ * sllx %g1, 12, %g1
+ * jmp %g1+%l44(addr)
* nop
* nop
* nop
@@ -552,7 +544,7 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
__asm __volatile("iflush %0+4" : : "r" (where));
} else if (offset < 0 && offset > -(1L<<44)) {
- /*
+ /*
* We're withing 44 bits. We can generate this pattern:
*
* The resulting code in the jump slot is:
@@ -560,8 +552,8 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
* sethi %hi(. - .PLT0), %g1
* sethi %h44(-addr), %g1
* xor %g1, %m44(-addr), %g1
- * sllx %g1, 12, %g1
- * jmp %g1+%l44(addr)
+ * sllx %g1, 12, %g1
+ * jmp %g1+%l44(addr)
* nop
* nop
* nop
@@ -577,7 +569,7 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
__asm __volatile("iflush %0+4" : : "r" (where));
} else {
- /*
+ /*
* We need to load all 64-bits
*
* The resulting code in the jump slot is:
@@ -604,7 +596,6 @@ _dl_reloc_plt(Elf_Word *where, Elf_Addr value, Elf_RelA *rela)
__asm __volatile("iflush %0+12" : : "r" (where));
__asm __volatile("iflush %0+8" : : "r" (where));
__asm __volatile("iflush %0+4" : : "r" (where));
-
}
}
@@ -655,7 +646,7 @@ _dl_bind(elf_object_t *object, int index)
_dl_printf("lazy binding failed!\n");
*((int *)0) = 0; /* XXX */
}
-
+
_dl_reloc_plt(addr, ooff + this->st_value, rela);
return (void *)ooff + this->st_value;
diff --git a/libexec/ld.so/strdup.c b/libexec/ld.so/strdup.c
index 55eade02f05..9be7fa17378 100644
--- a/libexec/ld.so/strdup.c
+++ b/libexec/ld.so/strdup.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: strdup.c,v 1.5 2002/04/09 19:59:47 drahn Exp $ */
+/* $OpenBSD: strdup.c,v 1.6 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -36,12 +36,13 @@
#include <sys/types.h>
#include "archdep.h"
-void * _dl_malloc(int);
+void *_dl_malloc(int);
char *
_dl_strdup(const char *orig)
{
char *newstr;
+
newstr = _dl_malloc(_dl_strlen(orig)+1);
strcpy(newstr, orig);
return (newstr);
diff --git a/libexec/ld.so/util.c b/libexec/ld.so/util.c
index 30861a619ba..4b399fa7136 100644
--- a/libexec/ld.so/util.c
+++ b/libexec/ld.so/util.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: util.c,v 1.2 2002/04/09 19:59:47 drahn Exp $ */
+/* $OpenBSD: util.c,v 1.3 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -82,11 +82,10 @@ _dl_malloc(int size)
return((void *)t);
}
}
- if ((_dl_malloc_pool == 0) ||
- (_dl_malloc_pool + size > _dl_malloc_base + 4096)) {
+ if (_dl_malloc_pool == 0 ||
+ _dl_malloc_pool + size > _dl_malloc_base + 4096) {
_dl_malloc_pool = (void *)_dl_mmap((void *)0, 4096,
- PROT_READ|PROT_WRITE,
- MAP_ANON|MAP_PRIVATE, -1, 0);
+ PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0);
if (_dl_malloc_pool == 0 || _dl_malloc_pool == MAP_FAILED ) {
_dl_printf("Dynamic loader failure: malloc.\n");
_dl_exit(7);
diff --git a/libexec/ld.so/util.h b/libexec/ld.so/util.h
index d71f951010b..a6d1131a46e 100644
--- a/libexec/ld.so/util.h
+++ b/libexec/ld.so/util.h
@@ -1,8 +1,8 @@
-/* $OpenBSD: util.h,v 1.2 2002/04/09 19:59:47 drahn Exp $ */
+/* $OpenBSD: util.h,v 1.3 2002/05/24 03:44:37 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -47,7 +47,7 @@ void _dl_printf(const char *fmt, ...);
static inline void
_dl_wrstderr(const char *s)
{
- while(*s) {
+ while (*s) {
_dl_write(2, s, 1);
s++;
}
@@ -58,7 +58,7 @@ _dl_memset(void *p, const char v, size_t c)
{
char *ip = p;
- while(c--)
+ while (c--)
*ip++ = v;
return(p);
}
@@ -68,7 +68,7 @@ _dl_strlen(const char *p)
{
const char *s = p;
- while(*s != '\0')
+ while (*s != '\0')
s++;
return(s - p);
}
@@ -78,41 +78,39 @@ _dl_strcpy(char *d, const char *s)
{
char *rd = d;
- while((*d++ = *s++) != '\0');
-
+ while ((*d++ = *s++) != '\0')
+ ;
return(rd);
}
static inline int
_dl_strncmp(const char *d, const char *s, int c)
{
- while(c-- && *d && *d == *s) {
+ while (c-- && *d && *d == *s) {
d++;
s++;
- };
- if(c < 0) {
- return(0);
}
+ if (c < 0)
+ return(0);
return(*d - *s);
}
-
+
static inline int
_dl_strcmp(const char *d, const char *s)
{
- while(*d && *d == *s) {
+ while (*d && *d == *s) {
d++;
s++;
}
return(*d - *s);
}
-
+
static inline const char *
_dl_strchr(const char *p, const int c)
{
- while(*p) {
- if(*p == c) {
+ while (*p) {
+ if (*p == c)
return(p);
- }
p++;
}
return(0);