[binutils-gdb] Re: elf_backend_finish_dynamic_symbol returning false

Alan Modra amodra@sourceware.org
Thu Feb 15 08:45:20 GMT 2024


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

commit 313f04b6edcd09e0e7ff224bd54a892ab8f029aa
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Feb 15 19:03:07 2024 +1030

    Re: elf_backend_finish_dynamic_symbol returning false
    
    I didn't examine ld testsuite logs properly after cf95b909e2c2.
    Replacing one of the "return false" with BFD_ASSERT in
    finish_dynamic_symbol was wrong as it causes segmentation faults on
    testcases expected to fail.  Revert those changes and instead make
    a bfd_final_link failure noisy.

Diff:
---
 bfd/elf32-s390.c    | 3 ++-
 bfd/elf64-s390.c    | 3 ++-
 bfd/elf64-x86-64.c  | 3 ++-
 bfd/elfnn-aarch64.c | 3 ++-
 bfd/elfnn-kvx.c     | 3 ++-
 ld/ldwrite.c        | 6 +-----
 6 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c
index 06d54e6fa2d..1a2ade0414e 100644
--- a/bfd/elf32-s390.c
+++ b/bfd/elf32-s390.c
@@ -3505,7 +3505,8 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
 	     RELATIVE reloc.  The entry in the global offset table
 	     will already have been initialized in the
 	     relocate_section function.  */
-	  BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
+	  if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
+	    return false;
 	  BFD_ASSERT((h->got.offset & 1) != 0);
 	  rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE);
 	  rela.r_addend = (h->root.u.def.value
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index bef90f6ed84..ab9ec3f5b48 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -3371,7 +3371,8 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
 	     RELATIVE reloc.  The entry in the global offset table
 	     will already have been initialized in the
 	     relocate_section function.  */
-	  BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
+	  if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
+	    return false;
 	  BFD_ASSERT((h->got.offset & 1) != 0);
 	  rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
 	  rela.r_addend = (h->root.u.def.value
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 6cc70a7d4c3..3300a2017bd 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -4921,7 +4921,8 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
       else if (bfd_link_pic (info)
 	       && SYMBOL_REFERENCES_LOCAL_P (info, h))
 	{
-	  BFD_ASSERT (SYMBOL_DEFINED_NON_SHARED_P (h));
+	  if (!SYMBOL_DEFINED_NON_SHARED_P (h))
+	    return false;
 	  BFD_ASSERT((h->got.offset & 1) != 0);
 	  if (info->enable_dt_relr)
 	    generate_dynamic_reloc = false;
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index cf21f62d73a..560983aaed6 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -9739,7 +9739,8 @@ elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
 	}
       else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
 	{
-	  BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
+	  if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
+	    return false;
 	  BFD_ASSERT ((h->got.offset & 1) != 0);
 	  rela.r_info = ELFNN_R_INFO (0, AARCH64_R (RELATIVE));
 	  rela.r_addend = (h->root.u.def.value
diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
index 00446c9a8d8..ae5ed6bf3f7 100644
--- a/bfd/elfnn-kvx.c
+++ b/bfd/elfnn-kvx.c
@@ -4479,7 +4479,8 @@ elfNN_kvx_finish_dynamic_symbol (bfd *output_bfd,
 
       if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
 	{
-	  BFD_ASSERT (h->def_regular);
+	  if (!h->def_regular)
+	    return false;
 
 	  /* in case of PLT related GOT entry, it is not clear who is
 	     supposed to set the LSB of GOT entry...
diff --git a/ld/ldwrite.c b/ld/ldwrite.c
index 46fb33c825e..8ce4297853b 100644
--- a/ld/ldwrite.c
+++ b/ld/ldwrite.c
@@ -549,13 +549,9 @@ ldwrite (void)
     split_sections (link_info.output_bfd, &link_info);
   if (!bfd_final_link (link_info.output_bfd, &link_info))
     {
-      /* If there was an error recorded, print it out.  Otherwise assume
-	 an appropriate error message like unknown symbol was printed
-	 out.  */
-
       if (bfd_get_error () != bfd_error_no_error)
 	einfo (_("%F%P: final link failed: %E\n"));
       else
-	xexit (1);
+	einfo (_("%F%P: final link failed\n"));
     }
 }


More information about the Binutils-cvs mailing list