[2/2] MIPS: Make the IRIX naming of local section symbols consistent

Message ID alpine.LFD.2.21.2007270130470.1561071@eddie.linux-mips.org
State New
Headers show
Series
  • MIPS: IRIX ELF format symbol table sort/section symbol name fixes
Related show

Commit Message

Maciej W. Rozycki July 27, 2020, 9:48 a.m.
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.

commit 174fd7f9556183397625dbfa99ef68ecd325c74b
Author: Richard Sandiford <rdsandiford@googlemail.com>
Date:   Mon Feb 9 08:04:00 2004 +0000

commit 174fd7f95561 ("New bfd elf hook: force naming of local section symbols")

<https://sourceware.org/ml/binutils/2004-02/msg00072.html>

	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.
---
 bfd/elflink.c                                                        |   16 +++++++--
 bfd/elfxx-mips.c                                                     |    2 -
 binutils/testsuite/binutils-all/mips/global-local-symtab-final-n32.d |    9 +++++
 binutils/testsuite/binutils-all/mips/global-local-symtab-final-n64.d |    9 +++++
 binutils/testsuite/binutils-all/mips/global-local-symtab-final-o32.d |    9 +++++
 binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n32.d  |    8 ++++
 binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n32t.d |    8 ++++
 binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n64.d  |   14 ++++++++
 binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n64t.d |   14 ++++++++
 binutils/testsuite/binutils-all/mips/global-local-symtab-sort-o32.d  |   14 ++++++++
 binutils/testsuite/binutils-all/mips/global-local-symtab-sort-o32t.d |   14 ++++++++
 binutils/testsuite/binutils-all/mips/mips.exp                        |    6 +++
 gas/testsuite/gas/mips/global-local-symtab-sort-n32.d                |    6 +++
 gas/testsuite/gas/mips/global-local-symtab-sort-n32t.d               |    6 +++
 gas/testsuite/gas/mips/global-local-symtab-sort-n64.d                |   17 ++++++++++
 gas/testsuite/gas/mips/global-local-symtab-sort-n64t.d               |   17 ++++++++++
 gas/testsuite/gas/mips/global-local-symtab-sort-o32.d                |   17 ++++++++++
 gas/testsuite/gas/mips/global-local-symtab-sort-o32t.d               |   17 ++++++++++
 gas/testsuite/gas/mips/mips.exp                                      |    3 +
 ld/testsuite/ld-elf/sec64k.exp                                       |    2 -
 ld/testsuite/ld-mips-elf/global-local-symtab-final-n32.d             |    6 +++
 ld/testsuite/ld-mips-elf/global-local-symtab-final-n64.d             |    6 +++
 ld/testsuite/ld-mips-elf/global-local-symtab-final-o32.d             |    6 +++
 ld/testsuite/ld-mips-elf/global-local-symtab-sort-n32.d              |    6 +++
 ld/testsuite/ld-mips-elf/global-local-symtab-sort-n32t.d             |    6 +++
 ld/testsuite/ld-mips-elf/global-local-symtab-sort-n64.d              |   13 +++++++
 ld/testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d             |   13 +++++++
 ld/testsuite/ld-mips-elf/global-local-symtab-sort-o32.d              |   13 +++++++
 ld/testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d             |   13 +++++++
 ld/testsuite/ld-mips-elf/mips-elf.exp                                |    6 +++
 30 files changed, 291 insertions(+), 5 deletions(-)

binutils-mips-bfd-local-section-symbols-et-rel.diff

Patch

Index: binutils/bfd/elflink.c
===================================================================
--- binutils.orig/bfd/elflink.c
+++ binutils/bfd/elflink.c
@@ -12268,6 +12268,9 @@  bfd_elf_final_link (bfd *abfd, struct bf
 
   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);
