-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arch/x86: Fix comments about stack frame with -pg / -mfentry #96
Conversation
55f36d7
to
e673670
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to describe the addresses before mcount adjusts the stack pointer. Note that in -pg
case, the "%rsp" might be changed already for local variables, so you should be "%rbp" to get the addresses. On the other hand, in -pg -mfentry
case, the "%rbp" is not set yet.
4aa4daf
to
1c00c03
Compare
@namhyung , I modified the comments again based on your mention. |
arch/x86_64/fentry.S
Outdated
@@ -1,8 +1,44 @@ | |||
/* argument passing: %rdi, %rsi, %rdx, %rcx, %r8, %r9 */ | |||
/* return value: %rax */ | |||
/* callee saved: %rbx, %rbp, %rsp, %r12-r15 */ | |||
/* stack frame (with -pg): return addr = 8(%rbp), prev fp = 0(%rbp) */ | |||
/* stack frame (with -fentry): return addr = (%rsp), prev fp = 8(%rsp) */ | |||
/* stack frame (with -pg -mfentry): parent location = addr of 52(%rsp), child ip = 48(%rsp) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
52 seems wrong. And I'd like to see stack frame info at the beginning of mcount() - not after libmcount.so:mcount subtracts the stack pointer. Also please just show parent addr and child addr like "parent addr = 8(%rsp), child addr = (%rsp)"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, parent addr is 56(%rsp), right ? https://github.com/namhyung/uftrace/blob/master/arch/x86_64/fentry.S#L29-L30
Okey, will change the format for parent and child addr !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namhyung , You mean that we can show stack frame info
at the beginning of mcount()
or __fentry__()
like below, right ?
For example:
__fentry__
case
(gdb) info f
Stack level 0, frame at 0x7fffffffdd48:
rip = 0x7ffff7bc9d70 in __fentry__; saved rip = 0x4006b3
called by frame at 0x7fffffffdd50
Arglist at 0x7fffffffdd38, args:
Locals at 0x7fffffffdd38, Previous frame's sp is 0x7fffffffdd48
Saved registers:
rip at 0x7fffffffdd40
mcount
case
Stack level 0, frame at 0x7fffffffdd30:
rip = 0x7ffff7bc9ce0 in mcount; saved rip = 0x40069b
called by frame at 0x7fffffffdd50
Arglist at 0x7fffffffdd20, args:
Locals at 0x7fffffffdd20, Previous frame's sp is 0x7fffffffdd30
Saved registers:
rip at 0x7fffffffdd28
arch/x86_64/mcount.S
Outdated
@@ -1,8 +1,43 @@ | |||
/* argument passing: %rdi, %rsi, %rdx, %rcx, %r8, %r9 */ | |||
/* return value: %rax */ | |||
/* callee saved: %rbx, %rbp, %rsp, %r12-r15 */ | |||
/* stack frame (with -pg): return addr = 8(%rbp), prev fp = 0(%rbp) */ | |||
/* stack frame (with -fentry): return addr = (%rsp), prev fp = %rbp */ | |||
/* stack frame (with -pg): parent location = addr of 8(%rbp), child ip = 56(%rsp) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
1c00c03
to
dbb274f
Compare
@namhyung , I sent v3 based on your mention, |
e159775
to
86ad061
Compare
arch/x86_64/fentry.S
Outdated
@@ -1,8 +1,55 @@ | |||
/* argument passing: %rdi, %rsi, %rdx, %rcx, %r8, %r9 */ | |||
/* return value: %rax */ | |||
/* callee saved: %rbx, %rbp, %rsp, %r12-r15 */ | |||
/* stack frame (with -pg): return addr = 8(%rbp), prev fp = 0(%rbp) */ | |||
/* stack frame (with -fentry): return addr = (%rsp), prev fp = 8(%rsp) */ | |||
/* stack frame (with -pg -mfentry): parent addr = 56(%rsp), child addr = 48(%rsp) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant you need to subtrace 48 from the offsets since it was adjusted by our __fentry__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood !
At the very beginning of __fentry__()
,
parent addr (an address that has the return address of hello()
): 8(%rsp)
child addr (the return address of __fentry__()
): %rsp
Because the "%rbp" is not set yet.
Right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Child addr is in "(%rsp)".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the below ?
child addr == (%rsp)
child ip == %rsp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I wrote %rsp
instead of (%rsp)
is
the value of %rsp
is the return address of __fentry__()
.
(e.g. 0x00000000004006ab)
Dump of assembler code for function hello:
0x00000000004006a6 <+0>: callq 0x400550 <__fentry__@plt>
child addr => 0x00000000004006ab <+5>: push %rbp
0x00000000004006ac <+6>: mov %rsp,%rbp
Sorry for my confusion..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
I meant "child addr == child ip".
-
Really? %rsp is a stack pointer so its value should point to a stack address. Dereferencing %rsp can result in a return address (of a function).
For example:
- %rsp = 0x7fffff8720
- (%rsp) = 0x4006ab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I got it. will change that !
arch/x86_64/fentry.S
Outdated
0x00000000004006b9 <+19>: nop | ||
0x00000000004006ba <+20>: pop %rbp | ||
0x00000000004006bb <+21>: retq | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems too verbose, and comments below from here can be omitted IMHO.
arch/x86_64/fentry.S
Outdated
movq 48(%rsp), %rsi | ||
/* parent ip */ | ||
/* parent addr */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it should be "parent location" since it takes address by "lea" insn.
arch/x86_64/mcount.S
Outdated
@@ -1,8 +1,54 @@ | |||
/* argument passing: %rdi, %rsi, %rdx, %rcx, %r8, %r9 */ | |||
/* return value: %rax */ | |||
/* callee saved: %rbx, %rbp, %rsp, %r12-r15 */ | |||
/* stack frame (with -pg): return addr = 8(%rbp), prev fp = 0(%rbp) */ | |||
/* stack frame (with -fentry): return addr = (%rsp), prev fp = %rbp */ | |||
/* stack frame (with -pg): parent addr = 8(%rbp), child addr = 56(%rsp) */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Please remove 56 here. Also it'd be great if you could mention why fentry needs 48 and mcount needs 56 (regarding #92). It's because of the 16-byte stack alignment required from GCC 7..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namhyung , What about adding the explanation about #92 at fentry.S:27~ and mcount.S:27~ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@namhyung ,
If there isn't the problem about the 16-byte stack alignment,
we could just use push
and pop
insn.
However, because it is required from GCC7, we should manually adjust stack pointer %rsp
, right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, using push/pop or manual adjusting is essentially same. What matters is the offset it changes.
arch/x86_64/mcount.S
Outdated
0x0000000000400687 <+1>: mov %rsp,%rbp | ||
0x000000000040068a <+4>: sub $0x10,%rsp | ||
0x000000000040068e <+8>: callq 0x400520 <mcount@plt> | ||
child addr => 0x0000000000400693 <+13>: movl $0x1,-0x4(%rbp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Please omit below..
arch/x86_64/mcount.S
Outdated
movq 56(%rsp), %rsi | ||
sub $9, %rsi | ||
|
||
/* parent location */ | ||
/* parent addr */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"parent location" is correct.
86ad061
to
af3e1ca
Compare
@namhyung , I sent v4 ! |
arch/x86_64/fentry.S
Outdated
0x00000000004006c2 <+6>: mov %rsp,%rbp | ||
0x00000000004006c5 <+9>: mov $0x0,%eax | ||
0x00000000004006ca <+14>: callq 0x4006a6 <hello> | ||
return address => 0x00000000004006cf <+19>: nop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/return address/parent addr/
arch/x86_64/mcount.S
Outdated
0x00000000004006b5 <+4>: callq 0x400520 <mcount@plt> | ||
0x00000000004006ba <+9>: mov $0x0,%eax | ||
0x00000000004006bf <+14>: callq 0x400686 <hello> | ||
return address => 0x00000000004006c4 <+19>: nop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
af3e1ca
to
5ba1a2b
Compare
The comment about stack frame (with -pg, -mfentry) had wrong information and seems to be lack of explanation, so fix it and add examples. Reported-by: Namhyung Kim <namhyung@gmail.com> Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
5ba1a2b
to
5622b13
Compare
I'm late, I changed this PR !! , @namhyung |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi @namhyung , 😄
I fixed comments about stack frame (with -pg, -mfentry)
based on your mention yesterday. 😄
I'd appreciate some feedback on this PR!
Thanks,
Taeung