Skip to content

Commit

Permalink
13884 dis(1) should pick stable names for symbols
Browse files Browse the repository at this point in the history
Reviewed by: Yuri Pankov <ypankov@tintri.com>
Reviewed by: Jason King <jason.brian.king+illumos@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
  • Loading branch information
richlowe committed Jul 5, 2021
1 parent 1e9e241 commit 7781236
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions usr/src/cmd/dis/dis_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ typedef struct sym_entry {
* mess up symbol resolution (which uses the virtual address).
*/
typedef struct dis_shnmap {
const char *dm_name; /* name of section */
const char *dm_name; /* name of section */
uint64_t dm_start; /* virtual address of section */
size_t dm_length; /* address length */
boolean_t dm_mapped; /* did we assign the mapping */
Expand Down Expand Up @@ -157,6 +157,8 @@ sym_compare(const void *a, const void *b)
const sym_entry_t *symb = b;
const char *aname = syma->se_name;
const char *bname = symb->se_name;
size_t alen;
size_t blen;

if (syma->se_sym.st_value < symb->se_sym.st_value)
return (-1);
Expand All @@ -179,9 +181,9 @@ sym_compare(const void *a, const void *b)
* For symbols with the same address and type, we sort them according to
* a hierarchy:
*
* 1. weak symbols (common name)
* 2. global symbols (external name)
* 3. local symbols
* 1. weak symbols (common name)
* 2. global symbols (external name)
* 3. local symbols
*/
if (GELF_ST_BIND(syma->se_sym.st_info) !=
GELF_ST_BIND(symb->se_sym.st_info)) {
Expand Down Expand Up @@ -224,10 +226,23 @@ sym_compare(const void *a, const void *b)
return (1);

/*
* We really do have two identical symbols for some reason. Just report
* them as equal, and to the lucky one go the spoils.
* We really do have two identical symbols, choose the one with the
* shortest name if we can, heuristically taking it to be the most
* representative.
*/
return (0);
alen = strlen(syma->se_name);
blen = strlen(symb->se_name);

if (alen < blen)
return (-1);
else if (alen > blen)
return (1);

/*
* If all else fails, compare the names, so that we give a stable
* sort
*/
return (strcmp(syma->se_name, symb->se_name));
}

/*
Expand Down

0 comments on commit 7781236

Please sign in to comment.