From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id BDBB43858C83; Thu, 14 Jul 2022 06:19:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BDBB43858C83 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/symtab] Make per_cu->m_lang atomic X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: b35bd7d552f80518ad90e81f592b73ee2ef736d7 X-Git-Newrev: 14dd1080c6127e7ad7566598860a885aa244ff8d Message-Id: <20220714061919.BDBB43858C83@sourceware.org> Date: Thu, 14 Jul 2022 06:19:14 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jul 2022 06:19:19 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D14dd1080c612= 7e7ad7566598860a885aa244ff8d commit 14dd1080c6127e7ad7566598860a885aa244ff8d Author: Tom de Vries Date: Thu Jul 14 08:19:00 2022 +0200 [gdb/symtab] Make per_cu->m_lang atomic =20 When building gdb with -fsanitize=3Dthread and running test-case gdb.dwarf2/inlined_subroutine-inheritance.exp, we run into a data race between: ... Read of size 1 at 0x7b2000003010 by thread T4: #0 packed::operator language() const packed.h:54 #1 dwarf2_per_cu_data::set_lang(language) read.h:363 ... and: ... Previous write of size 1 at 0x7b2000003010 by main thread: #0 dwarf2_per_cu_data::set_lang(language) read.h:365 ... =20 Fix this by making per_cu->m_lang atomic. =20 Tested on x86_64-linux. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29286 Diff: --- gdb/dwarf2/read.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index acbe298b310..c2f86a9d367 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -181,7 +181,7 @@ private: std::atomic> m_unit_type {(dwarf_unit_type)0}; =20 /* The language of this CU. */ - packed m_lang =3D language_unknown; + std::atomic> m_lang {language_unknown}; =20 public: /* True if this CU has been scanned by the indexer; false if @@ -351,21 +351,25 @@ public: =20 enum language lang (bool strict_p =3D true) const { + enum language l =3D m_lang.load (); if (strict_p) - gdb_assert (m_lang !=3D language_unknown); - return m_lang; + gdb_assert (l !=3D language_unknown); + return l; } =20 void set_lang (enum language lang) { if (unit_type () =3D=3D DW_UT_partial) return; - if (m_lang =3D=3D language_unknown) - /* Set if not set already. */ - m_lang =3D lang; - else - /* If already set, verify that it's the same value. */ - gdb_assert (m_lang =3D=3D lang); + /* Set if not set already. */ + packed nope =3D language_unknown; + if (m_lang.compare_exchange_strong (nope, lang)) + return; + /* If already set, verify that it's the same value. */ + nope =3D lang; + if (m_lang.compare_exchange_strong (nope, lang)) + return; + gdb_assert_not_reached (); } =20 /* Free any cached file names. */