[binutils-gdb] gas: replace bfd_alloc with notes_alloc
Alan Modra
amodra@sourceware.org
Thu Feb 13 22:47:15 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7763858d27b8a9b1ddc840beb4b352e173149ba1
commit 7763858d27b8a9b1ddc840beb4b352e173149ba1
Author: Alan Modra <amodra@gmail.com>
Date: Thu Feb 13 10:59:51 2025 +1030
gas: replace bfd_alloc with notes_alloc
bfd_alloc can return NULL on out-of-memory so code needs to check the
return value and print an error. That check was missing in write.c.
notes_alloc won't return NULL, instead the underlying obstack_alloc
prints an OOM message and the process exits. This is more convenient,
and when the bfd_alloc memory is attached to the gas output bfd it is
released only slightly before the notes obstack.
* config/obj-macho.c (obj_mach_o_set_indirect_symbols): Use
notes_calloc rather than bfd_zalloc.
* write.c (set_symtab): Use notes_alloc.
Diff:
---
gas/config/obj-macho.c | 9 ++-------
gas/write.c | 3 +--
2 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/gas/config/obj-macho.c b/gas/config/obj-macho.c
index 249791f9081..89c2e0494db 100644
--- a/gas/config/obj-macho.c
+++ b/gas/config/obj-macho.c
@@ -1818,13 +1818,8 @@ obj_mach_o_set_indirect_symbols (bfd *abfd, asection *sec,
if (nactual < bfd_get_symcount (abfd))
nactual = bfd_get_symcount (abfd);
- ms->indirect_syms =
- bfd_zalloc (abfd,
- nactual * sizeof (bfd_mach_o_asymbol *));
-
- if (ms->indirect_syms == NULL)
- as_fatal (_("internal error: failed to allocate %d indirect"
- "symbol pointers"), nactual);
+ ms->indirect_syms = notes_calloc (nactual,
+ sizeof (*ms->indirect_syms));
for (isym = list, n = 0; isym != NULL; isym = isym->next, n++)
{
diff --git a/gas/write.c b/gas/write.c
index 439f6a6913a..325c4402061 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -1804,9 +1804,8 @@ set_symtab (void)
if (nsyms)
{
int i;
- bfd_size_type amt = (bfd_size_type) nsyms * sizeof (asymbol *);
- asympp = (asymbol **) bfd_alloc (stdoutput, amt);
+ asympp = notes_alloc (nsyms * sizeof (asymbol *));
symp = symbol_rootP;
for (i = 0; i < nsyms; symp = symbol_next (symp))
if (!symbol_removed_p (symp)
More information about the Binutils-cvs
mailing list