the source code is here
#include <stdio.h>
int gcd(a, b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main(int argc, char **argv) {
int a = atoi(argv[1]);
int b = atoi(argv[2]);
int res = gcd(a, b);
printf("%d\n", res);
return 0;
}
and compiled with gcc -O0 gcd.c -o gcd -g
Before I run gcd, the gcd()
address is 0x1169
.
After I run it, the address of the same function becomes to 0x555555555169
.
$ gdb -q gcd
Reading symbols from gcd...
(gdb) p gcd
$1 = {int (int, int)} 0x1169 <gcd>
(gdb) run 42 24
Starting program: ~/Workstation/gcd 42 24
6
[Inferior 1 (process 104126) exited normally]
(gdb) p gcd
$2 = {int (int, int)} 0x555555555169 <gcd>
Why there're such a difference between before and after running the code?