@@ -12290,10 +12293,15 @@  bfd_elf_final_link (bfd *abfd, struct bf
 
       /* 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;
@@ -12308,7 +12316,9 @@  bfd_elf_final_link (bfd *abfd, struct bf
 	      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;
 	    }
Index: binutils/bfd/elfxx-mips.c
===================================================================
--- binutils.orig/bfd/elfxx-mips.c
+++ binutils/bfd/elfxx-mips.c
@@ -7262,7 +7262,7 @@  _bfd_mips_elf_eh_frame_address_size (bfd
 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);
 }
 
 /* Work over a section just before writing it out.  This routine is
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-final-n32.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-final-n32.d
@@ -0,0 +1,9 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-final-n64.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-final-n64.d
@@ -0,0 +1,9 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-final-o32.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-final-o32.d
@@ -0,0 +1,9 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n32.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n32.d
@@ -0,0 +1,8 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n32t.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n32t.d
@@ -0,0 +1,8 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n64.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n64.d
@@ -0,0 +1,14 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n64t.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-n64t.d
@@ -0,0 +1,14 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-o32.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-o32.d
@@ -0,0 +1,14 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-o32t.d
===================================================================
--- /dev/null
+++ binutils/binutils/testsuite/binutils-all/mips/global-local-symtab-sort-o32t.d
@@ -0,0 +1,14 @@ 
+#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
Index: binutils/binutils/testsuite/binutils-all/mips/mips.exp
===================================================================
--- binutils.orig/binutils/testsuite/binutils-all/mips/mips.exp
+++ binutils/binutils/testsuite/binutils-all/mips/mips.exp
@@ -252,3 +252,9 @@  run_dump_test_n32 "mips-reginfo-n32"
 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
Index: binutils/gas/testsuite/gas/mips/global-local-symtab-sort-n32.d
===================================================================
--- /dev/null
+++ binutils/gas/testsuite/gas/mips/global-local-symtab-sort-n32.d
@@ -0,0 +1,6 @@ 
+#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
Index: binutils/gas/testsuite/gas/mips/global-local-symtab-sort-n32t.d
===================================================================
--- /dev/null
+++ binutils/gas/testsuite/gas/mips/global-local-symtab-sort-n32t.d
@@ -0,0 +1,6 @@ 
+#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
Index: binutils/gas/testsuite/gas/mips/global-local-symtab-sort-n64.d
===================================================================
--- /dev/null
+++ binutils/gas/testsuite/gas/mips/global-local-symtab-sort-n64.d
@@ -0,0 +1,17 @@ 
+#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
Index: binutils/gas/testsuite/gas/mips/global-local-symtab-sort-n64t.d
===================================================================
--- /dev/null
+++ binutils/gas/testsuite/gas/mips/global-local-symtab-sort-n64t.d
@@ -0,0 +1,17 @@ 
+#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
Index: binutils/gas/testsuite/gas/mips/global-local-symtab-sort-o32.d
===================================================================
--- /dev/null
+++ binutils/gas/testsuite/gas/mips/global-local-symtab-sort-o32.d
@@ -0,0 +1,17 @@ 
+#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
Index: binutils/gas/testsuite/gas/mips/global-local-symtab-sort-o32t.d
===================================================================
--- /dev/null
+++ binutils/gas/testsuite/gas/mips/global-local-symtab-sort-o32t.d
@@ -0,0 +1,17 @@ 
+#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
Index: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp
+++ binutils/gas/testsuite/gas/mips/mips.exp
@@ -2094,8 +2094,11 @@  if { [istarget mips*-*-vxworks*] } {
     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}"
     }
 }
Index: binutils/ld/testsuite/ld-elf/sec64k.exp
===================================================================
--- binutils.orig/ld/testsuite/ld-elf/sec64k.exp
+++ binutils/ld/testsuite/ld-elf/sec64k.exp
@@ -145,7 +145,7 @@  if { ![istarget "m32r-*-*"] } then {
     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 "#..."
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-final-n32.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-final-n32.d
@@ -0,0 +1,6 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-final-n64.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-final-n64.d
@@ -0,0 +1,6 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-final-o32.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-final-o32.d
@@ -0,0 +1,6 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-n32.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-n32.d
@@ -0,0 +1,6 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-n32t.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-n32t.d
@@ -0,0 +1,6 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-n64.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-n64.d
@@ -0,0 +1,13 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-n64t.d
@@ -0,0 +1,13 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-o32.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-o32.d
@@ -0,0 +1,13 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d
===================================================================
--- /dev/null
+++ binutils/ld/testsuite/ld-mips-elf/global-local-symtab-sort-o32t.d
@@ -0,0 +1,13 @@ 
+#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
Index: binutils/ld/testsuite/ld-mips-elf/mips-elf.exp
===================================================================
--- binutils.orig/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ binutils/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -1663,3 +1663,9 @@  run_dump_test_o32 "reloc-pcrel-r6"
 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"