# HG changeset patch # User Michael Spacefalcon # Date 1395804200 0 # Node ID 192da19c7506da4b1ec278c9a6b9cb9d3f30c55d # Parent da103b9377e3735fd085ef4744d35f22135b1d5c tiobjd: symbol sorting implemented diff -r da103b9377e3 -r 192da19c7506 ticoff/main.c --- a/ticoff/main.c Wed Mar 26 02:44:19 2014 +0000 +++ b/ticoff/main.c Wed Mar 26 03:23:20 2014 +0000 @@ -10,6 +10,7 @@ #include "globals.h" extern int cmd_basics(); +extern int cmd_nm(); extern int cmd_profile(); extern int cmd_sechdr(); extern int cmd_symtab(); @@ -22,6 +23,7 @@ {"basics", cmd_basics}, {"dumpsym", cmd_symtab}, /* backward compat */ {"hdr", dump_filehdr_info}, + {"nm", cmd_nm}, {"profile", cmd_profile}, {"sechdr", cmd_sechdr}, {"symtab", cmd_symtab}, diff -r da103b9377e3 -r 192da19c7506 ticoff/symtab.c --- a/ticoff/symtab.c Wed Mar 26 02:44:19 2014 +0000 +++ b/ticoff/symtab.c Wed Mar 26 03:23:20 2014 +0000 @@ -141,3 +141,81 @@ extern_profile_report(objfilename); exit(0); } + +static void +initial_fill_for_sort(sec) + struct internal_scnhdr *sec; +{ + unsigned n, m; + struct internal_syment *sym; + + m = 0; + for (n = 0; n < nsymtab; n++) { + sym = symtab[n]; + if (!sym) + continue; + if (sym->section != sec) + continue; + sec->sorted_symbols[m++] = sym; + } +} + +static int +compare_for_sort(p1, p2) + struct internal_syment **p1, **p2; +{ + if ((*p1)->value < (*p2)->value) + return(-1); + if ((*p1)->value > (*p2)->value) + return(1); + else + return(0); +} + +void +sort_symbols_of_sec(sec) + struct internal_scnhdr *sec; +{ + if (sec->sorted_symbols) + return; + if (!sec->nsymbols) { + fprintf(stderr, + "BUG: sort_symbols_of_sec() called for section \"%s\" w/o symbols\n", + sec->name); + exit(1); + } + sec->sorted_symbols = malloc(sizeof(void *) * sec->nsymbols); + if (!sec->sorted_symbols) { + perror("malloc"); + exit(1); + } + initial_fill_for_sort(sec); + qsort(sec->sorted_symbols, sec->nsymbols, sizeof(void *), + compare_for_sort); +} + +cmd_nm() +{ + unsigned n, m; + struct internal_scnhdr *sec; + struct internal_syment *sym; + char classbuf[8]; + + get_int_section_table(); + get_int_symbol_table(); + for (n = 0; n < nsections; n++) { + sec = sections + n; + if (!sec->nsymbols) + continue; + printf("%s:\n\n", sec->name); + sort_symbols_of_sec(sec); + for (m = 0; m < sec->nsymbols; m++) { + sym = sec->sorted_symbols[m]; + printf("%08X %-7s %s\n", sym->value, + storage_class_to_string(sym->class, classbuf), + sym->name); + } + putchar('\n'); + } + exit(0); +}