Re: [PATCH] Use backtrace() instead of __builtin_return_address()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bernhard Walle wrote:
When crash is compiled with gcc 4.3 and -O2, the __builtin_return_address()
causes crash to crash. See also [1] for a discussion about that. The gcc
documentation [2] says

	__builtin_return_address()

	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. In addition, __builtin_frame_address may be used to determine if
	the top of the stack has been reached.
	
	This function should only be used with a nonzero argument for debugging
	purposes.

Even the __builtin_frame_address() does not work here. Instead of checking
if the crash is built with -O2 and introducing new preprocessor checks here,
I use the backtrace() function which is available via glibc. This works here
(tested without the other patch which brought my attention to this bug).

Since crash only runs on Linux (IIRC), the glibc dependency should not be
a problem.

Signed-off-by: Bernhard Walle <bwalle@xxxxxxx>


[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=165992
[2] http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html

---
 defs.h |   10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

--- a/defs.h
+++ b/defs.h
@@ -1803,15 +1803,7 @@ struct alias_data {                 /* c
 static inline void
 save_return_address(ulong *retaddr)
 {
-	retaddr[0] = (ulong) __builtin_return_address(0);
-#if defined(X86) || defined(PPC) || defined(X86_64) || defined(PPC64)
-	if (__builtin_frame_address(1))
-		retaddr[1] = (ulong) __builtin_return_address(1);
-	if (__builtin_frame_address(2))
-                retaddr[2] = (ulong) __builtin_return_address(2);
-	if (__builtin_frame_address(3))
-                retaddr[3] = (ulong) __builtin_return_address(3);
-#endif
+	backtrace(retaddr, 4);
 }
#endif /* !GDB_COMMON */


A few questions on this one...

Do you know if this works OK on ia64, s390 and s390x?

For whatever reason, __builtin_return_address() used
to fail on those arches if the arg was anything but zero.
That's why it was restricted to the 4 arches above,
although that was a long time ago...

Compiling with warnings turned on yields:

  defs.h:1804: warning: implicit declaration of function ‘backtrace’

I haven't looked at the glibc sources, but I'm presuming it's
a "void backtrace(int)".

And __builtin_return_address() is still being called in getbuf() on a
zero-size memory allocation.

Anyway, I'm mostly concerned about not breaking the other arches.

Dave

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux