This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] MIPS/BFD: For n64 hold the number of internal relocs in `->reloc_count'


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e5713223cbc1025f484fa2548d58f74173646b8a

commit e5713223cbc1025f484fa2548d58f74173646b8a
Author: Maciej W. Rozycki <macro@imgtec.com>
Date:   Fri May 19 15:11:31 2017 +0100

    MIPS/BFD: For n64 hold the number of internal relocs in `->reloc_count'
    
    Revert parts of commit fee24f1c5bfe ("objdump improvements for mips
    elf64"), <https://sourceware.org/ml/binutils/2003-03/msg00108.html>, and
    make the `->reloc_count' member of `struct bfd_section' hold the actual
    number of internal relocations stored in its `->relocation' vector.  To
    do so adjust `mips_elf64_slurp_one_reloc_table' to set `->reloc_count'
    to the actual number of internal relocations retrieved and discard
    `mips_elf64_canonicalize_reloc', `mips_elf64_canonicalize_dynamic_reloc'
    and their corresponding target macros.  Contrary to the description of
    `mips_elf64_slurp_one_reloc_table', adjusted appropriately, this makes
    generic relocation processing code happy and satisfies the "merge notes
    section" binutils test case.
    
    Add extra binutils test cases to expand the coverage of the generic
    "merge notes section" test case, now passing with the n64 ABI, across
    the MIPS o32, n32 and n64 ABIs regardless of the default ABI selected in
    target configuration, and also to verify correctness of the relocations
    produced.  Conversely, do not provide any additional test cases for the
    original issue addressed with the commit referred:
    
    - objdump would display only 1/3 of the total number of relocations,
      because it used the external relocation count, but each external
      relocation is brought in as 3 internal relocations.
    
    as n64 ABI relocation processing with `objdump -r' and `objdump -R' is
    already widely covered across the GAS and LD test suites.
    
    	bfd/
    	* elf64-mips.c (mips_elf64_canonicalize_reloc): Remove prototype
    	and function.
    	(mips_elf64_canonicalize_dynamic_reloc): Likewise.
    	(mips_elf64_slurp_one_reloc_table): Set `reloc_count' to the
    	actual number of internal relocations retrieved.  Adjust
    	function description.
    	(bfd_elf64_canonicalize_reloc): Remove macro.
    	(bfd_elf64_canonicalize_dynamic_reloc): Likewise.
    
    	binutils/
    	* testsuite/binutils-all/mips/mips-note-2.d: New test.
    	* testsuite/binutils-all/mips/mips-note-2r.d: New test.
    	* testsuite/binutils-all/mips/mips-note-2-n32.d: New test.
    	* testsuite/binutils-all/mips/mips-note-2-n64.d: New test.
    	* testsuite/binutils-all/mips/mips-note-2r-n32.d: New test.
    	* testsuite/binutils-all/mips/mips-note-2r-n64.d: New test.
    	* testsuite/binutils-all/mips/mips.exp: Define `has_newabi'.
    	Run the new tests.

Diff:
---
 bfd/ChangeLog                                      | 11 +++
 bfd/elf64-mips.c                                   | 82 ++--------------------
 binutils/ChangeLog                                 | 11 +++
 .../testsuite/binutils-all/mips/mips-note-2-n32.d  |  7 ++
 .../testsuite/binutils-all/mips/mips-note-2-n64.d  |  7 ++
 binutils/testsuite/binutils-all/mips/mips-note-2.d |  7 ++
 .../testsuite/binutils-all/mips/mips-note-2r-n32.d | 11 +++
 .../testsuite/binutils-all/mips/mips-note-2r-n64.d | 15 ++++
 .../testsuite/binutils-all/mips/mips-note-2r.d     | 11 +++
 binutils/testsuite/binutils-all/mips/mips.exp      | 15 ++++
 10 files changed, 102 insertions(+), 75 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 26b96f3..38462fe 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,14 @@
+2017-05-19  Maciej W. Rozycki  <macro@imgtec.com>
+
+	* elf64-mips.c (mips_elf64_canonicalize_reloc): Remove prototype
+	and function.
+	(mips_elf64_canonicalize_dynamic_reloc): Likewise.
+	(mips_elf64_slurp_one_reloc_table): Set `reloc_count' to the
+	actual number of internal relocations retrieved.  Adjust
+	function description.
+	(bfd_elf64_canonicalize_reloc): Remove macro.
+	(bfd_elf64_canonicalize_dynamic_reloc): Likewise.
+
 2017-05-19  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
 	* archures.c (bfd_mach_sparc_v9m8): Define.
diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c
index a66c319..e95db2c 100644
--- a/bfd/elf64-mips.c
+++ b/bfd/elf64-mips.c
@@ -88,12 +88,8 @@ static void mips_elf64_info_to_howto_rela
   (bfd *, arelent *, Elf_Internal_Rela *);
 static long mips_elf64_get_reloc_upper_bound
   (bfd *, asection *);
-static long mips_elf64_canonicalize_reloc
-  (bfd *, asection *, arelent **, asymbol **);
 static long mips_elf64_get_dynamic_reloc_upper_bound
   (bfd *);
-static long mips_elf64_canonicalize_dynamic_reloc
-  (bfd *, arelent **, asymbol **);
 static bfd_boolean mips_elf64_slurp_one_reloc_table
   (bfd *, asection *, Elf_Internal_Shdr *, bfd_size_type, arelent *,
    asymbol **, bfd_boolean);
@@ -3663,76 +3659,14 @@ mips_elf64_get_dynamic_reloc_upper_bound (bfd *abfd)
   return _bfd_elf_get_dynamic_reloc_upper_bound (abfd) * 3;
 }
 
-/* We must also copy more relocations than the corresponding functions
-   in elf.c would, so the two following functions are slightly
-   modified from elf.c, that multiply the external relocation count by
-   3 to obtain the internal relocation count.  */
-
-static long
-mips_elf64_canonicalize_reloc (bfd *abfd, sec_ptr section,
-			       arelent **relptr, asymbol **symbols)
-{
-  arelent *tblptr;
-  unsigned int i;
-  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
-
-  if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE))
-    return -1;
-
-  tblptr = section->relocation;
-  for (i = 0; i < section->reloc_count * 3; i++)
-    *relptr++ = tblptr++;
-
-  *relptr = NULL;
-
-  return section->reloc_count * 3;
-}
-
-static long
-mips_elf64_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage,
-				       asymbol **syms)
-{
-  bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
-  asection *s;
-  long ret;
-
-  if (elf_dynsymtab (abfd) == 0)
-    {
-      bfd_set_error (bfd_error_invalid_operation);
-      return -1;
-    }
-
-  slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
-  ret = 0;
-  for (s = abfd->sections; s != NULL; s = s->next)
-    {
-      if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
-	  && (elf_section_data (s)->this_hdr.sh_type == SHT_REL
-	      || elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
-	{
-	  arelent *p;
-	  long count, i;
-
-	  if (! (*slurp_relocs) (abfd, s, syms, TRUE))
-	    return -1;
-	  count = s->size / elf_section_data (s)->this_hdr.sh_entsize * 3;
-	  p = s->relocation;
-	  for (i = 0; i < count; i++)
-	    *storage++ = p++;
-	  ret += count;
-	}
-    }
-
-  *storage = NULL;
-
-  return ret;
-}
-
 /* Read the relocations from one reloc section.  This is mostly copied
    from elfcode.h, except for the changes to expand one external
-   relocation to 3 internal ones.  We must unfortunately set
-   reloc_count to the number of external relocations, because a lot of
-   generic code seems to depend on this.  */
+   relocation to 3 internal ones.  To reduce processing effort we
+   could discard those R_MIPS_NONE relocations that occupy the second
+   and the third entry of a triplet, as `mips_elf64_write_rel' and
+   `mips_elf64_write_rela' recreate them in output automagically,
+   however that would also remove them from `objdump -r' output,
+   breaking a long-established tradition and likely confusing people.  */
 
 static bfd_boolean
 mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
@@ -3885,7 +3819,7 @@ mips_elf64_slurp_one_reloc_table (bfd *abfd, asection *asect,
 	}
     }
 
