全部博文(52)
分类: LINUX
2008-06-24 21:47:24
Gnu c routines' entry point
I have validated that “_start” is the entry point of Gnu c routines.
The following are the verified materials:
/* test.c */
int main(void)
{
}
root@ubuntu:/work/learning/c/before_main# gcc -g -o test test.c
root@ubuntu:/work/learning/c/before_main# readelf -h test
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x80482c0 <---From here ,we sure its entry point is ox80482c0
Start of program headers: 52 (bytes into file)
Start of section headers: 3716 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 38
Section header string table index: 35
root@ubuntu:/work/learning/c/before_main# gdb -q test
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) disassemble 0x80482c0 //disassemble the entry point
Dump of assembler code for function _start: <----And from here ,we know the entry point is "_start", not "__main"
0x080482c0 <__libc_start_main@plt+28>: xor %ebp,%ebp
0x080482c2 <__libc_start_main@plt+30>: pop %esi
0x080482c3 <__libc_start_main@plt+31>: mov %esp,%ecx
0x080482c5 <__libc_start_main@plt+33>: and $0xfffffff0,%esp
……
End of assembler dump.
(gdb)
root@ubuntu:/work/learning/c/before_main# objdump -t test | grep __main
root@ubuntu:/work/learning/c/before_main# objdump -t test | grep _start
08049420 l .ctors 00000000 .hidden __init_array_start
0804951c w .data 00000000 data_start
080482c0 g F .text 00000000 _start
00000000 w *UND* 00000000 __gmon_start__
00000000 F *UND* 000001b2 __libc_start_main@@GLIBC_2.0
0804951c g .data 00000000 __data_start
08049528 g *ABS* 00000000 __bss_start
So the conclusion is that use “__main” as default entry point is arm’s implementation mode , while gnu c uses “_start” as default entry point.
Reference: << Before main() >>