Make the MIPS/IRIX naming of local section symbols consistent between
files produced by generic ELF code and ELF linker code, complementing
commit 
174fd7f95561 ("New bfd elf hook: force naming of local section
symbols"), <https://sourceware.org/ml/binutils/2004-02/msg00072.html>.
Local section symbols have no names in the standard ELF gABI, however
the lack of a name causes problems with IRIX's MIPSpro linker.  To work
around the issue we give them names, however we do that in generic ELF
code only, based on what the `elf_backend_name_local_section_symbols'
hook returns if present.  That makes objects created by GAS or `objdump'
work correctly, however not ones created by `ld -r'.  That would not
normally cause issues with IRIX systems using GAS and `objdump' only
with the MIPSpro linker, however if GNU LD was used for whatever reason
in producing objects later fed to IRIX's MIPSpro linker, then things
would break.
Modify ELF linker code accordingly then, using the same hook.  Adjust
the `ld-elf/64ksec-r' test accordingly so that it also accepts a section
symbol with a name.
Also modify the hook itself so that only actual ET_REL objects have
names assigned to local section symbols.  Other kinds of ELF files are
not ever supposed to be relocated with the MIPSpro linker, so we can
afford producing more standard output.
Add suitable GAS, LD and `objcopy' test cases to the relevant testsuites
to keep these tools consistently verified.  This change also fixes:
FAIL: objcopy executable (pr25662)
across MIPS targets using the IRIX compatibility mode.
	bfd/
	* elflink.c (bfd_elf_final_link): Give local symbols a name if
	so requested.
	* elfxx-mips.c (_bfd_mips_elf_name_local_section_symbols): Only
	return TRUE if making ET_REL output.
	binutils/
	* testsuite/binutils-all/mips/global-local-symtab-sort-o32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-o32t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n32t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n64.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-sort-n64t.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-o32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-n32.d:
	New test.
	* testsuite/binutils-all/mips/global-local-symtab-final-n64.d:
	New test.
	* testsuite/binutils-all/mips/mips.exp: Run the new tests.
	gas/
	* testsuite/gas/mips/global-local-symtab-sort-o32.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-o32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n32.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n32t.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n64.d: New test.
	* testsuite/gas/mips/global-local-symtab-sort-n64t.d: New test.
	* testsuite/gas/mips/mips.exp: Run the new tests.
	ld/
	* testsuite/ld-elf/sec64k.exp: Also accept a section symbol with
	a name.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n32t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-o32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-n32.d: New
	test.
	* testsuite/ld-mips-elf/global-local-symtab-final-n64.d: New
	test.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
+2020-07-29  Maciej W. Rozycki  <macro@linux-mips.org>
+
+       * elflink.c (bfd_elf_final_link): Give local symbols a name if
+       so requested.
+       * elfxx-mips.c (_bfd_mips_elf_name_local_section_symbols): Only
+       return TRUE if making ET_REL output.
+
 2020-07-29  Maciej W. Rozycki  <macro@linux-mips.org>
 
        * elf-bfd.h (elf_backend_data): Add
 
 
   if (info->strip != strip_all || emit_relocs)
     {
+      bfd_boolean name_local_sections;
+      const char *name;
+
       file_ptr off = elf_next_file_pos (abfd);
 
       _bfd_elf_assign_file_position_for_section (symtab_hdr, off, TRUE);
 
       /* Output a symbol for each section.  We output these even if we are
         discarding local symbols, since they are used for relocs.  These
-        symbols have no names.  We store the index of each one in the
-        index field of the section, so that we can find it again when
+        symbols usually have no names.  We store the index of each one in
+        the index field of the section, so that we can find it again when
         outputting relocs.  */
 
+      name_local_sections
+       = (bed->elf_backend_name_local_section_symbols
+          && bed->elf_backend_name_local_section_symbols (abfd));
+
+      name = NULL;
       elfsym.st_size = 0;
       elfsym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
       elfsym.st_other = 0;
              elfsym.st_shndx = i;
              if (!bfd_link_relocatable (info))
                elfsym.st_value = o->vma;
-             if (elf_link_output_symstrtab (&flinfo, NULL, &elfsym, o,
+             if (name_local_sections)
+               name = o->name;
+             if (elf_link_output_symstrtab (&flinfo, name, &elfsym, o,
                                             NULL) != 1)
                goto error_return;
            }
 
 bfd_boolean
 _bfd_mips_elf_name_local_section_symbols (bfd *abfd)
 {
-  return SGI_COMPAT (abfd);
+  return elf_elfheader (abfd)->e_type == ET_REL && SGI_COMPAT (abfd);
 }
 \f
 /* Work over a section just before writing it out.  This routine is
 
+2020-07-29  Maciej W. Rozycki  <macro@linux-mips.org>
+
+       * testsuite/binutils-all/mips/global-local-symtab-sort-o32.d:
+       New test.
+       * testsuite/binutils-all/mips/global-local-symtab-sort-o32t.d:
+       New test.
+       * testsuite/binutils-all/mips/global-local-symtab-sort-n32.d:
+       New test.
+       * testsuite/binutils-all/mips/global-local-symtab-sort-n32t.d:
+       New test.
+       * testsuite/binutils-all/mips/global-local-symtab-sort-n64.d:
+       New test.
+       * testsuite/binutils-all/mips/global-local-symtab-sort-n64t.d:
+       New test.
+       * testsuite/binutils-all/mips/global-local-symtab-final-o32.d:
+       New test.
+       * testsuite/binutils-all/mips/global-local-symtab-final-n32.d:
+       New test.
+       * testsuite/binutils-all/mips/global-local-symtab-final-n64.d:
+       New test.
+       * testsuite/binutils-all/mips/mips.exp: Run the new tests.
+
 2020-07-29  Maciej W. Rozycki  <macro@linux-mips.org>
 
        * testsuite/binutils-all/mips/global-local-symtab-o32.d: New
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (fully linked) (n32)
+#as: -n32 -mno-pdr -mips3
+#ld: -e 0 -T ../../../../ld/testsuite/ld-mips-elf/global-local-symtab.ld
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+#dump: global-local-symtab-sort-o32t.d
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (fully linked) (n64)
+#as: -64 -mno-pdr -mips3
+#ld: -e 0 -T ../../../../ld/testsuite/ld-mips-elf/global-local-symtab.ld
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+#dump: global-local-symtab-sort-n64t.d
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (fully linked) (o32)
+#as: -32 -mno-pdr
+#ld: -e 0 -T ../../../../ld/testsuite/ld-mips-elf/global-local-symtab.ld
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+#dump: global-local-symtab-sort-o32t.d
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (relocatable) (n32)
+#as: -n32 -mno-pdr -mips3
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+#dump: global-local-symtab-sort-o32.d
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (relocatable) (n32)
+#as: -n32 -mno-pdr -mips3
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+#dump: global-local-symtab-sort-o32t.d
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (relocatable) (n64)
+#as: -64 -mno-pdr -mips3
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+
+Symbol table '\.symtab' contains 4 entries:
+   Num:    Value          Size Type    Bind   Vis      Ndx Name
+     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 \.data
+     2: 0000000000000004     4 OBJECT  LOCAL  DEFAULT    1 bar
+     3: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    1 foo
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (relocatable) (n64)
+#as: -64 -mno-pdr -mips3
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+
+Symbol table '\.symtab' contains 4 entries:
+   Num:    Value          Size Type    Bind   Vis      Ndx Name
+     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
+     2: 0000000000000004     4 OBJECT  LOCAL  DEFAULT    1 bar
+     3: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    1 foo
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (relocatable) (o32)
+#as: -32 -mno-pdr
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+
+Symbol table '\.symtab' contains 4 entries:
+   Num:    Value  Size Type    Bind   Vis      Ndx Name
+     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 00000000     0 SECTION LOCAL  DEFAULT    1 \.data
+     2: 00000000     4 OBJECT  GLOBAL DEFAULT    1 foo
+     3: 00000004     4 OBJECT  LOCAL  DEFAULT    1 bar
 
--- /dev/null
+#PROG: objcopy
+#DUMPPROG: readelf
+#name: MIPS symbol table sort and section symbol names (relocatable) (o32)
+#as: -32 -mno-pdr
+#objcopy: -j .data -j .symtab -j .strtab -j .shstrtab
+#readelf: -s
+#source: ../../../../gas/testsuite/gas/mips/global-local-symtab.s
+
+Symbol table '\.symtab' contains 4 entries:
+   Num:    Value  Size Type    Bind   Vis      Ndx Name
+     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 00000000     0 SECTION LOCAL  DEFAULT    1 
+     2: 00000004     4 OBJECT  LOCAL  DEFAULT    1 bar
+     3: 00000000     4 OBJECT  GLOBAL DEFAULT    1 foo
 
 run_dump_test_o32 "global-local-symtab-o32${tmips}"
 run_dump_test_n32 "global-local-symtab-n32${tmips}"
 run_dump_test_n64 "global-local-symtab-n64"
+run_dump_test_o32 "global-local-symtab-sort-o32${tmips}"
+run_dump_test_n32 "global-local-symtab-sort-n32${tmips}"
+run_dump_test_n64 "global-local-symtab-sort-n64${tmips}"
+run_dump_test_o32 "global-local-symtab-final-o32" useld
+run_dump_test_n32 "global-local-symtab-final-n32" useld
+run_dump_test_n64 "global-local-symtab-final-n64" useld
 
+2020-07-29  Maciej W. Rozycki  <macro@linux-mips.org>
+
+       * testsuite/gas/mips/global-local-symtab-sort-o32.d: New test.
+       * testsuite/gas/mips/global-local-symtab-sort-o32t.d: New test.
+       * testsuite/gas/mips/global-local-symtab-sort-n32.d: New test.
+       * testsuite/gas/mips/global-local-symtab-sort-n32t.d: New test.
+       * testsuite/gas/mips/global-local-symtab-sort-n64.d: New test.
+       * testsuite/gas/mips/global-local-symtab-sort-n64t.d: New test.
+       * testsuite/gas/mips/mips.exp: Run the new tests.
+
 2020-07-29  Maciej W. Rozycki  <macro@linux-mips.org>
 
        * testsuite/gas/mips/global-local-symtab-o32.d: New test.
 
--- /dev/null
+#DUMPPROG: readelf
+#readelf: -s
+#name: MIPS global/local symbol table sort and section symbol names (n32)
+#as: -n32 -mno-pdr -mips3
+#source: global-local-symtab.s
+#dump: global-local-symtab-sort-o32.d
 
--- /dev/null
+#DUMPPROG: readelf
+#readelf: -s
+#name: MIPS global/local symbol table sort and section symbol names (n32)
+#as: -n32 -mno-pdr -mips3
+#source: global-local-symtab.s
+#dump: global-local-symtab-sort-o32t.d
 
--- /dev/null
+#DUMPPROG: readelf
+#readelf: -s
+#name: MIPS global/local symbol table sort and section symbol names (n64)
+#as: -64 -mno-pdr -mips3
+#source: global-local-symtab.s
+
+Symbol table '\.symtab' contains 9 entries:
+   Num:    Value          Size Type    Bind   Vis      Ndx Name
+     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 \.text
+     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    2 \.data
+     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 \.bss
+     4: 0000000000000004     4 OBJECT  LOCAL  DEFAULT    2 bar
+     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 \.MIPS\.options
+     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    5 \.MIPS\.abiflags
+     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    6 \.gnu\.attributes
+     8: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    2 foo
 
--- /dev/null
+#DUMPPROG: readelf
+#readelf: -s
+#name: MIPS global/local symbol table sort and section symbol names (n64)
+#as: -64 -mno-pdr -mips3
+#source: global-local-symtab.s
+
+Symbol table '\.symtab' contains 9 entries:
+   Num:    Value          Size Type    Bind   Vis      Ndx Name
+     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
+     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    2 
+     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    3 
+     4: 0000000000000004     4 OBJECT  LOCAL  DEFAULT    2 bar
+     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    4 
+     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    5 
+     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    6 
+     8: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    2 foo
 
--- /dev/null
+#DUMPPROG: readelf
+#readelf: -s
+#name: MIPS global/local symbol table sort and section symbol names (o32)
+#as: -32 -mno-pdr
+#source: global-local-symtab.s
+
+Symbol table '\.symtab' contains 9 entries:
+   Num:    Value  Size Type    Bind   Vis      Ndx Name
+     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 00000000     0 SECTION LOCAL  DEFAULT    1 \.text
+     2: 00000000     0 SECTION LOCAL  DEFAULT    2 \.data
+     3: 00000000     0 SECTION LOCAL  DEFAULT    3 \.bss
+     4: 00000000     0 SECTION LOCAL  DEFAULT    4 \.reginfo
+     5: 00000000     0 SECTION LOCAL  DEFAULT    5 \.MIPS\.abiflags
+     6: 00000000     0 SECTION LOCAL  DEFAULT    6 \.gnu\.attributes
+     7: 00000000     4 OBJECT  GLOBAL DEFAULT    2 foo
+     8: 00000004     4 OBJECT  LOCAL  DEFAULT    2 bar
 
--- /dev/null
+#DUMPPROG: readelf
+#readelf: -s
+#name: MIPS global/local symbol table sort and section symbol names (o32)
+#as: -32 -mno-pdr
+#source: global-local-symtab.s
+
+Symbol table '\.symtab' contains 9 entries:
+   Num:    Value  Size Type    Bind   Vis      Ndx Name
+     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 00000000     0 SECTION LOCAL  DEFAULT    1 
+     2: 00000000     0 SECTION LOCAL  DEFAULT    2 
+     3: 00000000     0 SECTION LOCAL  DEFAULT    3 
+     4: 00000004     4 OBJECT  LOCAL  DEFAULT    2 bar
+     5: 00000000     0 SECTION LOCAL  DEFAULT    4 
+     6: 00000000     0 SECTION LOCAL  DEFAULT    5 
+     7: 00000000     0 SECTION LOCAL  DEFAULT    6 
+     8: 00000000     4 OBJECT  GLOBAL DEFAULT    2 foo
 
     run_dump_test "insn-isa-mode"
     run_dump_test "insn-isa-mode"
     run_dump_test "global-local-symtab-o32${tmips}"
+    run_dump_test "global-local-symtab-sort-o32${tmips}"
     if $has_newabi {
        run_dump_test "global-local-symtab-n32${tmips}"
        run_dump_test "global-local-symtab-n64"
+       run_dump_test "global-local-symtab-sort-n32${tmips}"
+       run_dump_test "global-local-symtab-sort-n64${tmips}"
     }
 }
 
+2020-07-29  Maciej W. Rozycki  <macro@linux-mips.org>
+
+       * testsuite/ld-elf/sec64k.exp: Also accept a section symbol with
+       a name.
+       * testsuite/ld-mips-elf/global-local-symtab-sort-o32.d: New
+       test.
+       * testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d: New
+       test.
+       * testsuite/ld-mips-elf/global-local-symtab-sort-n32.d: New
+       test.
+       * testsuite/ld-mips-elf/global-local-symtab-sort-n32t.d: New
+       test.
+       * testsuite/ld-mips-elf/global-local-symtab-sort-n64.d: New
+       test.
+       * testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d: New
+       test.
+       * testsuite/ld-mips-elf/global-local-symtab-final-o32.d: New
+       test.
+       * testsuite/ld-mips-elf/global-local-symtab-final-n32.d: New
+       test.
+       * testsuite/ld-mips-elf/global-local-symtab-final-n64.d: New
+       test.
+       * testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
+
 2020-07-29  Maciej W. Rozycki  <macro@linux-mips.org>
 
        * testsuite/ld-mips-elf/global-local-symtab-o32.d: New test.
 
     puts $ofd "  \\\[65279\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*"
     puts $ofd "  \\\[65280\\\] (.rel\[a\]?)?\\.foo\\.\[0-9\]+ .*"
     puts $ofd "#..."
-    puts $ofd " 340..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+68... "
+    puts $ofd " 340..: 0+\[ \]+0\[ \]+SECTION\[ \]+LOCAL\[ \]+DEFAULT\[ \]+68... .*"
     puts $ofd "#..."
     puts $ofd " 340..: 0+(2|4|8)\[ \]+0\[ \]+NOTYPE\[ \]+LOCAL\[ \]+DEFAULT\[ \]+\[2-7\] bar_1$"
     puts $ofd "#..."
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (fully linked) (n32)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -e 0 -T global-local-symtab.ld
+#readelf: -sW
+#dump: global-local-symtab-sort-o32t.d
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (fully linked) (n64)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -e 0 -T global-local-symtab.ld
+#readelf: -sW
+#dump: global-local-symtab-sort-n64t.d
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (fully linked) (n32)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -e 0 -T global-local-symtab.ld
+#readelf: -sW
+#dump: global-local-symtab-sort-o32t.d
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (relocatable) (n32)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -r -T global-local-symtab.ld
+#readelf: -sW
+#dump: global-local-symtab-sort-o32.d
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (relocatable) (n32)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -r -T global-local-symtab.ld
+#readelf: -sW
+#dump: global-local-symtab-sort-o32t.d
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (relocatable) (n64)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -r -T global-local-symtab.ld
+#readelf: -sW
+
+Symbol table '\.symtab' contains 5 entries:
+   Num:    Value          Size Type    Bind   Vis      Ndx Name
+     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 \.data
+     2: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS tmpdir/global-local-symtab\.o
+     3: 0000000000000004     4 OBJECT  LOCAL  DEFAULT    1 bar
+     4: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    1 foo
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (relocatable) (n64)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -r -T global-local-symtab.ld
+#readelf: -sW
+
+Symbol table '\.symtab' contains 5 entries:
+   Num:    Value          Size Type    Bind   Vis      Ndx Name
+     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 
+     2: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS tmpdir/global-local-symtab\.o
+     3: 0000000000000004     4 OBJECT  LOCAL  DEFAULT    1 bar
+     4: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    1 foo
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (relocatable) (n32)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -r -T global-local-symtab.ld
+#readelf: -sW
+
+Symbol table '\.symtab' contains 5 entries:
+   Num:    Value  Size Type    Bind   Vis      Ndx Name
+     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 00000000     0 SECTION LOCAL  DEFAULT    1 \.data
+     2: 00000000     0 FILE    LOCAL  DEFAULT  ABS tmpdir/global-local-symtab\.o
+     3: 00000004     4 OBJECT  LOCAL  DEFAULT    1 bar
+     4: 00000000     4 OBJECT  GLOBAL DEFAULT    1 foo
 
--- /dev/null
+#name: MIPS symbol table sort and section symbol names (relocatable) (n32)
+#source: ../../../gas/testsuite/gas/mips/global-local-symtab.s
+#as: -mno-pdr
+#ld: -r -T global-local-symtab.ld
+#readelf: -sW
+
+Symbol table '\.symtab' contains 5 entries:
+   Num:    Value  Size Type    Bind   Vis      Ndx Name
+     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
+     1: 00000000     0 SECTION LOCAL  DEFAULT    1 
+     2: 00000000     0 FILE    LOCAL  DEFAULT  ABS tmpdir/global-local-symtab\.o
+     3: 00000004     4 OBJECT  LOCAL  DEFAULT    1 bar
+     4: 00000000     4 OBJECT  GLOBAL DEFAULT    1 foo
 
 run_dump_test_o32 "global-local-symtab-o32${tmips}"
 run_dump_test_n32 "global-local-symtab-n32${tmips}"
 run_dump_test_n64 "global-local-symtab-n64"
+run_dump_test_o32 "global-local-symtab-sort-o32${tmips}"
+run_dump_test_n32 "global-local-symtab-sort-n32${tmips}"
+run_dump_test_n64 "global-local-symtab-sort-n64${tmips}"
+run_dump_test_o32 "global-local-symtab-final-o32"
+run_dump_test_n32 "global-local-symtab-final-n32"
+run_dump_test_n64 "global-local-symtab-final-n64"