RISC-V: Fix 3 PIE related ld testsuite failures.

Message ID 20180621184647.23991-1-jimw@sifive.com
State New
Headers show
Series
  • RISC-V: Fix 3 PIE related ld testsuite failures.
Related show

Commit Message

Jim Wilson June 21, 2018, 6:46 p.m.
This fixes these native riscv64-linux failures:
FAIL: PIE PR ld/14525
FAIL: Build pr23162a
FAIL: Build pr23162b

The patch uses SYMBOL_REFERENCES_LOCAL same as is already used in other ports,
and adds some asserts to verify that the code here is consistent with the code
in riscv_elf_relocate_section which sets the low bit of got.offset to indicate
whether this is a local symbol reference or not.

Tested native on riscv64-linux, and cross for riscv{32,64}-{elf,linux} with
binutils and gcc builds and checks, and a linux+buildroot build and boot.

Committed.

Jim

	bfd/
	* elfnn-riscv.c (riscv_elf_finish_dynamic_symbol): Update comment.
	Use SYMBOL_REFERENCES_LOCAL.  Add asserts for h->got.offset.
---
 bfd/elfnn-riscv.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

-- 
2.17.1

Patch

diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 7b1ca47083..934704a87e 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -2394,15 +2394,15 @@  riscv_elf_finish_dynamic_symbol (bfd *output_bfd,
 
       rela.r_offset = sec_addr (sgot) + (h->got.offset &~ (bfd_vma) 1);
 
-      /* If this is a -Bsymbolic link, and the symbol is defined
-	 locally, we just want to emit a RELATIVE reloc.  Likewise if
+      /* If this is a local symbol reference, we just want to emit a RELATIVE
+	 reloc.  This can happen if it is a -Bsymbolic link, or a pie link, or
 	 the symbol was forced to be local because of a version file.
 	 The entry in the global offset table will already have been
 	 initialized in the relocate_section function.  */
       if (bfd_link_pic (info)
-	  && (info->symbolic || h->dynindx == -1)
-	  && h->def_regular)
+	  && SYMBOL_REFERENCES_LOCAL (info, h))
 	{
+	  BFD_ASSERT((h->got.offset & 1) != 0);
 	  asection *sec = h->root.u.def.section;
 	  rela.r_info = ELFNN_R_INFO (0, R_RISCV_RELATIVE);
 	  rela.r_addend = (h->root.u.def.value
@@ -2411,6 +2411,7 @@  riscv_elf_finish_dynamic_symbol (bfd *output_bfd,
 	}
       else
 	{
+	  BFD_ASSERT((h->got.offset & 1) == 0);
 	  BFD_ASSERT (h->dynindx != -1);
 	  rela.r_info = ELFNN_R_INFO (h->dynindx, R_RISCV_NN);
 	  rela.r_addend = 0;