[PATCH v2 4/8] RISC-V: Use NEED_IFUNC_SECTIONS to check if we need IFUNC sections or not.

Nelson Chu nelson.chu@sifive.com
Fri Aug 7 03:57:09 GMT 2020


	bfd/
	* elfnn-riscv.c (NEED_IFUNC_SECTIONS): New defined.
	(riscv_elf_check_relocs): Use NEED_IFUNC_SECTIONS to check if we
	need to create IFUNC sections or not.
---
 bfd/elfnn-riscv.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index c37351c..38ade9c 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -582,6 +582,17 @@ bad_static_reloc (bfd *abfd, unsigned r_type, struct elf_link_hash_entry *h)
   bfd_set_error (bfd_error_bad_value);
   return FALSE;
 }
+
+/* Create the IFUNC sections, iplt and ipltgot, for static executables.  */
+#define NEED_IFUNC_SECTIONS(RELOC) \
+  (RELOC == R_RISCV_32 \
+   || RELOC == R_RISCV_64 \
+   || RELOC == R_RISCV_CALL \
+   || RELOC == R_RISCV_CALL_PLT \
+   || RELOC == R_RISCV_HI20 \
+   || RELOC == R_RISCV_PCREL_HI20 \
+   || RELOC == R_RISCV_GOT_HI20)
+
 /* Look through the relocs for a section during the first phase, and
    allocate space in the global offset table or procedure linkage
    table.  */
@@ -659,25 +670,10 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
       if (h != NULL)
 	{
-	  switch (r_type)
-	    {
-	    case R_RISCV_32:
-	    case R_RISCV_64:
-	    case R_RISCV_CALL:
-	    case R_RISCV_CALL_PLT:
-	    case R_RISCV_HI20:
-	    case R_RISCV_GOT_HI20:
-	    case R_RISCV_PCREL_HI20:
-	      /* Create the IFUNC sections, iplt and ipltgot, for static
-		 executables.  */
-	      if (h->type == STT_GNU_IFUNC
-		  && !_bfd_elf_create_ifunc_sections (htab->elf.dynobj, info))
-		return FALSE;
-	      break;
-
-	    default:
-	      break;
-	    }
+	  if (h->type == STT_GNU_IFUNC
+	      && NEED_IFUNC_SECTIONS (r_type)
+	      && !_bfd_elf_create_ifunc_sections (htab->elf.dynobj, info))
+	    return FALSE;
 
 	  /* It is referenced by a non-shared object.  */
 	  h->ref_regular = 1;
-- 
2.7.4



More information about the Binutils mailing list