/* 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.
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 *);
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;
som_swap_subspace_dictionary_in (&ext_subspace, &subspace);
/* Setup the subspace name string. */
+ if (subspace.name >= file_hdr->space_strings_size)
+ goto error_return;
+
subspace_name = subspace.name + space_strings;
amt = strlen (subspace_name) + 1;
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;
}
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. */
/* 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);
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;
}
/* 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;
}
if (!bfd_malloc_and_get_section (section->owner, section,
&contents))
{
- if (contents != NULL)
- free (contents);
+ free (contents);
return (unsigned) -1;
}
section->contents = contents;
/* 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;
}
(*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;
}
}
/* 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;
}
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;
}
unsigned int module_count;
/* We'll use this for the archive's date and mode later. */
- if (stat (abfd->filename, &statbuf) != 0)
+ if (stat (bfd_get_filename (abfd), &statbuf) != 0)
{
bfd_set_error (bfd_error_system_call);
return FALSE;
{
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));