From 660df28acfa1b58c978d65d9cb26d37023f791ce Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Tue, 17 Dec 2019 19:06:02 +1030
Subject: [PATCH] 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.
---
 binutils/ChangeLog                            | 11 ++++
 binutils/objdump.c                            | 52 +++++++++++++------
 ld/ChangeLog                                  | 44 ++++++++++++++++
 ld/testsuite/ld-avr/lds-mega.d                |  2 +-
 ld/testsuite/ld-avr/lds-tiny.d                |  2 +-
 ld/testsuite/ld-mips-elf/compact-eh1.s        |  1 +
 ld/testsuite/ld-mips-elf/compact-eh1a.s       |  3 +-
 ld/testsuite/ld-mips-elf/compact-eh1b.s       |  1 +
 ld/testsuite/ld-mips-elf/compact-eh2.s        |  1 +
 ld/testsuite/ld-mips-elf/compact-eh3.s        |  1 +
 ld/testsuite/ld-mips-elf/compact-eh3a.s       |  1 +
 ld/testsuite/ld-mips-elf/eh-frame5.s          | 11 ++++
 ld/testsuite/ld-mips-elf/ehdr_start-new.s     |  1 +
 ld/testsuite/ld-mips-elf/ehdr_start-o32.s     |  1 +
 ld/testsuite/ld-mips-elf/emit-relocs-1a.s     |  1 +
 ld/testsuite/ld-mips-elf/jaloverflow-2.s      |  1 +
 ld/testsuite/ld-mips-elf/jaloverflow.s        |  1 +
 .../ld-mips-elf/mips16-call-global-1.s        |  1 +
 ld/testsuite/ld-mips-elf/mips16-intermix-1.s  |  1 +
 ld/testsuite/ld-mips-elf/mips16-pic-1b.s      |  1 +
 ld/testsuite/ld-mips-elf/mips16-pic-4c.s      |  2 +
 ld/testsuite/ld-mips-elf/no-shared-1-n64.s    |  1 +
 ld/testsuite/ld-mips-elf/no-shared-1-o32.s    |  1 +
 .../ld-mips-elf/pic-and-nonpic-1b-micromips.s |  1 +
 ld/testsuite/ld-mips-elf/pic-and-nonpic-1b.s  |  1 +
 ld/testsuite/ld-mips-elf/pic-and-nonpic-2a.s  |  1 +
 ld/testsuite/ld-mips-elf/pic-and-nonpic-3b.s  |  2 +
 ld/testsuite/ld-mips-elf/pic-and-nonpic-4b.s  |  1 +
 ld/testsuite/ld-mips-elf/pic-and-nonpic-5a.s  |  1 +
 .../ld-mips-elf/pic-and-nonpic-6-n32c.s       |  1 +
 .../ld-mips-elf/pic-and-nonpic-6-n64c.s       |  1 +
 .../ld-mips-elf/pic-and-nonpic-6-o32c.s       |  1 +
 ld/testsuite/ld-mips-elf/pie.s                |  1 +
 ld/testsuite/ld-mips-elf/relax-jalr.s         |  7 +--
 ld/testsuite/ld-mips-elf/reloc-1a.s           |  1 +
 ld/testsuite/ld-mips-elf/reloc-2a.s           |  1 +
 ld/testsuite/ld-mips-elf/reloc-4.s            |  1 +
 ld/testsuite/ld-mips-elf/reloc-5.s            |  1 +
 ld/testsuite/ld-mips-elf/reloc-6b.s           |  1 +
 ld/testsuite/ld-mips-elf/textrel-1.s          |  1 +
 ld/testsuite/ld-mips-elf/undefweak-overflow.d | 36 ++++++-------
 ld/testsuite/ld-mips-elf/undefweak-overflow.s |  1 +
 ld/testsuite/ld-x86-64/load2.d                |  2 +-
 43 files changed, 164 insertions(+), 41 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index b8ae470f836..d6dbbf3cd1b 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,14 @@
