va_end (args);
}
+/* Like xmalloc except that ABFD's objalloc memory is returned.
+ Use objalloc_free_block to free this memory and all more recently
+ allocated, or more usually, leave it to bfd_close to free. */
+
+void *
+bfd_xalloc (bfd *abfd, size_t size)
+{
+ void *ret = bfd_alloc (abfd, size);
+ if (ret == NULL)
+ bfd_fatal (NULL);
+ return ret;
+}
+
/* Set the default BFD target based on the configured target. Doing
this permits the binutils to be configured for a particular target,
and linked against a shared BFD library which was configured for a
}
else
{
- relpp = (arelent **) xmalloc (relsize);
+ relpp = bfd_xalloc (obfd, relsize);
relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
if (relcount < 0)
{
status = 1;
bfd_nonfatal_message (NULL, ibfd, isection,
_("relocation count is negative"));
- free (relpp);
return;
}
}
{
/* Remove relocations which are not in
keep_strip_specific_list. */
- arelent **temp_relpp;
- long temp_relcount = 0;
+ arelent **w_relpp;
long i;
- temp_relpp = (arelent **) xmalloc (relsize);
- for (i = 0; i < relcount; i++)
- {
- /* PR 17512: file: 9e907e0c. */
- if (relpp[i]->sym_ptr_ptr
- /* PR 20096 */
- && * relpp[i]->sym_ptr_ptr)
- if (is_specified_symbol (bfd_asymbol_name (*relpp[i]->sym_ptr_ptr),
- keep_specific_htab))
- temp_relpp [temp_relcount++] = relpp [i];
- }
- relcount = temp_relcount;
- if (relpp != isection->orelocation)
- free (relpp);
- relpp = temp_relpp;
+ for (w_relpp = relpp, i = 0; i < relcount; i++)
+ /* PR 17512: file: 9e907e0c. */
+ if (relpp[i]->sym_ptr_ptr
+ /* PR 20096 */
+ && *relpp[i]->sym_ptr_ptr
+ && is_specified_symbol (bfd_asymbol_name (*relpp[i]->sym_ptr_ptr),
+ keep_specific_htab))
+ *w_relpp++ = relpp[i];
+ relcount = w_relpp - relpp;
+ *w_relpp = 0;
}
bfd_set_reloc (obfd, osection, relcount == 0 ? NULL : relpp, relcount);
if (relcount == 0)
- {
- osection->flags &= ~SEC_RELOC;
- if (relpp != isection->orelocation)
- free (relpp);
- }
+ osection->flags &= ~SEC_RELOC;
}
}