ref: 955a99b7c855cfc2378a9857bfbb8cb853047d6c
parent: a702a8bbbb8f268715e71ef4010eeb383c39e059
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Nov 28 17:24:33 EST 2017
[objdump] Print symbols in one line format It helps to scripts
--- a/inc/myro.h
+++ b/inc/myro.h
@@ -53,6 +53,13 @@
MYROSEC_ABS = 1 << 5,
};
+enum myrosymflg {
+ MYROSYM_DEDUP = 1 << 0,
+ MYROSYM_COMMON = 1 << 1,
+ MYROSYM_EXTERN = 1 << 2,
+ MYROSYM_UNDEF = 1 << 3,
+};
+
extern int wrmyrohdr(FILE *fp, struct myrohdr *hdr);
extern int wrmyrosec(FILE *fp, struct myrosect *sect);
extern int wrmyrosym(FILE *fp, struct myrosym *sym);
--- a/objdump/main.c
+++ b/objdump/main.c
@@ -124,6 +124,23 @@
return 0;
}
+static char *
+symflags(struct myrosym *sym)
+{
+ static char flags[10];
+ char *s = flags + sizeof(flags);
+
+ if (sym->flags & MYROSYM_DEDUP)
+ *--s = 'D';
+ if (sym->flags & MYROSYM_COMMON)
+ *--s = 'C';
+ if (sym->flags & MYROSYM_EXTERN)
+ *--s = 'G';
+ if (sym->flags & MYROSYM_UNDEF)
+ *s-- = 'U';
+ return s;
+}
+
static int
printsymbols(struct myrohdr *hdr, FILE *fp)
{
@@ -130,23 +147,24 @@
unsigned long long n, i;
struct myrosym sym;
- puts("symbols:");
+ printf("symbols:\n"
+ "[Nr]\t%s\t%-16s\t%s\t%s\t%s\n",
+ "Name",
+ "Value",
+ "Section",
+ "Flags",
+ "Type");
n = hdr->symsize / MYROSYM_SIZ;
for (i = 0; i < n; ++i) {
if (rdmyrosym(fp, &sym) < 0)
return -1;
- printf("\tname: %lu (\"%s\")\n"
- "\ttype: %lu (\"%s\")\n"
- "\tsection: %u\n"
- "\tflags: %x\n"
- "\toffset: %llu\n"
- "\tlength: %llu\n\n",
- sym.name, getstring(sym.name),
- sym.type, getstring(sym.type),
- sym.section,
- sym.flags,
+ printf("[%2u]\t%s\t%016X\t%u\t%s\t%s\n",
+ i,
+ getstring(sym.name),
sym.offset,
- sym.len);
+ sym.section,
+ symflags(&sym),
+ getstring(sym.type));
}
return 0;
}