[binutils-gdb] RISC-V: Fix weak function call reloc overflow on llvm build.

Jim Wilson wilson@sourceware.org
Mon Jan 6 23:37:00 GMT 2020


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

commit 85f783647061e58968ecdc516137d8df9f2d5e16
Author: Jim Wilson <jimw@sifive.com>
Date:   Mon Jan 6 15:34:50 2020 -0800

    RISC-V: Fix weak function call reloc overflow on llvm build.
    
    	bfd/
    	PR 25205
    	* elfnn-riscv.c (riscv_elf_relocate_section) <R_RISCV_CALL>: Add
    	check for !bfd_link_pic (info).
    	<R_RISCV_CALL_PLT>: Move next to R_RISCV_CALL.
    	<R_RISCV_JAL>: Add comment.
    	(_bfd_riscv_relax_section): For plt.offset check, add check for
    	bfd_link_pic (info).  Add comment.
    
    Change-Id: Ie769bc3d5adf096a51df5cc12efe3d50e80acb8f

Diff:
---
 bfd/ChangeLog     | 10 ++++++++++
 bfd/elfnn-riscv.c |  9 ++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 97c9309..da9260b 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,13 @@
+2020-01-06  Jim Wilson  <jimw@sifive.com>
+
+	PR 25205
+	* elfnn-riscv.c (riscv_elf_relocate_section) <R_RISCV_CALL>: Add
+	check for !bfd_link_pic (info).
+	<R_RISCV_CALL_PLT>: Move next to R_RISCV_CALL.
+	<R_RISCV_JAL>: Add comment.
+	(_bfd_riscv_relax_section): For plt.offset check, add check for
+	bfd_link_pic (info).  Add comment.
+
 2020-01-06  Alan Modra  <amodra@gmail.com>
 
 	* format.c (bfd_check_format_matches): Ignore bfd_error on target
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index d30fc8b..46f0100 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -1987,10 +1987,11 @@ riscv_elf_relocate_section (bfd *output_bfd,
 	  break;
 
 	case R_RISCV_CALL:
+	case R_RISCV_CALL_PLT:
 	  /* Handle a call to an undefined weak function.  This won't be
 	     relaxed, so we have to handle it here.  */
 	  if (h != NULL && h->root.type == bfd_link_hash_undefweak
-	      && h->plt.offset == MINUS_ONE)
+	      && (!bfd_link_pic (info) || h->plt.offset == MINUS_ONE))
 	    {
 	      /* We can use x0 as the base register.  */
 	      bfd_vma insn = bfd_get_32 (input_bfd,
@@ -2003,9 +2004,9 @@ riscv_elf_relocate_section (bfd *output_bfd,
 	    }
 	  /* Fall through.  */
 
-	case R_RISCV_CALL_PLT:
 	case R_RISCV_JAL:
 	case R_RISCV_RVC_JUMP:
+	  /* This line has to match the check in _bfd_riscv_relax_section.  */
 	  if (bfd_link_pic (info) && h != NULL && h->plt.offset != MINUS_ONE)
 	    {
 	      /* Refer to the PLT entry.  */
@@ -4128,7 +4129,9 @@ _bfd_riscv_relax_section (bfd *abfd, asection *sec,
 	      undefined_weak = TRUE;
 	    }
 
-	  if (h->plt.offset != MINUS_ONE)
+	  /* This line has to match the check in riscv_elf_relocate_section
+	     in the R_RISCV_CALL[_PLT] case.  */
+	  if (bfd_link_pic (info) && h->plt.offset != MINUS_ONE)
 	    {
 	      sym_sec = htab->elf.splt;
 	      symval = h->plt.offset;



More information about the Binutils-cvs mailing list