From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 75751 invoked by alias); 15 May 2015 17:40:57 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 75569 invoked by uid 48); 15 May 2015 17:40:53 -0000 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/66146] call_once not C++11-compliant on ppc64le Date: Fri, 15 May 2015 17:40:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 5.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.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: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-05/txt/msg01208.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66146 --- Comment #3 from Martin Sebor --- On Power, both glibc and AIX pthread_once behave the same way: i.e., they fail to clear the once flag on exception. The test case below mimics glibc's pthread_once and demonstrates the root cause of the problem: the cancellation handler is not invoked when an exception is thrown unless the pthread_cleanup_push/pop macros are compiled in C++ code. Simply recompiling glibc's pthread_once.c using a C++ compiler (and adding the apprpriate extern "C" decoration) should fix it. Until it's fixed, as a workaround, it seems that libstdc++ could clear the flag when an exception is thrown before propagating it out of call_once. $ cat t.c && gcc -O2 -Wall -c -fasynchronous-unwind-tables -g t.c && g++ -DMAIN -O2 -Wall t.o -pthread t.c && ./a.out #include #include extern int n; #if MAIN extern "C" void foo () { throw 0; } extern "C" void bar (void (*)()); int main () { try { bar (foo); } catch (...) { printf ("caught exception: pthread cleanup handler %sinvoked\n", n ? "" : "not "); } return n == 1 ? 0 : 1; } #else int n; #if __cplusplus extern "C" { #endif static void cleanup (void *arg) { ++n; } void bar (void (*pf)(void)) { pthread_cleanup_push (cleanup, 0); pf (); pthread_cleanup_pop (0); } #if __cplusplus } #endif #endif caught exception: pthread cleanup handler not invoked