[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Libunwind-devel] Backtrace on linux_x86_64 having a weird behavior
From: |
Dave Watson |
Subject: |
Re: [Libunwind-devel] Backtrace on linux_x86_64 having a weird behavior with binary compiled with gcc -O2 flag |
Date: |
Wed, 16 Aug 2017 10:07:51 -0700 |
User-agent: |
Mutt/1.6.0 (2016-04-01) |
On 08/16/17 09:50 AM, hai huang wrote:
> Actually, this problem can be reproduced with an even simpler program:
>
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/time.h>
>
> int main() {
> struct timeval tv;
> gettimeofday(&tv, NULL);
> }
>
>
> If I compile this with `gcc -O2 -o test_O2 test.c` and run
> `libunwind/tests/test-ptrace -s -v ./test_O2` to trace it, I will get the
> same behavior as above with `main+0x1e` showing up twice in the backtrace.
> However, the weird thing is if I replace gettimeofday() call with a
> sleep(1) call, even compiling with the `-O2` flag, backtrace looks fine.
> Maybe there's a strange interaction between libunwind and gettimeofday
> syscall?
So my first guess would be that it's because you are trying to ptrace
and backtrace syscalls, but gettimeofday is no longer a syscall on
modern linux systems, it's a vdso call:
https://github.com/lattera/glibc/blob/master/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c#L34
And this is why sleep works fine - it's stil a normal syscall