1.3 What the linker does when constructing an executable image
armlink performs many operations, depending on the content of the input files and the command-line options you specify.
When you use the linker to construct an executable image, it:
Resolves symbolic references between the input object files.
Extracts object modules from libraries to satisfy otherwise unsatisfied symbolic references.
Removes unused sections.
Eliminates duplicate common groups and common code, data, and debug sections.
Sorts input sections according to their attributes and names, and merges sections with similar attributes and names into contiguous chunks.
Organizes object fragments into memory regions according to the grouping and placement information provided.
Assigns addresses to relocatable values.
Generates an executable image.
1. RESET
2. XIP on 主Flash
3. 代碼執行序列到_main
3.1 將 non-root (RO and RW) execution regions 從 加載地址 拷貝到 執行地址.如果data sections被壓縮,則將它們從加載地址(加載區域)解壓縮到執行地址(執行區域)。//具體實現在(InRoot$$Sections) ------------對應 .code 段 和 .ro-data 段
// 其實 RO(RO-data) 的 加載地址 和 執行地址是一樣的.都在0x08000000(主Flash上)------------對應 .data 段
// RW(RW-data) 加載地址在 0x08000000 + sizeof(RO-data),執行地址在0x20000000(SRAM1)------------對應 .bss 段
// ZI(ZI-data) 加載地址在 0x08000000 + sizeof(RO-data),執行地址在0x20000000(SRAM1) // 其實這一段並沒有加載,因爲加載了也要清0,所以乾脆留空.只記錄 ZI-data 執行地址的開始地址和結束地址------------對應 .bss 段
3.2. 將ZI regions清03.3. 跳轉到__rt_entry
------------對應 .stack 段 和 .heap段
// 棧的初始化不涉及到內存,只涉及到SP寄存器// 堆的初始化涉及到內存, 1.清零堆空間 2.在堆中建立數據結構來對堆進行分塊 3.3.1. Sets up the stack and the heap by one of a number of means that include calling __user_setup_stackheap(), calling __rt_stackheap_init(), or loading the absolute addresses of scatter-loaded regions.3.3.2. Calls __rt_lib_init() to initialize referenced library functions, initialize the locale and,if necessary, set up argc and argv formain(). For C++, calls the constructors for any top-level objects by way of __cpp_initialize__aeabi_ .3.3.3. Calls main(), the user-level root of the application. From main(), your program might call, among other things, library functions.3.3.4. Calls exit() with the value returned by main()