+2019-12-17  Alan Modra  <amodra@gmail.com>
+
+	* 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.
+
 2019-12-17  Alan Modra  <amodra@gmail.com>
 
 	* testsuite/binutils-all/objcopy.exp: Remove tic80 support.
diff --git a/binutils/objdump.c b/binutils/objdump.c
index c10136edc31..3cc7aec1873 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -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;
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 8a38d869b10..417bb151c15 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,47 @@
+2019-12-17  Alan Modra  <amodra@gmail.com>
+
+	* 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.
+
 2019-12-17  Alan Modra  <amodra@gmail.com>
 
 	* testsuite/ld-elf/pr21233-l.sd: Accept OBJECT for type and
diff --git a/ld/testsuite/ld-avr/lds-mega.d b/ld/testsuite/ld-avr/lds-mega.d
index 078bf73807a..1537b8f7524 100644
--- a/ld/testsuite/ld-avr/lds-mega.d
+++ b/ld/testsuite/ld-avr/lds-mega.d
@@ -11,7 +11,7 @@
 Disassembly of section .text:
 
 00000000 <main>:
-   0:	80 91 00 01 	lds	r24, 0x0100	; 0x800100 <_edata>
+   0:	80 91 00 01 	lds	r24, 0x0100	; 0x800100 <myvar1>
    4:	08 2e       	mov	r0, r24
    6:	00 0c       	add	r0, r0
    8:	99 0b       	sbc	r25, r25
diff --git a/ld/testsuite/ld-avr/lds-tiny.d b/ld/testsuite/ld-avr/lds-tiny.d
index 405546ad0a7..957606f89f8 100644
--- a/ld/testsuite/ld-avr/lds-tiny.d
+++ b/ld/testsuite/ld-avr/lds-tiny.d
@@ -11,7 +11,7 @@
 Disassembly of section .text:
 
 00000000 <main>:
-   0:	20 a1       	lds	r18, 0x40	; 0x800040 <_edata>
+   0:	20 a1       	lds	r18, 0x40	; 0x800040 <myvar1>
    2:	42 a1       	lds	r20, 0x42	; 0x800042 <myvar2\+0x1>
    4:	53 a1       	lds	r21, 0x43	; 0x800043 <_end>
    6:	08 95       	ret
diff --git a/ld/testsuite/ld-mips-elf/compact-eh1.s b/ld/testsuite/ld-mips-elf/compact-eh1.s
index 941ac8f447d..81c3008674e 100644
--- a/ld/testsuite/ld-mips-elf/compact-eh1.s
+++ b/ld/testsuite/ld-mips-elf/compact-eh1.s
@@ -6,6 +6,7 @@
 	.cfi_personality_id 0x2
 	.cfi_lsda 0x1b,.LLSDA3
 	.global main
+	.type	main, @function
 main:
 .LEHB0 = .
 	jal	compact1a
diff --git a/ld/testsuite/ld-mips-elf/compact-eh1a.s b/ld/testsuite/ld-mips-elf/compact-eh1a.s
index 3f5c7ec0860..3b12bfec007 100644
--- a/ld/testsuite/ld-mips-elf/compact-eh1a.s
+++ b/ld/testsuite/ld-mips-elf/compact-eh1a.s
@@ -1,6 +1,7 @@
 	.cfi_sections .eh_frame_entry
 	.section .text.compact1a,"ax",@progbits
-	.globl compact1a
+	.globl	compact1a
+	.type	compact1a, @function
 	.cfi_startproc
 compact1a:
 	sw	$2,16($fp)
diff --git a/ld/testsuite/ld-mips-elf/compact-eh1b.s b/ld/testsuite/ld-mips-elf/compact-eh1b.s
index e96289a81e9..1aabe5f906a 100644
--- a/ld/testsuite/ld-mips-elf/compact-eh1b.s
+++ b/ld/testsuite/ld-mips-elf/compact-eh1b.s
@@ -1,6 +1,7 @@
 	.cfi_sections .eh_frame_entry
 	.section	.text.compact1b,"ax",@progbits
 	.globl	compact1b
+	.type	compact1b, @function
 	.cfi_startproc
 compact1b:
 	lw	$31,44($sp)
