Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is the ELF entry point 0x8048000 not changeable with the "ld -e" option?
    primarykey
    data
    text
    <p>Following up <a href="https://stackoverflow.com/questions/2187484/elf-binary-entry-point">Why is the ELF execution entry point virtual address of the form 0x80xxxxx and not zero 0x0?</a> and <a href="https://stackoverflow.com/questions/2966426/why-do-virtual-memory-addresses-for-linux-binaries-start-at-0x8048000">Why do virtual memory addresses for linux binaries start at 0x8048000?</a>, why cannot I make <code>ld</code> use a different entry point than the default with <code>ld -e</code>?</p> <p>If I do so, I either get a <code>segmentation fault</code> with return code 139, even for addresses close by the default entry point. Why?</p> <p><strong>EDIT:</strong></p> <p>I will make the question more specific:</p> <pre><code> .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 </code></pre> <p>If I compile this with <code>as program.s -o program.o</code> and then link it statically with <code>ld -N program.o -o program</code>, <code>readelf -l program</code> shows <code>0x0000000000400078</code> as the <code>VirtAddr</code> of the text segment and <code>0x400078</code> as entry point. When run, `Hello world" is printed.</p> <p>However, when I try to link with <code>ld -N -e0x400082 -Ttext=0x400082 program.o -o program</code> (moving text segment and entry point by 4 bytes), the program will be <code>killed</code>. Inspecting it with <code>readelf -l</code> now shows two different headers of type <code>LOAD</code>, one at <code>0x0000000000400082</code> and one at <code>0x00000000004000b0</code>.</p> <p>When I try <code>0x400086</code>, it all works, and there is only one <code>LOAD</code> section.</p> <ol> <li>What's going on here?</li> <li>Which memory addresses may I chose, which ones cannot I chose and why?</li> </ol> <p>Thanks you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload