title: How to get the size of an input section (to place it at the end of memory)
body: <p>I have the following linker script:
  <code>.data</code> &amp; <code>.bss</code> are placed into ram, then a <code>.heap</code> section fills the remaining memory.</p>
  
  <p>Now I want to add a <code>.noinit</code> section that always gets placed at the end of the memory. That is so it gets ignored by bootloaders and the like.</p>
  
  <p>I still want my <code>.heap</code> section to occupy all available space between <code>.bss</code> and <code>.noinit</code>, but for this I need to know the size of the <code>.noinit</code> section.</p>
  
  <p>A naive approach failed:</p>
  
  <pre><code>/* .bss section which is used for uninitialized data */
  .bss (NOLOAD) :
  {
      . = ALIGN(4);
      _sbss = . ;
      _szero = .;
      *(.bss .bss.*)
      *(COMMON)
      . = ALIGN(4);
      _ebss = . ;
      _ezero = .;
  } &gt; ram
  
  /* heap section */
  .heap (NOLOAD) :
  {
      . = ALIGN(4);
      _sheap = . ;
      . = ORIGIN(ram) + LENGTH(ram) - SIZEOF(.noinit);
      _eheap = . ;
  }  &gt; ram
  
  /*
   * collect all uninitialized sections that go into RAM
   */
  .noinit (NOLOAD) :
  {
      . = ALIGN(4);
      __noinit_start = .;
      *(.noinit)
      __noinit_end = .;
  }  &gt; ram
  </code></pre>
  
  <p>Here <code>SIZEOF(.noinit)</code> is always 0 because the section is defined after that statement.</p>
  
  <p>But in fact what I want is <code>SIZEOF(*(.noinit))</code> - however this is a syntax error.</p>
  
  <p>So how do I get the size of an input section without placing it into an output section first?</p>