This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 转发: Call into a function?
- From: James E Wilson <wilson at specifixinc dot com>
- To: Zhenyu Guo <guozy03 at mails dot tsinghua dot edu dot cn>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 21 Apr 2005 12:06:32 -0700
- Subject: Re: 转发: Call into a function?
- References: <000b01c54624$6b0df150$2b00000a@appletree>
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