title: How do I know where the .data section needs to get the init data from? (gcc linker)
body: <p>When building a gcc based bare metal mcu project you need to take care of the initialization of the .data and .bss sections during startup.</p>
  
  <p>The .bss section is quite easy since I just fill the entire section to 0.
  But variables in the .data section needs to have their initialization data in rom/flash and copied during startup.</p>
  
  <p>How do I know where the data with the initialization values can be found? </p>
  
  <p>Let's take a example.</p>
  
  <p>Let's say that I create two global variables in main.c</p>
  
  <pre><code>unsigned int my_global_variable_one  = 1;
  unsigned int my_global_variable_two  = 2;
  </code></pre>
  
  <p>Then I can use objdump on the object file to see in what section they will be in, 
  but I can't find anything in the objdump out put where the init data should be placed.</p>
  
  <pre><code>$ arm-none-eabi-objdump --syms main.o | grep my_global_variable
  00000000 g     O .data  00000004 my_global_variable_one
  00000004 g     O .data  00000004 my_global_variable_two
  </code></pre>
  
  <p>Then I can look at the resulting elf for the entire system, in this case main.elf.</p>
  
  <pre><code>$ arm-none-eabi-nm -n main.elf | grep my_global_variable
  20000000 D my_global_variable_one
  20000004 D my_global_variable_two
  </code></pre>
  
  <p>Where can I find where they are so I can do copy the data?
  What do I need to put into my linker script?</p>
  
  <p>It should be in something like .text or .rodata, but how do I know? </p>
  
  <p>How can I check where the init data for my_global_variable_one is? </p>
  
  <p>Can I find where this data is with any of the binutils commands like readelf or objdump?</p>
  
  <p>/Thanks</p>
  
  <hr>
  
  <p>This is on a stm32 (Cortex M3) mcu, and the CodeBench version of gcc is used.</p>