I wrote a very simple program with time() calls to illustrate the use of strace , but I had a problem; calling time() does not seem to create self-tuning!
I ended up moving to the time() function in GDB, and now I'm more confused than ever. From disassembling the time() function:
0x7ffff7ffad90 <time>: push rbp 0x7ffff7ffad91 <time+1>: test rdi,rdi 0x7ffff7ffad94 <time+4>: mov rax,QWORD PTR [rip+0xffffffffffffd30d] # 0x7ffff7ff80a8 0x7ffff7ffad9b <time+11>: mov rbp,rsp 0x7ffff7ffad9e <time+14>: je 0x7ffff7ffada3 <time+19> 0x7ffff7ffada0 <time+16>: mov QWORD PTR [rdi],rax 0x7ffff7ffada3 <time+19>: pop rbp 0x7ffff7ffada4 <time+20>: ret
How does this function actually get the current time if it does not call the kernel? His stream:
- Prologue
- Get some value from
(0x7ffff7ffad94 + 0xffffffffffffd30d) ( 0x7ffff7ff80a8 ) and put it in rax (to return) - Check if rdi (first argument) was null
- If you do not put the value in rax (return value), also
- Epilogue
This makes sense with the time() functionality; if the argument is null, it just returns a value, but if not, it also puts it in the argument. The question I have is, where does it get the value of time? What is so magical about 0x7ffff7ff80a8 , and how to do it without syscall?
I am using GCC 6.3.0 and Ubuntu GLIBC 2.24-9ubuntu2.2.
assembly gcc linux x86-64 glibc
Leo tindall
source share