RISC-V: Pc-rel to gp-rel relaxation function cleanup.

Message ID 20180928001723.4472-1-jimw@sifive.com
State New
Headers show
Series
  • RISC-V: Pc-rel to gp-rel relaxation function cleanup.
Related show

Commit Message

Jim Wilson Sept. 28, 2018, 12:17 a.m.
This is a general cleanup of some of the pc-relative to gp-relative relaxation
code.  The patch adds comments to a number of functions missing them.  It
deletes 3 functions that do nothing useful.  riscv_delete_pcgp_hi_reloc doesn't
delete anything, and since it comes immediately after a call to
riscv_record_pcgp_hi_reloc it will always return TRUE.  riscv_use_pcgp_hi_reloc
comes immediately after a call to riscv_find_pcgp_hi_reloc so it will also
always return TRUE.  And riscv_delete_pcgp_lo_reloc obviously does nothing
useful since it is just a return.

This was tested with cross riscv32-elf and riscv64-linux toolchain builds and
gcc make checks configured with -mcmodel=medany -mexplicit-relocs to trigger
this code.  There were no regressions.  It was also tested with cross binutils
riscv{32,64}-{elf,linux} builds and make checks, with no regressions.

Committed.

Jim

	bfd/
	* elfnn-riscv.c (riscv_init_pcgp_relocs): Add explanatory comment.
	(riscv_free_pcgp_relocs, riscv_record_pcgp_reloc): Likewise.
	(riscv_find_pcgp_hi_reloc, riscv_reocrd_pcgp_lo_reloc): Likewise.
	(riscv_find_pcgp_lo_reloc): Likewise.
	(riscv_delete_pcgp_hi_reloc, riscv_use_pcgp_hi_reloc): Delete.
	(riscv_delete_pcgp_lo_reloc): Likewise.
	(_bfd_riscv_relax_pc): Don't call riscv_use_pcgp_hi_reloc. Replace
	calls to riscv_delete_pcgp_lo_reloc and riscv_delete_pcgp_hi_reloc
	with TRUE.  Mark abfd arg as ATTRIBUTE_UNUSED.
---
 bfd/elfnn-riscv.c | 62 +++++++++++++++--------------------------------
 1 file changed, 20 insertions(+), 42 deletions(-)

-- 
2.17.1

Patch

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index c99bcff5f1..88f491f914 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -2830,6 +2830,8 @@  typedef struct
   riscv_pcgp_lo_reloc *lo;
 } riscv_pcgp_relocs;
 
+/* Initialize the pcgp reloc info in P.  */
+
 static bfd_boolean
 riscv_init_pcgp_relocs (riscv_pcgp_relocs *p)
 {
@@ -2838,6 +2840,8 @@  riscv_init_pcgp_relocs (riscv_pcgp_relocs *p)
   return TRUE;
 }
 
+/* Free the pcgp reloc info in P.  */
+
 static void
 riscv_free_pcgp_relocs (riscv_pcgp_relocs *p,
 			bfd *abfd ATTRIBUTE_UNUSED,
@@ -2861,6 +2865,10 @@  riscv_free_pcgp_relocs (riscv_pcgp_relocs *p,
     }
 }
 
