Prefer object over notype symbols when disassembling

Changing objdump disassembly output like this always requires some
testsuite changes, with the avr and x64_64 changes simply due to
picking up better symbols, the whole point of the patch.

The mips changes are due to mips-sgi-irix changing STT_NOTYPE symbols
to STT_OBJECT, which objdump now chooses in preference to script
symbols.  The problem is that objdump looks at the first symbol in the
section being disassembled, and if object type, just dumps out bytes
rather than disassembling.  This results in new failures:

FAIL: JAL overflow 2
FAIL: undefined weak symbol overflow
FAIL: undefined weak symbol overflow (n32)
FAIL: undefined weak symbol overflow (n64)

So for mips-sgi-irix function symbols really do need to be function
type.  I fixed a few more than just the required minimum to avoid the
above test fails.

binutils/
	* objdump.c (compare_section): New static var.
	(compare_symbols): Sort by current section only.  Don't access
	symbol name out of bounds when checking for file symbols.
	Sort section symbols and object symbols.
	(find_symbol_for_address): Remove bogus debugging and section
	symbol test.
	(disassemble_data): Move symbol sort from here..
	(disassemble_section): ..to here.  Set compare_section.
ld/
	* testsuite/ld-avr/lds-mega.d: Adjust symbols to suit objdump change.
	* testsuite/ld-avr/lds-tiny.d: Likewise.
	* testsuite/ld-x86-64/load2.d: Likewise.
	* testsuite/ld-mips-elf/compact-eh1.s: Give function symbols
	function type.
	* testsuite/ld-mips-elf/compact-eh1a.s: Likewise.
	* testsuite/ld-mips-elf/compact-eh1b.s: Likewise.
	* testsuite/ld-mips-elf/compact-eh2.s: Likewise.
	* testsuite/ld-mips-elf/compact-eh3.s: Likewise.
	* testsuite/ld-mips-elf/compact-eh3a.s: Likewise.
	* testsuite/ld-mips-elf/eh-frame5.s: Likewise.
	* testsuite/ld-mips-elf/ehdr_start-new.s: Likewise.
	* testsuite/ld-mips-elf/ehdr_start-o32.s: Likewise.
	* testsuite/ld-mips-elf/emit-relocs-1a.s: Likewise.
	* testsuite/ld-mips-elf/jaloverflow-2.s: Likewise.
	* testsuite/ld-mips-elf/jaloverflow.s: Likewise.
	* testsuite/ld-mips-elf/mips16-call-global-1.s: Likewise.
	* testsuite/ld-mips-elf/mips16-intermix-1.s: Likewise.
	* testsuite/ld-mips-elf/mips16-pic-1b.s: Likewise.
	* testsuite/ld-mips-elf/mips16-pic-4c.s: Likewise.
	* testsuite/ld-mips-elf/no-shared-1-n64.s: Likewise.
	* testsuite/ld-mips-elf/no-shared-1-o32.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-1b-micromips.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-1b.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-2a.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-3b.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-4b.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-5a.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-6-n32c.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-6-n64c.s: Likewise.
	* testsuite/ld-mips-elf/pic-and-nonpic-6-o32c.s: Likewise.
	* testsuite/ld-mips-elf/pie.s: Likewise.
	* testsuite/ld-mips-elf/relax-jalr.s: Likewise.
	* testsuite/ld-mips-elf/reloc-1a.s: Likewise.
	* testsuite/ld-mips-elf/reloc-2a.s: Likewise.
	* testsuite/ld-mips-elf/reloc-4.s: Likewise.
	* testsuite/ld-mips-elf/reloc-5.s: Likewise.
	* testsuite/ld-mips-elf/reloc-6b.s: Likewise.
	* testsuite/ld-mips-elf/textrel-1.s: Likewise.
	* testsuite/ld-mips-elf/undefweak-overflow.s: Likewise.
	* testsuite/ld-mips-elf/undefweak-overflow.d: Adjust.
This commit is contained in:
Alan Modra 2019-12-17 19:06:02 +10:30
parent 260bcd09bf
commit 660df28acf
43 changed files with 164 additions and 41 deletions

View file

