From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29794 invoked by alias); 30 Nov 2012 21:10:02 -0000 Received: (qmail 29768 invoked by uid 22791); 30 Nov 2012 21:10:01 -0000 X-SWARE-Spam-Status: No, hits=-5.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-wg0-f53.google.com (HELO mail-wg0-f53.google.com) (74.125.82.53) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 30 Nov 2012 21:09:51 +0000 Received: by mail-wg0-f53.google.com with SMTP id ei8so325487wgb.8 for ; Fri, 30 Nov 2012 13:09:50 -0800 (PST) Received: by 10.180.72.232 with SMTP id g8mr45656034wiv.0.1354309790488; Fri, 30 Nov 2012 13:09:50 -0800 (PST) Received: from [192.168.1.7] (16.122.69.86.rev.sfr.net. [86.69.122.16]) by mx.google.com with ESMTPS id p2sm516565wic.7.2012.11.30.13.09.48 (version=SSLv3 cipher=OTHER); Fri, 30 Nov 2012 13:09:49 -0800 (PST) Message-ID: <1354309786.2662.18.camel@mathieu-UX21E> Subject: Re: using -fsplit-stack From: mathieu lacage To: Ian Lance Taylor Cc: gcc-help@gcc.gnu.org Date: Fri, 30 Nov 2012 21:10:00 -0000 In-Reply-To: References: <1354284795.6211.28.camel@mathieu-UX21E> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg00226.txt.bz2 On Fri, 2012-11-30 at 07:16 -0800, Ian Lance Taylor wrote: > On Fri, Nov 30, 2012 at 6:13 AM, mathieu lacage > wrote: > > > > $ gcc -fsplit-stack ./test.c -o test > > $ ./test > > hello 0x7fbecfd58960 > > Segmentation fault (core dumped) > > You neglected to say which version of GCC you are using. Ah.yes, sorry. gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 > > I tried your test case with both GCC mainline and the GCC 4.7 branch, > and it worked fine. But I am using the gold linker, not GNU ld. > > > > Obviously, the same test will also segfault without -fsplit-stack but > > now, it segfaults with an interesting backtrace: > > I don't really see why this test will segfault without using > -fsplit-stack. For me it works fine without -fsplit-stack, which is > what I would expect. Well, it seems to be segfaulting on my box because the default stack space is smaller that the above (big ?) array. Program received signal SIGSEGV, Segmentation fault. 0x0000000000400597 in main () (gdb) bt #0 0x0000000000400597 in main () (gdb) disas Dump of assembler code for function main: 0x000000000040058c <+0>: push %rbp 0x000000000040058d <+1>: mov %rsp,%rbp 0x0000000000400590 <+4>: sub $0x9896a0,%rsp => 0x0000000000400597 <+11>: mov %edi,-0x989694(%rbp) > > 1) I have disassembled the generated code and I see one symbol that > > appears to be related to this:__morestack > > Is there documentation somewhere on the exact semantics that is supposed > > to be provided by this function ? Are there other functions that the > > stack-split code will potentially call ? > > The detailed documentation on that internal function are in the source > code. libgcc/config/i386/morestack.S. Thanks a lot for this pointer ! > > gold -lc ./test.o -o test > > gold: error: ./test.o: could not convert call to '__morestack' to > > '__morestack_non_split' > > ./test.o:test.c:function main: error: undefined reference to > > '__morestack' > > You neglected to say which version of gold you are using. In any Right, my bad. GNU gold (GNU Binutils for Ubuntu 2.22.90.20120924) 1.11 > case, note that you should not invoke gold directly. You should > arrange for the GCC driver to invoke it on your behalf. Otherwise you > won't get the right files. The way to do this is to install gold > under the name "ld" in some directory DIR, and pass the option -BDIR > to gcc. You can use gcc -Wl,-debug to see precisely which linker gcc > is running, and make sure that it is gold and not GNU ld. thanks for the hint: this is especially useful. How is this expected to fail if I am not using gold ? (at link-time or run-time ?) > > > But, anyway, I can't see how that link-time code change would work for > > libraries. Say, binary A links to B and C. A and B are stack-split. C > > is not. What is the linker going to do ?. > > The linker adjusts the code on a function by function basis, based on > whether the function calls a non-split-stack function or not. The > general scheme is outlined on the wiki page: > http://gcc.gnu.org/wiki/SplitStacks . ok > > 4) Any data on CPU/memory performance for using -fsplit-stack ? i.e., > > what would be the downsides of compiling everything with this feature > > on ? > > I don't have any precise measurements. The cost of code that does not > split the stack is low: a few additional instructions per function > call. This is unlikely to make any difference except perhaps in a > program that is heavily CPU bound and makes lots of function calls in > tight loops. However, actually splitting the stack is relatively > expensive because it requires a couple of system calls. That can add > up pretty quickly if you have a tight loop that winds up needing to > split the stack to an unfortunate coincidence of available stack space > and the stack requirements of the function being called. Are you aware of anyone who has tried to rebuild a distribution with this flag and make the system gcc use this flag by default? It would be nice from a usability perspective to not have to worry about stack size ever without having to pay too high for this. Mathieu