+/* Record pcgp hi part reloc info in P, using HI_SEC_OFF as the lookup index.
+   The HI_ADDEND, HI_ADDR, HI_SYM, and SYM_SEC args contain info required to
+   relax the corresponding lo part reloc.  */
+
 static bfd_boolean
 riscv_record_pcgp_hi_reloc (riscv_pcgp_relocs *p, bfd_vma hi_sec_off,
 			    bfd_vma hi_addend, bfd_vma hi_addr,
@@ -2879,6 +2887,9 @@  riscv_record_pcgp_hi_reloc (riscv_pcgp_relocs *p, bfd_vma hi_sec_off,
   return TRUE;
 }
 
+/* Look up hi part pcgp reloc info in P, using HI_SEC_OFF as the lookup index.
+   This is used by a lo part reloc to find the corresponding hi part reloc.  */
+
 static riscv_pcgp_hi_reloc *
 riscv_find_pcgp_hi_reloc(riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
 {
@@ -2890,31 +2901,8 @@  riscv_find_pcgp_hi_reloc(riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
   return NULL;
 }
 
-static bfd_boolean
-riscv_delete_pcgp_hi_reloc(riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
-{
-  bfd_boolean out = FALSE;
-  riscv_pcgp_hi_reloc *c;
-
-  for (c = p->hi; c != NULL; c = c->next)
-      if (c->hi_sec_off == hi_sec_off)
-	out = TRUE;
-
-  return out;
-}
-
-static bfd_boolean
-riscv_use_pcgp_hi_reloc(riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
-{
-  bfd_boolean out = FALSE;
-  riscv_pcgp_hi_reloc *c;
-
-  for (c = p->hi; c != NULL; c = c->next)
-    if (c->hi_sec_off == hi_sec_off)
-      out = TRUE;
-
-  return out;
-}
+/* Record pcgp lo part reloc info in P, using HI_SEC_OFF as the lookup info.
+   This is used to record relocs that can't be relaxed.  */
 
 static bfd_boolean
 riscv_record_pcgp_lo_reloc (riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
@@ -2928,6 +2916,9 @@  riscv_record_pcgp_lo_reloc (riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
   return TRUE;
 }
 
+/* Look up lo part pcgp reloc info in P, using HI_SEC_OFF as the lookup index.
+   This is used by a hi part reloc to find the corresponding lo part reloc.  */
+
 static bfd_boolean
 riscv_find_pcgp_lo_reloc (riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
 {
@@ -2939,14 +2930,6 @@  riscv_find_pcgp_lo_reloc (riscv_pcgp_relocs *p, bfd_vma hi_sec_off)
   return FALSE;
 }
 
-static bfd_boolean
-riscv_delete_pcgp_lo_reloc (riscv_pcgp_relocs *p ATTRIBUTE_UNUSED,
-			    bfd_vma lo_sec_off ATTRIBUTE_UNUSED,
-			    size_t bytes ATTRIBUTE_UNUSED)
-{
-  return TRUE;
-}
-
 typedef bfd_boolean (*relax_func_t) (bfd *, asection *, asection *,
 				     struct bfd_link_info *,
 				     Elf_Internal_Rela *,
@@ -3230,7 +3213,7 @@  _bfd_riscv_relax_align (bfd *abfd, asection *sec,
 /* Relax PC-relative references to GP-relative references.  */
 
 static bfd_boolean
-_bfd_riscv_relax_pc  (bfd *abfd,
+_bfd_riscv_relax_pc  (bfd *abfd ATTRIBUTE_UNUSED,
 		      asection *sec,
 		      asection *sym_sec,
 		      struct bfd_link_info *link_info,
@@ -3270,11 +3253,6 @@  _bfd_riscv_relax_pc  (bfd *abfd,
 	hi_reloc = *hi;
 	symval = hi_reloc.hi_addr;
 	sym_sec = hi_reloc.sym_sec;
-	if (!riscv_use_pcgp_hi_reloc(pcgp_relocs, hi->hi_sec_off))
-	  _bfd_error_handler
-	    (_("%pB(%pA+%#" PRIx64 "): Unable to clear RISCV_PCREL_HI20 reloc "
-	       "for corresponding RISCV_PCREL_LO12 reloc"),
-	     abfd, sec, (uint64_t) rel->r_offset);
       }
       break;
 
@@ -3318,12 +3296,12 @@  _bfd_riscv_relax_pc  (bfd *abfd,
 	case R_RISCV_PCREL_LO12_I:
 	  rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_I);
 	  rel->r_addend += hi_reloc.hi_addend;
-	  return riscv_delete_pcgp_lo_reloc (pcgp_relocs, rel->r_offset, 4);
+	  return TRUE;
 
 	case R_RISCV_PCREL_LO12_S:
 	  rel->r_info = ELFNN_R_INFO (sym, R_RISCV_GPREL_S);
 	  rel->r_addend += hi_reloc.hi_addend;
-	  return riscv_delete_pcgp_lo_reloc (pcgp_relocs, rel->r_offset, 4);
+	  return TRUE;
 
 	case R_RISCV_PCREL_HI20:
 	  riscv_record_pcgp_hi_reloc (pcgp_relocs,
@@ -3335,7 +3313,7 @@  _bfd_riscv_relax_pc  (bfd *abfd,
 	  /* We can delete the unnecessary AUIPC and reloc.  */
 	  rel->r_info = ELFNN_R_INFO (0, R_RISCV_DELETE);
 	  rel->r_addend = 4;
-	  return riscv_delete_pcgp_hi_reloc (pcgp_relocs, rel->r_offset);
+	  return TRUE;
 
 	default:
 	  abort ();