public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <20021128051601.8743.eddy@opera.no>
@ 2003-07-18 23:16 ` dhazeghi at yahoo dot com
  2005-08-20  0:57 ` [Bug middle-end/8743] " pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: dhazeghi at yahoo dot com @ 2003-07-18 23:16 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743


dhazeghi at yahoo dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2003-07-18 23:16:07
               date|                            |


------- Additional Comments From dhazeghi at yahoo dot com  2003-07-18 23:16 -------
Confirmed still present with gcc 3.3 branch and mainline (20030717).


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <20021128051601.8743.eddy@opera.no>
  2003-07-18 23:16 ` [Bug c/8743] receiving result from __builtin_return_address() beyond stack top causes segfault dhazeghi at yahoo dot com
@ 2005-08-20  0:57 ` pinskia at gcc dot gnu dot org
  2005-08-20  2:14 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-20  0:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-08-20 00:57 -------
This is just a doc problem really.  Also note __builtin_return_address for other than 0 is just for 
debuging puposes.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |documentation


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <20021128051601.8743.eddy@opera.no>
  2003-07-18 23:16 ` [Bug c/8743] receiving result from __builtin_return_address() beyond stack top causes segfault dhazeghi at yahoo dot com
  2005-08-20  0:57 ` [Bug middle-end/8743] " pinskia at gcc dot gnu dot org
@ 2005-08-20  2:14 ` pinskia at gcc dot gnu dot org
  2005-08-25 11:25 ` eddy at opera dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-08-20  2:14 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |minor


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <20021128051601.8743.eddy@opera.no>
                   ` (2 preceding siblings ...)
  2005-08-20  2:14 ` pinskia at gcc dot gnu dot org
@ 2005-08-25 11:25 ` eddy at opera dot com
  2005-09-08  1:43 ` normbograham at yahoo dot com
  2005-09-08  7:54 ` eddy at opera dot com
  5 siblings, 0 replies; 9+ messages in thread
From: eddy at opera dot com @ 2005-08-25 11:25 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From eddy at opera dot com  2005-08-25 11:19 -------
Subject: Re:  receiving result from __builtin_return_address() beyond stack top causes segfault

> This is just a doc problem really.

If it is "just a doc problem" then the doc needs to change to say:

   __builtin_return_address(0) returns the address to which the
   current function will return; __builtin_return_address(1+n) may
   crash but if you're lucky it'll give the address to which the
   function indicated by __builtin_return_address(n) will return.
   This function is only provided for debug purposes.

but I'm deeply skeptical.  The function should either *not* take a
parameter (how far up the stack to look) or *not* crash when that
parameter is supplied or have some predictable way of knowing what
values to not pass as parameter if you don't want to crash.  Since the
pattern of calls that doesn't crash (i.e. my work-around, see earlier
notes on this bug) depends on hardware architecture, this means the
code needs to change, even if the documentation is changed.

	Eddy.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <20021128051601.8743.eddy@opera.no>
                   ` (3 preceding siblings ...)
  2005-08-25 11:25 ` eddy at opera dot com
@ 2005-09-08  1:43 ` normbograham at yahoo dot com
  2005-09-08  7:54 ` eddy at opera dot com
  5 siblings, 0 replies; 9+ messages in thread
From: normbograham at yahoo dot com @ 2005-09-08  1:43 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <20021128051601.8743.eddy@opera.no>
                   ` (4 preceding siblings ...)
  2005-09-08  1:43 ` normbograham at yahoo dot com
@ 2005-09-08  7:54 ` eddy at opera dot com
  5 siblings, 0 replies; 9+ messages in thread
From: eddy at opera dot com @ 2005-09-08  7:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From eddy at opera dot com  2005-09-08 07:54 -------
Subject: Re:  receiving result from __builtin_return_address() beyond stack top causes segfault

Yes, that's one of the work-arounds I considered: but has an
inconvenient problem - when shared libraries are loading, _start (the
function that calls main) hasn't yet been entered and main hasn't yet
recorded its address.  This means we have to not record the call-stack
when our global variable recording main's caller's address is as yet
unset.  Indeed, using ccmalloc got me a segfault before main was
entered in exactly this way, since it doesn't (or didn't, back when I
reported this bug - it's about time I had another look at ccmalloc) do
the work-around just described.

	Eddy.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <bug-8743-4@http.gcc.gnu.org/bugzilla/>
  2012-06-18 19:34 ` gcc at kalvdans dot no-ip.org
  2012-06-19  9:18 ` rguenth at gcc dot gnu.org
@ 2015-06-29 15:23 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2015-06-29 15:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #12 from Martin Sebor <msebor at gcc dot gnu.org> ---
A GCC patch to issue a warning for potentially unsafe calls to
__builtin_return_address() and __builtin_frame_address() posted here:

https://gcc.gnu.org/ml/gcc-patches/2015-06/msg00886.html


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <bug-8743-4@http.gcc.gnu.org/bugzilla/>
  2012-06-18 19:34 ` gcc at kalvdans dot no-ip.org
@ 2012-06-19  9:18 ` rguenth at gcc dot gnu.org
  2015-06-29 15:23 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-06-19  9:18 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX

--- Comment #11 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-06-19 09:18:12 UTC ---
Indeed.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/8743] receiving result from __builtin_return_address() beyond stack top causes segfault
       [not found] <bug-8743-4@http.gcc.gnu.org/bugzilla/>
@ 2012-06-18 19:34 ` gcc at kalvdans dot no-ip.org
  2012-06-19  9:18 ` rguenth at gcc dot gnu.org
  2015-06-29 15:23 ` msebor at gcc dot gnu.org
  2 siblings, 0 replies; 9+ messages in thread
From: gcc at kalvdans dot no-ip.org @ 2012-06-18 19:34 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8743

Christian Häggström <gcc at kalvdans dot no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gcc at kalvdans dot
                   |                            |no-ip.org

--- Comment #10 from Christian Häggström <gcc at kalvdans dot no-ip.org> 2012-06-18 19:34:23 UTC ---
I guess this bug can be closed now, my gcc 4.7 documentation states:

 -- Built-in Function: void * __builtin_return_address (unsigned int LEVEL)
[...]
     On some machines it may be impossible to determine the return
     address of any function other than the current one; in such cases,
     or when the top of the stack has been reached, this function will
     return `0' or a random value.
[...]
     This function should only be used with a nonzero argument for
     debugging purposes.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-06-29 15:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20021128051601.8743.eddy@opera.no>
2003-07-18 23:16 ` [Bug c/8743] receiving result from __builtin_return_address() beyond stack top causes segfault dhazeghi at yahoo dot com
2005-08-20  0:57 ` [Bug middle-end/8743] " pinskia at gcc dot gnu dot org
2005-08-20  2:14 ` pinskia at gcc dot gnu dot org
2005-08-25 11:25 ` eddy at opera dot com
2005-09-08  1:43 ` normbograham at yahoo dot com
2005-09-08  7:54 ` eddy at opera dot com
     [not found] <bug-8743-4@http.gcc.gnu.org/bugzilla/>
2012-06-18 19:34 ` gcc at kalvdans dot no-ip.org
2012-06-19  9:18 ` rguenth at gcc dot gnu.org
2015-06-29 15:23 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).