char * otherstring(struct nlist *sym) { static char buf[3]; char *result; result = buf; if (N_BIND(sym) == BIND_WEAK) *result++ = 'w'; if (N_AUX(sym) == AUX_OBJECT) *result++ = 'o'; else if (N_AUX(sym) == AUX_FUNC) *result++ = 'f'; *result++ = 0; return buf; }
/* build the new symbol and string tables */ static void buildNewTables(const HDR *x, long nsyms) { long remaining = nsyms; // total number of symbol table entries remaining to process #if FAST_NONPORTABLE_STRUCT_ARRAY_READ const int bunch = 1024; // number of symbol table entries to process at a time #else const int bunch = 1; #endif char *syms = new char[bunch*SYMSZ]; // buffer of old symbol table entries fseek(sym, N_SYMOFF(*x), 0); // go to old symbol table // fill the buffer int numInBuffer = xfread(syms, SYMSZ, min(bunch, remaining), sym); int symsi = 0; // index in buffer char *thisSym = syms; // pointer to entry symsi in buffer int auxEntries = 0; // number of aux entries still to skip over while (remaining) { if (auxEntries) // skip over them { if (auxEntries < 0) fatalError("Bad symbol table"); int skip = min(numInBuffer-symsi, auxEntries); if (remaining < skip) fatalError("Bad symbol table (missing auxiliary entries)"); auxEntries -= skip; remaining -= skip; symsi += skip; thisSym += skip*SYMSZ; } else { transformSymEntry((SYM*)thisSym); auxEntries = N_AUX(*(SYM*)thisSym); remaining--; symsi++; thisSym += SYMSZ; } assert (symsi <= bunch); if (symsi == bunch) // write and then refill the buffer { xfwrite(syms, SYMSZ, numInBuffer, newSym); numInBuffer = xfread(syms, SYMSZ, min(bunch, remaining), sym); symsi = 0; thisSym = syms; } } xfwrite(syms, SYMSZ, numInBuffer, newSym); delete syms; }
ostream &operator<<(ostream &oo, const SYM & #ifdef SYSV n #endif ) { #ifdef SYSV char s[SYMNMLEN+1]; s[SYMNMLEN] = 0; if (n.n_zeroes != 0L) // it's in n->n_name { strncpy(s, n.n_name, SYMNMLEN); oo << "(" << s << ") "; } oo << (int)N_AUX(n); #endif return oo; }
static void dump_sym(const struct nlist *np) { char type[8]; char aux[8]; char weak; char *p; switch (np->n_type & ~N_EXT) { case N_UNDF: strcpy(type, "undf"); break; case N_ABS: strcpy(type, "abs"); break; case N_TEXT: strcpy(type, "text"); break; case N_DATA: strcpy(type, "data"); break; case N_BSS: strcpy(type, "bss"); break; case N_INDR: strcpy(type, "indr"); break; case N_SIZE: strcpy(type, "size"); break; case N_COMM: strcpy(type, "comm"); break; case N_SETA: strcpy(type, "seta"); break; case N_SETT: strcpy(type, "sett"); break; case N_SETD: strcpy(type, "setd"); break; case N_SETB: strcpy(type, "setb"); break; case N_SETV: strcpy(type, "setv"); break; case N_FN: strcpy(type, np->n_type&N_EXT ? "fn" : "warn"); break; case N_GSYM: strcpy(type, "gsym"); break; case N_FNAME: strcpy(type, "fname"); break; case N_FUN: strcpy(type, "fun"); break; case N_STSYM: strcpy(type, "stsym"); break; case N_LCSYM: strcpy(type, "lcsym"); break; case N_MAIN: strcpy(type, "main"); break; case N_PC: strcpy(type, "pc"); break; case N_RSYM: strcpy(type, "rsym"); break; case N_SLINE: strcpy(type, "sline"); break; case N_DSLINE: strcpy(type, "dsline"); break; case N_BSLINE: strcpy(type, "bsline"); break; case N_SSYM: strcpy(type, "ssym"); break; case N_SO: strcpy(type, "so"); break; case N_LSYM: strcpy(type, "lsym"); break; case N_BINCL: strcpy(type, "bincl"); break; case N_SOL: strcpy(type, "sol"); break; case N_PSYM: strcpy(type, "psym"); break; case N_EINCL: strcpy(type, "eincl"); break; case N_ENTRY: strcpy(type, "entry"); break; case N_LBRAC: strcpy(type, "lbrac"); break; case N_EXCL: strcpy(type, "excl"); break; case N_RBRAC: strcpy(type, "rbrac"); break; case N_BCOMM: strcpy(type, "bcomm"); break; case N_ECOMM: strcpy(type, "ecomm"); break; case N_ECOML: strcpy(type, "ecoml"); break; case N_LENG: strcpy(type, "leng"); break; default: snprintf(type, sizeof type, "%#02x", np->n_type); break; } if (np->n_type & N_EXT && type[0] != '0') for (p = type; *p != '\0'; ++p) *p = toupper(*p); switch (N_AUX(np)) { case 0: strcpy(aux, ""); break; case AUX_OBJECT: strcpy(aux, "objt"); break; case AUX_FUNC: strcpy(aux, "func"); break; default: snprintf(aux, sizeof aux, "%#01x", N_AUX(np)); break; } weak = N_BIND(np) == BIND_WEAK ? 'w' : ' '; printf("%c%-6s %-4s %8lx", weak, type, aux, np->n_value); }