Fix race condition in dwarf2_section_info::read It can occur in dwarf2_section_info::read that: - thread A sets readin to true, and buffer to nullptr, and then - thread B reads readin as true, returns and finds that buffer is nullptr and concludes that there no such such section. Which is not true, it's just that thread A hasn't finished reading it yet, which would make buffer != nullptr. --- gdb/dwarf2/section.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdb/dwarf2/section.c b/gdb/dwarf2/section.c index 8e1c0197c85..e6940103d77 100644 --- a/gdb/dwarf2/section.c +++ b/gdb/dwarf2/section.c @@ -30,6 +30,8 @@ #include "objfiles.h" #include "complaints.h" +#include + void dwarf2_section_info::overflow_complaint () const { @@ -118,10 +120,12 @@ dwarf2_section_info::empty () const void dwarf2_section_info::read (struct objfile *objfile) { + static std::mutex mutex; asection *sectp; bfd *abfd; gdb_byte *buf, *retbuf; + std::lock_guard guard (mutex); if (readin) return; buffer = NULL;