diff --git a/ld/testsuite/ld-mips-elf/compact-eh2.s b/ld/testsuite/ld-mips-elf/compact-eh2.s
index b899e563c34..234297b7be5 100644
--- a/ld/testsuite/ld-mips-elf/compact-eh2.s
+++ b/ld/testsuite/ld-mips-elf/compact-eh2.s
@@ -6,6 +6,7 @@
 	.cfi_personality_id 0x2
 	.cfi_lsda 0x1b,.LLSDA3
 	.global main
+	.type	main, @function
 main:
 .LEHB0 = .
 	move	$4,$2
diff --git a/ld/testsuite/ld-mips-elf/compact-eh3.s b/ld/testsuite/ld-mips-elf/compact-eh3.s
index 2bcf5ca6c30..9ee7558dc96 100644
--- a/ld/testsuite/ld-mips-elf/compact-eh3.s
+++ b/ld/testsuite/ld-mips-elf/compact-eh3.s
@@ -6,6 +6,7 @@
 	.cfi_personality_id 0x2
 	.cfi_lsda 0x1b,.LLSDA3
 	.global main
+	.type	main, @function
 main:
 .LEHB0 = .
 	move	$4,$2
diff --git a/ld/testsuite/ld-mips-elf/compact-eh3a.s b/ld/testsuite/ld-mips-elf/compact-eh3a.s
index 3780cf23e37..a1276ab575d 100644
--- a/ld/testsuite/ld-mips-elf/compact-eh3a.s
+++ b/ld/testsuite/ld-mips-elf/compact-eh3a.s
@@ -1,6 +1,7 @@
 	.cfi_sections .eh_frame_entry
 	.section	.text.compact3a,"ax",@progbits
 	.globl	compact3a
+	.type	compact3a, @function
 	.cfi_startproc
 compact3a:
 	lw	$31,44($sp)
diff --git a/ld/testsuite/ld-mips-elf/eh-frame5.s b/ld/testsuite/ld-mips-elf/eh-frame5.s
index 741a021685d..cf5a11c37ab 100644
--- a/ld/testsuite/ld-mips-elf/eh-frame5.s
+++ b/ld/testsuite/ld-mips-elf/eh-frame5.s
@@ -2,6 +2,7 @@
 	.cfi_personality 0x0,local_pers
 	.cfi_lsda 0x0,LSDA
 	.ent	f1
+	.type	f1, @function
 f1:
 	nop
 	.end	f1
@@ -11,6 +12,7 @@ f1:
 	.cfi_personality 0x0,hidden_pers
 	.cfi_lsda 0x0,LSDA
 	.ent	f2
+	.type	f2, @function
 f2:
 	nop
 	.end	f2
@@ -20,6 +22,7 @@ f2:
 	.cfi_personality 0x0,global_pers
 	.cfi_lsda 0x0,LSDA
 	.ent	f3
+	.type	f3, @function
 f3:
 	nop
 	.end	f3
@@ -29,6 +32,7 @@ f3:
 	.cfi_personality 0x0,extern_pers
 	.cfi_lsda 0x0,LSDA
 	.ent	f4
+	.type	f4, @function
 f4:
 	nop
 	.end	f4
@@ -38,6 +42,7 @@ f4:
 	.cfi_personality 0x80,local_indirect_ptr
 	.cfi_lsda 0x0,LSDA
 	.ent	f5
+	.type	f5, @function
 f5:
 	nop
 	.end	f5
@@ -47,6 +52,7 @@ f5:
 	.cfi_personality 0x80,hidden_indirect_ptr
 	.cfi_lsda 0x0,LSDA
 	.ent	f6
+	.type	f6, @function
 f6:
 	nop
 	.end	f6
@@ -56,6 +62,7 @@ f6:
 	.cfi_personality 0x80,global_indirect_ptr
 	.cfi_lsda 0x0,LSDA
 	.ent	f7
+	.type	f7, @function
 f7:
 	nop
 	.end	f7
