📄 symbol.c
字号:
n->index.size = p->size; y->size += p->size; n = (symnode *) __mp_getslot(&y->table); } return n;}#if FORMAT == FORMAT_AOUT || FORMAT == FORMAT_COFF || \ FORMAT == FORMAT_XCOFF || FORMAT == FORMAT_ELF32 || \ FORMAT == FORMAT_ELF64 || FORMAT == FORMAT_BFD/* Decide whether to store a symbol by looking at its name. */staticintaddsymname(char **s){ /* We don't bother storing a symbol which has no name or whose name * contains a '$', '@' or a '.', although GNU C++ destructors begin * with `_._'. However, in XCOFF the symbol name is likely to be the * name of a CSECT beginning with a '.' and not the original name of * the function, so we skip the first character. In addition, the * HP/UX $START$ symbol contains dollar characters but we don't want * to bother allowing any other symbols containing dollars. */ if ((*s != NULL) && (**s != '\0') &&#if ((SYSTEM == SYSTEM_AIX || SYSTEM == SYSTEM_LYNXOS) && \ (ARCH == ARCH_POWER || ARCH == ARCH_POWERPC)) || FORMAT == FORMAT_XCOFF (*(*s)++ == '.') && (strcmp(*s, "text") != 0) &&#endif /* SYSTEM && ARCH && FORMAT */ ((strncmp(*s, "_._", 3) == 0) ||#if SYSTEM == SYSTEM_HPUX (strcmp(*s, "$START$") == 0) ||#endif /* SYSTEM */ !strpbrk(*s, "$@."))) return 1; return 0;}#endif /* FORMAT */#if FORMAT == FORMAT_AOUT/* Allocate a new symbol node for a given a.out symbol. */staticintaddsymbol(symhead *y, struct nlist *p, char *f, char *s, size_t b){ symnode *n; char *r; size_t a; a = b + p->n_value; /* We don't allocate a symbol node for symbols which have a virtual * address of zero. */ if (addsymname(&s) && (a > 0)) { if ((n = getsymnode(y)) == NULL) return 0; if ((r = __mp_addstring(&y->strings, s)) == NULL) { __mp_freeslot(&y->table, n); return 0; } __mp_treeinsert(&y->dtree, &n->data.node, a); n->data.file = f; n->data.name = r; n->data.addr = (void *) a; /* The a.out file format doesn't record symbol sizes, so we have * to rely on the assumption that a function symbol ends at the * beginning of the next function symbol. This will be calculated * in __mp_fixsymbols(). */ n->data.size = 0; n->data.index = 0; n->data.offset = 0; /* The linkage information is required for when we look up a symbol. */ n->data.flags = p->n_type;#if MP_INITFUNC_SUPPORT /* Check to see if this function should be called when the mpatrol * library is initialised or terminated. */ if ((strncmp(r, "__mp_init_", 10) == 0) && (r[10] != '\0')) __mp_atinit((infohead *) y->inits, (void (*)(void)) a); else if ((strncmp(r, "__mp_fini_", 10) == 0) && (r[10] != '\0')) __mp_atfini((infohead *) y->inits, (void (*)(void)) a);#endif /* MP_INITFUNC_SUPPORT */ } return 1;}#elif FORMAT == FORMAT_COFF || FORMAT == FORMAT_XCOFF/* Allocate a new symbol node for a given COFF or XCOFF symbol. */staticintaddsymbol(symhead *y, SYMENT *p, char *f, char *s, size_t b){ AUXENT *e; symnode *n; char *r; size_t a; a = b + p->n_value; /* We don't allocate a symbol node for symbols which have a virtual * address of zero and we only remember symbols that are declared * statically or externally visible. */ if (addsymname(&s) && (a > 0) &&#if FORMAT == FORMAT_XCOFF (ISFCN(p->n_type) || (p->n_sclass == C_EXT)))#else /* FORMAT */ ((p->n_sclass == C_STAT) || (p->n_sclass == C_EXT)))#endif /* FORMAT */ { if ((n = getsymnode(y)) == NULL) return 0; if ((r = __mp_addstring(&y->strings, s)) == NULL) { __mp_freeslot(&y->table, n); return 0; } __mp_treeinsert(&y->dtree, &n->data.node, a); n->data.file = f; n->data.name = r; n->data.addr = (void *) a; /* Attempt to figure out the size of the symbol. */ if (p->n_numaux > 0) { e = (AUXENT *) ((char *) p + SYMESZ); if (ISFCN(p->n_type)) n->data.size = e->x_sym.x_misc.x_fsize; else n->data.size = e->x_sym.x_misc.x_lnsz.x_size; } else n->data.size = 0; n->data.index = 0; n->data.offset = 0; /* The linkage information is required for when we look up a symbol. */ n->data.flags = p->n_sclass;#if MP_INITFUNC_SUPPORT /* Check to see if this function should be called when the mpatrol * library is initialised or terminated. */ if ((strncmp(r, "__mp_init_", 10) == 0) && (r[10] != '\0')) __mp_atinit((infohead *) y->inits, (void (*)(void)) a); else if ((strncmp(r, "__mp_fini_", 10) == 0) && (r[10] != '\0')) __mp_atfini((infohead *) y->inits, (void (*)(void)) a);#endif /* MP_INITFUNC_SUPPORT */ } return 1;}#elif FORMAT == FORMAT_ELF32/* Allocate a new symbol node for a given ELF32 symbol. */staticintaddsymbol(symhead *y, Elf32_Sym *p, char *f, char *s, size_t b){ symnode *n; char *r; size_t a; unsigned char t; a = b + p->st_value; /* We don't allocate a symbol node for symbols which have a virtual * address of zero or are of object type. */ if (addsymname(&s) && (a > 0) && (((t = ELF32_ST_TYPE(p->st_info)) == STT_NOTYPE) || (t == STT_FUNC))) { if ((n = getsymnode(y)) == NULL) return 0; if ((r = __mp_addstring(&y->strings, s)) == NULL) { __mp_freeslot(&y->table, n); return 0; } __mp_treeinsert(&y->dtree, &n->data.node, a); n->data.file = f; n->data.name = r; n->data.addr = (void *) a; n->data.size = p->st_size; n->data.index = 0; n->data.offset = 0; /* The linkage information is required for when we look up a symbol. */ n->data.flags = ELF32_ST_BIND(p->st_info);#if MP_INITFUNC_SUPPORT /* Check to see if this function should be called when the mpatrol * library is initialised or terminated. */ if ((strncmp(r, "__mp_init_", 10) == 0) && (r[10] != '\0')) __mp_atinit((infohead *) y->inits, (void (*)(void)) a); else if ((strncmp(r, "__mp_fini_", 10) == 0) && (r[10] != '\0')) __mp_atfini((infohead *) y->inits, (void (*)(void)) a);#endif /* MP_INITFUNC_SUPPORT */ } return 1;}#elif FORMAT == FORMAT_ELF64/* Allocate a new symbol node for a given ELF64 symbol. */staticintaddsymbol(symhead *y, Elf64_Sym *p, char *f, char *s, size_t b){ symnode *n; char *r; size_t a; unsigned char t; a = b + p->st_value; /* We don't allocate a symbol node for symbols which have a virtual * address of zero or are of object type. */ if (addsymname(&s) && (a > 0) && (((t = ELF64_ST_TYPE(p->st_info)) == STT_NOTYPE) || (t == STT_FUNC))) { if ((n = getsymnode(y)) == NULL) return 0; if ((r = __mp_addstring(&y->strings, s)) == NULL) { __mp_freeslot(&y->table, n); return 0; } __mp_treeinsert(&y->dtree, &n->data.node, a); n->data.file = f; n->data.name = r; n->data.addr = (void *) a; n->data.size = p->st_size; n->data.index = 0; n->data.offset = 0; /* The linkage information is required for when we look up a symbol. */ n->data.flags = ELF64_ST_BIND(p->st_info);#if MP_INITFUNC_SUPPORT /* Check to see if this function should be called when the mpatrol * library is initialised or terminated. */ if ((strncmp(r, "__mp_init_", 10) == 0) && (r[10] != '\0')) __mp_atinit((infohead *) y->inits, (void (*)(void)) a); else if ((strncmp(r, "__mp_fini_", 10) == 0) && (r[10] != '\0')) __mp_atfini((infohead *) y->inits, (void (*)(void)) a);#endif /* MP_INITFUNC_SUPPORT */ } return 1;}#elif FORMAT == FORMAT_BFD/* Allocate a new symbol node for a given BFD symbol. */staticintaddsymbol(symhead *y, asymbol *p, char *f, char *s, size_t b){ symnode *n; char *r; size_t a; a = b + (size_t) p->value; /* We don't allocate a symbol node for symbols which have a virtual * address of zero and we only remember symbols that are declared * statically, externally or weakly visible. */ if (addsymname(&s) && (a > 0) && (p->flags & (BSF_LOCAL | BSF_GLOBAL | BSF_WEAK))) { if ((n = getsymnode(y)) == NULL) return 0; if ((r = __mp_addstring(&y->strings, s)) == NULL) { __mp_freeslot(&y->table, n); return 0; } __mp_treeinsert(&y->dtree, &n->data.node, a); n->data.file = f; n->data.name = r; n->data.addr = (void *) a; /* The BFD library doesn't seem to support reading symbol sizes, * so we have to rely on the assumption that a function symbol * ends at the beginning of the next function symbol. This will * be calculated in __mp_fixsymbols(). */ n->data.size = 0; n->data.index = 0; n->data.offset = 0; /* The linkage information is required for when we look up a symbol. */ n->data.flags = p->flags;#if MP_INITFUNC_SUPPORT /* Check to see if this function should be called when the mpatrol * library is initialised or terminated. */ if ((strncmp(r, "__mp_init_", 10) == 0) && (r[10] != '\0')) __mp_atinit((infohead *) y->inits, (void (*)(void)) a); else if ((strncmp(r, "__mp_fini_", 10) == 0) && (r[10] != '\0')) __mp_atfini((infohead *) y->inits, (void (*)(void)) a);#endif /* MP_INITFUNC_SUPPORT */ } return 1;}#endif /* FORMAT */#if DYNLINK == DYNLINK_WINDOWS/* The callback function called to allocate a new symbol node for each * symbol located in a module by the imagehlp library. */staticint __stdcalladdsym(char *s, unsigned long a, unsigned long l, void *p){ syminfo *i; symhead *y; symnode *n; char *r; i = (syminfo *) p; y = i->syms; /* We don't bother storing a symbol which has no name or which has a * virtual address of zero. Unfortunately, the imagehlp library does * not provide information about the types of symbols so we will just * have to add any symbols representing objects here as well. */ if ((s != NULL) && (*s != '\0') && (a > 0)) { if ((n = getsymnode(y)) == NULL) return 0; if ((r = __mp_addstring(&y->strings, s)) == NULL) { __mp_freeslot(&y->table, n); return 0; } __mp_treeinsert(&y->dtree, &n->data.node, a); n->data.file = i->file; n->data.name = r; n->data.addr = (void *) a; n->data.size = l; n->data.index = 0; n->data.offset = 0; /* Unfortunately, the imagehlp library does not provide information * about the visibility of symbols. */ n->data.flags = 0; } return 1;}#endif /* DYNLINK */#if FORMAT == FORMAT_AOUT/* Allocate a set of symbol nodes for an a.out executable file. */staticintaddsymbols(symhead *y, char *e, char *l, char *f, size_t b, size_t a){ struct exec *o; struct nlist *p; char *c, *m; size_t i, n; /* Check that we have a valid a.out executable file. */ if (b < sizeof(struct exec)) { c = "not an object file"; if (l != NULL) __mp_warn(ET_MAX, AT_MAX, NULL, 0, "%s [%s]: %s\n", l, f, c); else __mp_warn(ET_MAX, AT_MAX, NULL, 0, "%s: %s\n", f, c); return 1; } o = (struct exec *) e; if (N_BADMAG(*o)) { c = "not an executable file"; if (l != NULL) __mp_warn(ET_MAX, AT_MAX, NULL, 0, "%s [%s]: %s\n", l, f, c); else __mp_warn(ET_MAX, AT_MAX, NULL, 0, "%s: %s\n", f, c); return 1; } /* Look for the symbol table. */ i = N_SYMOFF(*o); n = o->a_syms; if ((i == 0) || (n == 0) || (b < i + n)) { c = "missing symbol table"; if (l != NULL) __mp_warn(ET_MAX, AT_MAX, NULL, 0, "%s [%s]: %s\n", l, f, c); else __mp_warn(ET_MAX, AT_MAX, NULL, 0, "%s: %s\n", f, c); return 1; } p = (struct nlist *) (e + i); b -= i + n;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -