RISC-V: Ouput __global_pointer$ as dynamic symbol when generating dynamic PDE.
[deliverable/binutils-gdb.git] / bfd / som.c
index d36d163bb6b11910325c0581d9f1ad28fbab6045..5897ae6c5b7e29d07f5f38454ab08cdd9830d643 100644 (file)
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -1,5 +1,5 @@
 /* bfd back-end for HP PA-RISC SOM objects.
-   Copyright (C) 1990-2020 Free Software Foundation, Inc.
+   Copyright (C) 1990-2021 Free Software Foundation, Inc.
 
    Contributed by the Center for Software Science at the
    University of Utah.
@@ -37,7 +37,7 @@ static bfd_boolean som_mkobject (bfd *);
 static bfd_boolean som_is_space (asection *);
 static bfd_boolean som_is_subspace (asection *);
 static int compare_subspaces (const void *, const void *);
-static unsigned long som_compute_checksum (struct som_external_header *);
+static uint32_t som_compute_checksum (struct som_external_header *);
 static bfd_boolean som_build_and_write_symbol_table (bfd *);
 static unsigned int som_slurp_symbol_table (bfd *);
 
@@ -114,7 +114,7 @@ static unsigned int som_slurp_symbol_table (bfd *);
 
    Note one side effect of using a R_PREV_FIXUP is the relocation that
    is being repeated moves to the front of the queue.  */
-struct reloc_queue
+static struct reloc_queue
 {
   unsigned char *reloc;
   unsigned int size;
@@ -2369,20 +2369,13 @@ setup_sections (bfd *abfd,
   for (i = 0; i < total_subspaces; i++)
     subspace_sections[i]->target_index = i;
 
-  if (space_strings != NULL)
-    free (space_strings);
-
-  if (subspace_sections != NULL)
-    free (subspace_sections);
-
+  free (space_strings);
+  free (subspace_sections);
   return TRUE;
 
  error_return:
-  if (space_strings != NULL)
-    free (space_strings);
-
-  if (subspace_sections != NULL)
-    free (subspace_sections);
+  free (space_strings);
+  free (subspace_sections);
   return FALSE;
 }
 
@@ -2811,6 +2804,9 @@ som_prep_for_fixups (bfd *abfd, asymbol **syms, unsigned long num_syms)
   asymbol **sorted_syms;
   size_t amt;
 
+  if (num_syms == 0)
+    return TRUE;
+
   /* Most SOM relocations involving a symbol have a length which is
      dependent on the index of the symbol.  So symbols which are
      used often in relocations should have a small index.  */
@@ -4288,14 +4284,15 @@ som_finish_writing (bfd *abfd)
 
 /* Compute and return the checksum for a SOM file header.  */
 
-static unsigned long
+static uint32_t
 som_compute_checksum (struct som_external_header *hdr)
 {
-  unsigned long checksum, count, i;
-  unsigned long *buffer = (unsigned long *) hdr;
+  size_t count, i;
+  uint32_t checksum;
+  uint32_t *buffer = (uint32_t *) hdr;
 
   checksum = 0;
-  count = sizeof (struct som_external_header) / 4;
+  count = sizeof (*hdr) / sizeof (*buffer);
   for (i = 0; i < count; i++)
     checksum ^= *(buffer + i);
 
@@ -4528,12 +4525,11 @@ som_build_and_write_symbol_table (bfd *abfd)
   if (bfd_bwrite ((void *) som_symtab, symtab_size, abfd) != symtab_size)
     goto error_return;
 
-  if (som_symtab != NULL)
-    free (som_symtab);
+  free (som_symtab);
   return TRUE;
+
  error_return:
-  if (som_symtab != NULL)
-    free (som_symtab);
+  free (som_symtab);
   return FALSE;
 }
 
@@ -4827,15 +4823,12 @@ som_slurp_symbol_table (bfd *abfd)
   /* Save our results and return success.  */
   obj_som_symtab (abfd) = symbase;
  successful_return:
-  if (buf != NULL)
-    free (buf);
+  free (buf);
   return (TRUE);
 
  error_return:
-  if (symbase != NULL)
-    free (symbase);
-  if (buf != NULL)
-    free (buf);
+  free (symbase);
+  free (buf);
   return FALSE;
 }
 
