]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
elf_backend_finish_dynamic_symbol returning false
authorAlan Modra <amodra@gmail.com>
Wed, 14 Feb 2024 04:04:47 +0000 (14:34 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 15 Feb 2024 00:54:13 +0000 (11:24 +1030)
Returning false from elf_backend_finish_dynamic_symbol will not result
in an error being printed unless bfd_error is set but will result in
the linker exiting with a non-zero status.  If just bfd_error is set
then a generic "final link failed" will result, which doesn't help a
user much.  So elf_backend_finish_dynamic_symbol should print its own
error message whenever returning false, or use BFD_ASSERT or abort to
print assertion failures for conditions that shouldn't occur.

This patch does that, and removes unnecessary "htab != NULL" tests in
elf_backend_finish_dynamic_symbol.  Such tests aren't needed in a
function only called via elf_backend_data.

24 files changed:
bfd/elf32-arc.c
bfd/elf32-arm.c
bfd/elf32-cris.c
bfd/elf32-csky.c
bfd/elf32-hppa.c
bfd/elf32-i386.c
bfd/elf32-lm32.c
bfd/elf32-m32r.c
bfd/elf32-microblaze.c
bfd/elf32-or1k.c
bfd/elf32-s390.c
bfd/elf32-score.c
bfd/elf32-score7.c
bfd/elf32-sh.c
bfd/elf64-hppa.c
bfd/elf64-ia64-vms.c
bfd/elf64-ppc.c
bfd/elf64-s390.c
bfd/elf64-x86-64.c
bfd/elfnn-aarch64.c
bfd/elfnn-ia64.c
bfd/elfnn-kvx.c
bfd/elfnn-riscv.c
bfd/elfxx-mips.c

index 1061e54e9d73aa4167e85c62e7df0bc89675d850..5727bfbf889bea1cceb208103d6232efe338ca3e 100644 (file)
@@ -2486,9 +2486,6 @@ elf_arc_finish_dynamic_symbol (bfd * output_bfd,
     {
       struct elf_arc_link_hash_table *arc_htab = elf_arc_hash_table (info);
 
-      if (arc_htab == NULL)
-       return false;
-
       if (h->dynindx == -1
          || (h->root.type != bfd_link_hash_defined
              && h->root.type != bfd_link_hash_defweak)
index 4ad7c3542a7f9e6e2a221a9f62bb71f57980cd97..1913be50cfe5743374be16992e7b8a2b69f99f6d 100644 (file)
@@ -17199,8 +17199,6 @@ elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
   struct elf32_arm_link_hash_entry *eh;
 
   htab = elf32_arm_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   eh = (struct elf32_arm_link_hash_entry *) h;
 
index 188f1e1e8e8c2bcdcd75b8b9c34db1e2e6110dc6..e2e402a593e21bd78936a9142ec1907931f27012 100644 (file)
@@ -2082,8 +2082,6 @@ elf_cris_finish_dynamic_symbol (bfd *output_bfd,
   const bfd_byte *plt_pic_entry = elf_cris_pic_plt_entry;
 
   htab = elf_cris_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   /* Adjust the various PLT entry offsets.  */
   if (bfd_get_mach (output_bfd) == bfd_mach_cris_v32)
index 9479705d37e4ecdb4325f55d3d1b912138c2ed52..87c37259fa126bb08b3c58136d4dff3cefce94fa 100644 (file)
@@ -2105,8 +2105,6 @@ csky_elf_finish_dynamic_symbol (bfd *output_bfd,
   struct csky_elf_link_hash_table *htab;
 
   htab = csky_elf_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   /* Sanity check to make sure no unexpected symbol reaches here.
      This matches the test in csky_elf_relocate_section handling
index 28aadfb8f9cfe8323eafd13f0bfe9ea22f639a3d..bb4bfdc00b82dfd842b6af2a4136a67dd159b231 100644 (file)
@@ -4139,8 +4139,6 @@ elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
   bfd_byte *loc;
 
   htab = hppa_link_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   if (eh->plt.offset != (bfd_vma) -1)
     {
index e2f88a114879c629e4d02bf0baa94b408475eb39..703a48c2c0ab2b380fb110456e5b9419b26ba358 100644 (file)
@@ -3581,8 +3581,6 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
   bool use_plt_second;
 
   htab = elf_x86_hash_table (info, I386_ELF_DATA);
-  if (htab == NULL)
-    return false;
 
   plt_entry_size = htab->plt.plt_entry_size;
 
index 80223e6941d14f73bcd48936440dd98612b6b4f4..b0eaa06180f8e2eb6715740fd4453b5600ff8858 100644 (file)
@@ -1427,8 +1427,6 @@ lm32_elf_finish_dynamic_symbol (bfd *output_bfd,
   bfd_byte *loc;
 
   htab = lm32_elf_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
index 41468a64c48f6e626c0064153334a55b151b90b2..ab2f45a8946bb4d5982c7a7eb0411e1fdafa9fd3 100644 (file)
@@ -2877,8 +2877,6 @@ m32r_elf_finish_dynamic_symbol (bfd *output_bfd,
 #endif
 
   htab = m32r_elf_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
index 64198b8f1a639e59df32faa6cce50ec97f28a68c..fd2855d4f9f81ca5d3317fe3154bf07ffa52b845 100644 (file)
@@ -3168,8 +3168,6 @@ microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
   struct elf32_mb_link_hash_entry *eh = elf32_mb_hash_entry(h);
 
   htab = elf32_mb_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
index 81d63d45c29df2dc672fb0ccf97d8edbf80a984f..358d2e3940fdd4b7a35ad1772c74485895227adc 100644 (file)
@@ -2451,8 +2451,6 @@ or1k_elf_finish_dynamic_symbol (bfd *output_bfd,
   bfd_byte *loc;
 
   htab = or1k_elf_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
index 1a2ade0414e0065b8f65cbac7bd45105510411ed..06d54e6fa2d5c40307e74d694d6496c67da6c4d5 100644 (file)
@@ -3505,8 +3505,7 @@ 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.  */
-         if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
-           return false;
+         BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
          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
index 448aba87c8642c71d8669e445a1d52af9d1b5047..0c4a29f336c96dc24d9f4d96a1d61b7945c0b6d4 100644 (file)
@@ -3485,7 +3485,13 @@ s3_bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
 
       /* FIXME: Can h->dynindex be more than 64K?  */
       if (h->dynindx & 0xffff0000)
-       return false;
+       {
+         _bfd_error_handler
+           (_("%pB: cannot handle more than %d dynamic symbols"),
+            output_bfd, 0xffff);
+         bfd_set_error (bfd_error_bad_value);
+         return false;
+       }
 
       /* Fill the stub.  */
       score_bfd_put_32 (output_bfd, STUB_LW, stub);
index c20fa7a3ecaea485f4c3101332bd7e685cffd8df..d1155bfdb1365641fb4837fe44dceacf78c03941 100644 (file)
@@ -3296,7 +3296,13 @@ s7_bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
 
       /* FIXME: Can h->dynindex be more than 64K?  */
       if (h->dynindx & 0xffff0000)
-       return false;
+       {
+         _bfd_error_handler
+           (_("%pB: cannot handle more than %d dynamic symbols"),
+            output_bfd, 0xffff);
+         bfd_set_error (bfd_error_bad_value);
+         return false;
+       }
 
       /* Fill the stub.  */
       bfd_put_32 (output_bfd, STUB_LW, stub);
index 0f5117b6beb194426adc4af48a877957efd6cd19..bf4cb2a82429ccddd8ac31d5ff74a18d8e89f392 100644 (file)
@@ -5945,8 +5945,6 @@ sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
   struct elf_sh_link_hash_table *htab;
 
   htab = sh_elf_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
index 59e798305481b6f30562b06e53c31b4b0780612f..bc91bc4c08ac0472e13f78094530e5cc67aa899e 100644 (file)
@@ -1898,8 +1898,6 @@ elf64_hppa_finish_dynamic_symbol (bfd *output_bfd,
   struct elf64_hppa_link_hash_table *hppa_info;
 
   hppa_info = hppa_link_hash_table (info);
-  if (hppa_info == NULL)
-    return false;
 
   stub = hppa_info->stub_sec;
   splt = hppa_info->root.splt;
index 2f37e90cc15e9cf0538c15fe5c450bcb5b36c863..aa058a1793eee8ce6610658a529310810b7437a7 100644 (file)
@@ -4003,8 +4003,6 @@ elf64_ia64_finish_dynamic_symbol (bfd *output_bfd,
   struct elf64_ia64_dyn_sym_info *dyn_i;
 
   ia64_info = elf64_ia64_hash_table (info);
-  if (ia64_info == NULL)
-    return false;
 
   dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
 
index e95f9fbe6519f1d21caf6800523b5e64a66817a8..508419bfedc55a283194bebec90af8f31e5fbbd2 100644 (file)
@@ -18135,8 +18135,6 @@ ppc64_elf_finish_dynamic_symbol (bfd *output_bfd,
   struct plt_entry *ent;
 
   htab = ppc_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   if (!htab->opd_abi && !h->def_regular)
     for (ent = h->plt.plist; ent != NULL; ent = ent->next)
index a7979604a6fe90d25d60b05d2e33d5d24982fa18..bef90f6ed847911d78269fa206fe007186c6b528 100644 (file)
@@ -3225,8 +3225,6 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
   struct elf_s390_link_hash_entry *eh = (struct elf_s390_link_hash_entry*)h;
 
   htab = elf_s390_hash_table (info);
-  if (htab == NULL)
-    return false;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
@@ -3373,8 +3371,7 @@ 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.  */
-         if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
-           return false;
+         BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
          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
index 2ed120af7801647458c554e4cb68b2c9d9338d7b..6cc70a7d4c37d87f4ac859bce17489b65b13fdf0 100644 (file)
@@ -4581,8 +4581,6 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
   bool local_undefweak;
 
   htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
-  if (htab == NULL)
-    return false;
 
   /* Use the second PLT section only if there is .plt section.  */
   use_plt_second = htab->elf.splt != NULL && htab->plt_second != NULL;
@@ -4923,8 +4921,7 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
       else if (bfd_link_pic (info)
               && SYMBOL_REFERENCES_LOCAL_P (info, h))
        {
-         if (!SYMBOL_DEFINED_NON_SHARED_P (h))
-           return false;
+         BFD_ASSERT (SYMBOL_DEFINED_NON_SHARED_P (h));
          BFD_ASSERT((h->got.offset & 1) != 0);
          if (info->enable_dt_relr)
            generate_dynamic_reloc = false;
index 109517db4aac3ec84611fabcf527ea9512439f4d..cf21f62d73a1df0a4ef0925f157e7962bf5e8c89 100644 (file)
@@ -9671,7 +9671,7 @@ elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
          || plt == NULL
          || gotplt == NULL
          || relplt == NULL)
-       return false;
+       abort ();
 
       elfNN_aarch64_create_small_pltn_entry (h, htab, output_bfd, info);
       if (!h->def_regular)
@@ -9739,9 +9739,7 @@ elfNN_aarch64_finish_dynamic_symbol (bfd *output_bfd,
        }
       else if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
        {
-         if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
-           return false;
-
+         BFD_ASSERT (h->def_regular || ELF_COMMON_DEF_P (h));
          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
index 7081ba1bcbc7f74b2eb5b1e8ce02e5c875e02427..9951a47349b00ebf9830bf271bfa02ac6cb82d89 100644 (file)
@@ -4517,8 +4517,6 @@ elfNN_ia64_finish_dynamic_symbol (bfd *output_bfd,
   struct elfNN_ia64_dyn_sym_info *dyn_i;
 
   ia64_info = elfNN_ia64_hash_table (info);
-  if (ia64_info == NULL)
-    return false;
 
   dyn_i = get_dyn_sym_info (ia64_info, h, NULL, NULL, false);
 
index ae5ed6bf3f75eaa81421ea6c697d0fdb00f0dc8d..00446c9a8d806d1ee7c5ded81ecae5471ea142ff 100644 (file)
@@ -4479,8 +4479,7 @@ elfNN_kvx_finish_dynamic_symbol (bfd *output_bfd,
 
       if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
        {
-         if (!h->def_regular)
-           return false;
+         BFD_ASSERT (h->def_regular);
 
          /* in case of PLT related GOT entry, it is not clear who is
             supposed to set the LSB of GOT entry...
index 8b27e3b8d6aef4f1375bcaff5d2e61a885ee72ee..951b19a911df36b92625c41488cb4967ef998666 100644 (file)
@@ -3136,7 +3136,7 @@ riscv_elf_finish_dynamic_symbol (bfd *output_bfd,
          || plt == NULL
          || gotplt == NULL
          || relplt == NULL)
-       return false;
+       abort ();
 
       /* Calculate the address of the PLT header.  */
       header_address = sec_addr (plt);
index b888e7622b77b10cacccb9defa28db9bfc005b0e..479030692717c38b6f9e088472de829ca76018f5 100644 (file)
@@ -6842,6 +6842,7 @@ mips_elf_create_dynamic_relocation (bfd *output_bfd,
        indx = 0;
       else if (sec == NULL || sec->owner == NULL)
        {
+         BFD_ASSERT (0);
          bfd_set_error (bfd_error_bad_value);
          return false;
        }
@@ -11186,7 +11187,13 @@ _bfd_mips_elf_finish_dynamic_symbol (bfd *output_bfd,
         sign extension at runtime in the stub, resulting in a negative
         index value.  */
       if (h->dynindx & ~0x7fffffff)
-       return false;
+       {
+         _bfd_error_handler
+           (_("%pB: cannot handle more than %d dynamic symbols"),
+            output_bfd, 0x7fffffff);
+         bfd_set_error (bfd_error_bad_value);
+         return false;
+       }
 
       /* Fill the stub.  */
       if (micromips_p)