@@ -65,6 +72,7 @@ f7:
 	.cfi_personality 0x80,extern_indirect_ptr
 	.cfi_lsda 0x0,LSDA
 	.ent	f8
+	.type	f8, @function
 f8:
 	nop
 	.end	f8
@@ -72,6 +80,7 @@ f8:
 
 
 	.ent	local_pers
+	.type	local_pers, @function
 local_pers:
 	nop
 	.end	local_pers
@@ -79,12 +88,14 @@ local_pers:
 	.globl	hidden_pers
 	.hidden	hidden_pers
 	.ent	hidden_pers
+	.type	hidden_pers, @function
 hidden_pers:
 	nop
 	.end	hidden_pers
 
 	.globl	global_pers
 	.ent	global_pers
+	.type	global_pers, @function
 global_pers:
 	nop
 	.end	global_pers
diff --git a/ld/testsuite/ld-mips-elf/ehdr_start-new.s b/ld/testsuite/ld-mips-elf/ehdr_start-new.s
index 5ee00dc4add..ccf20db024a 100644
--- a/ld/testsuite/ld-mips-elf/ehdr_start-new.s
+++ b/ld/testsuite/ld-mips-elf/ehdr_start-new.s
@@ -2,6 +2,7 @@
 	.text
 	.weak	__ehdr_start
 	.globl	__start
+	.type	__start, @function
 	.ent	__start
 	.frame	$29, 0, $31
 	.mask	0x00000000, 0
diff --git a/ld/testsuite/ld-mips-elf/ehdr_start-o32.s b/ld/testsuite/ld-mips-elf/ehdr_start-o32.s
index 09734473fa3..60a5854b9b8 100644
--- a/ld/testsuite/ld-mips-elf/ehdr_start-o32.s
+++ b/ld/testsuite/ld-mips-elf/ehdr_start-o32.s
@@ -2,6 +2,7 @@
 	.text
 	.weak	__ehdr_start
 	.globl	__start
+	.type	__start, @function
 	.ent	__start
 	.frame	$29, 0, $31
 	.mask	0x00000000, 0
diff --git a/ld/testsuite/ld-mips-elf/emit-relocs-1a.s b/ld/testsuite/ld-mips-elf/emit-relocs-1a.s
index 35c3a6f84d9..c8fd7d6151e 100644
--- a/ld/testsuite/ld-mips-elf/emit-relocs-1a.s
+++ b/ld/testsuite/ld-mips-elf/emit-relocs-1a.s
@@ -1,6 +1,7 @@
 	.text
 	.align	4
 	.globl	_start
+	.type	_start, @function
 _start:
 	jr	$31
 
diff --git a/ld/testsuite/ld-mips-elf/jaloverflow-2.s b/ld/testsuite/ld-mips-elf/jaloverflow-2.s
index 71acf296ea5..48ede45a483 100644
--- a/ld/testsuite/ld-mips-elf/jaloverflow-2.s
+++ b/ld/testsuite/ld-mips-elf/jaloverflow-2.s
@@ -2,6 +2,7 @@
 # overflowing
 
 	.globl	start
+	.type	start, @function
 	.weak	foo
 start:
 	jal	foo
diff --git a/ld/testsuite/ld-mips-elf/jaloverflow.s b/ld/testsuite/ld-mips-elf/jaloverflow.s
index 4dd98b80f89..e6de2e08c32 100644
--- a/ld/testsuite/ld-mips-elf/jaloverflow.s
+++ b/ld/testsuite/ld-mips-elf/jaloverflow.s
@@ -1,6 +1,7 @@
 # This file gets linked to start at 0xffffff0, so the call is an overflow.
 	.text
 	.global start
+	.type	start, @function
 	.set	noreorder
 start:
 	nop
diff --git a/ld/testsuite/ld-mips-elf/mips16-call-global-1.s b/ld/testsuite/ld-mips-elf/mips16-call-global-1.s
index 4c6d0a43aae..485e77c31ef 100644
--- a/ld/testsuite/ld-mips-elf/mips16-call-global-1.s
+++ b/ld/testsuite/ld-mips-elf/mips16-call-global-1.s
@@ -1,6 +1,7 @@
 	.set	mips16
 
 	.globl	__start
