跟進Why is the ELF execution entry point virtual address of the form 0x80xxxxx and not zero 0x0?和Why do virtual memory addresses for linux binaries start at 0x8048000?,爲什麼我不能讓ld
使用不同的入口點比默認的ld -e
?爲什麼ELF入口點0x8048000不能使用「ld -e」選項更改?
如果我這樣做了,我要麼得到一個segmentation fault
,返回代碼139,即使對於靠近默認入口點的地址。爲什麼?
編輯:
我會讓問題更具體:
.text
.globl _start
_start:
movl $0x4,%eax # eax = code for 'write' system call
movl $1,%ebx # ebx = file descriptor to standard output
movl $message,%ecx # ecx = pointer to the message
movl $13,%edx # edx = length of the message
int $0x80 # make the system call
movl $0x0,%ebx # the status returned by 'exit'
movl $0x1,%eax # eax = code for 'exit' system call
int $0x80 # make the system call
.data
.globl message
message:
.string "Hello world\n" # The message as data
如果我編譯這個與as program.s -o program.o
,然後用ld -N program.o -o program
,readelf -l program
顯示0x0000000000400078
靜態鏈接它作爲文本的VirtAddr
段和0x400078
作爲入口點。在運行時,'Hello World」的打印。
然而,當我嘗試用ld -N -e0x400082 -Ttext=0x400082 program.o -o program
鏈接(由4個字節移動文本段和入口點),程序會killed
。與readelf -l
檢查現在顯示兩個不同的頁眉
的LOAD
類型,一個在0x0000000000400082
,一個在0x00000000004000b0
。當我嘗試0x400086
,所有的工作,並且只有一個LOAD
部分。
- 這是怎麼回事?
- 我可以選擇哪些內存地址,哪些是我不能選擇的,爲什麼?
謝謝你。
我也一直能夠修改與鏈接腳本的入口點:http://stackoverflow.com/a/30536800/895245 –