-  asect->reloc_count += (relent - relents) / 3;
+  asect->reloc_count += relent - relents;
 
   if (allocated != NULL)
     free (allocated);
@@ -4504,9 +4438,7 @@ const struct elf_size_info mips_elf64_size_info =
 				_bfd_mips_elf_print_private_bfd_data
 
 #define bfd_elf64_get_reloc_upper_bound mips_elf64_get_reloc_upper_bound
-#define bfd_elf64_canonicalize_reloc mips_elf64_canonicalize_reloc
 #define bfd_elf64_get_dynamic_reloc_upper_bound mips_elf64_get_dynamic_reloc_upper_bound
-#define bfd_elf64_canonicalize_dynamic_reloc mips_elf64_canonicalize_dynamic_reloc
 #define bfd_elf64_mkobject		_bfd_mips_elf_mkobject
 
 /* The SGI style (n)64 NewABI.  */
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index b8e94d2..59e3bb3 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,5 +1,16 @@
 2017-05-19  Maciej W. Rozycki  <macro@imgtec.com>
 
+	* testsuite/binutils-all/mips/mips-note-2.d: New test.
+	* testsuite/binutils-all/mips/mips-note-2r.d: New test.
+	* testsuite/binutils-all/mips/mips-note-2-n32.d: New test.
+	* testsuite/binutils-all/mips/mips-note-2-n64.d: New test.
+	* testsuite/binutils-all/mips/mips-note-2r-n32.d: New test.
+	* testsuite/binutils-all/mips/mips-note-2r-n64.d: New test.
+	* testsuite/binutils-all/mips/mips.exp: Define `has_newabi'.
+	Run the new tests.
+
+2017-05-19  Maciej W. Rozycki  <macro@imgtec.com>
+
 	* testsuite/lib/utils-lib.exp (run_dump_test): Handle the `dump'
 	option.
 
