Remove need to clear obj_coff_keep_syms in coff object_p
authorAlan Modra <amodra@gmail.com>
Thu, 30 Jan 2020 06:36:35 +0000 (17:06 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 30 Jan 2020 06:36:35 +0000 (17:06 +1030)
* coffgen.c (coff_real_object_p): Don't clear obj_coff_keep_syms
or obj_coff_keep_strings here.
(coff_get_normalized_symtab): Free external syms directly.
* xcofflink.c (xcoff_link_input_bfd): Restore obj_coff_keep_syms
on error exit path.

bfd/ChangeLog
bfd/coffgen.c
bfd/xcofflink.c

index 83a1cc67430329da70fd0596c8b52fc21663d2fe..1e2740eacc8ed85b7aa7c6350f76da2857e820fe 100644 (file)
@@ -1,3 +1,11 @@
+2020-01-30  Alan Modra  <amodra@gmail.com>
+
+       * coffgen.c (coff_real_object_p): Don't clear obj_coff_keep_syms
+       or obj_coff_keep_strings here.
+       (coff_get_normalized_symtab): Free external syms directly.
+       * xcofflink.c (xcoff_link_input_bfd): Restore obj_coff_keep_syms
+       on error exit path.
+
 2020-01-27  Jim Wilson  <jimw@sifive.com>
 
        * cpu-riscv.c (riscv_scan): New.
index 3ddd2d89a83a5a9bb8f3a0a479682d72869be760..31e6fa7a083f2ab58e2ff8c6f928a46544f54f22 100644 (file)
@@ -302,14 +302,10 @@ coff_real_object_p (bfd *abfd,
        }
     }
 
-  obj_coff_keep_syms (abfd) = FALSE;
-  obj_coff_keep_strings (abfd) = FALSE;
   _bfd_coff_free_symbols (abfd);
   return abfd->xvec;
 
  fail:
-  obj_coff_keep_syms (abfd) = FALSE;
-  obj_coff_keep_strings (abfd) = FALSE;
   _bfd_coff_free_symbols (abfd);
   bfd_release (abfd, tdata);
  fail2:
@@ -1877,10 +1873,13 @@ coff_get_normalized_symtab (bfd *abfd)
        }
     }
 
-  /* Free the raw symbols, but not the strings (if we have them).  */
-  obj_coff_keep_strings (abfd) = TRUE;
-  if (! _bfd_coff_free_symbols (abfd))
-    return NULL;
+  /* Free the raw symbols.  */
+  if (obj_coff_external_syms (abfd) != NULL
+      && ! obj_coff_keep_syms (abfd))
+    {
+      free (obj_coff_external_syms (abfd));
+      obj_coff_external_syms (abfd) = NULL;
+    }
 
   for (internal_ptr = internal; internal_ptr < internal_end;
        internal_ptr++)
index 7078f253efc069e8acb2058c88ec0346df36e35e..2a431dbecf9829ffd6c8e0bed86e5a2bb15e92b5 100644 (file)
@@ -4782,7 +4782,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
        {
          bfd_size_type sz = o->rawsize ? o->rawsize : o->size;
          if (!bfd_get_section_contents (input_bfd, o, flinfo->contents, 0, sz))
-           return FALSE;
+           goto err_out;
          contents = flinfo->contents;
        }
 
@@ -4804,7 +4804,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                              (flinfo->section_info[target_index].relocs
                               + o->output_section->reloc_count)));
          if (internal_relocs == NULL)
-           return FALSE;
+           goto err_out;
 
          /* Call processor specific code to relocate the section
             contents.  */
@@ -4814,7 +4814,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                                           internal_relocs,
                                           flinfo->internal_syms,
                                           xcoff_data (input_bfd)->csects))
-           return FALSE;
+           goto err_out;
 
          offset = o->output_section->vma + o->output_offset - o->vma;
          irel = internal_relocs;
@@ -4866,7 +4866,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                          amt = sizeof (* n);
                          n = bfd_alloc (flinfo->output_bfd, amt);
                          if (n == NULL)
-                           return FALSE;
+                           goto err_out;
                          si = flinfo->section_info + target_index;
                          n->next = si->toc_rel_hashes;
                          n->h = h;
@@ -4948,7 +4948,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                                      (input_bfd, is, buf));
 
                              if (name == NULL)
-                               return FALSE;
+                               goto err_out;
 
                              (*flinfo->info->callbacks->unattached_reloc)
                                (flinfo->info, name,
@@ -4972,7 +4972,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
                  if (!xcoff_create_ldrel (output_bfd, flinfo,
                                           o->output_section, input_bfd,
                                           irel, sec, h))
-                   return FALSE;
+                   goto err_out;
                }
            }
 
@@ -4983,7 +4983,7 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
       if (! bfd_set_section_contents (output_bfd, o->output_section,
                                      contents, (file_ptr) o->output_offset,
                                      o->size))
-       return FALSE;
+       goto err_out;
     }
 
   obj_coff_keep_syms (input_bfd) = keep_syms;
@@ -4995,6 +4995,10 @@ xcoff_link_input_bfd (struct xcoff_final_link_info *flinfo,
     }
 
   return TRUE;
+
+ err_out:
+  obj_coff_keep_syms (input_bfd) = keep_syms;
+  return FALSE;
 }
 
 #undef N_TMASK