title: Understanding C runtime environment (ARM) - where to start
body: <p>I'am embedded developer working with ARM Cortex-M devices mainly. Recently I've switched to Linux and decided to learn more about the build/assemble/link process, how to write makefiles etc. as I was using IDEs (IAR, Keil, Eclipse etc.) where lot of stuff is automated and the user has actually no clue what is happening in the background. The target is to understand more of this low level process, how to use the tools properly and not just rely on the IDE default settings.</p>
  
  <p>After writing a makefile I was able to build my application. However, I decided to perform the link process manually by invoking the linker directly (not through compiler) and surprisingly troubles showed up! Undefined references to libc, _init function in __libc_init_array, _exit etc. were the issues. After whole day of investigations I was able to include all the object files (crt0.o, crti.o) and libraries (libnosys.a) manually. Apparently the compiler is doing this stuff automatically.</p>
  
  <p>After overcoming these hassles I figured out, that I've absolutely no clue about these internals. Why do I need some ctr0.o, crti.o etc. Where those come from etc. Is it linked to the compiler/linker or C runtime libraries or the system?</p>
  
  <p>I would like to learn more about these internals, however, I'm not sure, what em I looking for actually. Is it a library, system, compiler all together?</p>
  
  <p>I understand, that the system (MCU) need's to initialize the variables in RAM, and other stuff, however I miss the complete picture. Can you direct me to a good book/manuals, readings about these things, please? What am I looking for actually?</p>
  
  <p>Edit:</p>
  
  <p>After discussions here with you I most probably figured out, what I need, so I would rephrase my question following way:</p>
  
  <p>1) I've received an MCU (let's say STM32F4xx) and I should create a blinking LED example. All this should be done from scratch, own startup code, no usage external libraries etc.</p>
  
  <p>2) In the second step, someone told me that all this has already been done by others (GCC toolchain/standard libraries, MCU vendor startup files etc.). So I just need to understand/link my work with what was done and compare the differences, why they do it that way etc.</p>
  
  <p>All this was answered by @mbjoe + I found some interesting reading:
  <a href="https://rads.stackoverflow.com/amzn/click/com/0750676094" rel="noreferrer" rel="nofollow noreferrer">https://www.amazon.com/Embedded-Shoestring-experience-designing-software/dp/0750676094</a></p>
  
  <p>Thank all of you for your help and directing me the right way!</p>