From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dmitry Antipov Newsgroups: gmane.emacs.devel Subject: Re: Avoid C stack overflow Date: Fri, 14 Mar 2014 15:27:46 +0400 Message-ID: <5322E7B2.7080204@yandex.ru> References: <5321E00C.2010107@yandex.ru> <5321F18D.5080008@cs.ucla.edu> <532297FB.7090608@yandex.ru> <5322A8DE.3080109@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1394796478 1224 80.91.229.3 (14 Mar 2014 11:27:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 14 Mar 2014 11:27:58 +0000 (UTC) Cc: Emacs development discussions To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Mar 14 12:28:07 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WOQHX-00033K-7s for ged-emacs-devel@m.gmane.org; Fri, 14 Mar 2014 12:28:07 +0100 Original-Received: from localhost ([::1]:44038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WOQHW-0006wi-Pz for ged-emacs-devel@m.gmane.org; Fri, 14 Mar 2014 07:28:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WOQHN-0006oT-Kb for emacs-devel@gnu.org; Fri, 14 Mar 2014 07:28:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WOQHH-0004kb-MM for emacs-devel@gnu.org; Fri, 14 Mar 2014 07:27:57 -0400 Original-Received: from forward9l.mail.yandex.net ([84.201.143.142]:54463) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WOQHH-0004kP-8K for emacs-devel@gnu.org; Fri, 14 Mar 2014 07:27:51 -0400 Original-Received: from smtp13.mail.yandex.net (smtp13.mail.yandex.net [95.108.130.68]) by forward9l.mail.yandex.net (Yandex) with ESMTP id A213CE610F1; Fri, 14 Mar 2014 15:27:47 +0400 (MSK) Original-Received: from smtp13.mail.yandex.net (localhost [127.0.0.1]) by smtp13.mail.yandex.net (Yandex) with ESMTP id 2D04BE40060; Fri, 14 Mar 2014 15:27:47 +0400 (MSK) Original-Received: from unknown (unknown [37.139.80.10]) by smtp13.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id dzyewSE5F8-RkqOA0iL; Fri, 14 Mar 2014 15:27:46 +0400 (using TLSv1 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) X-Yandex-Uniq: 9b8ee5b3-5000-4613-8077-c95c92d03ef5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1394796466; bh=C6aajLVGv0j0StzIFeJPvCWcZ7q0guuE4kib7QWfF6U=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=cwFxgBh4nO7jIO+XkR5iYzsUOJusGS1DSoReT89Xub0XzXZu7OopG4/a3VZbueVNU Vb8Nsoai+nVAVHlZnN1QPDZXF8bqj5Uni5Nk0yUTYPALcsPcvLb7OykZ1edgpVVDqi k/shxKZPV7glV6Wp/T9TvGsAksEqCMoYDoYpIobw= Authentication-Results: smtp13.mail.yandex.net; dkim=pass header.i=@yandex.ru User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 In-Reply-To: <5322A8DE.3080109@cs.ucla.edu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 84.201.143.142 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:170352 Archived-At: On 03/14/2014 10:59 AM, Paul Eggert wrote: > Good point, I forgot about the stack-scanning problem. After reading http://gcc.gnu.org/wiki/SplitStacks and looking into libgcc sources, this looks reasonably simple: === modified file 'src/alloc.c' --- src/alloc.c 2014-02-28 21:45:34 +0000 +++ src/alloc.c 2014-03-14 11:17:42 +0000 @@ -4866,11 +4866,30 @@ #endif /* not GC_SAVE_REGISTERS_ON_STACK */ #endif /* not HAVE___BUILTIN_UNWIND_INIT */ +#ifdef SPLIT_STACK + + /* This assumes gcc >= 4.6.0 with -fsplit-stack + and corresponding support in libgcc. */ + { + size_t stack_size; + extern void * __splitstack_find (void *, void *, size_t *, + void **, void **, void **); + void *next_segment = NULL, *next_sp = NULL, *initial_sp = NULL, *stack; + + while ((stack = __splitstack_find (next_segment, next_sp, &stack_size, + &next_segment, &next_sp, &initial_sp))) + mark_memory (stack, (char *) stack + stack_size); + } + +#else /* not SPLIT_STACK */ + /* This assumes that the stack is a contiguous region in memory. If that's not the case, something has to be done here to iterate over the stack segments. */ mark_memory (stack_base, end); +#endif /* SPLIT_STACK */ + /* Allow for marking a secondary stack, like the register stack on the ia64. */ #ifdef GC_MARK_SECONDARY_STACK After compiling with CPPFLAGS='-DSPLIT_STACK' and CFLAGS='-O0 -fsplit-stack -g3', I even got the binary which doesn't crash immediately (but do it somewhat later, after a long byte-compile run :-(). Dmitry