Why the top of the stack contain the address of <_dl_fini>?

0

I disassemble the next simple source:

#include <stdio.h>

void func3() {
   int i = 11;
   printf("\t\t\t[in func3] i = %d\n", i);
}

void func2() {
   int i = 7;
   printf("\t\t[in func2] i = %d\n", i);
   func3();
   printf("\t\t[back in func2] i = %d\n", i);
}

void func1() {
   int i = 5;
   printf("\t[in func1] i = %d\n", i);
   func2();
   printf("\t[back in func1] i = %d\n", i);
}

int main() {
   int i = 3;
   printf("[in main] i = %d\n", i);
   func1();
   printf("[back in main] i = %d\n", i);
}

and break with gdb: main then func1:

Breakpoint 2, func1 () at /home/storenth/scope.c:16
16     int i = 5;
(gdb) i r rbp rsp
rbp            0x7fffffffda50   0x7fffffffda50
rsp            0x7fffffffda40   0x7fffffffda40
(gdb) x/4x 0x7fffffffda50
0x7fffffffda50: 0x00007fffffffda70  0x0000555555554731
0x7fffffffda60: 0x00007fffffffdb50  0x0000000300000000
(gdb) x/4x 0x7fffffffda40
0x7fffffffda40: 0x00007ffff7de59f0  0x0000000000000000
0x7fffffffda50: 0x00007fffffffda70  0x0000555555554731
(gdb) nexti
17     printf("\t[in func1] i = %d\n", i);
(gdb) x/4x 0x7fffffffda40
0x7fffffffda40: 0x00007ffff7de59f0  0x0000000500000000
0x7fffffffda50: 0x00007fffffffda70  0x0000555555554731
(gdb) x/4xw 0x7fffffffda40
0x7fffffffda40: 0xf7de59f0  0x00007fff  0x00000000  0x00000005
(gdb) x/x 0x00007ffff7de59f0
0x7ffff7de59f0 <_dl_fini>:  0xe5894855

So, I expect to see only 0x5 under the RSP in the current stack frame because of the variable int i = 5; but also get 0x00007ffff7de59f0 which point me at <_dl_fini>:0xe5894855.

  1. Where am I wrong in my reasoning?
  2. And what is <_dl_fini>?
c
gdb
x86-64
cpu-registers
callstack
asked on Stack Overflow Aug 23, 2020 by storenth • edited Aug 24, 2020 by Peter Cordes

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0