2016-04-15 71 views
1

我發現程序的入口點是我機器中的動態鏈接程序/lib/ld-linux-so.2。在調用/lib/ld-linux.so.2中的_start函數之前會發生什麼?

enter image description here

readelf -h /lib/ld-linux.so.2 |grep Entry 
Entry point address:    0x11d0 

其實進入點在0xb7fdf1d0。一些上下文信息如下。

gdb-peda$ context_code 
[-------------------------------------code-------------------------------------] 
    0xb7fdf1c3: ret  
    0xb7fdf1c4: lea esi,[esi+0x0] 
    0xb7fdf1ca: lea edi,[edi+0x0] 
=> 0xb7fdf1d0 <_start>: mov eax,esp 
    0xb7fdf1d2 <_start+2>: call 0xb7fe2c80 <_dl_start> 
    0xb7fdf1d7 <_dl_start_user>: mov edi,eax 
    0xb7fdf1d9 <_dl_start_user+2>: call 0xb7fdf1c0 
    0xb7fdf1de <_dl_start_user+7>: add ebx,0x1fe16 
gdb-peda$ bt 
#0 0xb7fdf1d0 in _start() from /lib/ld-linux.so.2 
gdb-peda$ i r esp 
esp   0xbffff3e0 0xbffff3e0 

enter image description here

但堆棧此時已inited,並將其保存program.So的環境變量和args誰inited _start函數之前棧?

回答

1

內核設置堆棧。

當內核處理動態加載器的exec時,它會初始化一些數據結構,以跟蹤虛擬內存映射和堆棧位置。在fs/exec.c設置堆棧位置。

當調度程序將控制權交給這個新進程時,它會將堆棧指針的值設置爲相應的值。

+0

你是對的,bash程序將通過「execve()」函數將控制權轉移給內核。 – Faker

相關問題