From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24732 invoked by alias); 8 Sep 2005 01:43:52 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24721 invoked by uid 48); 8 Sep 2005 01:43:48 -0000 Date: Thu, 08 Sep 2005 01:43:00 -0000 Message-ID: <20050908014348.24720.qmail@sourceware.org> From: "normbograham at yahoo dot com" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20021128051601.8743.eddy@opera.no> References: <20021128051601.8743.eddy@opera.no> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault X-Bugzilla-Reason: CC X-SW-Source: 2005-09/txt/msg00903.txt.bz2 List-Id: ------- Additional Comments From normbograham at yahoo dot com 2005-09-08 01:43 ------- Ed: I also have the same problem, but a little thought gives you a good work- around. First a little background. There is a function that calls main. This is the last function on the stack you can query using __builtin_return_address. If you query who calls that function you get a seg "fault" , quicker then grass through a goose. They should have called their __builtin_return_address(0) logic from there and stored the address, stopping future calls to this function from going further. This is exactly what you can do from main. (This is your workaround) Call _builtin_return_address(0) from main, store the result to a global, and you can compare against this address in the future (provided your not in an at_exit, or on_exit function call stack). Of course you've got to turn optimization off (-O0), I think or the results could be silly. Then you can query back to the main function (or one up if you wish to the boot-up routine.). Again: Dont be silly, turn off optmization (or function calls will colapse), store the result from main, and DONT call from "onexit" or "atexit" routines. good luck. n. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743