if (sym_bfd == NULL)
return NULL;
- {
- /* The operations below are not thread-safe, use a lock to synchronize
- concurrent accesses. */
- static gdb::mutex mutex;
- gdb::lock_guard<gdb::mutex> lock (mutex);
-
- if (!gdb_bfd_check_format (sym_bfd.get (), bfd_object))
- return NULL;
+ if (!gdb_bfd_check_format (sym_bfd.get (), bfd_object))
+ return NULL;
- /* Success. Record the bfd as having been included by the objfile's bfd.
+ /* Success. Record the bfd as having been included by the objfile's bfd.
This is important because things like demangled_names_hash lives in the
objfile's per_bfd space and may have references to things like symbol
names that live in the DWO/DWP file's per_bfd space. PR 16426. */
- gdb_bfd_record_inclusion (per_bfd->obfd, sym_bfd.get ());
- }
+ gdb_bfd_record_inclusion (per_bfd->obfd, sym_bfd.get ());
return sym_bfd;
}
void
gdb_bfd_record_inclusion (bfd *includer, bfd *includee)
{
- struct gdb_bfd_data *gdata;
+ gdb::lock_guard<gdb::recursive_mutex> guard (gdb_bfd_mutex);
- gdata = (struct gdb_bfd_data *) bfd_usrdata (includer);
+ struct gdb_bfd_data *gdata = (struct gdb_bfd_data *) bfd_usrdata (includer);
gdata->included_bfds.push_back (gdb_bfd_ref_ptr::new_reference (includee));
}
bool
gdb_bfd_check_format (bfd *abfd, bfd_format format)
{
+ gdb::lock_guard<gdb::recursive_mutex> guard (gdb_bfd_mutex);
+
return bfd_check_format (abfd, format);
}
bool
gdb_bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
{
+ gdb::lock_guard<gdb::recursive_mutex> guard (gdb_bfd_mutex);
+
return bfd_check_format_matches (abfd, format, matching);
}
extern gdb::array_view<asymbol *> gdb_bfd_canonicalize_symtab
(bfd *abfd, bool should_throw = true);
-/* A wrapper for bfd_check_format. */
+/* A wrapper for bfd_check_format that acquires the BFD lock. */
extern bool gdb_bfd_check_format (bfd *abfd, bfd_format format);
-/* A wrapper for bfd_check_format_matches. */
+/* A wrapper for bfd_check_format_matches that acquires the BFD lock. */
extern bool gdb_bfd_check_format_matches (bfd *abfd, bfd_format format,
char ***matching);