+	.type	__start, @function
 	.ent	__start
 	.align	4
 __start:
diff --git a/ld/testsuite/ld-mips-elf/mips16-intermix-1.s b/ld/testsuite/ld-mips-elf/mips16-intermix-1.s
index c596619c949..56527ea217b 100644
--- a/ld/testsuite/ld-mips-elf/mips16-intermix-1.s
+++ b/ld/testsuite/ld-mips-elf/mips16-intermix-1.s
@@ -1,6 +1,7 @@
 	.text
 	.align	2
 	.globl	__start
+	.type	__start, @function
 	.set	nomips16
 	.ent	__start
 __start:
diff --git a/ld/testsuite/ld-mips-elf/mips16-pic-1b.s b/ld/testsuite/ld-mips-elf/mips16-pic-1b.s
index 9a17072f2e4..1fc03c40eb7 100644
--- a/ld/testsuite/ld-mips-elf/mips16-pic-1b.s
+++ b/ld/testsuite/ld-mips-elf/mips16-pic-1b.s
@@ -12,6 +12,7 @@
 	callpic	used21,mips16
 
 	.globl	__start
+	.type	__start, @function
 	.ent	__start
 	.set	nomips16
 __start:
diff --git a/ld/testsuite/ld-mips-elf/mips16-pic-4c.s b/ld/testsuite/ld-mips-elf/mips16-pic-4c.s
index 338d378d756..985a7f150d5 100644
--- a/ld/testsuite/ld-mips-elf/mips16-pic-4c.s
+++ b/ld/testsuite/ld-mips-elf/mips16-pic-4c.s
@@ -7,6 +7,7 @@
 
 	.section .mips16.call.f2, "ax", @progbits
 	.ent	__call
+	.type	__call, @function
 __call:
 	la	$25,f2
 	jr	$25
@@ -18,6 +19,7 @@ __call:
 
 	.section .mips16.call.fp.f3, "ax", @progbits
 	.ent	__call_fp
+	.type	__call_fp, @function
 __call_fp:
 	la	$25,f3
 	jr	$25
diff --git a/ld/testsuite/ld-mips-elf/no-shared-1-n64.s b/ld/testsuite/ld-mips-elf/no-shared-1-n64.s
index 8eedf12157b..c63b8c879c4 100644
--- a/ld/testsuite/ld-mips-elf/no-shared-1-n64.s
+++ b/ld/testsuite/ld-mips-elf/no-shared-1-n64.s
@@ -1,6 +1,7 @@
 	.abicalls
 	.text
 	.globl	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	lui	$2,%hi(__gnu_local_gp)
diff --git a/ld/testsuite/ld-mips-elf/no-shared-1-o32.s b/ld/testsuite/ld-mips-elf/no-shared-1-o32.s
index f00fc4ba915..80be39bf36a 100644
--- a/ld/testsuite/ld-mips-elf/no-shared-1-o32.s
+++ b/ld/testsuite/ld-mips-elf/no-shared-1-o32.s
@@ -1,6 +1,7 @@
 	.abicalls
 	.text
 	.globl	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	lui	$2,%hi(__gnu_local_gp)
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-1b-micromips.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-1b-micromips.s
index 1eff3093c8b..abd01568912 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-1b-micromips.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-1b-micromips.s
@@ -1,6 +1,7 @@
 	.abicalls
 	.option	pic0
 	.global	__start
+	.type	__start, @function
 	.set	micromips
 	.ent	__start
 __start:
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-1b.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-1b.s
index 5739fef104d..2615f24a224 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-1b.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-1b.s
@@ -1,6 +1,7 @@
 	.abicalls
 	.option	pic0
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	jal	f1
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-2a.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-2a.s
index 45a490f945a..f360b0eb2df 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-2a.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-2a.s
@@ -1,6 +1,7 @@
 	.abicalls
 	.option	pic0
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	jal	foo
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-3b.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-3b.s
index 571c774cdf7..2a9ad89dee6 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-3b.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-3b.s
@@ -1,6 +1,7 @@
 	.abicalls
 	.option	pic0
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	jal	foo
@@ -8,6 +9,7 @@ __start:
 	.end	__start
 
 	.global	ext
