I'm compiling this code with gcc hello.c -o hello -O3
#include <stdio.h>
int main(void) {
printf("Hello world\n");
return 0;
}
when I list the relocations I get:
test@southpark$ readelf -r hello | grep gmon
080495a4 00000106 R_386_GLOB_DAT 00000000 __gmon_start__
080495b4 00000107 R_386_JUMP_SLOT 00000000 __gmon_start__
when I list the symbols in this file I get:
test@southpark$ readelf -s hello | grep gmon
1: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
48: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
Does gmon_start have anything todo with gprof? Why does have an relocation for that symbol even I didn't compiling/linking with -pg or -g ? What library would resolve this symbol?
Did a little googling and found this from here:
So...
Update:
Okay, so I compiled your code with and without
-pg
. It looks like__gmon_start__
gets mapped to an address within the compiled program. So with that being said, I don't think there's a library which resolves that symbol, but the program itself.with
-pg
:objdump of __gmon_start__ code:
With the
__gmon_start__
present in the compiledhello
program, you can see that that__monstartup
is called into. (monstartup man page)without
-pg
:You can see here, that the symbol value of
__gmon_start__
is set to00000000
.