aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfxx-mips.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-06-08 19:55:55 +0930
committerAlan Modra <amodra@gmail.com>2023-06-09 12:56:12 +0930
commitce3ab55fa72dd8778f5fd5fea7d6389af16d141e (patch)
tree72712c30fe65f06cd6b365231e3596f95db4013e /bfd/elfxx-mips.c
parent8fd82abda0f367f89db50040d519e1464a84c3a0 (diff)
downloadgdb-ce3ab55fa72dd8778f5fd5fea7d6389af16d141e.zip
gdb-ce3ab55fa72dd8778f5fd5fea7d6389af16d141e.tar.gz
gdb-ce3ab55fa72dd8778f5fd5fea7d6389af16d141e.tar.bz2
ecoff find_nearest_line and final link leaks
Freeing ecoff_debug_info "pointers to the unswapped symbolic info" isn't a simple matter, due to differing allocation strategies. In _bfd_ecoff_slurp_symbolic_info the pointers are to objalloc memory. In the ecoff linker they are to separately malloc'd memory. In gas we have most (obj-elf) or all (obj-ecoff) into a single malloc'd buffer. This patch fixes the leaks for binutils and ld, leaving the gas leaks for another day. The mips elf backend already had this covered, and the ecoff backend had a pointer, raw_syments used as a flag, so most of the patch is moving these around a little so they are accessible for both ecoff and elf. include/ * coff/ecoff.h (struct ecoff_debug_info): Add alloc_syments. bfd/ * libecoff.h (struct ecoff_tdata): Delete raw_syments. * elfxx-mips.c (free_ecoff_debug): Delete. Replace uses with _bfd_ecoff_free_ecoff_debug_info. (_bfd_mips_elf_final_link): Init debug.alloc_syments. * ecofflink.c (_bfd_ecoff_free_ecoff_debug_info): New function. * ecoff.c (_bfd_ecoff_bfd_free_cached_info): Call _bfd_ecoff_free_ecoff_debug_info. (_bfd_ecoff_slurp_symbolic_info): Replace uses of raw_syments with alloc_syments. (ecoff_final_link_debug_accumulate): Likewise. Use _bfd_ecoff_free_ecoff_debug_info. (_bfd_ecoff_bfd_copy_private_bfd_data): Set alloc_syments for copied output. * elf64-alpha.c (elf64_alpha_read_ecoff_info): Use _bfd_ecoff_free_ecoff_debug_info. * libbfd-in.h (_bfd_ecoff_free_ecoff_debug_info): Declare. * libbfd.h: Regenerate. gas/ * config/obj-ecoff.c (ecoff_frob_file): Set alloc_syments. * config/obj-elf.c (elf_frob_file_after_relocs): Likewise.
Diffstat (limited to 'bfd/elfxx-mips.c')
-rw-r--r--bfd/elfxx-mips.c40
1 files changed, 6 insertions, 34 deletions
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 7d29ec2..a618f6f 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -1389,35 +1389,6 @@ struct mips_elf_find_line
struct ecoff_find_line i;
};
-/* Free ECOFF debugging info used by find_nearest_line. */
-
-static void
-free_ecoff_debug (struct ecoff_debug_info *debug)
-{
- free (debug->line);
- free (debug->external_dnr);
- free (debug->external_pdr);
- free (debug->external_sym);
- free (debug->external_opt);
- free (debug->external_aux);
- free (debug->ss);
- free (debug->ssext);
- free (debug->external_fdr);
- free (debug->external_rfd);
- free (debug->external_ext);
- debug->line = NULL;
- debug->external_dnr = NULL;
- debug->external_pdr = NULL;
- debug->external_sym = NULL;
- debug->external_opt = NULL;
- debug->external_aux = NULL;
- debug->ss = NULL;
- debug->ssext = NULL;
- debug->external_fdr = NULL;
- debug->external_rfd = NULL;
- debug->external_ext = NULL;
-}
-
bool
_bfd_mips_elf_free_cached_info (bfd *abfd)
{
@@ -1435,7 +1406,7 @@ _bfd_mips_elf_free_cached_info (bfd *abfd)
free (hi);
}
if (tdata->find_line_info != NULL)
- free_ecoff_debug (&tdata->find_line_info->d);
+ _bfd_ecoff_free_ecoff_debug_info (&tdata->find_line_info->d);
}
return _bfd_elf_free_cached_info (abfd);
}
@@ -1523,7 +1494,7 @@ _bfd_mips_elf_read_ecoff_info (bfd *abfd, asection *section,
error_return:
free (ext_hdr);
- free_ecoff_debug (debug);
+ _bfd_ecoff_free_ecoff_debug_info (debug);
return false;
}
@@ -13225,7 +13196,7 @@ _bfd_mips_elf_find_nearest_line (bfd *abfd, asymbol **symbols,
fi->d.fdr = bfd_alloc (abfd, amt);
if (fi->d.fdr == NULL)
{
- free_ecoff_debug (&fi->d);
+ _bfd_ecoff_free_ecoff_debug_info (&fi->d);
msec->flags = origflags;
return false;
}
@@ -15043,6 +15014,7 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info)
/* We accumulate the debugging information itself in the
debug_info structure. */
+ debug.alloc_syments = false;
debug.line = NULL;
debug.external_dnr = NULL;
debug.external_pdr = NULL;
@@ -15128,7 +15100,7 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info)
(mdebug_handle, abfd, &debug, swap, input_bfd,
&input_debug, input_swap, info)))
{
- free_ecoff_debug (&input_debug);
+ _bfd_ecoff_free_ecoff_debug_info (&input_debug);
return false;
}
@@ -15171,7 +15143,7 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info)
}
/* Free up the information we just read. */
- free_ecoff_debug (&input_debug);
+ _bfd_ecoff_free_ecoff_debug_info (&input_debug);
/* Hack: reset the SEC_HAS_CONTENTS flag so that
elf_link_input_bfd ignores this section. */