From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 373D2385355A; Wed, 8 Jun 2022 05:19:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 373D2385355A From: "chrisj at rtems dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/105880] New: eh_globals_init destructor not setting _M_init to false Date: Wed, 08 Jun 2022 05:19:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 12.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: chrisj at rtems dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 05:19:25 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105880 Bug ID: 105880 Summary: eh_globals_init destructor not setting _M_init to false Product: gcc Version: 12.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: chrisj at rtems dot org Target Milestone: --- RTEMS 6 with GCC 12 (gcc version 12.1.1 20220509 (RTEMS 6, RSB e73a258a3aa4af8735b589a2d770571b2105ac5f, Newlib 64b2081) (GCC)) is calling `std::terminate()` in `__cxa_get_globals()`. The `_M_init` value is `true` after the static destructor has run. RTEMS is tracking the issue with https://devel.rtems.org/ticket/4661. When `exit()` is called the static destructor for `eh_gloabls init` runs and deletes the POSIX key however the `_M_init` variable is not set to false. Later `__cxxabiv1::__cxa_get_globals()` is called and sees `_M_init` is `tr= ue` so attempts to get the POSIX key value. This fails because the key has been deleted so `NULL` is returned. Memory is allocated and the set fails because there is no key so `std::terminate()` is called. The issue is `init._M_init` is not set to false in the static destructor. T= he code for aarch64 and arm is: 006562e0 <__eh_globals_init::~__eh_globals_init()>: 6562e0: 7903 ldrb r3, [r0, #4] 6562e2: b510 push {r4, lr} 6562e4: 4604 mov r4, r0 6562e6: b90b cbnz r3, 6562ec <__eh_globals_init::~__eh_globals_init()+0xc> 6562e8: 4620 mov r0, r4 6562ea: bd10 pop {r4, pc} 6562ec: 6800 ldr r0, [r0, #0] 6562ee: f04d fe6b bl 6a3fc8 6562f2: 4620 mov r0, r4 6562f4: bd10 pop {r4, pc} 0000000010222c30 <__eh_globals_init::~__eh_globals_init()>: 10222c30: 39401001 ldrb w1, [x0, #4] 10222c34: 35000041 cbnz w1, 10222c3c <__eh_globals_init::~__eh_globals_init()+0xc> 10222c38: d65f03c0 ret 10222c3c: a9bf7bfd stp x29, x30, [sp, #-16]! 10222c40: 910003fd mov x29, sp return pthread_key_delete (__key); 10222c44: b9400000 ldr w0, [x0] 10222c48: 94008806 bl 10244c60 10222c4c: a8c17bfd ldp x29, x30, [sp], #16 10222c50: d65f03c0 ret=