aboutsummaryrefslogtreecommitdiff
path: root/bfd/ecoff.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/ecoff.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/ecoff.c')
-rw-r--r--bfd/ecoff.c52
1 files changed, 17 insertions, 35 deletions
diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index f2626c5..522a442 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -117,12 +117,15 @@ _bfd_ecoff_bfd_free_cached_info (bfd *abfd)
if ((bfd_get_format (abfd) == bfd_object
|| bfd_get_format (abfd) == bfd_core)
&& (tdata = ecoff_data (abfd)) != NULL)
- while (tdata->mips_refhi_list != NULL)
- {
- struct mips_hi *ref = tdata->mips_refhi_list;
- tdata->mips_refhi_list = ref->next;
- free (ref);
- }
+ {
+ while (tdata->mips_refhi_list != NULL)
+ {
+ struct mips_hi *ref = tdata->mips_refhi_list;
+ tdata->mips_refhi_list = ref->next;
+ free (ref);
+ }
+ _bfd_ecoff_free_ecoff_debug_info (&tdata->debug_info);
+ }
return _bfd_generic_bfd_free_cached_info (abfd);
}
@@ -524,7 +527,7 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
/* Check whether we've already gotten it, and whether there's any to
get. */
- if (ecoff_data (abfd)->raw_syments != NULL)
+ if (debug->alloc_syments)
return true;
if (ecoff_data (abfd)->sym_filepos == 0)
{
@@ -595,7 +598,7 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
if (raw == NULL)
return false;
- ecoff_data (abfd)->raw_syments = raw;
+ debug->alloc_syments = true;
/* Get pointers for the numeric offsets in the HDRR structure. */
#define FIX(start, count, ptr, type) \
@@ -1918,6 +1921,9 @@ _bfd_ecoff_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
oinfo->symbolic_header.crfd = iinfo->symbolic_header.crfd;
oinfo->external_rfd = iinfo->external_rfd;
+
+ /* Flag that oinfo entries should not be freed. */
+ oinfo->alloc_syments = true;
}
else
{
@@ -3809,9 +3815,9 @@ ecoff_final_link_debug_accumulate (bfd *output_bfd,
((char *) debug->ptr)[amt] = 0; \
} while (0)
- /* If raw_syments is not NULL, then the data was already by read by
+ /* If alloc_syments is true, then the data was already by read by
_bfd_ecoff_slurp_symbolic_info. */
- if (ecoff_data (input_bfd)->raw_syments == NULL)
+ if (!debug->alloc_syments)
{
READ (line, cbLineOffset, cbLine, sizeof (unsigned char));
READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size);
@@ -3833,31 +3839,7 @@ ecoff_final_link_debug_accumulate (bfd *output_bfd,
input_bfd, debug, swap, info));
return_something:
- if (ecoff_data (input_bfd)->raw_syments == NULL)
- {
- 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->external_fdr);
- free (debug->external_rfd);
-
- /* Make sure we don't accidentally follow one of these pointers
- into freed memory. */
- 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->external_fdr = NULL;
- debug->external_rfd = NULL;
- }
-
+ _bfd_ecoff_free_ecoff_debug_info (debug);
return ret;
}