+	.type	ext, @function
 	.ent	ext
 ext:
 	lui	$gp,%hi(__gnu_local_gp)
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-4b.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-4b.s
index 7e25bf48bf4..863a01b02cc 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-4b.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-4b.s
@@ -1,6 +1,7 @@
 	.abicalls
 	.option	pic0
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	lui	$2,%hi(obj1)
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-5a.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-5a.s
index 7452f5e8e3a..e85655fbe1a 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-5a.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-5a.s
@@ -1,6 +1,7 @@
 	.abicalls
 	.option	pic0
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	lui	$2,%hi(foo)
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-n32c.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-n32c.s
index 578626a18ca..3d5660c2ade 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-n32c.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-n32c.s
@@ -2,6 +2,7 @@
 	.option	pic0
 	.set	noreorder
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	jal	f1
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-n64c.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-n64c.s
index 578626a18ca..3d5660c2ade 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-n64c.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-n64c.s
@@ -2,6 +2,7 @@
 	.option	pic0
 	.set	noreorder
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	jal	f1
diff --git a/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-o32c.s b/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-o32c.s
index 578626a18ca..3d5660c2ade 100644
--- a/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-o32c.s
+++ b/ld/testsuite/ld-mips-elf/pic-and-nonpic-6-o32c.s
@@ -2,6 +2,7 @@
 	.option	pic0
 	.set	noreorder
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	jal	f1
diff --git a/ld/testsuite/ld-mips-elf/pie.s b/ld/testsuite/ld-mips-elf/pie.s
index c7f2b206b9f..442de015006 100644
--- a/ld/testsuite/ld-mips-elf/pie.s
+++ b/ld/testsuite/ld-mips-elf/pie.s
@@ -1,5 +1,6 @@
 	.abicalls
 	.global	__start
+	.type	__start, @function
 	.ent	__start
 __start:
 	jr $31
diff --git a/ld/testsuite/ld-mips-elf/relax-jalr.s b/ld/testsuite/ld-mips-elf/relax-jalr.s
index ba7ea1a04dd..b8478faef02 100644
--- a/ld/testsuite/ld-mips-elf/relax-jalr.s
+++ b/ld/testsuite/ld-mips-elf/relax-jalr.s
@@ -1,6 +1,7 @@
-.globl __start
+ .globl __start
+ .type __start, @function
 	.space 8
-.ent __start
+ .ent __start
 __start:
 .Lstart:
 	.space 16
@@ -9,7 +10,7 @@ __start:
         jal __start
 	.space 64
 	jal .Lstart
-.end __start
+ .end __start
 
 # make objdump print ...
 	.space 8
diff --git a/ld/testsuite/ld-mips-elf/reloc-1a.s b/ld/testsuite/ld-mips-elf/reloc-1a.s
index 5fcd4bb18c5..2d1c9f1f52a 100644
--- a/ld/testsuite/ld-mips-elf/reloc-1a.s
+++ b/ld/testsuite/ld-mips-elf/reloc-1a.s
@@ -1,4 +1,5 @@
 	.globl	_start
+	.type	_start, @function
 	.globl	sdg
 	.set	noreorder
 	.ent	tstarta
diff --git a/ld/testsuite/ld-mips-elf/reloc-2a.s b/ld/testsuite/ld-mips-elf/reloc-2a.s
index 0ea830a9dae..570b7248233 100644
--- a/ld/testsuite/ld-mips-elf/reloc-2a.s
+++ b/ld/testsuite/ld-mips-elf/reloc-2a.s
@@ -1,4 +1,5 @@
 	.globl	_start
+	.type	_start, @function
 	.globl	sdg
 	.set	noreorder
 	.ent	tstarta
