summaryrefslogtreecommitdiff
path: root/gdb/coffread.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/coffread.c
parent4d44946794e68cf79cfba467fa414a958dba2185 (diff)
downloadbinutils-gdb-98badbfdc222d1d7f346046f23a64522b88d22a0.tar.gz
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/coffread.c')
-rw-r--r--gdb/coffread.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/gdb/coffread.c b/gdb/coffread.c
index f7f5bb007ca..45d41d08449 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -278,7 +278,7 @@ cs_to_bfd_section (struct coff_symbol *cs, struct objfile *objfile)
args.targ_index = cs->c_secnum;
args.resultp = &sect;
- bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
+ bfd_map_over_sections (objfile->obfd.get (), find_targ_sec, &args);
return sect;
}
@@ -290,7 +290,7 @@ cs_to_section (struct coff_symbol *cs, struct objfile *objfile)
if (sect == NULL)
return SECT_OFF_TEXT (objfile);
- return gdb_bfd_section_index (objfile->obfd, sect);
+ return gdb_bfd_section_index (objfile->obfd.get (), sect);
}
/* Return the address of the section of a COFF symbol. */
@@ -579,7 +579,8 @@ coff_read_minsyms (file_ptr symtab_offset, unsigned int nsyms,
name1 = name + 6;
if (name1 != NULL)
{
- int lead = bfd_get_symbol_leading_char (objfile->obfd);
+ int lead
+ = bfd_get_symbol_leading_char (objfile->obfd.get ());
struct bound_minimal_symbol found;
if (lead != '\0' && *name1 == lead)
@@ -610,7 +611,7 @@ static void
coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{
struct coff_symfile_info *info;
- bfd *abfd = objfile->obfd;
+ bfd *abfd = objfile->obfd.get ();
coff_data_type *cdata = coff_data (abfd);
const char *filename = bfd_get_filename (abfd);
int val;
@@ -655,8 +656,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
FIXME: We should use BFD to read the symbol table, and thus avoid
this problem. */
pe_file =
- startswith (bfd_get_target (objfile->obfd), "pe")
- || startswith (bfd_get_target (objfile->obfd), "epoc-pe");
+ startswith (bfd_get_target (objfile->obfd.get ()), "pe")
+ || startswith (bfd_get_target (objfile->obfd.get ()), "epoc-pe");
/* End of warning. */
@@ -742,7 +743,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{
gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ()));
- symbol_file_add_separate (debug_bfd.get (), debugfile.c_str (),
+ symbol_file_add_separate (debug_bfd, debugfile.c_str (),
symfile_flags, objfile);
}
}
@@ -817,15 +818,15 @@ coff_symtab_read (minimal_symbol_reader &reader,
FIXME: Find out if this has been reported to Sun, whether it has
been fixed in a later release, etc. */
- bfd_seek (objfile->obfd, 0, 0);
+ bfd_seek (objfile->obfd.get (), 0, 0);
/* Position to read the symbol table. */
- val = bfd_seek (objfile->obfd, symtab_offset, 0);
+ val = bfd_seek (objfile->obfd.get (), symtab_offset, 0);
if (val < 0)
perror_with_name (objfile_name (objfile));
coffread_objfile = objfile;
- nlist_bfd_global = objfile->obfd;
+ nlist_bfd_global = objfile->obfd.get ();
nlist_nsyms_global = nsyms;
set_last_source_file (NULL);
memset (opaque_type_chain, 0, sizeof opaque_type_chain);
@@ -1565,7 +1566,7 @@ process_coff_symbol (struct coff_symbol *cs,
char *name;
name = cs->c_name;
- name = EXTERNAL_NAME (name, objfile->obfd);
+ name = EXTERNAL_NAME (name, objfile->obfd.get ());
sym->set_language (get_current_subfile ()->language,
&objfile->objfile_obstack);
sym->compute_and_set_names (name, true, objfile->per_bfd);
@@ -2001,7 +2002,7 @@ coff_read_struct_type (int index, int length, int lastsym,
{
read_one_sym (ms, &sub_sym, &sub_aux);
name = ms->c_name;
- name = EXTERNAL_NAME (name, objfile->obfd);
+ name = EXTERNAL_NAME (name, objfile->obfd.get ());
switch (ms->c_sclass)
{
@@ -2095,7 +2096,7 @@ coff_read_enum_type (int index, int length, int lastsym,
{
read_one_sym (ms, &sub_sym, &sub_aux);
name = ms->c_name;
- name = EXTERNAL_NAME (name, objfile->obfd);
+ name = EXTERNAL_NAME (name, objfile->obfd.get ());
switch (ms->c_sclass)
{