diff --git a/binutils/testsuite/binutils-all/mips/mips-note-2-n32.d b/binutils/testsuite/binutils-all/mips/mips-note-2-n32.d
new file mode 100644
index 0000000..fe2066c
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-note-2-n32.d
@@ -0,0 +1,7 @@
+#PROG: objcopy
+#readelf: --notes --wide
+#objcopy: --merge-notes
+#name: MIPS merge notes section (n32)
+#as: -n32 -mips3
+#source: ../note-2-32.s
+#dump: ../note-2-32.d
diff --git a/binutils/testsuite/binutils-all/mips/mips-note-2-n64.d b/binutils/testsuite/binutils-all/mips/mips-note-2-n64.d
new file mode 100644
index 0000000..e34b083
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-note-2-n64.d
@@ -0,0 +1,7 @@
+#PROG: objcopy
+#readelf: --notes --wide
+#objcopy: --merge-notes
+#name: MIPS merge notes section (n64)
+#as: -64 -mips3
+#source: ../note-2-64.s
+#dump: ../note-2-64.d
diff --git a/binutils/testsuite/binutils-all/mips/mips-note-2.d b/binutils/testsuite/binutils-all/mips/mips-note-2.d
new file mode 100644
index 0000000..4bb328b
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-note-2.d
@@ -0,0 +1,7 @@
+#PROG: objcopy
+#readelf: --notes --wide
+#objcopy: --merge-notes
+#name: MIPS merge notes section (o32)
+#as: -32
+#source: ../note-2-32.s
+#dump: ../note-2-32.d
diff --git a/binutils/testsuite/binutils-all/mips/mips-note-2r-n32.d b/binutils/testsuite/binutils-all/mips/mips-note-2r-n32.d
new file mode 100644
index 0000000..caf9972
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-note-2r-n32.d
@@ -0,0 +1,11 @@
+#PROG: objcopy
+#readelf: --relocs
+#objcopy: --merge-notes
+#name: MIPS merge notes section relocations (n32)
+#as: -n32 -mips3
+#source: ../note-2-32.s
+
+Relocation section '\.rela\.gnu\.build\.attributes' at offset .* contains 2 entries:
+ Offset     Info    Type            Sym\.Value  Sym\. Name \+ Addend
+00000010  ......02 R_MIPS_32         00000100   note1\.s \+ 0
+0000006c  ......02 R_MIPS_32         00000104   note2\.s \+ 0
diff --git a/binutils/testsuite/binutils-all/mips/mips-note-2r-n64.d b/binutils/testsuite/binutils-all/mips/mips-note-2r-n64.d
new file mode 100644
index 0000000..0fbcc39
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-note-2r-n64.d
@@ -0,0 +1,15 @@
+#PROG: objcopy
+#readelf: --relocs
+#objcopy: --merge-notes
+#name: MIPS merge notes section relocations (n64)
+#as: -64 -mips3
+#source: ../note-2-64.s
+
+Relocation section '\.rela\.gnu\.build\.attributes' at offset .* contains 2 entries:
+  Offset          Info           Type           Sym\. Value    Sym\. Name \+ Addend
+000000000010  ....00000012 R_MIPS_64         0000000000000100 note1\.s \+ 0
+                    Type2: R_MIPS_NONE      
+                    Type3: R_MIPS_NONE      
+000000000070  ....00000012 R_MIPS_64         0000000000000104 note2\.s \+ 0
+                    Type2: R_MIPS_NONE      
+                    Type3: R_MIPS_NONE      
diff --git a/binutils/testsuite/binutils-all/mips/mips-note-2r.d b/binutils/testsuite/binutils-all/mips/mips-note-2r.d
new file mode 100644
index 0000000..c025727
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-note-2r.d
@@ -0,0 +1,11 @@
+#PROG: objcopy
+#readelf: --relocs
+#objcopy: --merge-notes
+#name: MIPS merge notes section relocations (o32)
+#as: -32
+#source: ../note-2-32.s
+
+Relocation section '\.rel\.gnu\.build\.attributes' at offset .* contains 2 entries:
+ Offset     Info    Type            Sym\.Value  Sym\. Name
+00000010  ......02 R_MIPS_32         00000100   note1\.s
+0000006c  ......02 R_MIPS_32         00000104   note2\.s
diff --git a/binutils/testsuite/binutils-all/mips/mips.exp b/binutils/testsuite/binutils-all/mips/mips.exp
index 7949445..28c2197 100644
--- a/binutils/testsuite/binutils-all/mips/mips.exp
+++ b/binutils/testsuite/binutils-all/mips/mips.exp
@@ -27,6 +27,12 @@ if [is_remote host] {
     set copyfile tmpdir/copy
 }
 
+set has_newabi [expr [istarget *-*-irix6*] \
+		     || [istarget mips*-*-linux*] \
+		     || [istarget mips*-sde-elf*] \
+		     || [istarget mips*-mti-elf*] \
+		     || [istarget mips*-img-elf*]]
+
 run_dump_test "mips-ase-1"
 run_dump_test "mips-ase-2"
 run_dump_test "mips-ase-3"
@@ -41,3 +47,12 @@ run_dump_test "mips16-extend-insn"
 run_dump_test "mips16e2-extend-insn"
 run_dump_test "mips16-alias"
 run_dump_test "mips16-noalias"
+
+run_dump_test "mips-note-2"
+run_dump_test "mips-note-2r"
+if $has_newabi {
+    run_dump_test "mips-note-2-n32"
+    run_dump_test "mips-note-2-n64"
+    run_dump_test "mips-note-2r-n32"
+    run_dump_test "mips-note-2r-n64"
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]