#include <sys/trace.h>
/*#include <sys/types.h> gen.h*/
+#ifdef X_
+struct NLIST {
+ union {
+ char *n_name; /* for use when in-core */
+ } n_un;
+unsigned char n_type; /* type flag, i.e. N_TEXT etc; see below */
+ char n_other; /* unused */
+ short n_desc; /* see <stab.h> */
+unsigned long n_value; /* value of this symbol (or sdb offset) */
+};
+#else
+#define NLIST nlist
+#endif
+
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* symbol table segment first.)
*/
struct symseg {
- struct nlist *sy_first; /* base of this alloc'ed segment */
- struct nlist *sy_last; /* end of this segment, for n_strx */
+ struct NLIST *sy_first; /* base of this alloc'ed segment */
+ struct NLIST *sy_last; /* end of this segment, for n_strx */
int sy_used; /* symbols used in this seg */
- struct nlist **sy_hfirst; /* base of hash table, this seg */
- struct nlist **sy_hlast; /* end of hash table, this seg */
+ struct NLIST **sy_hfirst; /* base of hash table, this seg */
+ struct NLIST **sy_hlast; /* end of hash table, this seg */
} symseg[NSEG], *csymseg;
/*
#define xsym(x) (symseg[(x)/NSYM].sy_first+((x)%NSYM))
/* symx() is a function, defined below */
-struct nlist cursym; /* current symbol */
-struct nlist *lastsym; /* last symbol entered */
-struct nlist *nextsym; /* next available symbol table entry */
-struct nlist *addsym; /* first sym defined during incr load */
+struct NLIST cursym; /* current symbol */
+struct NLIST *lastsym; /* last symbol entered */
+struct NLIST *nextsym; /* next available symbol table entry */
+struct NLIST *addsym; /* first sym defined during incr load */
int nsym; /* pass2: number of local symbols in a.out */
/* nsym + symx(nextsym) is the symbol table size during pass2 */
-/*struct nlist **lookup(), **slookup();*/
-struct nlist *p_etext, *p_edata, *p_end, *entrypt;
+/*struct NLIST **lookup(), **slookup();*/
+struct NLIST *p_etext, *p_edata, *p_end, *entrypt;
/*
* Definitions of segmentation for library member table.
#define LHSIZ 31
struct local {
int l_index; /* index to symbol in file */
- struct nlist *l_symbol; /* ptr to symbol table */
+ struct NLIST *l_symbol; /* ptr to symbol table */
struct local *l_link; /* hash link */
} *lochash[LHSIZ], lhinit[NSYMPR];
struct locseg {
struct ranlib *tab; /* the table of contents (dynamically allocated) */
char *tabstr; /* string table for table of contents */
+#ifdef X_
+#define RAN_NAME(x) (tabstr + (x).ran_un.ran_strx)
+#else
+#define RAN_NAME(x) ((x).ran_un.ran_name)
+#endif
+
/*
* We open each input file or library only once, but in pass2 we
* (historically) read from such a file at 2 different places at the
int ldrand __P((void));
int load1 __P((int libflg, off_t loc));
void middle __P((void));
-void fixspec __P((struct nlist *sym, long offset));
-void ldrsym __P((register struct nlist *sp, long val, int type));
+void fixspec __P((struct NLIST *sym, long offset));
+void ldrsym __P((register struct NLIST *sp, long val, int type));
void setupout __P((void));
void outb __P((register struct biobuf **bp, int inc, int bufsize));
void load2arg __P((char *acp));
void mkfsym __P((char *s));
void getarhdr __P((void));
void mget __P((void *_loc, int n, register STREAM *sp));
-void symwrite __P((struct nlist *sp, struct biobuf *bp));
+void symwrite __P((struct NLIST *sp, struct biobuf *bp));
void dseek __P((register STREAM *sp, long loc, long s));
char get __P((STREAM *asp));
int getfile __P((char *acp));
int libopen __P((char *name, int oflags));
-struct nlist **lookup __P((void));
-void symfree __P((struct nlist *saved));
-struct nlist **slookup __P((char *s));
-int enter __P((register struct nlist **hp));
-int symx __P((struct nlist *sp));
+struct NLIST **lookup __P((void));
+void symfree __P((struct NLIST *saved));
+struct NLIST **slookup __P((char *s));
+int enter __P((register struct NLIST **hp));
+int symx __P((struct NLIST *sp));
void symreloc __P((void));
void error __P((int n, char *s));
void readhdr __P((off_t loc));
if (tp->ran_un.ran_strx < 0 ||
tp->ran_un.ran_strx >= ssiz)
error(1, "mangled archive table of contents");
+#ifndef X_
tp->ran_un.ran_name = tabstr + tp->ran_un.ran_strx;
+#endif
}
while (ldrand())
continue;
* Indicate to our caller whether this process netted any more symbols.
*/
int ldrand() {
- register struct nlist *sp, **hp;
+ register struct NLIST *sp, **hp;
register struct ranlib *tp, *tplast;
off_t loc;
int nsymt = symx(nextsym);
tplast = &tab[tnum-1];
for (tp = tab; tp <= tplast; tp++) {
- if ((hp = slookup(tp->ran_un.ran_name)) == 0 || *hp == 0)
+ if ((hp = slookup(RAN_NAME(*tp))) == 0 || *hp == 0)
continue;
sp = *hp;
if (sp->n_type != N_EXT+N_UNDF)
* Examine a single file or archive member on pass 1.
*/
int load1(libflg, loc) int libflg; off_t loc; {
- register struct nlist *sp;
- struct nlist *savnext;
+ register struct NLIST *sp;
+ struct NLIST *savnext;
int ndef, nlocal, type, size, nsymt;
register int i;
off_t maxoff;
struct stat stb;
+#ifdef X_
+ struct nlist temp;
+#endif
readhdr(loc);
if (filhdr.a_syms == 0) {
error(1, "too small (old format .o?)");
ctrel = tsize; cdrel += dsize; cbrel += bsize;
ndef = 0;
- nlocal = sizeof(cursym);
+ nlocal = sizeof(struct nlist);
savnext = nextsym;
loc += N_SYMOFF(filhdr);
dseek(&text, loc, filhdr.a_syms);
error(1, "no space for string table");
mget(curstr+sizeof(off_t), size-sizeof(off_t), &reloc);
while (text.size > 0) {
+#ifdef X_
+ mget(&temp, sizeof (struct nlist), &text);
+ if (temp.n_un.n_strx) {
+ if (temp.n_un.n_strx<sizeof(size) ||
+ temp.n_un.n_strx>=size)
+ error(1, "bad string table index (pass 1)");
+ cursym.n_un.n_name = curstr + temp.n_un.n_strx;
+ }
+ else
+ cursym.n_un.n_name = 0;
+ cursym.n_type = temp.n_type;
+ cursym.n_other = temp.n_other;
+ cursym.n_desc = temp.n_desc;
+ cursym.n_value = temp.n_value;
+#else
mget(&cursym, sizeof(struct nlist), &text);
if (cursym.n_un.n_strx) {
if (cursym.n_un.n_strx<sizeof(size) ||
error(1, "bad string table index (pass 1)");
cursym.n_un.n_name = curstr + cursym.n_un.n_strx;
}
+#endif
type = cursym.n_type;
if ((type&N_EXT)==0) {
if (Xflag==0 || cursym.n_un.n_name[0]!='L' ||
type & N_STAB)
- nlocal += sizeof cursym;
+ nlocal += sizeof (struct nlist);
continue;
}
symreloc();
}
void middle() {
- register struct nlist *sp;
+ register struct NLIST *sp;
long csize, t, corigin, ocsize;
int nund, rnd;
char s;
if (sflag || xflag)
ssize = 0;
bsize += csize;
- nsym = ssize / (sizeof cursym);
+ nsym = ssize / sizeof (struct nlist);
if (Aflag) {
fixspec(p_etext,torigin);
fixspec(p_edata,dorigin);
}
}
-void fixspec(sym, offset) struct nlist *sym; long offset; {
+void fixspec(sym, offset) struct NLIST *sym; long offset; {
if(symx(sym) < symx(addsym) && sym!=0)
sym->n_value += offset;
}
-void ldrsym(sp, val, type) register struct nlist *sp; long val; int type; {
+void ldrsym(sp, val, type) register struct NLIST *sp; long val; int type; {
if (sp == 0)
return;
filhdr.a_bss = bss;
filhdr.a_trsize = trsize;
filhdr.a_drsize = drsize;
- filhdr.a_syms = sflag? 0: (ssize + (sizeof cursym)*symx(nextsym));
+ filhdr.a_syms = sflag? 0: (ssize + sizeof (struct nlist)*symx(nextsym));
if (entrypt) {
if (entrypt->n_type!=N_EXT+N_TEXT)
error(0, "entry point not in text");
void load2(loc) long loc; {
int size;
- register struct nlist *sp;
+ register struct NLIST *sp;
register struct local *lp;
register int symno, i;
int type;
+#ifdef X_
+ struct nlist temp;
+#endif
readhdr(loc);
if (!funding) {
filhdr.a_trsize+filhdr.a_drsize, filhdr.a_syms);
while (text.size > 0) {
symno++;
+#ifdef X_
+ mget(&temp, sizeof (struct nlist), &text);
+ if (temp.n_un.n_strx) {
+ if (temp.n_un.n_strx<sizeof(size) ||
+ temp.n_un.n_strx>=size)
+ error(1, "bad string table index (pass 2)");
+ cursym.n_un.n_name = curstr + temp.n_un.n_strx;
+ }
+ else
+ cursym.n_un.n_name = 0;
+ cursym.n_type = temp.n_type;
+ cursym.n_other = temp.n_other;
+ cursym.n_desc = temp.n_desc;
+ cursym.n_value = temp.n_value;
+#else
mget(&cursym, sizeof(struct nlist), &text);
if (cursym.n_un.n_strx) {
if (cursym.n_un.n_strx<sizeof(size) ||
error(1, "bad string table index (pass 2)");
cursym.n_un.n_name = curstr + cursym.n_un.n_strx;
}
+#endif
/* inline expansion of symreloc() */
switch (cursym.n_type & 017) {
* each relocation datum address by our base position in the new segment.
*/
void load2td(creloc, position, b1, b2) long creloc; int position; struct biobuf *b1; struct biobuf *b2; {
- register struct nlist *sp;
+ register struct NLIST *sp;
register struct local *lp;
long tw;
register struct relocation_info *rp, *rpend;
#undef loc
}
-void symwrite(sp, bp) struct nlist *sp; struct biobuf *bp; {
+void symwrite(sp, bp) struct NLIST *sp; struct biobuf *bp; {
register int len;
register char *str;
+#ifdef X_
+ struct nlist temp;
+#endif
str = sp->n_un.n_name;
if (str) {
+#ifdef X_
+ temp.n_un.n_strx = offset;
+#else
sp->n_un.n_strx = offset;
+#endif
len = strlen(str) + 1;
bwrite(str, len, strout);
offset += len;
}
+#ifdef X_
+ else
+ temp.n_un.n_strx = 0;
+ temp.n_type = sp->n_type;
+ temp.n_other = sp->n_other;
+ temp.n_desc = sp->n_desc;
+ temp.n_value = sp->n_value;
+ bwrite(&temp, sizeof (temp), bp);
+#else
bwrite(sp, sizeof (*sp), bp);
sp->n_un.n_name = str;
+#endif
}
void dseek(sp, loc, s) register STREAM *sp; long loc; long s; {
return (fd);
}
-struct nlist **lookup() {
+struct NLIST **lookup() {
register int sh;
- register struct nlist **hp;
+ register struct NLIST **hp;
register char *cp, *cp1;
register struct symseg *gp;
register int i;
sh = (sh & 0x7fffffff) % HSIZE;
for (gp = symseg; gp < &symseg[NSEG]; gp++) {
if (gp->sy_first == 0) {
- gp->sy_first = (struct nlist *)
- calloc(NSYM, sizeof (struct nlist));
- gp->sy_hfirst = (struct nlist **)
- calloc(HSIZE, sizeof (struct nlist *));
+ gp->sy_first = (struct NLIST *)
+ calloc(NSYM, sizeof (struct NLIST));
+ gp->sy_hfirst = (struct NLIST **)
+ calloc(HSIZE, sizeof (struct NLIST *));
if (gp->sy_first == 0 || gp->sy_hfirst == 0)
error(1, "ran out of space for symbol table");
gp->sy_last = gp->sy_first + NSYM;
#endif
}
-void symfree(saved) struct nlist *saved; {
+void symfree(saved) struct NLIST *saved; {
register struct symseg *gp;
- register struct nlist *sp;
+ register struct NLIST *sp;
for (gp = csymseg; gp >= symseg; gp--, csymseg--) {
sp = gp->sy_first + gp->sy_used;
error(1, "symfree botch");
}
-struct nlist **slookup(s) char *s; {
+struct NLIST **slookup(s) char *s; {
cursym.n_un.n_name = s;
cursym.n_type = N_EXT+N_UNDF;
return (lookup());
}
-int enter(hp) register struct nlist **hp; {
- register struct nlist *sp;
+int enter(hp) register struct NLIST **hp; {
+ register struct NLIST *sp;
if (*hp==0) {
if (hp < csymseg->sy_hfirst || hp >= csymseg->sy_hlast)
}
}
-int symx(sp) struct nlist *sp; {
+int symx(sp) struct NLIST *sp; {
register struct symseg *gp;
if (sp == 0)