title: Why physical address of Aarch64 kernel image is nonnegative?
body: <p>I'm recently learning about booting system of Linux kernel. (v4.6, with ARM64 arch.)</p>
  
  <p>In the source code <code>arch/arm64/kernel/head.S</code>, definition of <code>__PHYS_OFFSET</code> is:</p>
  
  <p><code>#define __PHYS_OFFSET   (KERNEL_START - TEXT_OFFSET)</code></p>
  
  <p>where <code>KERNEL_START</code> is simply defined to be <code>_text</code> section.</p>
  
  <p>And if I'm right, <code>TEXT_OFFSET</code> is a random number determined during kernel compile, as /arch/arm64/Makefile says:</p>
  
  <p><code>TEXT_OFFSET := $(shell awk 'BEGIN {srand(); printf "0x%03x000\n", int(512 * rand())}')</code></p>
  
  <p>so that the kernel image file has random location, as the linker script <code>/arch/arm64/kernel/vmlinux.lds.S</code> includes:</p>
  
  <pre><code>. = KIMAGE_VADDR + TEXT_OFFSET; 
  .head.text : {                          
      _text = .;
      HEAD_TEXT
  }
  </code></pre>
  
  <p>Here, <code>KIMAGE_VADDR</code> is a virtual address <code>0xFFFF000000000000 + 128M</code>. Since <code>TEXT_OFFSET</code> is added, section <code>_text</code> will be randomly located.</p>
  
  <p>Rest parts of head.S map <code>KIMAGE_VADDR</code> to <code>__PHYS_OFFSET</code> to enable MMU. </p>
  
  <p>My question is this: is <code>__PHYS_OFFSET = _text - TEXT_OFFSET</code> always nonnegative?</p>
  
  <p>I don't know where would be exact physical location of <code>_text</code>, but I think <code>512 * rand()</code> might be as big as <code>512 * 32767 ~ 10MB</code>.</p>
  
  <p>Do I make sense? Is there any reason makes these codes safe?</p>