Zhenyu Guo wrote: > gcc --static test.c -o test Hmm, it turns out that the code really does do that. This had me puzzled for a bit until I remembered that a weak function call would look like this. This would have been easier if I had the source code to look at, but I couldn't find gmon_initializer in either gcc or glibc. I am not sure where it is coming from. Maybe I am looking at the wrong version of the gcc and glibc sources.
Anyways, the input is going to be something like this: extern void __gmon_start__ (void) __attribute__ ((weak)); void gmon_initializer (void) { ... if (__gmon_start__) __gmon_start__ (); ... } So in a normal link, __gmon_start__ will not be defined, the body of the if statement will never execute, and the __gmon_start__ call will be compiled to an offset of 0, which will be a recursive call to itself. Compile with -pg, and you will see that you now have a call to __gmon_start__ because it is now defined. You can also do "objdump -d -r /usr/lib/crti.o" to see the input code with relocations, and run "nm /usr/lib/crti.o" to see that __gmon_start__ is weak. -- Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com