From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id CCD7D3853D46; Thu, 17 Nov 2022 18:44:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCD7D3853D46 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668710681; bh=nq9pchvciwbpWBeMGti9iLkOt1gZk7lNy1gmlWibVLo=; h=From:To:Subject:Date:From; b=FD2vARLVXpbZNHkixMlsOnyG3AbhnXLWW6cwx84s2C1gEPy++dCRQaI5bv3l3mBu6 gVzONKiHXcj6MRpPPb/JrTXrsNw1BhYS6SKjL5Nxb1cVWIK76uwyldeZwqN2PimkSb qEAWKEGzlFvicNbX/Obzxkuscb6mwrdBFCAi/wrE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix static initialization order problem in windows-nat.c X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 2368c6bf61cc815e124a88f3414c35aff2022b6d X-Git-Newrev: c83b95d88feed26eb04f7eca97c08e3ace0b7cbb Message-Id: <20221117184441.CCD7D3853D46@sourceware.org> Date: Thu, 17 Nov 2022 18:44:41 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc83b95d88fee= d26eb04f7eca97c08e3ace0b7cbb commit c83b95d88feed26eb04f7eca97c08e3ace0b7cbb Author: Tom Tromey Date: Tue Nov 8 12:14:20 2022 -0700 Fix static initialization order problem in windows-nat.c =20 This patch fixes a static initialization order problem in windows-nat.c that was pointed out by Jon Turney. The underlying problem is that the windows_nat_target constructor relies on serial_logfile already being constructed, but this is not enforced by C++ rules. This patch fixes the problem by initializing the global windows_nat_target later. Diff: --- gdb/windows-nat.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 6250cbc27a5..5d506507b6d 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -384,7 +384,9 @@ private: bool m_is_async =3D false; }; =20 -static windows_nat_target the_windows_nat_target; +/* This is a pointer and not a global specifically to avoid a C++ + "static initializer fiasco" situation. */ +static windows_nat_target *the_windows_nat_target; =20 static void check (BOOL ok, const char *file, int line) @@ -620,7 +622,7 @@ windows_nat_target::delete_thread (ptid_t ptid, DWORD e= xit_code, target_pid_to_str (ptid).c_str (), (unsigned) exit_code); =20 - ::delete_thread (find_thread_ptid (&the_windows_nat_target, ptid)); + ::delete_thread (find_thread_ptid (the_windows_nat_target, ptid)); =20 auto iter =3D std::find_if (windows_process.thread_list.begin (), windows_process.thread_list.end (), @@ -3118,7 +3120,8 @@ _initialize_windows_nat () calling x86_set_debug_register_length function in processor windows specific native file. */ =20 - add_inf_child_target (&the_windows_nat_target); + the_windows_nat_target =3D new windows_nat_target; + add_inf_child_target (the_windows_nat_target); =20 #ifdef __CYGWIN__ cygwin_internal (CW_SET_DOS_FILE_WARNING, 0);