From patchwork Thu Jul 20 14:40:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 791626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-458594-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="HYv4JcIK"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xCxRH4VkLz9s3T for ; Fri, 21 Jul 2017 00:41:14 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=fX+IiFMWvlZDTCkzknk3GtBoHrlMRT5vPkChVnbtzmxC4SU4HEFii wpMIx3/C484wPZXTa6iuuMw0705cPUK+mum14/9MBORu6Bsl/1EgwKRqpdeHJNaJ XrzRuLZFPCZZPOMjjDpEzqUCD7t553nYHKPBvUr6omVKEMXtumdRKY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=sz17/UcY5Rgf3QlwAVDQVjcCAZM=; b=HYv4JcIKPMRbgvpx80w2 Lwgx/uDg1Kl3MmViAaw3/gt6OBVIsMOf14iBD+ulaxo5Fv4TtIP2gnrH1CtbP7Rp QsAUB4uN73tJYI+p9CzTan149kpbnSjiVMgv89mNiye0OYwzmYnTqc/xuGIlVTMj fV6Q2snNuOwgmvRVSHTuLEk= Received: (qmail 109921 invoked by alias); 20 Jul 2017 14:41:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 108502 invoked by uid 89); 20 Jul 2017 14:41:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:intra, Alternative, announce X-HELO: smtp.ispras.ru Received: from bran.ispras.ru (HELO smtp.ispras.ru) (83.149.199.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Jul 2017 14:41:01 +0000 Received: from monopod.intra.ispras.ru (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id 2A5B15FB8B for ; Thu, 20 Jul 2017 17:40:59 +0300 (MSK) Date: Thu, 20 Jul 2017 17:40:28 +0300 (MSK) From: Alexander Monakov To: gcc-patches@gcc.gnu.org Subject: [PATCH] toplev: avoid recursive emergency_dump_function Message-ID: User-Agent: Alpine 2.20.13 (LNX 116 2015-12-14) MIME-Version: 1.0 Hi, Segher pointed out on IRC that ICE reporting with dumps enabled got worse: if emergency_dump_function itself leads to an ICE (e.g. by segfaulting), nested ICE reporting will invoke emergency_dump_function in exactly the same context, but not only would we uselessly announce current pass again, this time around the second SIGSEGV will just terminate cc1 because the signal handler is unregistered (so we won't print the backtrace). Sorry for not really considering the implications when submitting that patch. Solve this by substituting the callback for global_dc->internal_error; this avoids invoking emergency_dump_function, and also gives a convenient point to flush the dump file. OK to apply? * topvel.c (dumpfile.h): New include. (internal_error_reentered): New static function. Use it... (internal_error_function): ...here to handle reentered internal_error. diff --git a/gcc/toplev.c b/gcc/toplev.c index e6c69a4..67254fb 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -80,6 +80,7 @@ along with GCC; see the file COPYING3. If not see #include "hsa-common.h" #include "edit-context.h" #include "tree-pass.h" +#include "dumpfile.h" #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO) #include "dbxout.h" @@ -1064,11 +1065,22 @@ open_auxiliary_file (const char *ext) return file; } +/* Alternative diagnostics callback for reentered ICE reporting. */ + +static void +internal_error_reentered (diagnostic_context *, const char *, va_list *) +{ + /* Flush the dump file if emergency_dump_function itself caused an ICE. */ + if (dump_file) + fflush (dump_file); +} + /* Auxiliary callback for the diagnostics code. */ static void internal_error_function (diagnostic_context *, const char *, va_list *) { + global_dc->internal_error = internal_error_reentered; warn_if_plugins (); emergency_dump_function (); }