@ -803,6 +803,8 @@ remove_useless_symbols (asymbol **symbols, long count)
return out_ptr - symbols;
}
static const asection *compare_section;
/* Sort symbols into value order. */
static int
@ -814,8 +816,7 @@ compare_symbols (const void *ap, const void *bp)
const char *bn;
size_t anl;
size_t bnl;
bfd_boolean af;
bfd_boolean bf;
bfd_boolean as, af, bs, bf;
flagword aflags;
flagword bflags;
@ -824,10 +825,16 @@ compare_symbols (const void *ap, const void *bp)
else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
return -1;
if (a->section > b->section)
return 1;
else if (a->section < b->section)
/* Prefer symbols from the section currently being disassembled.
Don't sort symbols from other sections by section, since there
isn't much reason to prefer one section over another otherwise.
See sym_ok comment for why we compare by section name. */
as = strcmp (compare_section->name, a->section->name) == 0;
bs = strcmp (compare_section->name, b->section->name) == 0;
if (as && !bs)
return -1;
if (!as && bs)
return 1;
an = bfd_asymbol_name (a);
bn = bfd_asymbol_name (b);
@ -853,7 +860,8 @@ compare_symbols (const void *ap, const void *bp)
#define file_symbol(s, sn, snl) \
(((s)->flags & BSF_FILE) != 0 \
|| ((sn)[(snl) - 2] == '.' \
|| ((snl) > 2 \
&& (sn)[(snl) - 2] == '.' \
&& ((sn)[(snl) - 1] == 'o' \
|| (sn)[(snl) - 1] == 'a')))
@ -865,8 +873,8 @@ compare_symbols (const void *ap, const void *bp)
if (! af && bf)
return -1;
/* Try to sort global symbols before local symbols before function
symbols before debugging symbols. */
/* Sort function and object symbols before global symbols before
local symbols before section symbols before debugging symbols. */
aflags = a->flags;
bflags = b->flags;
@ -878,6 +886,13 @@ compare_symbols (const void *ap, const void *bp)
else
return -1;
}
if ((aflags & BSF_SECTION_SYM) != (bflags & BSF_SECTION_SYM))
{
if ((aflags & BSF_SECTION_SYM) != 0)
return 1;
else
return -1;
}
if ((aflags & BSF_FUNCTION) != (bflags & BSF_FUNCTION))
{
if ((aflags & BSF_FUNCTION) != 0)
@ -885,6 +900,13 @@ compare_symbols (const void *ap, const void *bp)
else
return 1;
}
if ((aflags & BSF_OBJECT) != (bflags & BSF_OBJECT))
{
if ((aflags & BSF_OBJECT) != 0)
return -1;
else
return 1;
}
if ((aflags & BSF_LOCAL) != (bflags & BSF_LOCAL))
{
if ((aflags & BSF_LOCAL) != 0)
@ -1102,14 +1124,11 @@ find_symbol_for_address (bfd_vma vma,
/* The symbol we want is now in min, the low end of the range we
were searching. If there are several symbols with the same
value, we want the first (non-section/non-debugging) one. */
value, we want the first one. */
thisplace = min;
while (thisplace > 0
&& (bfd_asymbol_value (sorted_syms[thisplace])
== bfd_asymbol_value (sorted_syms[thisplace - 1]))
&& ((sorted_syms[thisplace - 1]->flags
& (BSF_SECTION_SYM | BSF_DEBUGGING)) == 0)
)
== bfd_asymbol_value (sorted_syms[thisplace - 1])))
--thisplace;
/* Prefer a symbol in the current section if we have multple symbols
@ -2389,6 +2408,10 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
pinfo->buffer_length = datasize;
pinfo->section = section;
/* Sort the symbols into value and section order. */
compare_section = section;
qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
/* Skip over the relocs belonging to addresses below the
start address. */
while (rel_pp < rel_ppend
@ -2632,9 +2655,6 @@ disassemble_data (bfd *abfd)
++sorted_symcount;
}
/* Sort the symbols into section and symbol order. */
qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
init_disassemble_info (&disasm_info, stdout, (fprintf_ftype) fprintf);
disasm_info.application_data = (void *) &aux;