MIPS/BFD: Remove duplicate NewABI JALR relocation handling
authorMaciej W. Rozycki <macro@imgtec.com>
Thu, 23 Feb 2017 22:27:50 +0000 (22:27 +0000)
committerMaciej W. Rozycki <macro@imgtec.com>
Thu, 23 Feb 2017 23:49:14 +0000 (23:49 +0000)
Remove separate original NewABI JALR relocation handling, introduced
with commit d06471104a83 ("relax jalr $t9 [R_MIPS_JALR symbol] to bal
symbol"), <https://sourceware.org/ml/binutils/2003-03/msg00394.html>,
and only used by LD with the `--relax' option specified, and rely solely
on `mips_elf_perform_relocation' code, which has been introduced with
commit 1367d393bb74 ("On the RM9000 convert jal to bal if in range"),
<https://www.sourceware.org/ml/binutils/2004-12/msg00088.html> and since
made more complete, across all the three ABIs.

Also remove the `--relax' option, now irrelevant, from the tests added
with the former commit.

bfd/
* elfxx-mips.h (_bfd_mips_relax_section): Remove prototype.
* elfxx-mips.c (_bfd_mips_relax_section): Remove function.
* elf64-mips.c (bfd_elf64_bfd_relax_section): Remove macro.
* elfn32-mips.c (bfd_elf32_bfd_relax_section): Likewise.

ld/
* testsuite/ld-mips-elf/relax-jalr-n32.d: Remove `--relax'
option.
* testsuite/ld-mips-elf/relax-jalr-n32-shared.d: Likewise.
* testsuite/ld-mips-elf/relax-jalr-n64.d: Likewise.
* testsuite/ld-mips-elf/relax-jalr-n64-shared.d: Likewise.

bfd/ChangeLog
bfd/elf64-mips.c
bfd/elfn32-mips.c
bfd/elfxx-mips.c
bfd/elfxx-mips.h
ld/ChangeLog
ld/testsuite/ld-mips-elf/relax-jalr-n32-shared.d
ld/testsuite/ld-mips-elf/relax-jalr-n32.d
ld/testsuite/ld-mips-elf/relax-jalr-n64-shared.d
ld/testsuite/ld-mips-elf/relax-jalr-n64.d

index 46f5f9cfdc2b34ad831d7c29ba3628aa6e799c62..7435d5abdcf6a4414e64c54a4d4817009f105e1e 100644 (file)
@@ -1,3 +1,10 @@
+2017-02-23  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * elfxx-mips.h (_bfd_mips_relax_section): Remove prototype.
+       * elfxx-mips.c (_bfd_mips_relax_section): Remove function.
+       * elf64-mips.c (bfd_elf64_bfd_relax_section): Remove macro.
+       * elfn32-mips.c (bfd_elf32_bfd_relax_section): Likewise.
+
 2017-02-23  Maciej W. Rozycki  <macro@imgtec.com>
 
        * elfxx-mips.c (mips_elf_calculate_relocation) <R_MIPS_JALR>
index 5edbd4a5d3fea9cc27fc5713e18468648c72e54b..a66c31977e52051fcbc0a0bb3e0fe5acd7d85a2b 100644 (file)
@@ -4507,7 +4507,6 @@ const struct elf_size_info mips_elf64_size_info =
 #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_bfd_relax_section     _bfd_mips_relax_section
 #define bfd_elf64_mkobject             _bfd_mips_elf_mkobject
 
 /* The SGI style (n)64 NewABI.  */
index c09713ad532d851e57bec3608decaffbb8ed6509..dce7ba1c7a0e214f1e7437246778785a13c37b89 100644 (file)
@@ -3721,7 +3721,6 @@ static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = {
 #define bfd_elf32_bfd_set_private_flags        _bfd_mips_elf_set_private_flags
 #define bfd_elf32_bfd_print_private_bfd_data \
                                        _bfd_mips_elf_print_private_bfd_data
-#define bfd_elf32_bfd_relax_section     _bfd_mips_relax_section
 #define bfd_elf32_mkobject             _bfd_mips_elf_mkobject
 
 /* Support for SGI-ish mips targets using n32 ABI.  */
index ec086de76efbfa605ba428d80175aed3cd231a53..9693442fbf0e8c2c1f1bb58c4151e65811ea211d 100644 (file)
@@ -8889,167 +8889,6 @@ _bfd_mips_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
   return TRUE;
 }
 \f
-bfd_boolean
-_bfd_mips_relax_section (bfd *abfd, asection *sec,
-                        struct bfd_link_info *link_info,
-                        bfd_boolean *again)
-{
-  Elf_Internal_Rela *internal_relocs;
-  Elf_Internal_Rela *irel, *irelend;
-  Elf_Internal_Shdr *symtab_hdr;
-  bfd_byte *contents = NULL;
-  size_t extsymoff;
-  bfd_boolean changed_contents = FALSE;
-  bfd_vma sec_start = sec->output_section->vma + sec->output_offset;
-  Elf_Internal_Sym *isymbuf = NULL;
-
-  /* We are not currently changing any sizes, so only one pass.  */
-  *again = FALSE;
-
-  if (bfd_link_relocatable (link_info))
-    return TRUE;
-
-  internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL,
-                                              link_info->keep_memory);
-  if (internal_relocs == NULL)
-    return TRUE;
-
-  irelend = internal_relocs + sec->reloc_count
-    * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel;
-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-  extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
-
-  for (irel = internal_relocs; irel < irelend; irel++)
-    {
-      bfd_vma symval;
-      bfd_signed_vma sym_offset;
-      unsigned int r_type;
-      unsigned long r_symndx;
-      asection *sym_sec;
-      unsigned long instruction;
-
-      /* Turn jalr into bgezal, and jr into beq, if they're marked
-        with a JALR relocation, that indicate where they jump to.
-        This saves some pipeline bubbles.  */
-      r_type = ELF_R_TYPE (abfd, irel->r_info);
-      if (r_type != R_MIPS_JALR)
-       continue;
-
-      r_symndx = ELF_R_SYM (abfd, irel->r_info);
-      /* Compute the address of the jump target.  */
-      if (r_symndx >= extsymoff)
-       {
-         struct mips_elf_link_hash_entry *h
-           = ((struct mips_elf_link_hash_entry *)
-              elf_sym_hashes (abfd) [r_symndx - extsymoff]);
-
-         while (h->root.root.type == bfd_link_hash_indirect
-                || h->root.root.type == bfd_link_hash_warning)
-           h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link;
-
-         /* If a symbol is undefined, or if it may be overridden,
-            skip it.  */
-         if (! ((h->root.root.type == bfd_link_hash_defined
-                 || h->root.root.type == bfd_link_hash_defweak)
-                && h->root.root.u.def.section)
-             || (bfd_link_pic (link_info) && ! link_info->symbolic
-                 && !h->root.forced_local))
-           continue;
-
-         sym_sec = h->root.root.u.def.section;
-         if (sym_sec->output_section)
-           symval = (h->root.root.u.def.value
-                     + sym_sec->output_section->vma
-                     + sym_sec->output_offset);
-         else
-           symval = h->root.root.u.def.value;
-       }
-      else
-       {
-         Elf_Internal_Sym *isym;
-
-         /* Read this BFD's symbols if we haven't done so already.  */
-         if (isymbuf == NULL && symtab_hdr->sh_info != 0)
-           {
-             isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
-             if (isymbuf == NULL)
-               isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-                                               symtab_hdr->sh_info, 0,
-                                               NULL, NULL, NULL);
-             if (isymbuf == NULL)
-               goto relax_return;
-           }
-
-         isym = isymbuf + r_symndx;
-         if (isym->st_shndx == SHN_UNDEF)
-           continue;
-         else if (isym->st_shndx == SHN_ABS)
-           sym_sec = bfd_abs_section_ptr;
-         else if (isym->st_shndx == SHN_COMMON)
-           sym_sec = bfd_com_section_ptr;
-         else
-           sym_sec
-             = bfd_section_from_elf_index (abfd, isym->st_shndx);
-         symval = isym->st_value
-           + sym_sec->output_section->vma
-           + sym_sec->output_offset;
-       }
-
-      /* Compute branch offset, from delay slot of the jump to the
-        branch target.  */
-      sym_offset = (symval + irel->r_addend)
-       - (sec_start + irel->r_offset + 4);
-
-      /* Branch offset must be properly aligned.  */
-      if ((sym_offset & 3) != 0)
-       continue;
-
-      sym_offset >>= 2;
-
-      /* Check that it's in range.  */
-      if (sym_offset < -0x8000 || sym_offset >= 0x8000)
-       continue;
-
-      /* Get the section contents if we haven't done so already.  */
-      if (!mips_elf_get_section_contents (abfd, sec, &contents))
-       goto relax_return;
-
-      instruction = bfd_get_32 (abfd, contents + irel->r_offset);
-
-      /* If it was jalr <reg>, turn it into bgezal $zero, <target>.  */
-      if ((instruction & 0xfc1fffff) == 0x0000f809)
-       instruction = 0x04110000;
-      /* If it was jr <reg>, turn it into b <target>.  */
-      else if ((instruction & 0xfc1fffff) == 0x00000008)
-       instruction = 0x10000000;
-      else
-       continue;
-
-      instruction |= (sym_offset & 0xffff);
-      bfd_put_32 (abfd, instruction, contents + irel->r_offset);
-      changed_contents = TRUE;
-    }
-
-  if (contents != NULL
-      && elf_section_data (sec)->this_hdr.contents != contents)
-    {
-      if (!changed_contents && !link_info->keep_memory)
-        free (contents);
-      else
-        {
-          /* Cache the section contents for elf_link_input_bfd.  */
-          elf_section_data (sec)->this_hdr.contents = contents;
-        }
-    }
-  return TRUE;
-
- relax_return:
-  if (contents != NULL
-      && elf_section_data (sec)->this_hdr.contents != contents)
-    free (contents);
-  return FALSE;
-}
-\f
 /* Allocate space for global sym dynamic relocs.  */
 
 static bfd_boolean
