summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2002-02-21 23:17:54 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2002-02-21 23:17:54 +0000
commit0d541fd9920e006280e60dadcdbd301c0b0e1d66 (patch)
tree1f92b0b3c9bb73f0740f3a77dfa9ca121a1f7555
parent0ba9fd5be7b2c0adde410a88b340bfc1038e359c (diff)
cleanup of MD/MI ld.so (elf), most changes by art@ cleanup by me.
tested on alpha sparc64 powerpc.
-rw-r--r--libexec/ld.so/Makefile7
-rw-r--r--libexec/ld.so/alpha/archdep.h84
-rw-r--r--libexec/ld.so/alpha/syscall.h6
-rw-r--r--libexec/ld.so/dlfcn.c4
-rw-r--r--libexec/ld.so/loader.c80
-rw-r--r--libexec/ld.so/mips/archdep.h92
-rw-r--r--libexec/ld.so/mips/syscall.h5
-rw-r--r--libexec/ld.so/powerpc/archdep.h94
-rw-r--r--libexec/ld.so/powerpc/syscall.h7
-rw-r--r--libexec/ld.so/resolve.c7
-rw-r--r--libexec/ld.so/resolve.h5
-rw-r--r--libexec/ld.so/sod.c7
-rw-r--r--libexec/ld.so/sparc64/archdep.h84
-rw-r--r--libexec/ld.so/sparc64/rtld_machine.c5
-rw-r--r--libexec/ld.so/sparc64/syscall.h7
-rw-r--r--libexec/ld.so/util.c78
-rw-r--r--libexec/ld.so/util.h87
17 files changed, 214 insertions, 445 deletions
diff --git a/libexec/ld.so/Makefile b/libexec/ld.so/Makefile
index 11aac544a01..33969261487 100644
--- a/libexec/ld.so/Makefile
+++ b/libexec/ld.so/Makefile
@@ -1,11 +1,12 @@
-# $OpenBSD: Makefile,v 1.11 2001/11/20 01:13:44 pvalchev Exp $
+# $OpenBSD: Makefile,v 1.12 2002/02/21 23:17:53 drahn Exp $
SUBDIR=ldconfig ldd
VPATH=${.CURDIR}/../../lib/libc/string:${.CURDIR}/../../sys/lib/libsa
NOMAN=
SRCS= ldasm.S loader.c library.c resolve.c dlfcn.c dl_printf.c rtld_machine.c
-SRCS+= sod.c strcmp.c strncmp.c strsep.c strtol.c strdup.c strcpy.c
+SRCS+= util.c
+SRCS+= sod.c strcmp.c strncmp.c strsep.c strtol.c
OBJS+= strchr.o
PROG= ld.so
MAN= ld.so.8
@@ -17,7 +18,7 @@ AFLAGS += -fpic
CFLAGS += -fpic -msoft-float
.endif
.if (${MACHINE_ARCH} == "alpha")
-CFLAGS += -Werror
+CFLAGS += -Werror -Wall -Wno-uninitialized
CFLAGS += -fpic -mno-fp-regs
LIBCSRCDIR=${.CURDIR}/../../lib/libc
.include "${LIBCSRCDIR}/arch/alpha/Makefile.inc"
diff --git a/libexec/ld.so/alpha/archdep.h b/libexec/ld.so/alpha/archdep.h
index c599ab776b6..999d5877d09 100644
--- a/libexec/ld.so/alpha/archdep.h
+++ b/libexec/ld.so/alpha/archdep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: archdep.h,v 1.4 2002/02/16 21:27:30 millert Exp $ */
+/* $OpenBSD: archdep.h,v 1.5 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -44,86 +44,8 @@
#include <elf_abi.h>
#include <machine/reloc.h>
-
-int _dl_write(int, const char *, int);
-
-/*
- * The following functions are declared inline so they can
- * be used before bootstrap linking has been finished.
- */
-static inline void
-_dl_wrstderr(const char *s)
-{
- while(*s) {
- _dl_write(2, s, 1);
- s++;
- }
-}
-
-static inline void *
-_dl_memset(void *p, const char v, size_t c)
-{
- char *ip = p;
-
- while(c--)
- *ip++ = v;
- return(p);
-}
-
-static inline int
-_dl_strlen(const char *p)
-{
- const char *s = p;
-
- while(*s != '\0')
- s++;
- return(s - p);
-}
-
-static inline char *
-_dl_strcpy(char *d, const char *s)
-{
- char *rd = d;
-
- while((*d++ = *s++) != '\0');
-
- return(rd);
-}
-
-static inline int
-_dl_strncmp(const char *d, const char *s, int c)
-{
- while(c-- && *d && *d == *s) {
- d++;
- s++;
- };
- if(c < 0) {
- return(0);
- }
- return(*d - *s);
-}
-
-static inline int
-_dl_strcmp(const char *d, const char *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) {
- return(p);
- }
- p++;
- }
- return(0);
-}
+#include "syscall.h"
+#include "util.h"
static inline void
RELOC_RELA(Elf64_Rela *r, const Elf64_Sym *s, Elf64_Addr *p, unsigned long v)
diff --git a/libexec/ld.so/alpha/syscall.h b/libexec/ld.so/alpha/syscall.h
index a1371d55119..ace18414da3 100644
--- a/libexec/ld.so/alpha/syscall.h
+++ b/libexec/ld.so/alpha/syscall.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall.h,v 1.3 2002/02/17 19:42:26 millert Exp $ */
+/* $OpenBSD: syscall.h,v 1.4 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 2001 Niklas Hallqvist
@@ -31,6 +31,8 @@
* SUCH DAMAGE.
*
*/
+#ifndef __DL_SYSCALL_H__
+#define __DL_SYSCALL_H__
#ifdef USE_CACHE
#include <sys/stat.h>
@@ -52,7 +54,6 @@ long _dl_mmap(void *, unsigned int, unsigned int, unsigned int, int, off_t);
int _dl_mprotect(const void *, int, int);
int _dl_munmap(const void*, unsigned int);
int _dl_open(const char*, unsigned int);
-void _dl_printf(const char *, ...);
int _dl_read(int, const char*, int);
#ifdef USE_CACHE
int _dl_stat(const char *, struct stat *);
@@ -77,3 +78,4 @@ _dl_suid_ok (void)
}
#include <elf_abi.h>
+#endif /*__DL_SYSCALL_H__*/
diff --git a/libexec/ld.so/dlfcn.c b/libexec/ld.so/dlfcn.c
index 39a570c31d0..c8a00170a2f 100644
--- a/libexec/ld.so/dlfcn.c
+++ b/libexec/ld.so/dlfcn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dlfcn.c,v 1.11 2001/11/06 15:32:11 drahn Exp $ */
+/* $OpenBSD: dlfcn.c,v 1.12 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -278,7 +278,7 @@ _dl_show_objects()
object = _dl_objects;
- _dl_printf("\tStart End Type Ref Name\n");
+ _dl_printf("\tStart Size Type Ref Name\n");
while (object) {
switch (object->obj_type) {
diff --git a/libexec/ld.so/loader.c b/libexec/ld.so/loader.c
index 3608480629c..259eb8c6d59 100644
--- a/libexec/ld.so/loader.c
+++ b/libexec/ld.so/loader.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: loader.c,v 1.23 2001/09/26 22:58:23 jason Exp $ */
+/* $OpenBSD: loader.c,v 1.24 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -49,13 +49,6 @@
*/
static char *_dl_getenv(const char *var, const char **env);
-/*
- * Static vars usable after bootsrapping.
- */
-static void *_dl_malloc_base;
-static void *_dl_malloc_pool = 0;
-static long *_dl_malloc_free = 0;
-
const char *_dl_progname;
int _dl_pagesz;
int _dl_trusted;
@@ -111,7 +104,6 @@ _dl_boot(const char **argv, const char **envp, const long loff,
Elf_Dyn *dynp, long *dl_data)
{
int n;
- int brk_addr;
Elf_Phdr *phdp;
char *us = "";
elf_object_t *dynobj;
@@ -157,17 +149,13 @@ _dl_boot(const char **argv, const char **envp, const long loff,
*/
phdp = (Elf_Phdr *)dl_data[AUX_phdr];
for (n = 0; n < dl_data[AUX_phnum]; n++) {
- if (phdp->p_type == PT_LOAD) { /*XXX*/
- if (phdp->p_vaddr + phdp->p_memsz > brk_addr) /*XXX*/
- brk_addr = phdp->p_vaddr + phdp->p_memsz;
- } /*XXX*/
if (phdp->p_type == PT_DYNAMIC) {
- exe_obj = _dl_add_object("", (Elf_Dyn *)phdp->p_vaddr,
- dl_data, OBJTYPE_EXE, 0, 0);
+ exe_obj = _dl_add_object(argv[0],
+ (Elf_Dyn *)phdp->p_vaddr, dl_data, OBJTYPE_EXE,
+ 0, 0);
}
if (phdp->p_type == PT_INTERP) {
- us = (char *)_dl_malloc(_dl_strlen((char *)phdp->p_vaddr) + 1);
- _dl_strcpy(us, (char *)phdp->p_vaddr);
+ us = _dl_strdup((char *)phdp->p_vaddr);
}
phdp++;
}
@@ -509,7 +497,6 @@ _dl_call_init(elf_object_t *object)
{
Elf_Addr ooff;
const Elf_Sym *sym;
- static void (*_dl_atexit)(Elf_Addr) = NULL;
if (object->next) {
_dl_call_init(object->next);
@@ -583,60 +570,3 @@ _dl_getenv(const char *var, const char **env)
return(0);
}
-
-
-/*
- * The following malloc/free code is a very simplified implementation
- * of a malloc function. However, we do not need to be very complex here
- * because we only free memory when 'dlclose()' is called and we can
- * reuse at least the memory allocated for the object descriptor. We have
- * one dynamic string allocated, the library name and it is likely that
- * we can reuse that one to without a lot of complex colapsing code.
- */
-
-void *
-_dl_malloc(int size)
-{
- long *p;
- long *t, *n;
-
- size = (size + 8 + DL_MALLOC_ALIGN - 1) & ~(DL_MALLOC_ALIGN - 1);
-
- if ((t = _dl_malloc_free) != 0) { /* Try free list first */
- n = (long *)&_dl_malloc_free;
- while (t && t[-1] < size) {
- n = t;
- t = (long *)*t;
- }
- if (t) {
- *n = *t;
- _dl_memset(t, 0, t[-1] - 4);
- return((void *)t);
- }
- }
- 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);
- if (_dl_malloc_pool == 0 || _dl_malloc_pool == MAP_FAILED ) {
- _dl_printf("Dynamic loader failure: malloc.\n");
- _dl_exit(7);
- }
- _dl_malloc_base = _dl_malloc_pool;
- }
- p = _dl_malloc_pool;
- _dl_malloc_pool += size;
- _dl_memset(p, 0, size);
- *p = size;
- return((void *)(p + 1));
-}
-
-void
-_dl_free(void *p)
-{
- long *t = (long *)p;
-
- *t = (long)_dl_malloc_free;
- _dl_malloc_free = p;
-}
diff --git a/libexec/ld.so/mips/archdep.h b/libexec/ld.so/mips/archdep.h
index 0a7eba55a13..e5d8c41e612 100644
--- a/libexec/ld.so/mips/archdep.h
+++ b/libexec/ld.so/mips/archdep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: archdep.h,v 1.1 2000/06/13 03:34:13 rahnds Exp $ */
+/* $OpenBSD: archdep.h,v 1.2 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -35,6 +35,9 @@
#ifndef _MIPS_ARCHDEP_H_
#define _MIPS_ARCHDEP_H_
+#include "syscall.h"
+#include "util.h"
+
#define DL_MALLOC_ALIGN 4 /* Arch constraint or otherwise */
#define MACHID EM_MIPS /* ELF e_machine ID value checked */
@@ -42,91 +45,4 @@
#define RELTYPE Elf32_Rel
#define RELSIZE sizeof(Elf32_Rel)
-/*
- * Simple reloc of REL32's. Used by bootstrapping.
- */
-#define SIMPLE_RELOC(r, s, p, v) \
- if(ELF32_R_TYPE((r)->r_info) == R_MIPS_REL32) { \
- if(ELF32_ST_BIND((s)->st_info) == STB_LOCAL && \
- (ELF32_ST_TYPE((s)->st_info) == STT_SECTION || \
- ELF32_ST_TYPE((s)->st_info) == STT_NOTYPE) ) { \
- *(p) += (v); \
- } \
- else { \
- *(p) = (v) + (s)->st_value; \
- } \
- }
-
-/*
- * The following functions are declared inline so they can
- * be used before bootstrap linking has been finished.
- */
-extern inline void
-_dl_wrstderr(const char *s)
-{
- while(*s) {
- _dl_write(2, s, 1);
- s++;
- }
-}
-
-extern inline void *
-_dl_memset(void *p, const char v, size_t c)
-{
- char *ip = p;
-
- while(c--)
- *ip++ = v;
- return(p);
-}
-
-extern inline int
-_dl_strlen(const char *p)
-{
- const char *s = p;
-
- while(*s != '\0')
- s++;
- return(s - p);
-}
-
-extern inline char *
-_dl_strcpy(char *d, const char *s)
-{
- char *rd = d;
-
- while((*d++ = *s++) != '\0');
-
- return(rd);
-}
-
-extern inline int
-_dl_strncmp(const char *d, const char *s, int c)
-{
- while(c-- && *d && *d++ == *s++) {};
- if(c < 0) {
- return(0);
- }
- return(d[-1] - s[-1]);
-}
-
-extern inline int
-_dl_strcmp(const char *d, const char *s)
-{
- while(*d && *d++ == *s++) {};
- return(d[-1] - s[-1]);
-}
-
-extern inline const char *
-_dl_strchr(const char *p, const int c)
-{
- while(*p) {
- if(*p == c) {
- return(p);
- }
- p++;
- }
- return(0);
-}
-
#endif /* _MIPS_ARCHDEP_H_ */
diff --git a/libexec/ld.so/mips/syscall.h b/libexec/ld.so/mips/syscall.h
index 8d1b4ba6aff..dd92915c265 100644
--- a/libexec/ld.so/mips/syscall.h
+++ b/libexec/ld.so/mips/syscall.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall.h,v 1.1 2000/06/13 03:34:17 rahnds Exp $ */
+/* $OpenBSD: syscall.h,v 1.2 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -31,6 +31,8 @@
* SUCH DAMAGE.
*
*/
+#ifndef __DL_SYSCALL_H__
+#define __DL_SYSCALL_H__
#ifdef USE_CACHE
#include <sys/stat.h>
@@ -243,3 +245,4 @@ _dl_suid_ok (void)
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 3e87fb34212..299f635bad9 100644
--- a/libexec/ld.so/powerpc/archdep.h
+++ b/libexec/ld.so/powerpc/archdep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: archdep.h,v 1.3 2000/10/19 02:44:16 drahn Exp $ */
+/* $OpenBSD: archdep.h,v 1.4 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -44,6 +44,8 @@
#include <elf_abi.h>
#include <machine/reloc.h>
+#include "syscall.h"
+#include "util.h"
/* HACK */
#define DT_PROCNUM 0
@@ -52,21 +54,6 @@
#endif
/*
- * Simple reloc of REL32's. Used by bootstrapping.
- */
-#define SIMPLE_RELOC(r, s, p, v) \
- if(ELF32_R_TYPE((r)->r_info) == RELOC_32) { \
- if((ELF32_ST_BIND((s)->st_info) == STB_LOCAL) && \
- (ELF32_ST_TYPE((s)->st_info) == STT_SECTION || \
- ELF32_ST_TYPE((s)->st_info) == STT_NOTYPE) ) { \
- *(p) += (v); \
- } \
- else { \
- *(p) = (v) + (s)->st_value; \
- } \
- }
-
-/*
* The following functions are declared inline so they can
* be used before bootstrap linking has been finished.
*/
@@ -81,81 +68,6 @@ _dl_dcbf(Elf32_Addr *addr)
: : "r" (addr) : "0");
}
-static inline int _dl_write (int fd, const char* buf, int len);
-static inline void
-_dl_wrstderr(const char *s)
-{
- while(*s) {
- _dl_write(2, s, 1);
- s++;
- }
-}
-
-static inline void *
-_dl_memset(void *p, const char v, size_t c)
-{
- char *ip = p;
-
- while(c--)
- *ip++ = v;
- return(p);
-}
-
-static inline int
-_dl_strlen(const char *p)
-{
- const char *s = p;
-
- while(*s != '\0')
- s++;
- return(s - p);
-}
-
-static inline char *
-_dl_strcpy(char *d, const char *s)
-{
- char *rd = d;
-
- while((*d++ = *s++) != '\0');
-
- return(rd);
-}
-
-static inline int
-_dl_strncmp(const char *d, const char *s, int c)
-{
- while(c-- && *d && *d == *s) {
- d++;
- s++;
- };
- if(c < 0) {
- return(0);
- }
- return(*d - *s);
-}
-
-static inline int
-_dl_strcmp(const char *d, const char *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) {
- return(p);
- }
- p++;
- }
- return(0);
-}
-
static inline void
RELOC_RELA(Elf32_Rela *r,
const Elf32_Sym *s, Elf32_Addr *p, int v)
diff --git a/libexec/ld.so/powerpc/syscall.h b/libexec/ld.so/powerpc/syscall.h
index cd7a8d6705a..eccc62229fa 100644
--- a/libexec/ld.so/powerpc/syscall.h
+++ b/libexec/ld.so/powerpc/syscall.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall.h,v 1.3 2000/10/01 00:51:20 rahnds Exp $ */
+/* $OpenBSD: syscall.h,v 1.4 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -31,6 +31,8 @@
* SUCH DAMAGE.
*
*/
+#ifndef __DL_SYSCALL_H__
+#define __DL_SYSCALL_H__
#ifdef USE_CACHE
#include <sys/stat.h>
@@ -49,8 +51,6 @@
* any dynamic address resoving has been done.
*/
-void _dl_printf(const char *, ...);
-
static inline int
_dl_exit (int status)
{
@@ -292,3 +292,4 @@ _dl_suid_ok (void)
}
#include <elf_abi.h>
+#endif /*__DL_SYSCALL_H__*/
diff --git a/libexec/ld.so/resolve.c b/libexec/ld.so/resolve.c
index 8de5ffbef72..3249f8e0fd7 100644
--- a/libexec/ld.so/resolve.c
+++ b/libexec/ld.so/resolve.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: resolve.c,v 1.5 2001/09/25 14:06:48 art Exp $ */
+/* $OpenBSD: resolve.c,v 1.6 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -45,8 +45,6 @@
elf_object_t *_dl_objects;
elf_object_t *_dl_last_object;
-void * _dl_malloc(int);
-
/*
* Initialize and add a new dynamic object to the object list.
* Perform necessary relocations of pointers.
@@ -133,8 +131,7 @@ d_un.d_val;
object->obj_type = objtype;
object->load_addr = laddr;
object->load_offs = loff;
- object->load_name = (char *)_dl_malloc(_dl_strlen(objname) + 1);
- _dl_strcpy(object->load_name, objname);
+ object->load_name = _dl_strdup(objname);
object->refcount = 1;
return(object);
diff --git a/libexec/ld.so/resolve.h b/libexec/ld.so/resolve.h
index 11114dec02b..442f3bfadc1 100644
--- a/libexec/ld.so/resolve.h
+++ b/libexec/ld.so/resolve.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: resolve.h,v 1.6 2001/09/26 09:16:42 art Exp $ */
+/* $OpenBSD: resolve.h,v 1.7 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -136,9 +136,6 @@ extern void _dl_md_reloc_got(elf_object_t *object, int lazy);
Elf_Addr _dl_find_symbol(const char *name, elf_object_t *startlook,
const Elf_Sym **ref, int myself, int warnnotfound);
-void * _dl_malloc(const int size);
-void _dl_free(void *);
-
void _dl_rtld(elf_object_t *object);
void _dl_call_init(elf_object_t *object);
diff --git a/libexec/ld.so/sod.c b/libexec/ld.so/sod.c
index ca84e135865..e29f1fec1ed 100644
--- a/libexec/ld.so/sod.c
+++ b/libexec/ld.so/sod.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sod.c,v 1.7 2001/09/22 04:58:18 drahn Exp $ */
+/* $OpenBSD: sod.c,v 1.8 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1993 Paul Kranenburg
* All rights reserved.
@@ -44,10 +44,9 @@
#include <syscall.h>
#include "archdep.h"
+#include "util.h"
#define PAGSIZ __LDPGSZ
-char * _dl_strdup(const char *);
-void _dl_free(void *);
int _dl_hinthash(char *cp, int vmajor, int vminor);
/*
@@ -68,7 +67,7 @@ _dl_build_sod(name, sodp)
sodp->sod_major = sodp->sod_minor = 0;
/* does it look like /^lib/ ? */
- if (strncmp((char *)sodp->sod_name, "lib", 3) != 0)
+ if (_dl_strncmp((char *)sodp->sod_name, "lib", 3) != 0)
return;
/* is this a filename? */
diff --git a/libexec/ld.so/sparc64/archdep.h b/libexec/ld.so/sparc64/archdep.h
index cd2ea9b3abe..b4ce7694c3c 100644
--- a/libexec/ld.so/sparc64/archdep.h
+++ b/libexec/ld.so/sparc64/archdep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: archdep.h,v 1.5 2002/02/16 21:27:30 millert Exp $ */
+/* $OpenBSD: archdep.h,v 1.6 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -46,86 +46,8 @@
#include <machine/exec.h>
#include <machine/reloc.h>
#include <sys/syscall.h>
-
-int _dl_write(int, const char *, int);
-
-/*
- * The following functions are declared inline so they can
- * be used before bootstrap linking has been finished.
- */
-static inline void
-_dl_wrstderr(const char *s)
-{
- while(*s) {
- _dl_write(2, s, 1);
- s++;
- }
-}
-
-static inline void *
-_dl_memset(void *p, const char v, size_t c)
-{
- char *ip = p;
-
- while(c--)
- *ip++ = v;
- return(p);
-}
-
-static inline int
-_dl_strlen(const char *p)
-{
- const char *s = p;
-
- while(*s != '\0')
- s++;
- return(s - p);
-}
-
-static inline char *
-_dl_strcpy(char *d, const char *s)
-{
- char *rd = d;
-
- while((*d++ = *s++) != '\0');
-
- return(rd);
-}
-
-static inline int
-_dl_strncmp(const char *d, const char *s, int c)
-{
- while(c-- && *d && *d == *s) {
- d++;
- s++;
- };
- if(c < 0) {
- return(0);
- }
- return(*d - *s);
-}
-
-static inline int
-_dl_strcmp(const char *d, const char *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) {
- return(p);
- }
- p++;
- }
- return(0);
-}
+#include "syscall.h"
+#include "util.h"
static inline long
_dl_mmap(void *addr, unsigned int len, unsigned int prot,
diff --git a/libexec/ld.so/sparc64/rtld_machine.c b/libexec/ld.so/sparc64/rtld_machine.c
index d15e24253dd..07641725708 100644
--- a/libexec/ld.so/sparc64/rtld_machine.c
+++ b/libexec/ld.so/sparc64/rtld_machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtld_machine.c,v 1.9 2002/02/20 05:04:34 jason Exp $ */
+/* $OpenBSD: rtld_machine.c,v 1.10 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 1999 Dale Rahn
@@ -289,6 +289,7 @@ resolve_failed:
fails++;
continue;
}
+ value += (Elf_Addr)(ooff + this->st_value);
#ifdef notyet
/*
* XXX Hmm, we should change the API of _dl_find_symbol and do this in there,
@@ -304,7 +305,6 @@ resolve_failed:
}
#endif
}
- value += (Elf_Addr)(ooff + this->st_value);
}
if (type == R_TYPE(JMP_SLOT)) {
@@ -316,7 +316,6 @@ resolve_failed:
void *dstaddr = where;
const void *srcaddr;
const Elf_Sym *dstsym = sym, *srcsym = NULL;
- const char *name = symn;
size_t size = dstsym->st_size;
Elf_Addr soff;
diff --git a/libexec/ld.so/sparc64/syscall.h b/libexec/ld.so/sparc64/syscall.h
index 9233615d393..f5bcca662b9 100644
--- a/libexec/ld.so/sparc64/syscall.h
+++ b/libexec/ld.so/sparc64/syscall.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: syscall.h,v 1.3 2002/02/16 21:27:30 millert Exp $ */
+/* $OpenBSD: syscall.h,v 1.4 2002/02/21 23:17:53 drahn Exp $ */
/*
* Copyright (c) 2001 Niklas Hallqvist
@@ -32,6 +32,9 @@
*
*/
+#ifndef __DL_SYSCALL_H__
+#define __DL_SYSCALL_H__
+
#ifdef USE_CACHE
#include <sys/stat.h>
#endif
@@ -52,7 +55,6 @@ long _dl___syscall(quad_t, ...);
int _dl_mprotect(const void *, int, int);
int _dl_munmap(const void*, unsigned int);
int _dl_open(const char*, unsigned int);
-void _dl_printf(const char *, ...);
int _dl_read(int, const char*, int);
#ifdef USE_CACHE
int _dl_stat(const char *, struct stat *);
@@ -77,3 +79,4 @@ _dl_suid_ok (void)
}
#include <elf_abi.h>
+#endif /*__DL_SYSCALL_H__*/
diff --git a/libexec/ld.so/util.c b/libexec/ld.so/util.c
new file mode 100644
index 00000000000..56b8cd282d2
--- /dev/null
+++ b/libexec/ld.so/util.c
@@ -0,0 +1,78 @@
+/* $OpenBSD: util.c,v 1.1 2002/02/21 23:17:53 drahn Exp $ */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <string.h>
+#include "archdep.h"
+
+/*
+ * Static vars usable after bootsrapping.
+ */
+static void *_dl_malloc_base;
+static void *_dl_malloc_pool = 0;
+static long *_dl_malloc_free = 0;
+
+char *
+_dl_strdup(const char *orig)
+{
+ char *newstr;
+ newstr = _dl_malloc(_dl_strlen(orig)+1);
+ _dl_strcpy(newstr, orig);
+ return (newstr);
+}
+
+/*
+ * The following malloc/free code is a very simplified implementation
+ * of a malloc function. However, we do not need to be very complex here
+ * because we only free memory when 'dlclose()' is called and we can
+ * reuse at least the memory allocated for the object descriptor. We have
+ * one dynamic string allocated, the library name and it is likely that
+ * we can reuse that one to without a lot of complex colapsing code.
+ */
+
+void *
+_dl_malloc(int size)
+{
+ long *p;
+ long *t, *n;
+
+ size = (size + 8 + DL_MALLOC_ALIGN - 1) & ~(DL_MALLOC_ALIGN - 1);
+
+ if ((t = _dl_malloc_free) != 0) { /* Try free list first */
+ n = (long *)&_dl_malloc_free;
+ while (t && t[-1] < size) {
+ n = t;
+ t = (long *)*t;
+ }
+ if (t) {
+ *n = *t;
+ _dl_memset(t, 0, t[-1] - 4);
+ return((void *)t);
+ }
+ }
+ 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);
+ if (_dl_malloc_pool == 0 || _dl_malloc_pool == MAP_FAILED ) {
+ _dl_printf("Dynamic loader failure: malloc.\n");
+ _dl_exit(7);
+ }
+ _dl_malloc_base = _dl_malloc_pool;
+ }
+ p = _dl_malloc_pool;
+ _dl_malloc_pool += size;
+ _dl_memset(p, 0, size);
+ *p = size;
+ return((void *)(p + 1));
+}
+
+void
+_dl_free(void *p)
+{
+ long *t = (long *)p;
+
+ *t = (long)_dl_malloc_free;
+ _dl_malloc_free = p;
+}
diff --git a/libexec/ld.so/util.h b/libexec/ld.so/util.h
new file mode 100644
index 00000000000..dd6985b39dd
--- /dev/null
+++ b/libexec/ld.so/util.h
@@ -0,0 +1,87 @@
+#ifndef __DL_UTIL_H__
+#define __DL_UTIL_H__
+int _dl_write __P((int, const char *, int));
+void *_dl_malloc(const int size);
+void _dl_free(void *);
+char *_dl_strdup(const char *);
+void _dl_printf(const char *fmt, ...);
+
+/*
+ * The following functions are declared inline so they can
+ * be used before bootstrap linking has been finished.
+ */
+static inline void
+_dl_wrstderr(const char *s)
+{
+ while(*s) {
+ _dl_write(2, s, 1);
+ s++;
+ }
+}
+
+static inline void *
+_dl_memset(void *p, const char v, size_t c)
+{
+ char *ip = p;
+
+ while(c--)
+ *ip++ = v;
+ return(p);
+}
+
+static inline int
+_dl_strlen(const char *p)
+{
+ const char *s = p;
+
+ while(*s != '\0')
+ s++;
+ return(s - p);
+}
+
+static inline char *
+_dl_strcpy(char *d, const char *s)
+{
+ char *rd = d;
+
+ while((*d++ = *s++) != '\0');
+
+ return(rd);
+}
+
+static inline int
+_dl_strncmp(const char *d, const char *s, int c)
+{
+ while(c-- && *d && *d == *s) {
+ d++;
+ s++;
+ };
+ if(c < 0) {
+ return(0);
+ }
+ return(*d - *s);
+}
+
+static inline int
+_dl_strcmp(const char *d, const char *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) {
+ return(p);
+ }
+ p++;
+ }
+ return(0);
+}
+
+#endif /*__DL_UTIL_H__*/