diff --git a/ld/testsuite/ld-mips-elf/reloc-4.s b/ld/testsuite/ld-mips-elf/reloc-4.s
index 061fa807152..d379e059630 100644
--- a/ld/testsuite/ld-mips-elf/reloc-4.s
+++ b/ld/testsuite/ld-mips-elf/reloc-4.s
@@ -1,5 +1,6 @@
 	.text
 	.globl	_start
+	.type	_start, @function
 _start:
         li.d    $f2,1.10000000000000000000e0
 
diff --git a/ld/testsuite/ld-mips-elf/reloc-5.s b/ld/testsuite/ld-mips-elf/reloc-5.s
index a4b31b7fa03..25c722a549e 100644
--- a/ld/testsuite/ld-mips-elf/reloc-5.s
+++ b/ld/testsuite/ld-mips-elf/reloc-5.s
@@ -1,5 +1,6 @@
 	.text
 	.globl	_start
+	.type	_start, @function
 _start:
         lw	$2, %gp_rel(i)($28)
 
diff --git a/ld/testsuite/ld-mips-elf/reloc-6b.s b/ld/testsuite/ld-mips-elf/reloc-6b.s
index ae4e9bcf8a9..e75060e1510 100644
--- a/ld/testsuite/ld-mips-elf/reloc-6b.s
+++ b/ld/testsuite/ld-mips-elf/reloc-6b.s
@@ -1,4 +1,5 @@
 	.globl	__start .text
+	.type	__start, @function
 	.globl	gs .text
 __start:
 gs:
diff --git a/ld/testsuite/ld-mips-elf/textrel-1.s b/ld/testsuite/ld-mips-elf/textrel-1.s
index f6b4a6a70df..43143f7c934 100644
--- a/ld/testsuite/ld-mips-elf/textrel-1.s
+++ b/ld/testsuite/ld-mips-elf/textrel-1.s
@@ -1,4 +1,5 @@
         .globl foo
+	.type foo, @function
 foo:
         .cfi_startproc
         nop
diff --git a/ld/testsuite/ld-mips-elf/undefweak-overflow.d b/ld/testsuite/ld-mips-elf/undefweak-overflow.d
index bbed9970dff..72fcc65cb70 100644
--- a/ld/testsuite/ld-mips-elf/undefweak-overflow.d
+++ b/ld/testsuite/ld-mips-elf/undefweak-overflow.d
@@ -3,38 +3,38 @@
 #ld: -Ttext=0x20000000 -e start
 #objdump: -dr --show-raw-insn
 #...
-[0-9a-f]+ <_ftext>:
-[ 0-9a-f]+:	d85fffff 	beqzc	v0,20000000 <_ftext>
+[0-9a-f]+ <start>:
+[ 0-9a-f]+:	d85fffff 	beqzc	v0,20000000 <start>
 [ 0-9a-f]+:	00000000 	nop
-[ 0-9a-f]+:	f85ffffd 	bnezc	v0,20000000 <_ftext>
-[ 0-9a-f]+:	ec4ffffd 	lwpc	v0,20000000 <_ftext>
-[ 0-9a-f]+:	ec5bfffe 	ldpc	v0,20000000 <_ftext>
-[ 0-9a-f]+:	cbfffffa 	bc	20000000 <_ftext>
-[ 0-9a-f]+:	1000fff9 	b	20000000 <_ftext>
+[ 0-9a-f]+:	f85ffffd 	bnezc	v0,20000000 <start>
+[ 0-9a-f]+:	ec4ffffd 	lwpc	v0,20000000 <start>
+[ 0-9a-f]+:	ec5bfffe 	ldpc	v0,20000000 <start>
+[ 0-9a-f]+:	cbfffffa 	bc	20000000 <start>
+[ 0-9a-f]+:	1000fff9 	b	20000000 <start>
 [ 0-9a-f]+:	00000000 	nop
-[ 0-9a-f]+:	0411fff7 	bal	20000000 <_ftext>
+[ 0-9a-f]+:	0411fff7 	bal	20000000 <start>
 [ 0-9a-f]+:	3c...... 	lui	a0,0x....
-[ 0-9a-f]+:	0c000000 	jal	20000000 <_ftext>
+[ 0-9a-f]+:	0c000000 	jal	20000000 <start>
 [ 0-9a-f]+:	00000000 	nop
