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()