index fa5b5d2de93a27a77d1031e0b818b3b80a49c5f7..32d8e91707cf65f84dd20acc9cad1e4c86089fe4 100644 (file)
@@ -139,8 +139,6 @@ extern bfd_reloc_status_type _bfd_mips_elf_generic_reloc
   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 extern unsigned long _bfd_elf_mips_mach
   (flagword);
-extern bfd_boolean _bfd_mips_relax_section
-  (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
 extern bfd_vma _bfd_mips_elf_sign_extend
   (bfd_vma, int);
 extern void _bfd_mips_elf_merge_symbol_attribute
index 3e88456a17966b5d72294cb3f3c9e0e2effa6e5e..420a9ab5b1d1d31b19f44dfc52eb3e1269651493 100644 (file)
@@ -1,3 +1,11 @@
+2017-02-23  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * testsuite/ld-mips-elf/relax-jalr-n32.d: Remove `--relax'
+       option.
+       * testsuite/ld-mips-elf/relax-jalr-n32-shared.d: Likewise.
+       * testsuite/ld-mips-elf/relax-jalr-n64.d: Likewise.
+       * testsuite/ld-mips-elf/relax-jalr-n64-shared.d: Likewise.
+
 2017-02-23  Maciej W. Rozycki  <macro@imgtec.com>
 
        * testsuite/ld-mips-elf/jalr4.dd: New test.
index 3b564412d5cd06088f396e2bfc1978df602d870c..2eb81522319233fe780b3dde71cd1869f58b5117 100644 (file)
@@ -2,7 +2,7 @@
 #source: relax-jalr.s
 #as: -march=from-abi -KPIC -n32 -EB
 #objdump: --prefix-addresses -d --show-raw-insn
-#ld: --relax -shared -melf32btsmipn32
+#ld: -shared -melf32btsmipn32
 
 .*:     file format elf.*mips.*
 
index 3a4b0b6bb9d859ffa63260504dbef06256c47b62..b0ea9c0cf318a145f1ca2bafcd74ed7ed989d3b6 100644 (file)
@@ -2,7 +2,7 @@
 #source: relax-jalr.s
 #as: -march=from-abi -KPIC -n32 -EB
 #objdump: --prefix-addresses -d --show-raw-insn
-#ld: --relax -melf32btsmipn32
+#ld: -melf32btsmipn32
 
 .*:     file format elf.*mips.*
 
index c0138ea06f9f2582cdf9d350024fac528f6e7460..fcb0b126e316557b1e37a53f7c6c27f361064d0a 100644 (file)
@@ -2,7 +2,7 @@
 #source: relax-jalr.s
 #as: -march=from-abi -KPIC -64 -EB
 #objdump: --prefix-addresses -d --show-raw-insn
-#ld: --relax -shared -melf64btsmip
+#ld: -shared -melf64btsmip
 
 .*:     file format elf.*mips.*
 
index 6b4f3f5992bb41a21f0d6fa1d375a670d1675c21..e3518ba0121bab24cacaeb3647d70b190ad127b1 100644 (file)
@@ -2,7 +2,7 @@
 #source: relax-jalr.s
 #as: -march=from-abi -KPIC -64 -EB
 #objdump: --prefix-addresses -d --show-raw-insn
-#ld: --relax -melf64btsmip
+#ld: -melf64btsmip
 
 .*:     file format elf.*mips.*