title: How can I use crt0.o to setup .bss and .data in my bare metal C program?
body: <p>I successfully wrote a bare metal C program which is running on my STM32F4. It's nothing fancy, just the usual led-blinky-program. In this project I have written the initialization routines which is clearing the <code>.bss</code> section and initializing the <code>.data</code> section myself.</p>
  
  <p>This wasn't really complicated. In the linker script, I just instructed the linker to create some symbols which are marking the start and the end of the <code>.data</code> and <code>.bss</code> section.</p>
  
  <pre><code>.data 0x20001000 :
      ALIGN(4)
      {
          __etext = LOADADDR(.data);
          __data_start__ = ADDR(.data) ;
          *(.data*) ;
          __data_end__ = ADDR(.data) + SIZEOF(.data) ;
      } &gt;RAM AT&gt;ROM
  
  
  .bss :
      ALIGN(4)
      {
          __bss_start__ = ADDR(.bss) ;
          *(.bss*) ;
          __bss_end__ = ADDR(.bss) + SIZEOF(.bss) ;
      } &gt;RAM
  </code></pre>
  
  <p>Then I was using these symbols in my code:</p>
  
  <pre><code>extern unsigned int __etext;
  extern unsigned int __data_start__;
  extern unsigned int __data_end__;
  extern unsigned int __bss_start__;
  extern unsigned int __bss_end__;
  
  
  void Reset_Handler()
  {
      unsigned int * src;
      unsigned int * dest;
  
      src = &amp;__etext;
      dest = &amp;__data_start__;
  
      /* copy .data */
      while (dest &lt; &amp;__data_end__)
          *(dest++) = *(src++);
  
      /* Zero bss.  */
      for (dest = &amp;__bss_start__; dest &lt; &amp;__bss_end__; dest++)
          *dest = 0;
  }
  </code></pre>
  
  <p>Now I would like to use the <code>crt0</code> for the purpose of setting-up <code>.bss</code> and <code>.data</code>. (I heard setting up things is the main purpose of <code>crt0</code>.)</p>
  
  <p>How can I do that?
  Is the basic principle of defining symbols in the linker script and using the in the code the same?</p>
  
  <hr>
  
  <h2>TL;DR</h2>
  
  <p>How can I use <code>crt0</code> to setup my <code>.bss</code> and <code>.data</code> section?</p>