title: Linker Script - Placing a section at the end of a memory region
body: <p>I have searched far and wide for how to do this and have failed to come up with an answer.</p>
  
  <p>My memory layout is as follows:</p>
  
  <pre><code>Fake Address | Section
       0       |  text
       7       |  relocate
      15       |  bss
      23       |  stack
  </code></pre>
  
  <p>At the end of the Stack I place the Heap. Which grows up and the stack is a full descending stack for the ARM chip I am using.</p>
  
  <p>Now, what I want to do is place a single section, let's call it <code>.persist</code>, into my ram memory. I want it to reside at the very end of RAM and I want to program this into my linker script. However, this <code>.persist</code> section's size is not defined by me but is computed by the compiler from the symbols that it contains.</p>
  
  <p>So far I've not come up with a good way to do it. Since I know the RAM start address and SIZE it would be trivial to calculate where the section needs to go if I knew the section size. However, according to <a href="http://web.eecs.umich.edu/~prabal/teaching/eecs373-f10/readings/Linker.pdf" rel="noreferrer">the GNU linker documentation (pg 74)</a> it seems that:</p>
  
  <blockquote>
    <p>SIZEOF(section) Returns the size in bytes of the named
    section, if that section has been allocated.
    If the section has not been allocated when this is evaluated, the linker will
    report an error.</p>
  </blockquote>
  
  <p>so I can't work out the size of the section in the linker script (since I want to calculate the size BEFORE I place it/allocate it).</p>
  
  <p>Does anyone know a good way to do this?</p>