@@ -5230,8 +5223,7 @@ som_set_reloc_info (unsigned char *fixup,
                      if (!bfd_malloc_and_get_section (section->owner, section,
                                                       &contents))
                        {
-                         if (contents != NULL)
-                           free (contents);
+                         free (contents);
                          return (unsigned) -1;
                        }
                      section->contents = contents;
@@ -5463,8 +5455,18 @@ som_bfd_copy_private_section_data (bfd *ibfd,
 
   /* Reparent if necessary.  */
   if (som_section_data (osection)->copy_data->container)
-    som_section_data (osection)->copy_data->container =
-      som_section_data (osection)->copy_data->container->output_section;
+    {
+      if (som_section_data (osection)->copy_data->container->output_section)
+       som_section_data (osection)->copy_data->container =
+         som_section_data (osection)->copy_data->container->output_section;
+      else
+       {
+         /* User has specified a subspace without its containing space.  */
+         _bfd_error_handler (_("%pB[%pA]: no output section for space %pA"),
+           obfd, osection, som_section_data (osection)->copy_data->container);
+         return FALSE;
+       }
+    }
 
   return TRUE;
 }
@@ -5977,13 +5979,11 @@ som_bfd_count_ar_symbols (bfd *abfd,
          (*count)++;
        }
     }
-  if (hash_table != NULL)
-    free (hash_table);
+  free (hash_table);
   return TRUE;
 
  error_return:
-  if (hash_table != NULL)
-    free (hash_table);
+  free (hash_table);
   return FALSE;
 }
 
@@ -6152,17 +6152,13 @@ som_bfd_fill_in_ar_symbols (bfd *abfd,
     }
   /* If we haven't died by now, then we successfully read the entire
      archive symbol table.  */
-  if (hash_table != NULL)
-    free (hash_table);
-  if (som_dict != NULL)
-    free (som_dict);
+  free (hash_table);
+  free (som_dict);
   return TRUE;
 
  error_return:
-  if (hash_table != NULL)
-    free (hash_table);
-  if (som_dict != NULL)
-    free (som_dict);
+  free (hash_table);
+  free (som_dict);
   return FALSE;
 }
 
@@ -6611,29 +6607,19 @@ som_bfd_ar_write_symbol_stuff (bfd *abfd,
   if (bfd_bwrite ((void *) strings, amt, abfd) != amt)
     goto error_return;
 
-  if (hash_table != NULL)
-    free (hash_table);
-  if (som_dict != NULL)
-    free (som_dict);
-  if (last_hash_entry != NULL)
-    free (last_hash_entry);
-  if (lst_syms != NULL)
-    free (lst_syms);
-  if (strings != NULL)
-    free (strings);
+  free (hash_table);
+  free (som_dict);
+  free (last_hash_entry);
+  free (lst_syms);
+  free (strings);
   return TRUE;
 
  error_return:
-  if (hash_table != NULL)
-    free (hash_table);
-  if (som_dict != NULL)
-    free (som_dict);
-  if (last_hash_entry != NULL)
-    free (last_hash_entry);
-  if (lst_syms != NULL)
-    free (lst_syms);
-  if (strings != NULL)
-    free (strings);
+  free (hash_table);
+  free (som_dict);
+  free (last_hash_entry);
+  free (lst_syms);
+  free (strings);
 
   return FALSE;
 }
@@ -6785,7 +6771,7 @@ som_bfd_free_cached_info (bfd *abfd)
     {
       asection *o;
 
-#define FREE(x) if (x != NULL) { free (x); x = NULL; }
+#define FREE(x) do { free (x); x = NULL; } while (0)
       /* Free the native string and symbol tables.  */
       FREE (obj_som_symtab (abfd));
       FREE (obj_som_stringtab (abfd));
This page took 0.025274 seconds and 4 git commands to generate.