1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <filehdr.h>
#ifdef n_offset
#undef n_offset
#endif
#include <syms.h>
#include <ldfcn.h>
extern SYMENT *lookupsym();
extern char *ldgetname();
#define INTERNAL_CNAME_PATTERN "_%s"
#define INTERNAL_FNAME_PATTERN "_%s_"
#define HAS_OWN_DYNLOAD
#define VERBDFLT TRUE
#define COFF_FORMAT
#define SYMVALUE(sym) ((char *) ((sym).n_value))
#define SYM_IS_GLOBAL_FUNCTION(ldptr,symbol) \
((symbol).n_sclass == C_EXT && (symbol).n_scnum > 0)
static char *libraries[] = {
"/lib/libc.a",
"/usr/lib/libm.a",
"/usr/lib/libF77.a",
"/usr/lib/libI77.a",
"/usr/lib/libU77.a",
NULL
};
static link_and_load(fname, libs, fort)
char *fname, *libs;
int fort;
{
char *code_start;
static int inited = FALSE;
LDFILE *fp;
SYMENT symbol, *sym;
char *symname, *symaddr;
int i;
if (! inited && initsyms(progname) == 0)
xlfail("couldn't initialize symbol table");
else inited = TRUE;
/* load the code */
if (dynload(fname, &code_start, 0L, libraries) <= 0) xlfail("load failed");
/* Enter the symbols. */
/* Assumes the value of the syment returned by lookupsym gives the */
/* offset from code_start. */
if ((fp = ldopen(fname, NULL)) == NULL)
xlfail("cannot open object file for symbol reading");
i = 0;
while (ldtbread(fp, i, &symbol) == SUCCESS) {
i++;
if (SYM_IS_GLOBAL_FUNCTION(input, symbol)) {
symname = ldgetname(fp, &symbol);
sym = lookupsym(symname);
if (sym != NULL) {
symaddr = code_start + (long) SYMVALUE(*sym);
enter_csymbol(symname, symaddr);
}
}
}
if (ldclose(fp) == FAILURE) xlfail("cannot close object file");
}
#undef n_name
#include <nlist.h>
|