2008-03-07 Paul Brook <paul@codesourcery.com>
[deliverable/binutils-gdb.git] / bfd / coffgen.c
index 7fad78c78f38723b70f8f14fa3370da3449ab6b3..0e8b7eda5c4263e8b82f95c95a93b8c2c0ac75dd 100644 (file)
@@ -409,6 +409,9 @@ _bfd_coff_read_internal_relocs (bfd *abfd,
   struct internal_reloc *irel;
   bfd_size_type amt;
 
+  if (sec->reloc_count == 0)
+    return internal_relocs;    /* Nothing to do.  */
+
   if (coff_section_data (abfd, sec) != NULL
       && coff_section_data (abfd, sec)->relocs != NULL)
     {
@@ -425,7 +428,7 @@ _bfd_coff_read_internal_relocs (bfd *abfd,
   if (external_relocs == NULL)
     {
       free_external = bfd_malloc (amt);
-      if (free_external == NULL && sec->reloc_count > 0)
+      if (free_external == NULL)
        goto error_return;
       external_relocs = free_external;
     }
@@ -439,7 +442,7 @@ _bfd_coff_read_internal_relocs (bfd *abfd,
       amt = sec->reloc_count;
       amt *= sizeof (struct internal_reloc);
       free_internal = bfd_malloc (amt);
-      if (free_internal == NULL && sec->reloc_count > 0)
+      if (free_internal == NULL)
        goto error_return;
       internal_relocs = free_internal;
     }
@@ -457,22 +460,17 @@ _bfd_coff_read_internal_relocs (bfd *abfd,
       free_external = NULL;
     }
 
-  if (free_internal != NULL)
+  if (cache && free_internal != NULL)
     {
-      if (cache)
-       free (free_internal);
-      else
+      if (coff_section_data (abfd, sec) == NULL)
        {
-         if (coff_section_data (abfd, sec) == NULL)
-           {
-             amt = sizeof (struct coff_section_tdata);
-             sec->used_by_bfd = bfd_zalloc (abfd, amt);
-             if (sec->used_by_bfd == NULL)
-               goto error_return;
-             coff_section_data (abfd, sec)->contents = NULL;
-           }
-         coff_section_data (abfd, sec)->relocs = free_internal;
+         amt = sizeof (struct coff_section_tdata);
+         sec->used_by_bfd = bfd_zalloc (abfd, amt);
+         if (sec->used_by_bfd == NULL)
+           goto error_return;
+         coff_section_data (abfd, sec)->contents = NULL;
        }
+      coff_section_data (abfd, sec)->relocs = free_internal;
     }
 
   return internal_relocs;
@@ -567,7 +565,8 @@ fixup_symbol_value (bfd *abfd,
                    struct internal_syment *syment)
 {
   /* Normalize the symbol flags.  */
-  if (bfd_is_com_section (coff_symbol_ptr->symbol.section))
+  if (coff_symbol_ptr->symbol.section 
+      && bfd_is_com_section (coff_symbol_ptr->symbol.section))
     {
       /* A common symbol is undefined with a value.  */
       syment->n_scnum = N_UNDEF;
@@ -1694,7 +1693,7 @@ coff_get_normalized_symtab (bfd *abfd)
              internal_ptr->u.syment._n._n_n._n_zeroes = 0;
            }
          else if (internal_ptr->u.syment._n._n_n._n_offset == 0)
-           internal_ptr->u.syment._n._n_n._n_offset = (bfd_vma) "";
+           internal_ptr->u.syment._n._n_n._n_offset = (bfd_hostptr_t) "";
          else if (!bfd_coff_symname_in_debug (abfd, &internal_ptr->u.syment))
            {
              /* Long name already.  Point symbol at the string in the
This page took 0.026804 seconds and 4 git commands to generate.