scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 3dbac045e8adbe8dc6eca3ede265cb8b773f2d58
parent 37ff3b0c5179d524dc5704ab30bb92222e2c223f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon,  5 Mar 2018 17:32:18 +0100

[nm] Add symbol type

This symbol can be used by the common part to do the common work.

Diffstat:
Mnm/main.c | 11++++++-----
Mnm/myro.c | 14+++++++-------
Mnm/nm.h | 9++++++++-
3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/nm/main.c b/nm/main.c @@ -71,9 +71,10 @@ ar(char *fname, FILE *fp) } void -print(char *file, char *member, char *name, int type, unsigned long long off, long siz) +print(char *file, char *member, struct symbol *sym) { char *fmt; + int type = sym->type; if (uflag && type != 'U') return; @@ -83,7 +84,7 @@ print(char *file, char *member, char *name, int type, unsigned long long off, lo if (Aflag) printf((arflag) ? "%s[%s]: " : "%s: ", file, member); if (Pflag) { - printf("%s %c", name, type); + printf("%s %c", sym->name, sym->type); if (type != 'U') { if (radix == 8) fmt = "%llo %llo"; @@ -91,7 +92,7 @@ print(char *file, char *member, char *name, int type, unsigned long long off, lo fmt = "%llu %llu"; else fmt = "%llx %llx"; - printf(fmt, off, siz); + printf(fmt, sym->off, sym->size); } } else { if (type == 'U') @@ -102,8 +103,8 @@ print(char *file, char *member, char *name, int type, unsigned long long off, lo fmt = "%016.16lld"; else fmt = "%016.16llx"; - printf(fmt, off); - printf(" %c %s", type, name); + printf(fmt, sym->off); + printf(" %c %s", sym->type, sym->name); } putchar('\n'); } diff --git a/nm/myro.c b/nm/myro.c @@ -58,6 +58,7 @@ nm(char *fname, char *member, FILE *fp) { struct myrohdr hdr; struct myrosym *syms = NULL, *sym; + struct symbol symbol; size_t n, i; long off; @@ -100,13 +101,12 @@ nm(char *fname, char *member, FILE *fp) } qsort(syms, n, sizeof(*syms), cmp); for (i = 0; i < n; ++i) { - sym = &sym[i]; - print(fname, - member, - strings + sym->name, - typeof(sym), - sym->offset, - sym->len); + sym = &syms[i]; + symbol.name = strings + sym->name; + symbol.type = typeof(sym); + symbol.off = sym->offset; + symbol.size = sym->len; + print(fname, member, &symbol); } free_arrays: diff --git a/nm/nm.h b/nm/nm.h @@ -1,6 +1,13 @@ +struct symbol { + char *name; + int type; + unsigned long long off; + unsigned long size; +}; + /* main.c */ -extern void print(char *file, char *member, char *name, int type, unsigned long long off, long siz); +extern void print(char *file, char *member, struct symbol *sym); /* object format file */ extern void nm(char *fname, char *member, FILE *fp);