title: Why Linux/gnu linker chose address 0x400000?
body: <p>I'm experimenting with ELF executables and the gnu toolchain on Linux x86_64:</p>
  
  <p>I've linked and stripped (by hand) a "Hello World" test.s:</p>
  
  <pre><code>        .global _start
          .text
  _start:
          mov     $1, %rax
          ...
  </code></pre>
  
  <p>into a 267 byte ELF64 executable...</p>
  
  <pre><code>0000000: 7f45 4c46 0201 0100 0000 0000 0000 0000  .ELF............
  0000010: 0200 3e00 0100 0000 d400 4000 0000 0000  ..&gt;.......@.....
  0000020: 4000 0000 0000 0000 0000 0000 0000 0000  @...............
  0000030: 0000 0000 4000 3800 0100 4000 0000 0000  ....@.8...@.....
  0000040: 0100 0000 0500 0000 0000 0000 0000 0000  ................
  0000050: 0000 4000 0000 0000 0000 4000 0000 0000  ..@.......@.....
  0000060: 0b01 0000 0000 0000 0b01 0000 0000 0000  ................
  0000070: 0000 2000 0000 0000 0000 0000 0000 0000  .. .............
  0000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................
  0000090: 0000 0000 0000 0000 0000 0000 0000 0000  ................
  00000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
  00000b0: 0400 0000 1400 0000 0300 0000 474e 5500  ............GNU.
  00000c0: c3b0 cbbd 0abf a73c 26ef e960 fc64 4026  .......&lt;&amp;..`.d@&amp;
  00000d0: e242 8bc7 48c7 c001 0000 0048 c7c7 0100  .B..H......H....
  00000e0: 0000 48c7 c6fe 0040 0048 c7c2 0d00 0000  ..H....@.H......
  00000f0: 0f05 48c7 c03c 0000 0048 31ff 0f05 4865  ..H..&lt;...H1...He
  0000100: 6c6c 6f2c 2057 6f72 6c64 0a              llo, World.
  </code></pre>
  
  <p>It has one program header (LOAD) and no sections:</p>
  
  <pre><code>There are 1 program headers, starting at offset 64
  
  Program Headers:
    Type           Offset             VirtAddr           PhysAddr
                   FileSiz            MemSiz              Flags  Align
    LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                   0x000000000000010b 0x000000000000010b  R E    200000
  </code></pre>
  
  <p>This seems to load the entire file (file offset 0 thru 0x10b - elf header and all) at address 0x400000.</p>
  
  <p>The entry point is:</p>
  
  <pre><code> Entry point address:               0x4000d4
  </code></pre>
  
  <p>Which corresponds to 0xd4 offset in the file, and as we can see that address is the start of the machine code (<code>mov $1, %rax1</code>)</p>
  
  <p>My question is why (how) did the gnu linker choose address <code>0x400000</code> to map the file to?</p>