Ask help for the value of _GLOBAL_OFFSET_TABLE_
JL
abcd.bpmf@gmail.com
Wed Jan 19 04:03:00 GMT 2005
Hi,
I read the function elf_machine_dynamic() in sysdeps/i386/dl-machine.h
. so I want to use this function in my prograom to get the
information of _GLOBAL_OFFSET_TABLE_ .
first, I want to get the value of symbol _DYNAMIC .the program as below
=======================
/*test.c*/
#include <elf.h>
#include <stdio.h>
static inline Elf32_Addr __attribute__ ((unused, const))
elf_machine_dynamic (void)
{
extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[]
__attribute__ ((visibility ("hidden")));
return _GLOBAL_OFFSET_TABLE_[0];
}
int main()
{
printf ("0x%x\n", elf_machine_dynamic());
}
=======================
I use gcc compile it , when I run it , Segmentation fault (core dumped).
second, I want to get the value of _GLOBAL_OFFSET_TABLE, so I modify
the statement "return _GLOBAL_OFFSET_TABLE_[0];" to "return
_GLOBAL_OFFSET_TABLE_;" in the function elf_machine_dynamic .
=======================
#include <elf.h>
#include <stdio.h>
static inline Elf32_Addr __attribute__ ((unused, const))
elf_machine_dynamic (void)
{
extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[]
__attribute__ ((visibility ("hidden")));
return _GLOBAL_OFFSET_TABLE_;
}
int main()
{
printf ("0x%x\n", elf_machine_dynamic());
}
=======================
[tmp]$ gcc test.c
test.c: In function `elf_machine_dynamic':
test.c:8: warning: return makes integer from pointer without a cast
[tmp]$ ./a.out
0x11d3
but
[tmp]$ readelf -s a.out | grep _GLOBAL
63: 08049578 0 OBJECT GLOBAL DEFAULT 21 _GLOBAL_OFFSET_TABLE_
the value of _GLOBAL_OFFSET_TABLE_ is 08049578!
who can tell me where I made a mistake? thanks in advance.
David
1.19
More information about the Libc-alpha
mailing list