Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Andrew Haley <aph@redhat.com>
Cc: Ulrich Drepper <drepper@redhat.com>,
	        Mark Kettenis <mark.kettenis@xs4all.nl>,
	gcc@gcc.gnu.org,         libc-alpha@sources.redhat.com,
	gdb@sourceware.org,         Jakub Jelinek <jakub@redhat.com>,
	Richard Henderson <rth@redhat.com>
Subject: Re: Unwinding CFI gcc practice of assumed `same value' regs
Date: Tue, 12 Dec 2006 15:50:00 -0000	[thread overview]
Message-ID: <20061212154958.GA20103@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <17790.51754.814267.773596@zebedee.pink>

[-- Attachment #1: Type: text/plain, Size: 2866 bytes --]

On Tue, 12 Dec 2006 16:26:34 +0100, Andrew Haley wrote:
...
> It's certainly an inconsistency in the specification, which says that
> null-termination is supported, and this implies that you can't put a zero in
> there.

I tested now that you can put the zero there for both the libgcc unwinder and
for gdb(1) [tested only Fedora Core gdb-6.5-13.fc6],
attached, on x86_64 compile [gcc-4.1.1-30] and run by:
	gcc -o fp0-x86_64 -O9 -fomit-frame-pointer -Wall fp0-x86_64.c -ggdb3; ./fp0-x86_64

The output provided at the end of this mail.

Therefore I believe this sentence is wrong and it should be removed:
	http://www.x86-64.org/documentation/abi.pdf (draft 0.98) Page 28 (29/124) 
	%rbp ... but the user code should mark the deepest stack frame by
	     %setting the frame pointer to zero.

On the other hand the right stack terminator for libgcc unwinder is `PC == 0':
unwind-dw2.c:uw_frame_state_for ():
	if (context->ra == 0)
		return _URC_END_OF_STACK;

And gdb should just get updated to behave the same way.
libunwind already assumed end of stack on `PC == 0' before and I do not expect
any platform would consider `PC == 0' as a valid _return_address_ (which is
usually several bytes after any starting function address due to the call
instruction).

...
> "All of these" might be the right way to go.  That is, keep
> null-terminating the stack, strengthen the rules about what you might
> do with %ebp, and extend debuginfo.

For best compatibility null terminate the stack but by CFI and its indicated
return address. Do not use %rbp (frame pointer register) in any way (regarding
the stack termination condition).
Believe only CFI-specified CFA address, unrelated to %rbp content.


Regards,
Jan

------------------------------------------------------------------------------

GNU gdb Red Hat Linux (6.5-13.fc6rh)
This GDB was configured as "x86_64-redhat-linux-gnu"...Using host libthread_db library "/lib64/libthread_db.so.1".

(gdb) b 12
Breakpoint 1 at 0x40060b: file fp0-x86_64.c, line 12.
(gdb) r
Starting program: /root/jkratoch/redhat/unwind/fp0-x86_64 

Breakpoint 1, backtracer () at fp0-x86_64.c:12
12		int i = backtrace (buf, 512);
(gdb) bt
#0  backtracer () at fp0-x86_64.c:12
#1  0x0000000000400739 in badone () at fp0-x86_64.c:31
#2  0x000000000040074e in main () at fp0-x86_64.c:47
(gdb) p/x $rbp
$1 = 0x7fff6ed61ca0
(gdb) up
#1  0x0000000000400739 in badone () at fp0-x86_64.c:31
31		backtracer ();
(gdb) p/x $rbp
$2 = 0x0
(gdb) c
Continuing.
dummy
5
/root/jkratoch/redhat/unwind/fp0-x86_64[0x40062c]
/root/jkratoch/redhat/unwind/fp0-x86_64[0x400739]
/root/jkratoch/redhat/unwind/fp0-x86_64[0x40074e]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x301e81da44]
/root/jkratoch/redhat/unwind/fp0-x86_64[0x400559]

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400684 in backtracer () at fp0-x86_64.c:21
21		RAFA(1);
(gdb) q

[-- Attachment #2: fp0-x86_64.c --]
[-- Type: text/plain, Size: 842 bytes --]

#include <pthread.h>
#include <execinfo.h>
#include <stdio.h>
#include <unistd.h>


static void backtracer (void) __attribute__((__noinline__));
static void backtracer (void)
{
	void *buf[512];
	puts("dummy");
	int i = backtrace (buf, 512);
	printf ("%d\n", i);
	fflush (stdout);
	backtrace_symbols_fd (buf, i, STDOUT_FILENO);
#define RAFA(level)					\
	printf("RA (%d) = %p, FA (%d) = %p\n",		\
	       level, __builtin_return_address (level),	\
	       level, __builtin_frame_address (level))
	RAFA(0);
	RAFA(1);
	RAFA(2);
	RAFA(3);
	RAFA(4);
	RAFA(5);
}

static int badone (void) __attribute__((__noinline__));
static int badone (void)
{
	backtracer ();
	return 0;
}

asm(
"	.text		\n"
"clearstack:		\n"
"	pushq	$0	\n"
"	popq	%rax	\n"
"	ret		\n"
);
extern void clearstack(void);

int main (void)
{
	clearstack ();
	badone ();
	return 0;
}

  parent reply	other threads:[~2006-12-12 15:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-11 19:03 Jan Kratochvil
2006-12-11 22:40 ` Roland McGrath
2006-12-12 15:54   ` Jakub Jelinek
2006-12-12 13:55 ` Andrew Haley
2006-12-12 14:55   ` Mark Kettenis
2006-12-12 15:04     ` Andrew Haley
2006-12-12 15:21       ` Ulrich Drepper
2006-12-12 15:26         ` Andrew Haley
2006-12-12 15:39           ` Ulrich Drepper
2006-12-13 18:11             ` Michael Matz
2006-12-12 15:50           ` Jan Kratochvil [this message]
2006-12-12 16:19           ` Jakub Jelinek
2006-12-12 16:55       ` Ian Lance Taylor
2006-12-12 17:06         ` Andrew Haley
2006-12-12 17:34           ` Mark Kettenis
2006-12-13 18:02           ` Michael Matz
2006-12-13 18:10 ` Michael Matz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061212154958.GA20103@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=aph@redhat.com \
    --cc=drepper@redhat.com \
    --cc=gcc@gcc.gnu.org \
    --cc=gdb@sourceware.org \
    --cc=jakub@redhat.com \
    --cc=libc-alpha@sources.redhat.com \
    --cc=mark.kettenis@xs4all.nl \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox