summaryrefslogtreecommitdiff
path: root/gdb/xcoffread.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-08-02 09:55:32 -0600
committerTom Tromey <tom@tromey.com>2022-08-03 13:26:58 -0600
commit98badbfdc222d1d7f346046f23a64522b88d22a0 (patch)
treea57a95b75f64a0e318e0b1bd31dd6b246e4797d8 /gdb/xcoffread.c
parent4d44946794e68cf79cfba467fa414a958dba2185 (diff)
Use gdb_bfd_ref_ptr in objfile
This changes struct objfile to use a gdb_bfd_ref_ptr. In addition to removing some manual memory management, this fixes a use-after-free that was introduced by the registry rewrite series. The issue there was that, in some cases, registry shutdown could refer to memory that had already been freed. This help fix the bug by delaying the destruction of the BFD reference (and thus the per-bfd object) until after the registry has been shut down.
Diffstat (limited to 'gdb/xcoffread.c')
-rw-r--r--gdb/xcoffread.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 6be0a7c446..b7d6577111 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -301,7 +301,7 @@ xcoff_secnum_to_sections (int n_scnum, struct objfile *objfile,
*bfd_sect = NULL;
*secnum = SECT_OFF_TEXT (objfile);
- bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
+ bfd_map_over_sections (objfile->obfd.get (), find_targ_sec, &args);
}
/* Return the section number (SECT_OFF_*) that N_SCNUM points to. */
@@ -782,7 +782,7 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset,
else
limit_offset -= 1;
- abfd = objfile->obfd;
+ abfd = objfile->obfd.get ();
linesz = coff_data (abfd)->local_linesz;
ext_lnno = alloca (linesz);
@@ -892,7 +892,7 @@ xcoff_next_symbol_text (struct objfile *objfile)
if (this_symtab_objfile)
objfile = this_symtab_objfile;
- bfd_coff_swap_sym_in (objfile->obfd, raw_symbol, &symbol);
+ bfd_coff_swap_sym_in (objfile->obfd.get (), raw_symbol, &symbol);
if (symbol.n_zeroes)
{
complaint (_("Unexpected symbol continuation"));
@@ -923,7 +923,7 @@ xcoff_next_symbol_text (struct objfile *objfile)
static void
read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
{
- bfd *abfd = objfile->obfd;
+ bfd *abfd = objfile->obfd.get ();
char *raw_auxptr; /* Pointer to first raw aux entry for sym. */
struct xcoff_symfile_info *xcoff = XCOFF_DATA (objfile);
char *strtbl = xcoff->strtbl;
@@ -1628,7 +1628,7 @@ read_symbol (struct internal_syment *symbol, int symno)
symbol->n_scnum = -1;
return;
}
- bfd_coff_swap_sym_in (this_symtab_objfile->obfd,
+ bfd_coff_swap_sym_in (this_symtab_objfile->obfd.get (),
stbl + (symno * local_symesz),
symbol);
}
@@ -1704,7 +1704,7 @@ read_symbol_lineno (int symno)
gotit:
/* Take aux entry and return its lineno. */
symno++;
- bfd_coff_swap_aux_in (objfile->obfd, stbl + symno * local_symesz,
+ bfd_coff_swap_aux_in (objfile->obfd.get (), stbl + symno * local_symesz,
symbol->n_type, symbol->n_sclass,
0, symbol->n_numaux, main_aux);
@@ -1989,7 +1989,7 @@ swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
const char **name, char **raw, unsigned int *symnump,
struct objfile *objfile)
{
- bfd_coff_swap_sym_in (objfile->obfd, *raw, symbol);
+ bfd_coff_swap_sym_in (objfile->obfd.get (), *raw, symbol);
if (symbol->n_zeroes)
{
/* If it's exactly E_SYMNMLEN characters long it isn't
@@ -2023,7 +2023,7 @@ swap_sym (struct internal_syment *symbol, union internal_auxent *aux,
*raw += coff_data (objfile->obfd)->local_symesz;
if (symbol->n_numaux > 0)
{
- bfd_coff_swap_aux_in (objfile->obfd, *raw, symbol->n_type,
+ bfd_coff_swap_aux_in (objfile->obfd.get (), *raw, symbol->n_type,
symbol->n_sclass, 0, symbol->n_numaux, aux);
*symnump += symbol->n_numaux;
@@ -2090,7 +2090,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
set_last_source_file (NULL);
- abfd = objfile->obfd;
+ abfd = objfile->obfd.get ();
next_symbol_text_func = xcoff_next_symbol_text;
sraw_symbol = XCOFF_DATA (objfile)->symtbl;
@@ -2120,7 +2120,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
if (symbol.n_numaux > 1)
{
bfd_coff_swap_aux_in
- (objfile->obfd,
+ (objfile->obfd.get (),
sraw_symbol - coff_data (abfd)->local_symesz,
symbol.n_type,
symbol.n_sclass,
@@ -2795,7 +2795,7 @@ xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags)
unsigned int size;
info = XCOFF_DATA (objfile);
- symfile_bfd = abfd = objfile->obfd;
+ symfile_bfd = abfd = objfile->obfd.get ();
name = objfile_name (objfile);
num_symbols = bfd_get_symcount (abfd); /* # of symbols */