-[ 0-9a-f]+:	08000000 	j	20000000 <_ftext>
+[ 0-9a-f]+:	08000000 	j	20000000 <start>
 [ 0-9a-f]+:	00000000 	nop
 
 [0-9a-f]+ <micro>:
-[ 0-9a-f]+:	8e63      	beqz	a0,20000000 <_ftext>
+[ 0-9a-f]+:	8e63      	beqz	a0,20000000 <start>
 [ 0-9a-f]+:	0c00      	nop
-[ 0-9a-f]+:	cfe1      	b	20000000 <_ftext>
+[ 0-9a-f]+:	cfe1      	b	20000000 <start>
 [ 0-9a-f]+:	0c00      	nop
-[ 0-9a-f]+:	9400 ffde 	b	20000000 <_ftext>
+[ 0-9a-f]+:	9400 ffde 	b	20000000 <start>
 [ 0-9a-f]+:	0c00      	nop
-[ 0-9a-f]+:	4060 ffdb 	bal	20000000 <_ftext>
+[ 0-9a-f]+:	4060 ffdb 	bal	20000000 <start>
 [ 0-9a-f]+:	0000 0000 	nop
-[ 0-9a-f]+:	f400 0000 	jal	20000000 <_ftext>
+[ 0-9a-f]+:	f400 0000 	jal	20000000 <start>
 [ 0-9a-f]+:	0000 0000 	nop
-[ 0-9a-f]+:	d400 0000 	j	20000000 <_ftext>
+[ 0-9a-f]+:	d400 0000 	j	20000000 <start>
 [ 0-9a-f]+:	0c00      	nop
 
 [0-9a-f]+ <mips16>:
-[ 0-9a-f]+:	f7df 1010 	b	20000000 <_ftext>
-[ 0-9a-f]+:	1800 0000 	jal	20000000 <_ftext>
+[ 0-9a-f]+:	f7df 1010 	b	20000000 <start>
+[ 0-9a-f]+:	1800 0000 	jal	20000000 <start>
 [ 0-9a-f]+:	6500      	nop
 #pass
diff --git a/ld/testsuite/ld-mips-elf/undefweak-overflow.s b/ld/testsuite/ld-mips-elf/undefweak-overflow.s
index d439d7c7c73..a8370ac6a57 100644
--- a/ld/testsuite/ld-mips-elf/undefweak-overflow.s
+++ b/ld/testsuite/ld-mips-elf/undefweak-overflow.s
@@ -3,6 +3,7 @@
 
 	.module mips64r6
 	.globl	start
+	.type	start, @function
 	.weak	foo
 start:
 	.set noreorder
diff --git a/ld/testsuite/ld-x86-64/load2.d b/ld/testsuite/ld-x86-64/load2.d
index f76ba9d55f2..0ae721c8167 100644
--- a/ld/testsuite/ld-x86-64/load2.d
+++ b/ld/testsuite/ld-x86-64/load2.d
@@ -14,5 +14,5 @@ Disassembly of section .text:
 [ 	]*[a-f0-9]+:	48 8d 05 ([0-9a-f]{2} ){4} *	lea    -0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <foo>
 [ 	]*[a-f0-9]+:	4c 8d 1d ([0-9a-f]{2} ){4} *	lea    0x[a-f0-9]+\(%rip\),%r11        # [a-f0-9]+ <bar>
 [ 	]*[a-f0-9]+:	48 8d 05 ([0-9a-f]{2} ){4} *	lea    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <__start_my_section>
-[ 	]*[a-f0-9]+:	4c 8d 1d ([0-9a-f]{2} ){4} *	lea    0x[a-f0-9]+\(%rip\),%r11        # [a-f0-9]+ <__stop_my_section>
+[ 	]*[a-f0-9]+:	4c 8d 1d ([0-9a-f]{2} ){4} *	lea    0x[a-f0-9]+\(%rip\),%r11        # [a-f0-9]+ <(__stop_my_section|pad)>
 #pass