* Renamed load-dl.c into loadlib.c.
* Removed support for bizarre dynamic linkers, will re-add them later. * Removed support for object linking with ld. git-svn-id: svn://svn.zoy.org/elk/trunk@116 55e467fa-43c5-0310-a8a2-de718669efc6
This commit is contained in:
parent
58b8dc6976
commit
af14b9bc14
|
@ -22,6 +22,7 @@ libelk_la_SOURCES = \
|
|||
libelk.c \
|
||||
list.c \
|
||||
load.c \
|
||||
loadlib.c \
|
||||
malloc.c \
|
||||
math.c \
|
||||
onfork.c \
|
||||
|
@ -47,10 +48,6 @@ EXTRA_DIST = \
|
|||
dump-vanilla.c \
|
||||
heap-gen.c \
|
||||
heap-sc.c \
|
||||
load-dl.c \
|
||||
load-ld.c \
|
||||
load-rld.c \
|
||||
load-shl.c \
|
||||
stab-bsd.c \
|
||||
stab-coff.c \
|
||||
stab-convex.c \
|
||||
|
|
|
@ -42,8 +42,8 @@ void Init_Features () {
|
|||
#ifdef CAN_DUMP
|
||||
P_Provide (Intern ("elk:dump"));
|
||||
#endif
|
||||
#ifdef CAN_LOAD_OBJ
|
||||
P_Provide (Intern ("elk:load-object"));
|
||||
#ifdef CAN_LOAD_LIB
|
||||
P_Provide (Intern ("elk:load-lib"));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
extern void Call_Initializers (SYMTAB *, char *, int);
|
||||
extern void Load_Source (Object);
|
||||
extern void Call_Finalizers ();
|
||||
extern void Finit_Load ();
|
||||
extern void Generational_GC_Reinitialize ();
|
||||
extern int Check_Stack_Grows_Down ();
|
||||
extern void Make_Heap (int);
|
||||
|
@ -105,16 +104,13 @@ char *A_Out_Name;
|
|||
char *Find_Executable();
|
||||
#endif
|
||||
|
||||
#if defined(CAN_LOAD_OBJ) || defined(INIT_OBJECTS)
|
||||
#if defined(CAN_LOAD_LIB) || defined(INIT_OBJECTS)
|
||||
SYMTAB *The_Symbols;
|
||||
#endif
|
||||
|
||||
void Exit_Handler () {
|
||||
#if defined(CAN_LOAD_OBJ) || defined(INIT_OBJECTS)
|
||||
#if defined(CAN_LOAD_LIB) || defined(INIT_OBJECTS)
|
||||
Call_Finalizers ();
|
||||
#endif
|
||||
#ifdef CAN_LOAD_OBJ
|
||||
Finit_Load ();
|
||||
#endif
|
||||
Free_Heap ();
|
||||
}
|
||||
|
|
192
src/load-dl.c
192
src/load-dl.c
|
@ -1,192 +0,0 @@
|
|||
/* load-dl.c
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 1990, 1991, 1992, 1993, 1994, 1995, Oliver Laumann, Berlin
|
||||
* Copyright 2002, 2003 Sam Hocevar <sam@zoy.org>, Paris
|
||||
*
|
||||
* This software was derived from Elk 1.2, which was Copyright 1987, 1988,
|
||||
* 1989, Nixdorf Computer AG and TELES GmbH, Berlin (Elk 1.2 has been written
|
||||
* by Oliver Laumann for TELES Telematic Services, Berlin, in a joint project
|
||||
* between TELES and Nixdorf Microprocessor Engineering, Berlin).
|
||||
*
|
||||
* Oliver Laumann, TELES GmbH, Nixdorf Computer AG and Sam Hocevar, as co-
|
||||
* owners or individual owners of copyright in this software, grant to any
|
||||
* person or company a worldwide, royalty free, license to
|
||||
*
|
||||
* i) copy this software,
|
||||
* ii) prepare derivative works based on this software,
|
||||
* iii) distribute copies of this software or derivative works,
|
||||
* iv) perform this software, or
|
||||
* v) display this software,
|
||||
*
|
||||
* provided that this notice is not removed and that neither Oliver Laumann
|
||||
* nor Teles nor Nixdorf are deemed to have made any representations as to
|
||||
* the suitability of this software for any purpose nor are held responsible
|
||||
* for any defects of this software.
|
||||
*
|
||||
* THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern void Free_Symbols (SYMTAB *);
|
||||
extern void Call_Initializers (SYMTAB *, char *, int);
|
||||
|
||||
void Dlopen_File (char *fn) {
|
||||
void *handle;
|
||||
SYM *sp;
|
||||
|
||||
if (Verb_Load)
|
||||
printf ("[dlopen %s]\n", fn);
|
||||
if ((handle = dlopen (fn, RTLD_NOW|RTLD_GLOBAL)) == 0) {
|
||||
char *errstr = dlerror ();
|
||||
Primitive_Error ("dlopen failed:~%~s",
|
||||
Make_String (errstr, strlen (errstr)));
|
||||
}
|
||||
if (The_Symbols)
|
||||
Free_Symbols (The_Symbols);
|
||||
The_Symbols = Open_File_And_Snarf_Symbols (fn);
|
||||
/*
|
||||
* dlsym() may fail for symbols not exported by object file;
|
||||
* this can be safely ignored.
|
||||
*/
|
||||
for (sp = The_Symbols->first; sp; sp = sp->next)
|
||||
sp->value = (unsigned long int)dlsym (handle, sp->name);
|
||||
Call_Initializers (The_Symbols, 0, PR_CONSTRUCTOR);
|
||||
Call_Initializers (The_Symbols, 0, PR_EXTENSION);
|
||||
}
|
||||
|
||||
static char *tempname;
|
||||
static char *tmpdir;
|
||||
static int tmplen;
|
||||
static int Seq_Num;
|
||||
|
||||
char *Temp_Name (int seq) {
|
||||
if (!tempname) {
|
||||
if (!(tmpdir = getenv ("TMPDIR")))
|
||||
tmpdir = "/tmp";
|
||||
tempname = Safe_Malloc (tmplen = strlen (tmpdir) + 20);
|
||||
sprintf (tempname, "%s/ldXXXXXX", tmpdir);
|
||||
(void)mktemp (tempname);
|
||||
strcat (tempname, ".");
|
||||
}
|
||||
sprintf (strrchr (tempname, '.'), ".%d", seq);
|
||||
return tempname;
|
||||
}
|
||||
|
||||
void Fork_Load () {
|
||||
int i;
|
||||
char *newtemp;
|
||||
|
||||
if (!tempname)
|
||||
return;
|
||||
Disable_Interrupts;
|
||||
newtemp = Safe_Malloc (tmplen);
|
||||
sprintf (newtemp, "%s/ldXXXXXX", tmpdir);
|
||||
(void)mktemp (newtemp);
|
||||
strcat (newtemp, ".");
|
||||
for (i = 0; i < Seq_Num; i++) {
|
||||
sprintf (strrchr (newtemp, '.'), ".%d", i);
|
||||
(void)link (Temp_Name (i), newtemp);
|
||||
}
|
||||
free (tempname);
|
||||
tempname = newtemp;
|
||||
Enable_Interrupts;
|
||||
}
|
||||
|
||||
void Load_Object (Object names) {
|
||||
Object port, tail, fullnames, libs;
|
||||
char *lp, *buf, *outfile;
|
||||
int len, liblen, i;
|
||||
GC_Node3;
|
||||
Alloca_Begin;
|
||||
|
||||
port = tail = fullnames = Null;
|
||||
GC_Link3 (port, tail, fullnames);
|
||||
for (len = 0, tail = names; !Nullp (tail); tail = Cdr (tail)) {
|
||||
port = General_Open_File (Car (tail), P_INPUT, Var_Get (V_Load_Path));
|
||||
fullnames = Cons (PORT(port)->name, fullnames);
|
||||
len += STRING(Car (fullnames))->size + 1;
|
||||
(void)P_Close_Input_Port (port);
|
||||
}
|
||||
GC_Unlink;
|
||||
|
||||
libs = Var_Get (V_Load_Libraries);
|
||||
if (TYPE(libs) == T_String) {
|
||||
liblen = STRING(libs)->size;
|
||||
lp = STRING(libs)->data;
|
||||
} else {
|
||||
liblen = 0;
|
||||
lp = "";
|
||||
}
|
||||
|
||||
Disable_Interrupts;
|
||||
|
||||
buf = Temp_Name (Seq_Num);
|
||||
Seq_Num++;
|
||||
Alloca (outfile, char*, tmplen);
|
||||
strcpy (outfile, buf);
|
||||
Alloca (buf, char*, len + liblen + Seq_Num*tmplen + 100);
|
||||
sprintf (buf, "%s %s -o %s ", LD_NAME, LDFLAGS_SHARED, outfile);
|
||||
|
||||
for (tail = fullnames; !Nullp (tail); tail = Cdr (tail)) {
|
||||
register struct S_String *str = STRING(Car (tail));
|
||||
strncat (buf, str->data, str->size);
|
||||
strcat (buf, " ");
|
||||
}
|
||||
for (i = 0; i < Seq_Num-1; i++) {
|
||||
strcat (buf, Temp_Name (i));
|
||||
strcat (buf, " ");
|
||||
}
|
||||
strncat (buf, lp, liblen);
|
||||
|
||||
if (Verb_Load)
|
||||
printf ("[%s]\n", buf);
|
||||
if (system (buf) != 0) {
|
||||
Seq_Num--;
|
||||
(void)unlink (outfile);
|
||||
Primitive_Error ("system linker failed");
|
||||
}
|
||||
Dlopen_File (outfile);
|
||||
Enable_Interrupts;
|
||||
Alloca_End;
|
||||
}
|
||||
|
||||
void Load_Lib (Object libs) {
|
||||
Object port, name;
|
||||
|
||||
if (Nullp (libs))
|
||||
return;
|
||||
|
||||
Load_Lib (Cdr (libs));
|
||||
|
||||
GC_Node2;
|
||||
port = name = Null;
|
||||
GC_Link2 (port, name);
|
||||
port = General_Open_File (Car (libs), P_INPUT, Var_Get (V_Load_Path));
|
||||
name = PORT(port)->name;
|
||||
Dlopen_File (STRING(name)->data);
|
||||
(void)P_Close_Input_Port (port);
|
||||
GC_Unlink;
|
||||
}
|
||||
|
||||
void Load_Library (Object libs) {
|
||||
Disable_Interrupts;
|
||||
Load_Lib (libs);
|
||||
Enable_Interrupts;
|
||||
}
|
||||
|
||||
void Finit_Load () {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < Seq_Num; i++)
|
||||
(void)unlink (Temp_Name (i));
|
||||
/*
|
||||
* The linker in SGI Irix 5 produces this file:
|
||||
*/
|
||||
(void)unlink ("so_locations");
|
||||
}
|
201
src/load-ld.c
201
src/load-ld.c
|
@ -1,201 +0,0 @@
|
|||
/* load-ld.c
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 1990, 1991, 1992, 1993, 1994, 1995, Oliver Laumann, Berlin
|
||||
* Copyright 2002, 2003 Sam Hocevar <sam@zoy.org>, Paris
|
||||
*
|
||||
* This software was derived from Elk 1.2, which was Copyright 1987, 1988,
|
||||
* 1989, Nixdorf Computer AG and TELES GmbH, Berlin (Elk 1.2 has been written
|
||||
* by Oliver Laumann for TELES Telematic Services, Berlin, in a joint project
|
||||
* between TELES and Nixdorf Microprocessor Engineering, Berlin).
|
||||
*
|
||||
* Oliver Laumann, TELES GmbH, Nixdorf Computer AG and Sam Hocevar, as co-
|
||||
* owners or individual owners of copyright in this software, grant to any
|
||||
* person or company a worldwide, royalty free, license to
|
||||
*
|
||||
* i) copy this software,
|
||||
* ii) prepare derivative works based on this software,
|
||||
* iii) distribute copies of this software or derivative works,
|
||||
* iv) perform this software, or
|
||||
* v) display this software,
|
||||
*
|
||||
* provided that this notice is not removed and that neither Oliver Laumann
|
||||
* nor Teles nor Nixdorf are deemed to have made any representations as to
|
||||
* the suitability of this software for any purpose nor are held responsible
|
||||
* for any defects of this software.
|
||||
*
|
||||
* THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include AOUT_H
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0
|
||||
#endif
|
||||
|
||||
#ifdef ECOFF
|
||||
# ifdef CACHECTL_H
|
||||
# include CACHECTL_H
|
||||
# endif
|
||||
|
||||
struct headers {
|
||||
struct filehdr fhdr;
|
||||
struct aouthdr aout;
|
||||
struct scnhdr section[3];
|
||||
};
|
||||
#endif
|
||||
|
||||
extern void Free_Symbols (SYMTAB *);
|
||||
extern void Call_Initializers (SYMTAB *, char *, int);
|
||||
|
||||
extern void *sbrk();
|
||||
extern char *getenv();
|
||||
|
||||
static char *Loader_Output;
|
||||
static char *tmpdir;
|
||||
|
||||
void Load_Object (Object names) {
|
||||
#ifdef ECOFF
|
||||
struct headers hdr;
|
||||
#else
|
||||
struct exec hdr;
|
||||
#endif
|
||||
register char *brk, *obrk, *lp, *li;
|
||||
char *buf;
|
||||
register int n, f, len, liblen;
|
||||
Object port, tail, fullnames, libs;
|
||||
FILE *fp;
|
||||
GC_Node3;
|
||||
Alloca_Begin;
|
||||
|
||||
li = Loader_Input;
|
||||
if (!li)
|
||||
li = A_Out_Name;
|
||||
if (!Loader_Output) {
|
||||
if (!(tmpdir = getenv ("TMPDIR")))
|
||||
tmpdir = "/tmp";
|
||||
Loader_Output = Safe_Malloc (strlen (tmpdir) + 20);
|
||||
}
|
||||
sprintf (Loader_Output, "%s/ldXXXXXX", tmpdir);
|
||||
(void)mktemp (Loader_Output);
|
||||
|
||||
port = tail = fullnames = Null;
|
||||
GC_Link3 (port, tail, fullnames);
|
||||
for (len = 0, tail = names; !Nullp (tail); tail = Cdr (tail)) {
|
||||
port = General_Open_File (Car (tail), P_INPUT, Var_Get (V_Load_Path));
|
||||
fullnames = Cons (PORT(port)->name, fullnames);
|
||||
len += STRING(Car (fullnames))->size + 1;
|
||||
(void)P_Close_Input_Port (port);
|
||||
}
|
||||
GC_Unlink;
|
||||
|
||||
libs = Var_Get (V_Load_Libraries);
|
||||
if (TYPE(libs) == T_String) {
|
||||
liblen = STRING(libs)->size;
|
||||
lp = STRING(libs)->data;
|
||||
} else {
|
||||
liblen = 3; lp = "-lc";
|
||||
}
|
||||
|
||||
Alloca (buf, char*, strlen (A_Out_Name) + len + liblen + 100);
|
||||
|
||||
obrk = brk = (char *)sbrk (0);
|
||||
brk = (char *)((int)brk + 7 & ~7);
|
||||
|
||||
#if defined(hp9000s300) || defined(__hp9000s300) || defined(__hp9000s300__)
|
||||
sprintf (buf, "%s -N %s -A %s -R %x -o %s ",
|
||||
#else
|
||||
sprintf (buf, "%s -N %s -A %s -T %x -o %s ",
|
||||
#endif
|
||||
LD_NAME, INC_LDFLAGS, li, (unsigned int)brk, Loader_Output);
|
||||
|
||||
for (tail = fullnames; !Nullp (tail); tail = Cdr (tail)) {
|
||||
register struct S_String *str = STRING(Car (tail));
|
||||
strncat (buf, str->data, str->size);
|
||||
strcat (buf, " ");
|
||||
}
|
||||
strncat (buf, lp, liblen);
|
||||
|
||||
if (Verb_Load)
|
||||
printf ("[%s]\n", buf);
|
||||
if (system (buf) != 0) {
|
||||
(void)unlink (Loader_Output);
|
||||
Primitive_Error ("system linker failed");
|
||||
}
|
||||
Disable_Interrupts; /* To ensure that f gets closed */
|
||||
if ((f = open (Loader_Output, O_RDONLY|O_BINARY)) == -1) {
|
||||
(void)unlink (Loader_Output);
|
||||
Primitive_Error ("cannot open tempfile");
|
||||
}
|
||||
if (Loader_Input)
|
||||
(void)unlink (Loader_Input);
|
||||
else
|
||||
Loader_Input = Safe_Malloc (strlen (tmpdir) + 20);
|
||||
strcpy (Loader_Input, Loader_Output);
|
||||
if (read (f, (char *)&hdr, sizeof (hdr)) != sizeof (hdr)) {
|
||||
err:
|
||||
close (f);
|
||||
Primitive_Error ("corrupt tempfile (`ld' is broken)");
|
||||
}
|
||||
#ifdef ECOFF
|
||||
n = hdr.aout.tsize + hdr.aout.dsize + hdr.aout.bsize;
|
||||
#else
|
||||
n = hdr.a_text + hdr.a_data + hdr.a_bss;
|
||||
#endif
|
||||
if ((char *)sbrk (n + brk-obrk) == (char *)-1) {
|
||||
close (f);
|
||||
Primitive_Error ("not enough memory to load object file");
|
||||
}
|
||||
memset (brk, 0, n);
|
||||
#ifdef ECOFF
|
||||
n -= hdr.aout.bsize;
|
||||
(void)lseek (f, (off_t)hdr.section[0].s_scnptr, 0);
|
||||
#else
|
||||
n -= hdr.a_bss;
|
||||
#endif
|
||||
if (read (f, brk, n) != n)
|
||||
goto err;
|
||||
if ((fp = fdopen (f, O_BINARY ? "rb" : "r")) == NULL) {
|
||||
close (f);
|
||||
Primitive_Error ("cannot fdopen object file");
|
||||
}
|
||||
if (The_Symbols)
|
||||
Free_Symbols (The_Symbols);
|
||||
The_Symbols = Snarf_Symbols (fp, &hdr);
|
||||
(void)fclose (fp);
|
||||
#if defined(ECOFF) && defined(CACHECTL_H)
|
||||
if (cacheflush (brk, n, BCACHE) == -1) {
|
||||
extern int errno;
|
||||
Saved_Errno = errno;
|
||||
Primitive_Error ("cacheflush failed: ~E");
|
||||
}
|
||||
#endif
|
||||
Call_Initializers (The_Symbols, brk, PR_CONSTRUCTOR);
|
||||
Call_Initializers (The_Symbols, brk, PR_EXTENSION);
|
||||
Enable_Interrupts;
|
||||
Alloca_End;
|
||||
}
|
||||
|
||||
void Finit_Load () {
|
||||
if (Loader_Input)
|
||||
(void)unlink (Loader_Input);
|
||||
}
|
||||
|
||||
void Fork_Load () {
|
||||
char *newlink;
|
||||
|
||||
if (Loader_Input) {
|
||||
Disable_Interrupts;
|
||||
newlink = Safe_Malloc (strlen (tmpdir) + 20);
|
||||
sprintf (newlink, "%s/ldXXXXXX", tmpdir);
|
||||
(void)mktemp (newlink);
|
||||
(void)link (Loader_Input, newlink);
|
||||
free (Loader_Input);
|
||||
Loader_Input = newlink;
|
||||
Enable_Interrupts;
|
||||
}
|
||||
}
|
109
src/load-rld.c
109
src/load-rld.c
|
@ -1,109 +0,0 @@
|
|||
/* load-rld.c
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 1990, 1991, 1992, 1993, 1994, 1995, Oliver Laumann, Berlin
|
||||
* Copyright 2002, 2003 Sam Hocevar <sam@zoy.org>, Paris
|
||||
*
|
||||
* This software was derived from Elk 1.2, which was Copyright 1987, 1988,
|
||||
* 1989, Nixdorf Computer AG and TELES GmbH, Berlin (Elk 1.2 has been written
|
||||
* by Oliver Laumann for TELES Telematic Services, Berlin, in a joint project
|
||||
* between TELES and Nixdorf Microprocessor Engineering, Berlin).
|
||||
*
|
||||
* Oliver Laumann, TELES GmbH, Nixdorf Computer AG and Sam Hocevar, as co-
|
||||
* owners or individual owners of copyright in this software, grant to any
|
||||
* person or company a worldwide, royalty free, license to
|
||||
*
|
||||
* i) copy this software,
|
||||
* ii) prepare derivative works based on this software,
|
||||
* iii) distribute copies of this software or derivative works,
|
||||
* iv) perform this software, or
|
||||
* v) display this software,
|
||||
*
|
||||
* provided that this notice is not removed and that neither Oliver Laumann
|
||||
* nor Teles nor Nixdorf are deemed to have made any representations as to
|
||||
* the suitability of this software for any purpose nor are held responsible
|
||||
* for any defects of this software.
|
||||
*
|
||||
* THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <mach-o/rld.h>
|
||||
|
||||
extern void Free_Symbols (SYMTAB *);
|
||||
extern void Call_Initializers (SYMTAB *, char *, int);
|
||||
|
||||
void Load_Object (Object names) {
|
||||
long retval;
|
||||
struct mach_header *hdr;
|
||||
char **filenames, *libs;
|
||||
NXStream *err_stream;
|
||||
register int i, n;
|
||||
Object port, tail, fullnames;
|
||||
extern char *strtok();
|
||||
GC_Node3;
|
||||
Alloca_Begin;
|
||||
|
||||
port = tail = fullnames = Null;
|
||||
GC_Link3 (port, tail, fullnames);
|
||||
for (n = 0, tail = names; !Nullp (tail); n++, tail = Cdr (tail)) {
|
||||
port = General_Open_File (Car (tail), P_INPUT, Var_Get (V_Load_Path));
|
||||
fullnames = Cons (PORT(port)->name, fullnames);
|
||||
(void)P_Close_Input_Port (port);
|
||||
}
|
||||
GC_Unlink;
|
||||
|
||||
libs = "";
|
||||
tail = Var_Get (V_Load_Libraries);
|
||||
if (TYPE(tail) == T_String)
|
||||
Get_Strsym_Stack (tail, libs);
|
||||
|
||||
Alloca (filenames, char**, (n+1 + strlen (libs)/2) * sizeof (char *));
|
||||
for (i = 0; i < n; i++, fullnames = Cdr (fullnames)) {
|
||||
Object s;
|
||||
|
||||
s = Car (fullnames);
|
||||
Get_Strsym_Stack (s, filenames[i]);
|
||||
}
|
||||
|
||||
/* Append the load-libraries to the end of the list of filenames
|
||||
* to be passed to rld_load:
|
||||
*/
|
||||
for ( ; (filenames[i] = strtok (libs, " \t")) != 0; i++, libs = 0)
|
||||
;
|
||||
if (Verb_Load) {
|
||||
printf ("[rld_load: ");
|
||||
for (i = 0; filenames[i]; i++) printf ("%s ", filenames[i]);
|
||||
printf ("]\n");
|
||||
}
|
||||
|
||||
Disable_Interrupts;
|
||||
/* Construct a stream for error logging:
|
||||
*/
|
||||
if ((err_stream = NXOpenFile (fileno (stderr), NX_WRITEONLY)) == 0)
|
||||
Primitive_Error ("NXOpenFile failed");
|
||||
|
||||
retval = rld_load (err_stream, /* report error messages here */
|
||||
&hdr, /* return header address here */
|
||||
filenames, /* load these */
|
||||
"/dev/null"); /* doesn't work if NULL?! */
|
||||
NXClose (err_stream);
|
||||
if (retval != 1)
|
||||
Primitive_Error ("rld_load() failed");
|
||||
|
||||
/* Grab the symbol table from the just-loaded file:
|
||||
*/
|
||||
if (The_Symbols)
|
||||
Free_Symbols (The_Symbols);
|
||||
The_Symbols = Snarf_Symbols (hdr);
|
||||
Call_Initializers (The_Symbols, 0, PR_CONSTRUCTOR);
|
||||
Call_Initializers (The_Symbols, 0, PR_EXTENSION);
|
||||
Enable_Interrupts;
|
||||
Alloca_End;
|
||||
}
|
||||
|
||||
void Finit_Load () {
|
||||
}
|
||||
|
||||
void Fork_Load () {
|
||||
}
|
115
src/load-shl.c
115
src/load-shl.c
|
@ -1,115 +0,0 @@
|
|||
/* load-shl.c
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 1990, 1991, 1992, 1993, 1994, 1995, Oliver Laumann, Berlin
|
||||
* Copyright 2002, 2003 Sam Hocevar <sam@zoy.org>, Paris
|
||||
*
|
||||
* This software was derived from Elk 1.2, which was Copyright 1987, 1988,
|
||||
* 1989, Nixdorf Computer AG and TELES GmbH, Berlin (Elk 1.2 has been written
|
||||
* by Oliver Laumann for TELES Telematic Services, Berlin, in a joint project
|
||||
* between TELES and Nixdorf Microprocessor Engineering, Berlin).
|
||||
*
|
||||
* Oliver Laumann, TELES GmbH, Nixdorf Computer AG and Sam Hocevar, as co-
|
||||
* owners or individual owners of copyright in this software, grant to any
|
||||
* person or company a worldwide, royalty free, license to
|
||||
*
|
||||
* i) copy this software,
|
||||
* ii) prepare derivative works based on this software,
|
||||
* iii) distribute copies of this software or derivative works,
|
||||
* iv) perform this software, or
|
||||
* v) display this software,
|
||||
*
|
||||
* provided that this notice is not removed and that neither Oliver Laumann
|
||||
* nor Teles nor Nixdorf are deemed to have made any representations as to
|
||||
* the suitability of this software for any purpose nor are held responsible
|
||||
* for any defects of this software.
|
||||
*
|
||||
* THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <dl.h>
|
||||
#include <string.h>
|
||||
|
||||
extern void Free_Symbols (SYMTAB *);
|
||||
extern void Call_Initializers (SYMTAB *, char *, int);
|
||||
|
||||
extern int errno;
|
||||
|
||||
static void Load_Them (Object names) {
|
||||
char *fn;
|
||||
shl_t handle;
|
||||
SYM *sp;
|
||||
static struct obj_loaded {
|
||||
struct obj_loaded *next;
|
||||
char *name;
|
||||
} *loaded, *lp;
|
||||
GC_Node;
|
||||
Alloca_Begin;
|
||||
|
||||
GC_Link(names);
|
||||
for ( ; !Nullp (names); names = Cdr (names)) {
|
||||
Get_Strsym_Stack (Car (names), fn);
|
||||
for (lp = loaded; lp; lp = lp->next)
|
||||
if (strcmp (lp->name, fn) == 0) break;
|
||||
if (lp) continue;
|
||||
lp = (struct obj_loaded *)Safe_Malloc (sizeof (*lp));
|
||||
lp->name = strdup (fn);
|
||||
lp->next = loaded;
|
||||
loaded = lp;
|
||||
if (Verb_Load)
|
||||
printf ("[shl_load %s]\n", fn);
|
||||
if ((handle = shl_load (fn, BIND_IMMEDIATE|BIND_VERBOSE, 0L)) == 0) {
|
||||
Saved_Errno = errno;
|
||||
Primitive_Error ("shl_load of ~s failed: ~E", Car (names));
|
||||
}
|
||||
if (The_Symbols)
|
||||
Free_Symbols (The_Symbols);
|
||||
The_Symbols = Open_File_And_Snarf_Symbols (fn);
|
||||
for (sp = The_Symbols->first; sp; sp = sp->next)
|
||||
if (shl_findsym (&handle, sp->name, TYPE_UNDEFINED, &sp->value)) {
|
||||
Saved_Errno = errno;
|
||||
Primitive_Error ("~s: shl_findsym on ~s failed: ~E",
|
||||
Car (names),
|
||||
Make_String (sp->name, strlen (sp->name)));
|
||||
}
|
||||
Call_Initializers (The_Symbols, 0, PR_CONSTRUCTOR);
|
||||
Call_Initializers (The_Symbols, 0, PR_EXTENSION);
|
||||
}
|
||||
GC_Unlink;
|
||||
Alloca_End;
|
||||
}
|
||||
|
||||
void Load_Object (Object names) {
|
||||
Object port, tail, fullnames, str;
|
||||
char *p, *libs = "";
|
||||
GC_Node3;
|
||||
Alloca_Begin;
|
||||
|
||||
port = tail = fullnames = Null;
|
||||
GC_Link3 (port, tail, fullnames);
|
||||
for (tail = names; !Nullp (tail); tail = Cdr (tail)) {
|
||||
port = General_Open_File (Car (tail), P_INPUT, Var_Get (V_Load_Path));
|
||||
fullnames = Cons (PORT(port)->name, fullnames);
|
||||
(void)P_Close_Input_Port (port);
|
||||
}
|
||||
tail = Var_Get (V_Load_Libraries);
|
||||
if (TYPE(tail) == T_String)
|
||||
Get_Strsym_Stack (tail, libs);
|
||||
Disable_Interrupts;
|
||||
for (tail = Null; (p = strtok (libs, " \t")) != 0; libs = 0) {
|
||||
str = Make_String (p, strlen (p));
|
||||
tail = Cons (str, tail);
|
||||
}
|
||||
Load_Them (tail);
|
||||
Load_Them (fullnames);
|
||||
Enable_Interrupts;
|
||||
GC_Unlink;
|
||||
Alloca_End;
|
||||
}
|
||||
|
||||
void Finit_Load () {
|
||||
}
|
||||
|
||||
void Fork_Load () {
|
||||
}
|
17
src/load.c
17
src/load.c
|
@ -30,6 +30,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
Object V_Load_Path, V_Load_Noisilyp, V_Load_Libraries;
|
||||
|
@ -37,17 +39,10 @@ Object V_Load_Path, V_Load_Noisilyp, V_Load_Libraries;
|
|||
char *Loader_Input; /* tmp file name used by load.xx.c */
|
||||
|
||||
extern void Switch_Environment (Object);
|
||||
void Load_Source (Object);
|
||||
|
||||
#if defined(USE_LD)
|
||||
# include "load-ld.c"
|
||||
#elif defined(USE_RLD)
|
||||
# include "load-rld.c"
|
||||
#elif defined(USE_SHL)
|
||||
# include "load-shl.c"
|
||||
#elif defined(USE_DLOPEN)
|
||||
# include "load-dl.c"
|
||||
#ifdef CAN_LOAD_LIB
|
||||
extern void Load_Library (Object libs);
|
||||
#endif
|
||||
void Load_Source (Object);
|
||||
|
||||
void Init_Load () {
|
||||
Define_Variable (&V_Load_Path, "load-path",
|
||||
|
@ -102,7 +97,7 @@ void Check_Loadarg (Object x) {
|
|||
f = Car (tail);
|
||||
if (TYPE(f) != T_Symbol && TYPE(f) != T_String)
|
||||
Wrong_Type_Combination (f, "string or symbol");
|
||||
if (!Has_Suffix (f, ".o") && !Has_Suffix (f, ".so"))
|
||||
if (!Has_Suffix (f, ".so"))
|
||||
Primitive_Error ("~s: not an object file", f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
/* load-dl.c
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Copyright 1990, 1991, 1992, 1993, 1994, 1995, Oliver Laumann, Berlin
|
||||
* Copyright 2002, 2003 Sam Hocevar <sam@zoy.org>, Paris
|
||||
*
|
||||
* This software was derived from Elk 1.2, which was Copyright 1987, 1988,
|
||||
* 1989, Nixdorf Computer AG and TELES GmbH, Berlin (Elk 1.2 has been written
|
||||
* by Oliver Laumann for TELES Telematic Services, Berlin, in a joint project
|
||||
* between TELES and Nixdorf Microprocessor Engineering, Berlin).
|
||||
*
|
||||
* Oliver Laumann, TELES GmbH, Nixdorf Computer AG and Sam Hocevar, as co-
|
||||
* owners or individual owners of copyright in this software, grant to any
|
||||
* person or company a worldwide, royalty free, license to
|
||||
*
|
||||
* i) copy this software,
|
||||
* ii) prepare derivative works based on this software,
|
||||
* iii) distribute copies of this software or derivative works,
|
||||
* iv) perform this software, or
|
||||
* v) display this software,
|
||||
*
|
||||
* provided that this notice is not removed and that neither Oliver Laumann
|
||||
* nor Teles nor Nixdorf are deemed to have made any representations as to
|
||||
* the suitability of this software for any purpose nor are held responsible
|
||||
* for any defects of this software.
|
||||
*
|
||||
* THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef CAN_LOAD_LIB
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
extern void Free_Symbols (SYMTAB *);
|
||||
extern void Call_Initializers (SYMTAB *, char *, int);
|
||||
|
||||
void Dlopen_File (char *fn) {
|
||||
void *handle;
|
||||
SYM *sp;
|
||||
|
||||
if (Verb_Load)
|
||||
printf ("[dlopen %s]\n", fn);
|
||||
if ((handle = dlopen (fn, RTLD_NOW|RTLD_GLOBAL)) == 0) {
|
||||
char *errstr = dlerror ();
|
||||
Primitive_Error ("dlopen failed:~%~s",
|
||||
Make_String (errstr, strlen (errstr)));
|
||||
}
|
||||
if (The_Symbols)
|
||||
Free_Symbols (The_Symbols);
|
||||
The_Symbols = Open_File_And_Snarf_Symbols (fn);
|
||||
/*
|
||||
* dlsym() may fail for symbols not exported by object file;
|
||||
* this can be safely ignored.
|
||||
*/
|
||||
for (sp = The_Symbols->first; sp; sp = sp->next)
|
||||
sp->value = (unsigned long int)dlsym (handle, sp->name);
|
||||
Call_Initializers (The_Symbols, 0, PR_CONSTRUCTOR);
|
||||
Call_Initializers (The_Symbols, 0, PR_EXTENSION);
|
||||
}
|
||||
|
||||
static void Load_Lib (Object libs) {
|
||||
Object port, name;
|
||||
|
||||
if (Nullp (libs))
|
||||
return;
|
||||
|
||||
Load_Lib (Cdr (libs));
|
||||
|
||||
GC_Node2;
|
||||
port = name = Null;
|
||||
GC_Link2 (port, name);
|
||||
port = General_Open_File (Car (libs), P_INPUT, Var_Get (V_Load_Path));
|
||||
name = PORT(port)->name;
|
||||
Dlopen_File (STRING(name)->data);
|
||||
(void)P_Close_Input_Port (port);
|
||||
GC_Unlink;
|
||||
}
|
||||
|
||||
void Load_Library (Object libs) {
|
||||
Disable_Interrupts;
|
||||
Load_Lib (libs);
|
||||
Enable_Interrupts;
|
||||
}
|
||||
|
||||
#endif /* CAN_LOAD_LIB */
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
void Free_Symbols (SYMTAB *);
|
||||
|
||||
#if defined(CAN_LOAD_OBJ) || defined (INIT_OBJECTS)
|
||||
#if defined(CAN_LOAD_LIB) || defined (INIT_OBJECTS)
|
||||
|
||||
#if defined(MACH_O)
|
||||
# include "stab-macho.c"
|
||||
|
|
Loading…
Reference in New Issue