From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101456 invoked by alias); 14 May 2015 15:05:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 101444 invoked by uid 89); 14 May 2015 15:05:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 14 May 2015 15:05:14 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4EF5BtG025209 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 14 May 2015 11:05:12 -0400 Received: from localhost.localdomain (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4EF5BQS025927; Thu, 14 May 2015 11:05:11 -0400 Message-ID: <5554B9A7.8000108@redhat.com> Date: Thu, 14 May 2015 15:15:00 -0000 From: Jeff Law User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Eric Botcazou , gcc-patches@gcc.gnu.org Subject: Re: [patch] Update SJLJ buffer after dynamic stack allocation References: <1931342.tuu8H0PoOE@polaris> In-Reply-To: <1931342.tuu8H0PoOE@polaris> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2015-05/txt/msg01332.txt.bz2 On 05/13/2015 04:45 AM, Eric Botcazou wrote: > Hi, > > the SJLJ EH schemes manipulate a buffer that contains a few pointers and, in > particular, the stack pointer. Therefore, when dynamic stack allocation is > also used, you need to update its value in the buffer, otherwise Bad Things > will happen if you resume execution where the stack is shifted. > > GNAT uses a manual SJLJ EH scheme that is piggybacked on the __builtin_setjmp > __builtin_longjmp machinery and has this block in gcc-interface/decl.c: > > /* If we are defining an object with variable size or an object with > fixed size that will be dynamically allocated, and we are using the > setjmp/longjmp exception mechanism, update the setjmp buffer. */ > if (definition > && Exception_Mechanism == Setjmp_Longjmp > && get_block_jmpbuf_decl () > && DECL_SIZE_UNIT (gnu_decl) > && (TREE_CODE (DECL_SIZE_UNIT (gnu_decl)) != INTEGER_CST > || (flag_stack_check == GENERIC_STACK_CHECK > && compare_tree_int (DECL_SIZE_UNIT (gnu_decl), > STACK_CHECK_MAX_VAR_SIZE) > 0))) > add_stmt_with_node (build_call_n_expr > (update_setjmp_buf_decl, 1, > build_unary_op (ADDR_EXPR, NULL_TREE, > get_block_jmpbuf_decl ())), > gnat_entity); > > It is necessary if you want to pass the ACATS testsuite. > > But the regular SJLJ scheme (--enable-sjlj-exceptions) doesn't do this update > and, therefore, doesn't play nice with dynamic stack allocation. It's a long- > standing issue and you can find messages about it in the archives. On the > other hand, this update has always been done for non-local gotos (they also > use a buffer, the non-local goto save area). > > The attached patch implements this update for the regular SJLJ scheme and > yields a clean ACATS testsuite. Tested on x86_64-suse-linux with --enable- > sjlj-exceptions, OK for the mainline? > > > 2015-05-13 Eric Botcazou > Tristan Gingold > > * insn-notes.def (UPDATE_SJLJ_CONTEXT): New note. > * builtins.c (expand_builtin_update_setjmp_buf): Make global. > (expand_stack_restore): Call record_new_stack_level. > (expand_stack_save): Do not call do_pending_stack_adjust. > * builtins.h (expand_builtin_update_setjmp_buf): Declare. > * calls.c (expand_call): Call record_new_stack_level for alloca. > * except.c (sjlj_mark_call_sites): Expand builtin_update_setjmp_buf > wherever a NOTE_INSN_UPDATE_SJLJ_CONTEXT note is present. > (update_sjlj_context): New global function. > * except.h (update_sjlj_context): Declare. > * explow.c (record_new_stack_level): New global function. > (allocate_dynamic_stack_space): Call record_new_stack_level. > * explow.h (record_new_stack_level): Declare. > * final.c (final_scan_insn): Deal with NOTE_INSN_UPDATE_SJLJ_CONTEXT. > * cfgrtl.c (duplicate_insn_chain): Likewise. OK. Thanks for tackling this. jeff