* objdump.c (compare_symbols): Sort gnu_compiled and gcc2_compiled

symbols after other symbols with the same value.  Likewise for
	symbols which look like file names.
	(objdump_print_address): Always chose the first reasonable symbol
	with a given value.
PR 8148.
This commit is contained in:
Ian Lance Taylor 1995-10-05 21:31:58 +00:00
parent f025d903c2
commit db552bdadc
2 changed files with 69 additions and 30 deletions

View file

@ -1,3 +1,11 @@
Thu Oct 5 17:25:21 1995 Ian Lance Taylor <ian@cygnus.com>
* objdump.c (compare_symbols): Sort gnu_compiled and gcc2_compiled
symbols after other symbols with the same value. Likewise for
symbols which look like file names.
(objdump_print_address): Always chose the first reasonable symbol
with a given value.
Tue Oct 3 22:38:55 1995 Ian Lance Taylor <ian@cygnus.com> Tue Oct 3 22:38:55 1995 Ian Lance Taylor <ian@cygnus.com>
* arsup.c (ar_save): Use rename, not unlink/link/unlink. * arsup.c (ar_save): Use rename, not unlink/link/unlink.

View file

@ -324,6 +324,9 @@ compare_symbols (ap, bp)
{ {
const asymbol *a = *(const asymbol **)ap; const asymbol *a = *(const asymbol **)ap;
const asymbol *b = *(const asymbol **)bp; const asymbol *b = *(const asymbol **)bp;
const char *an, *bn;
size_t anl, bnl;
boolean af, bf;
if (bfd_asymbol_value (a) > bfd_asymbol_value (b)) if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
return 1; return 1;
@ -334,6 +337,44 @@ compare_symbols (ap, bp)
return 1; return 1;
else if (a->section < b->section) else if (a->section < b->section)
return -1; return -1;
an = bfd_asymbol_name (a);
bn = bfd_asymbol_name (b);
anl = strlen (an);
bnl = strlen (bn);
/* The symbols gnu_compiled and gcc2_compiled convey no real
information, so put them after other symbols with the same value. */
af = (strstr (an, "gnu_compiled") != NULL
|| strstr (an, "gcc2_compiled") != NULL);
bf = (strstr (bn, "gnu_compiled") != NULL
|| strstr (bn, "gcc2_compiled") != NULL);
if (af && ! bf)
return 1;
if (! af && bf)
return -1;
/* We use a heuristic for the file name, to try to sort it after
more useful symbols. It may not work on non Unix systems, but it
doesn't really matter; the only difference is precisely which
symbol names get printed. */
#define file_symbol(s, sn, snl) \
(((s)->flags & BSF_FILE) != 0 \
|| ((sn)[(snl) - 2] == '.' \
&& ((sn)[(snl) - 1] == 'o' \
|| (sn)[(snl) - 1] == 'a')))
af = file_symbol (a, an, anl);
bf = file_symbol (b, bn, bnl);
if (af && ! bf)
return 1;
if (! af && bf)
return -1;
return 0; return 0;
} }
@ -410,6 +451,10 @@ objdump_print_address (vma, info)
/* The symbol we want is now in min, the low end of the range we /* The symbol we want is now in min, the low end of the range we
were searching. */ were searching. */
thisplace = min; thisplace = min;
while (thisplace > 0
&& (bfd_asymbol_value (sorted_syms[thisplace])
== bfd_asymbol_value (sorted_syms[thisplace - 1])))
--thisplace;
{ {
/* If this symbol isn't global, search for one with the same value /* If this symbol isn't global, search for one with the same value
@ -470,7 +515,11 @@ objdump_print_address (vma, info)
--i; --i;
for (; i >= 0; i--) for (; i >= 0; i--)
{ {
if (sorted_syms[i]->section == aux->sec) if (sorted_syms[i]->section == aux->sec
&& (i == 0
|| sorted_syms[i - 1]->section != aux->sec
|| (bfd_asymbol_value (sorted_syms[i])
!= bfd_asymbol_value (sorted_syms[i - 1]))))
{ {
thisplace = i; thisplace = i;
break; break;
@ -717,7 +766,6 @@ disassemble_data (abfd)
bfd *abfd; bfd *abfd;
{ {
long i; long i;
unsigned int (*print) () = 0; /* Old style */
disassembler_ftype disassemble_fn = 0; /* New style */ disassembler_ftype disassemble_fn = 0; /* New style */
struct disassemble_info disasm_info; struct disassemble_info disasm_info;
struct objdump_disasm_info aux; struct objdump_disasm_info aux;
@ -745,7 +793,7 @@ disassemble_data (abfd)
if (machine != (char *) NULL) if (machine != (char *) NULL)
{ {
bfd_arch_info_type *info = bfd_scan_arch (machine); const bfd_arch_info_type *info = bfd_scan_arch (machine);
if (info == NULL) if (info == NULL)
{ {
fprintf (stderr, "%s: Can't use supplied machine %s\n", fprintf (stderr, "%s: Can't use supplied machine %s\n",
@ -756,14 +804,6 @@ disassemble_data (abfd)
abfd->arch_info = info; abfd->arch_info = info;
} }
/* See if we can disassemble using bfd. */
if (abfd->arch_info->disassemble)
{
print = abfd->arch_info->disassemble;
}
else
{
disassemble_fn = disassembler (abfd); disassemble_fn = disassembler (abfd);
if (!disassemble_fn) if (!disassemble_fn)
{ {
@ -772,7 +812,6 @@ disassemble_data (abfd)
bfd_printable_arch_mach (bfd_get_arch (abfd), 0)); bfd_printable_arch_mach (bfd_get_arch (abfd), 0));
exit (1); exit (1);
} }
}
for (section = abfd->sections; for (section = abfd->sections;
section != (asection *) NULL; section != (asection *) NULL;
@ -874,18 +913,10 @@ disassemble_data (abfd)
aux.require_sec = false; aux.require_sec = false;
putchar (' '); putchar (' ');
if (disassemble_fn)
{
/* New style */
bytes = (*disassemble_fn) (section->vma + i, &disasm_info); bytes = (*disassemble_fn) (section->vma + i, &disasm_info);
if (bytes < 0) if (bytes < 0)
break; break;
}
else
{
/* Old style */
bytes = print (section->vma + i, data + i, stdout);
}
if (!wide_output) if (!wide_output)
putchar ('\n'); putchar ('\n');
else else