Cleanup global variable access so rtld can be self relocating. Also KNF
reloc.c and move md sparc parts to arch/sparc/mdreloc.c Now we don't need to load at address 0 on the i386 and the mips should be trivial to fix.
This commit is contained in:
parent
46e61f2db1
commit
84cb65780e
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.21 1999/02/21 18:10:24 kleink Exp $
|
||||
# $NetBSD: Makefile,v 1.22 1999/02/24 18:31:00 christos Exp $
|
||||
|
||||
.include <bsd.own.mk> # for OBJECT_FMT definition
|
||||
|
||||
|
@ -8,7 +8,7 @@ PROG= ld.elf_so
|
|||
|
||||
.if (${MACHINE} == "alpha") || (${MACHINE_ARCH} == "mips") || \
|
||||
(${MACHINE_ARCH} == "powerpc") || (${MACHINE} == "sparc64") || \
|
||||
(${MACHINE} == "i386")
|
||||
(${MACHINE} == "i386") || (${MACHINE} == "sparc")
|
||||
# Adds SRCS, CPPFLAGS, LDFLAGS, etc. Must go first so MD startup source
|
||||
# is first.
|
||||
.if exists(${.CURDIR}/arch/${MACHINE_ARCH}/Makefile.inc)
|
||||
|
@ -21,11 +21,13 @@ CLIBOBJ!=cd ${.CURDIR}/../../lib/libc; \
|
|||
SRCS+= rtld.c reloc.c symbol.c malloc.c xmalloc.c xprintf.c debug.c \
|
||||
map_object.c load.c search.c headers.c paths.c
|
||||
CPPFLAGS+= -Wall -DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
|
||||
CPPFLAGS+= -I${.CURDIR}
|
||||
CPPFLAGS+= -DDEBUG -DRTLD_LOADER
|
||||
#CPPFLAGS+= -DRTLD_DEBUG -DRTLD_DEBUG_RELOC
|
||||
|
||||
LDADD+= -L${DESTDIR}/${LIBDIR} -L${CLIBOBJ} -non_shared -lc_pic
|
||||
DPADD+= ${LIBC_PIC}
|
||||
CFLAGS+=-g
|
||||
|
||||
.if (${OBJECT_FMT} == "ELF")
|
||||
# to be installed
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# $NetBSD: Makefile.inc,v 1.1 1999/01/10 18:21:24 christos Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.2 1999/02/24 18:31:00 christos Exp $
|
||||
|
||||
SRCS+= rtld_start.S
|
||||
|
||||
CPPFLAGS+= -fpic -DELFSIZE=32
|
||||
CPPFLAGS+= -fpic -DELFSIZE=32 -DRTLD_RELOCATE_SELF
|
||||
LDFLAGS+= -Bshareable -Bsymbolic -e .rtld_start
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: debug.h,v 1.2 1999/01/10 17:19:01 christos Exp $ */
|
||||
/* $NetBSD: debug.h,v 1.3 1999/02/24 18:31:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 John D. Polstra.
|
||||
|
@ -51,9 +51,14 @@ extern void debug_printf(const char *, ...)
|
|||
extern int debug;
|
||||
|
||||
#ifdef DEBUG /* { */
|
||||
#define dbg(format, args...) debug_printf(format, ## args)
|
||||
#define dbg(format, args...) debug_printf(format, ## args)
|
||||
#else /* } { */
|
||||
#define dbg(format, args...) ((void) 0)
|
||||
#define dbg(format, args...) ((void) 0)
|
||||
#endif /* } */
|
||||
#ifdef RTLD_DEBUG_RELOC
|
||||
#define rdbg(f, format, args...) if (f) debug_printf(format, ## args)
|
||||
#else
|
||||
#define rdbg(f, format, args...) ((void) 0)
|
||||
#endif
|
||||
|
||||
#endif /* } */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: headers.c,v 1.2 1998/03/25 04:13:01 mhitch Exp $ */
|
||||
/* $NetBSD: headers.c,v 1.3 1999/02/24 18:31:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 John D. Polstra.
|
||||
|
@ -229,7 +229,8 @@ _rtld_digest_dynamic(
|
|||
obj->pltrelalim = (const Elf_RelA *) ((caddr_t) obj->pltrela + pltrelasize);
|
||||
|
||||
if (dyn_rpath != NULL) {
|
||||
_rtld_add_paths(&obj->rpaths, obj->strtab + dyn_rpath->d_un.d_val);
|
||||
_rtld_add_paths(&obj->rpaths, obj->strtab + dyn_rpath->d_un.d_val,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: load.c,v 1.1 1996/12/16 20:37:59 cgd Exp $ */
|
||||
/* $NetBSD: load.c,v 1.2 1999/02/24 18:31:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 John D. Polstra.
|
||||
|
@ -62,7 +62,8 @@
|
|||
*/
|
||||
Obj_Entry *
|
||||
_rtld_load_object(
|
||||
char *filepath)
|
||||
char *filepath,
|
||||
bool dodebug)
|
||||
{
|
||||
Obj_Entry *obj;
|
||||
|
||||
|
@ -92,11 +93,12 @@ _rtld_load_object(
|
|||
#ifdef RTLD_LOADER
|
||||
_rtld_linkmap_add(obj); /* for GDB */
|
||||
#endif
|
||||
|
||||
dbg(" %p .. %p: %s", obj->mapbase,
|
||||
obj->mapbase + obj->mapsize - 1, obj->path);
|
||||
if (obj->textrel)
|
||||
dbg(" WARNING: %s has impure text", obj->path);
|
||||
if (dodebug) {
|
||||
dbg(" %p .. %p: %s", obj->mapbase,
|
||||
obj->mapbase + obj->mapsize - 1, obj->path);
|
||||
if (obj->textrel)
|
||||
dbg(" WARNING: %s has impure text", obj->path);
|
||||
}
|
||||
} else
|
||||
free(filepath);
|
||||
|
||||
|
@ -126,7 +128,7 @@ _rtld_load_needed_objects(
|
|||
if (libpath == NULL) {
|
||||
status = -1;
|
||||
} else {
|
||||
needed->obj = _rtld_load_object(libpath);
|
||||
needed->obj = _rtld_load_object(libpath, true);
|
||||
if (needed->obj == NULL)
|
||||
status = -1; /* FIXME - cleanup */
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: paths.c,v 1.2 1997/10/08 08:55:36 mrg Exp $ */
|
||||
/* $NetBSD: paths.c,v 1.3 1999/02/24 18:31:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 Matt Thomas <matt@3am-software.com>
|
||||
|
@ -62,7 +62,8 @@ _rtld_find_path(
|
|||
void
|
||||
_rtld_add_paths(
|
||||
Search_Path **path_p,
|
||||
const char *pathstr)
|
||||
const char *pathstr,
|
||||
bool dodebug)
|
||||
{
|
||||
Search_Path *path, **head_p = path_p;
|
||||
|
||||
|
@ -96,7 +97,8 @@ _rtld_add_paths(
|
|||
(*path_p) = path;
|
||||
path_p = &path->sp_next;
|
||||
|
||||
dbg(" added path \"%s\"", path->sp_path);
|
||||
if (dodebug)
|
||||
dbg(" added path \"%s\"", path->sp_path);
|
||||
}
|
||||
|
||||
if (ep[0] == '\0')
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rtld.c,v 1.12 1999/01/10 18:18:56 christos Exp $ */
|
||||
/* $NetBSD: rtld.c,v 1.13 1999/02/24 18:31:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 John D. Polstra.
|
||||
|
@ -127,45 +127,62 @@ static void
|
|||
_rtld_init(
|
||||
caddr_t mapbase)
|
||||
{
|
||||
_rtld_add_paths(&_rtld_paths, RTLD_DEFAULT_LIBRARY_PATH);
|
||||
Obj_Entry objself; /* The dynamic linker shared object */
|
||||
#ifdef RTLD_RELOCATE_SELF
|
||||
int dodebug = false;
|
||||
#else
|
||||
int dodebug = true;
|
||||
#endif
|
||||
|
||||
/* Conjure up an Obj_Entry structure for the dynamic linker. */
|
||||
|
||||
_rtld_objself.path = _rtld_path;
|
||||
_rtld_objself.rtld = true;
|
||||
_rtld_objself.mapbase = mapbase;
|
||||
#if defined(__mips__) || defined(__i386__)
|
||||
objself.path = NULL;
|
||||
objself.rtld = true;
|
||||
objself.mapbase = mapbase;
|
||||
#if defined(__mips__)
|
||||
/*
|
||||
* mips and i386 ld.so currently linked at load address,
|
||||
* mips and ld.so currently linked at load address,
|
||||
* so no relocation needed
|
||||
*/
|
||||
_rtld_objself.relocbase = 0;
|
||||
objself.relocbase = 0;
|
||||
#else
|
||||
_rtld_objself.relocbase = mapbase;
|
||||
objself.relocbase = mapbase;
|
||||
#endif
|
||||
_rtld_objself.pltgot = NULL;
|
||||
objself.pltgot = NULL;
|
||||
#ifdef OLD_GOT
|
||||
_rtld_objself.dynamic = (Elf_Dyn *) _GLOBAL_OFFSET_TABLE_[0];
|
||||
objself.dynamic = (Elf_Dyn *)_GLOBAL_OFFSET_TABLE_[0];
|
||||
#else
|
||||
_rtld_objself.dynamic = &_DYNAMIC;
|
||||
objself.dynamic = (Elf_Dyn *)&_DYNAMIC;
|
||||
#endif
|
||||
|
||||
_rtld_digest_dynamic(&_rtld_objself);
|
||||
#ifdef RTLD_RELOCATE_SELF
|
||||
/* We have not been relocated yet, so fix the dynamic address */
|
||||
objself.dynamic = (Elf_Dyn *)((u_long)mapbase + (char *) objself.dynamic);
|
||||
#endif /* RTLD_RELOCATE_SELF */
|
||||
|
||||
_rtld_digest_dynamic(&objself);
|
||||
#ifdef __alpha__
|
||||
/* XXX XXX XXX */
|
||||
_rtld_objself.pltgot = NULL;
|
||||
/* XXX XXX XXX */
|
||||
objself.pltgot = NULL;
|
||||
#endif
|
||||
assert(_rtld_objself.needed == NULL);
|
||||
assert(objself.needed == NULL);
|
||||
#if !defined(__mips__) && !defined(__i386__)
|
||||
/* no relocation for mips/i386 */
|
||||
assert(!_rtld_objself.textrel);
|
||||
assert(!objself.textrel);
|
||||
#endif
|
||||
|
||||
_rtld_relocate_objects(&objself, true, dodebug);
|
||||
|
||||
/*
|
||||
* Now that we relocated ourselves, we can use globals.
|
||||
*/
|
||||
_rtld_objself = objself;
|
||||
|
||||
_rtld_objself.path = _rtld_path;
|
||||
_rtld_add_paths(&_rtld_paths, RTLD_DEFAULT_LIBRARY_PATH, true);
|
||||
|
||||
/* Set up the _rtld_objlist pointer, so that rtld symbols can be found. */
|
||||
_rtld_objlist = &_rtld_objself;
|
||||
|
||||
_rtld_relocate_objects(&_rtld_objself, true);
|
||||
|
||||
/* Make the object list empty again. */
|
||||
_rtld_objlist = NULL;
|
||||
_rtld_objtail = &_rtld_objlist;
|
||||
|
@ -217,7 +234,7 @@ _rtld(
|
|||
bool bind_now = 0;
|
||||
const char *ld_bind_now;
|
||||
const char **argv;
|
||||
#ifdef RTLD_DEBUG
|
||||
#if defined(RTLD_DEBUG) && !defined(RTLD_RELOCATE_SELF)
|
||||
int i = 0;
|
||||
#endif
|
||||
|
||||
|
@ -229,12 +246,12 @@ _rtld(
|
|||
*/
|
||||
/* Find the auxiliary vector on the stack. */
|
||||
/* first Elf_Word reserved to address of exit routine */
|
||||
#ifdef RTLD_DEBUG
|
||||
xprintf("sp = %p, argc = %d, argv = %p <%s>\n", sp, sp[2],
|
||||
#if defined(RTLD_DEBUG) && !defined(RTLD_RELOCATE_SELF)
|
||||
dbg("sp = %p, argc = %d, argv = %p <%s>\n", sp, sp[2],
|
||||
&sp[3], (char *)sp[3]);
|
||||
xprintf("got is at %p, dynamic is at %p\n", _GLOBAL_OFFSET_TABLE_, &_DYNAMIC);
|
||||
dbg("got is at %p, dynamic is at %p\n", _GLOBAL_OFFSET_TABLE_, &_DYNAMIC);
|
||||
debug = 1;
|
||||
xprintf("_ctype_ is %p\n", _ctype_);
|
||||
dbg("_ctype_ is %p\n", _ctype_);
|
||||
#endif
|
||||
|
||||
sp += 2; /* skip over return argument space */
|
||||
|
@ -242,8 +259,8 @@ _rtld(
|
|||
sp += sp[0] + 2; /* Skip over argc, arguments, and NULL terminator */
|
||||
env = (char **) sp;
|
||||
while (*sp++ != 0) { /* Skip over environment, and NULL terminator */
|
||||
#ifdef RTLD_DEBUG
|
||||
xprintf("env[%d] = %p %s\n", i++, (void *)sp[-1], (char *)sp[-1]);
|
||||
#if defined(RTLD_DEBUG) && !defined(RTLD_RELOCATE_SELF)
|
||||
dbg("env[%d] = %p %s\n", i++, (void *)sp[-1], (char *)sp[-1]);
|
||||
#endif
|
||||
}
|
||||
aux = (const AuxInfo *) sp;
|
||||
|
@ -273,7 +290,7 @@ _rtld(
|
|||
_rtld_init((caddr_t) pAUX_base->au_v);
|
||||
|
||||
#ifdef RTLD_DEBUG
|
||||
xprintf("_ctype_ is %p\n", _ctype_);
|
||||
dbg("_ctype_ is %p\n", _ctype_);
|
||||
#endif
|
||||
|
||||
__progname = _rtld_objself.path;
|
||||
|
@ -290,7 +307,7 @@ _rtld(
|
|||
if (ld_debug != NULL && *ld_debug != '\0')
|
||||
debug = 1;
|
||||
#endif
|
||||
_rtld_add_paths(&_rtld_paths, getenv("LD_LIBRARY_PATH"));
|
||||
_rtld_add_paths(&_rtld_paths, getenv("LD_LIBRARY_PATH"), true);
|
||||
}
|
||||
|
||||
dbg("%s is initialized, base address = %p", __progname,
|
||||
|
@ -341,11 +358,11 @@ _rtld(
|
|||
_rtld_die();
|
||||
|
||||
dbg("relocating objects");
|
||||
if (_rtld_relocate_objects(_rtld_objmain, bind_now) == -1)
|
||||
if (_rtld_relocate_objects(_rtld_objmain, bind_now, true) == -1)
|
||||
_rtld_die();
|
||||
|
||||
dbg("doing copy relocations");
|
||||
if (_rtld_do_copy_relocations(_rtld_objmain) == -1)
|
||||
if (_rtld_do_copy_relocations(_rtld_objmain, true) == -1)
|
||||
_rtld_die();
|
||||
|
||||
dbg("calling _init functions");
|
||||
|
@ -482,7 +499,7 @@ _rtld_dlopen(
|
|||
} else {
|
||||
char *path = _rtld_find_library(name, NULL);
|
||||
if (path != NULL)
|
||||
obj = _rtld_load_object(path);
|
||||
obj = _rtld_load_object(path, true);
|
||||
}
|
||||
|
||||
if (obj != NULL) {
|
||||
|
@ -494,7 +511,8 @@ _rtld_dlopen(
|
|||
if (_rtld_load_needed_objects(obj) == -1) {
|
||||
--obj->dl_refcount;
|
||||
obj = NULL;
|
||||
} else if (_rtld_relocate_objects(obj, (mode & 3) == RTLD_NOW) == -1) {
|
||||
} else if (_rtld_relocate_objects(obj, (mode & 3) == RTLD_NOW,
|
||||
true) == -1) {
|
||||
--obj->dl_refcount;
|
||||
obj = NULL;
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rtld.h,v 1.6 1998/11/24 11:34:30 tsubai Exp $ */
|
||||
/* $NetBSD: rtld.h,v 1.7 1999/02/24 18:31:00 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 John D. Polstra.
|
||||
|
@ -51,7 +51,11 @@
|
|||
#define SVR4_LIBDIRLEN (sizeof SVR4_LIBDIR - 1)
|
||||
|
||||
#ifndef PAGESIZE
|
||||
#define PAGESIZE CLBYTES
|
||||
# ifndef __sparc__
|
||||
# define PAGESIZE CLBYTES
|
||||
# else
|
||||
# define PAGESIZE 8192 /* NPBG is not constant! */
|
||||
# endif
|
||||
#endif
|
||||
#define round_down(x) ((x) & ~(PAGESIZE-1))
|
||||
#define round_up(x) round_down((x) + PAGESIZE - 1)
|
||||
|
@ -189,17 +193,21 @@ extern Obj_Entry *_rtld_digest_phdr(const Elf_Phdr *, int, caddr_t);
|
|||
|
||||
/* load.c */
|
||||
|
||||
extern Obj_Entry *_rtld_load_object(char *path);
|
||||
extern Obj_Entry *_rtld_load_object(char *path, bool);
|
||||
extern int _rtld_load_needed_objects(Obj_Entry *);
|
||||
|
||||
/* path.c */
|
||||
|
||||
extern void _rtld_add_paths(Search_Path **, const char *);
|
||||
extern void _rtld_add_paths(Search_Path **, const char *, bool);
|
||||
|
||||
/* reloc.c */
|
||||
extern int _rtld_do_copy_relocations(const Obj_Entry *);
|
||||
extern int _rtld_do_copy_relocations(const Obj_Entry *, bool);
|
||||
extern caddr_t _rtld_bind(const Obj_Entry *, Elf_Word);
|
||||
extern int _rtld_relocate_objects(Obj_Entry *, bool);
|
||||
extern int _rtld_relocate_objects(Obj_Entry *, bool, bool);
|
||||
extern int _rtld_relocate_nonplt_object(const Obj_Entry *, const Elf_RelA *,
|
||||
bool);
|
||||
extern int _rtld_relocate_plt_object(const Obj_Entry *, const Elf_RelA *,
|
||||
caddr_t *, bool, bool);
|
||||
|
||||
/* search.c */
|
||||
|
||||
|
|
Loading…
Reference in New Issue