title: Why do STM32 gcc linker scripts automatically discard all input sections from these standard libraries: libc.a, libm.a, libgcc.a?
body: <p>From the bottom of any auto-generated STM32CubeMx-generated linker script:</p>
  <pre><code>/* Remove information from the standard libraries */
  /DISCARD/ :
  {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
  }
  </code></pre>
  <p>From the GNU Binutils ld (linker script) manual, <a href="https://sourceware.org/binutils/docs-2.32/ld/Output-Section-Discarding.html#Output-Section-Discarding" rel="nofollow noreferrer">3.6.7 Output Section Discarding</a>:</p>
  <blockquote>
  <p>The special output section name ‘/DISCARD/’ may be used to discard input sections. Any input sections which are assigned to an output section named ‘/DISCARD/’ are not included in the output file.</p>
  </blockquote>
  <p>What do these 3 input object files contain, and why do we discard everything (all input sections) from them?</p>
  <h2>Other STM32 linker script topics of interest:</h2>
  <ol>
  <li><a href="https://stackoverflow.com/questions/55622174/is-accessing-the-value-of-a-linker-script-variable-undefined-behavior-in-c">Is accessing the &quot;value&quot; of a linker script variable undefined behavior in C?</a></li>
  <li><a href="https://stackoverflow.com/questions/48561217/how-to-get-value-of-variable-defined-in-ld-linker-script-from-c/54728097#54728097">How to get value of variable defined in ld linker script from C</a></li>
  </ol>