IAR MAP/ICF file study

Executable program generation process;

Source File -> Preprocessor -> Compiler -> Linker -> Executable Object File

Preprocessor: Executes directives beginning with #. The preprocessor can remove comments, include other files, and execute macros (macro is a short description of repeated text) instead.

Similar to an editor, you can add content to the program and modify it.


Compiler: translates a program into machine instructions, i.e. object code, but such a program is not yet executable


Linker: Integrate the object code generated by the compiler with other required additional code, and finally generate an executable program. A linker is a program that combines one or more of the The object file generated by the compiler plus the library link becomes an executable file.

This article mainly learns about linkers.

Links: Collect and combine pieces of code and data into a single file.

The main work of the linker:

1. Symbol resolution. The symbols defined and referenced by the object file, associate each symbol reference with exactly one symbol definition.

    What is a symbol? For example, if a function is defined, then the function name is a symbol. If a variable is defined, then the variable name is a symbol.

    The symbol table is a table that records the symbol name and the address location information of the symbol definition.

    Corresponding to the symbol table is the relocation table, which records a reference to a symbol at a certain location.

    The CPU does not know symbols, it only knows instructions and addresses, and the final match will be replaced by the address.

2. Relocation. The compiler generates zero-based code and data segments. The linker associates each symbol definition with a memory location, and then modifies all references to those symbols so that they point to this memory location. define these segments.


then ICF file. IAR with linker ILINK, reference file EWARM_DevelopmentGuide.ENU . pdf  

A standard ICF file includes the following contents;

1. Programmable memory space (memory)

2. Different memory address regions (region)

3. Different address blocks (block)

4. Section initialization or not

4. Section placement in storage space


The following introduces several common instructions in ICF files. For details, please refer to the ILINK related documentation (EWARM_DevelopmentGuide.pdf):

1. define [ exported ] symbol name = expr;
Function: Specify the value of a symbol.

Parameters: exported Export the symbol to make it available to the executable image
name --symbol name
expr --symbol value

example:
define symbol RAM_START_ADDRESS = 0x40000000;
define symbol RAM_END_ADDRESS = 0x4000FFFF;    

2. define memory name with size = expr [, unit -size];

Role: Define an addressable storage address space (memory).

Parameters: name -- the name of the memory
expr -- the size of the address space
unit-size -- the unit of expr, which can be a bit (unitbitsize), the default is a byte (unitbytesize)

Example:
define memory MEM with size = 4G;

3 .define region name = region-expr;

Role: Define a storage address region (region). A region can consist of one or more ranges, and the addresses within each range must be contiguous, but the ranges do not have to be contiguous.

参数:    name region的名称
region-expr memory:[from expr { to expr | size expr}],可以定义起止范围,也可以定义起始地址和region的大小

举例:
define region ROM = MEM:[from 0x0 size 0x10000];
define region ROM = MEM:[from 0x0 to 0xFFFF];

4.    define block name[ with param, param... ]

{

extended-selectors

};

作用:    定义一个地址块(block);它可以是个空块,比如栈、堆;也可以包含一系列sections。

参数:    name     block的名称
param 可以是:     size = expr (块的大小)
maximum size = expr (块大小的上限)
alignment = expr (最小对齐字节数)
fixed order (按照固定顺序放置sections)

extended-selector [ first | last ] { section-selector | block name | overlay name }
first 最先存放
last 最后存放
section-selector [ section-attribute ][ section sectionname ][object filename ]
section-attribute [ readonly [ code | data ] | readwrite [ code | data ] | zeroinit ]
sectionname section的名称
filename 目标文件的名称
即可以按照section的属性,名称及其所在目标文件的名称这三个过滤条件中,任意选取一个条件,或选取多个条件进行组合,来圈定所要求的 sections。
name block或overlay的名称

举例:
define block HEAP with size = 0x1000, alignment = 4 { };
define block MYBLOCK1 = { section mysection1, section mysection2, readwrite };
define block MYBLOCK2 = { readonly object myfile2.o };

5.    initialize { by copy | manually } [ with param, param... ]
{
section-selectors
};

作用:    初始化sections。

参数:    by copy 在程序启动时自动执行初始化。
manually 在程序启动时不自动执行初始化。
param 可以是: packing = { none | compress1 | compress2 | auto }
copy routine = functionname
packing表示是否压缩数据,缺省是auto。
functionname表示是否使用自己的拷贝函数来取代缺省函数。
section-selector 同上

举例:
initialize by copy { rw };

6.    do not initialize
{
section-selectors
};

作用:    规定在程序启动时不需要初始化的sections。一般用于__no_init声明的变量段(.noinit)。

参数:    section-selector 同上

举例:
do not initialize { .noinit };

7.    place at { address memory[: expr] | start of region_expr | end of region_expr }
{
extended-selectors
};

作用:    把一系列sections和blocks放置在某个具体的地址,或者一个region的开始或者结束处。

参数:    memory memory的名称
expr 地址值,该地址必须在memory所定义的范围内
region_expr region的名称
extended-selector 同上

举例:
place at start of ROM { section .cstart }; place at end of ROM { section .checksum }; place at address MEM:0x0 { section .intvec };

8.    place in region-expr
{
extended-selectors
};

作用:    把一系列sections和blocks放置在某个region中。sections和blocks将按任意顺序放置。

参数:    region-expr region的名称
extended-selector 同上

举例:
place in ROM { readonly };         /* all readonly sections */ 
place in RAM { readwrite };         /* all readwrite sections */
place in RAM { block HEAP, block CSTACK, block IRQ_STACK }; 
place in ROM { section .text object myfile.o };     /* the .text section of myfile.o */ 
place in ROM { readonly object myfile.o };         /* all read-only sections of myfile.o */ 
place in ROM { readonly data object myfile.o };     /* all read-only data sections myfile.o */
FROM:http://blog.21ic.com/user1/5910/archives/2009/61982.html


下面是stm8s103 的ICF文件

/////////////////////////////////////////////////////////////////
//      Example ILINK command file for
//      STM8 IAR C/C++ Compiler and Assembler.
//
//      Copyright 2010 IAR Systems AB.
//
//      $Revision: 2384 $
//
/////////////////////////////////////////////////////////////////


define memory with size = 16M;


define region TinyData = [from 0x00 to 0xFF];


define region NearData = [from 0x0000 to 0x03FF];


define region Eeprom = [from 0x4000 to 0x427F];


define region NearFuncCode = [from 0x8000 to 0x9FFF];


define region FarFuncCode = [from 0x8000 to 0x9FFF];


define region HugeFuncCode = [from 0x8000 to 0x9FFF];




/////////////////////////////////////////////////////////////////


define block CSTACK with size = _CSTACK_SIZE  {};


define block HEAP  with size = _HEAP_SIZE {};


define block INTVEC with size = 0x80 { ro section .intvec };


// Initialization
initialize by copy { rw section .far.bss,
                     rw section .far.data,
                     rw section .far_func.textrw,
                     rw section .huge.bss,
                     rw section .huge.data,
                     rw section .huge_func.textrw,
                     rw section .iar.dynexit,
                     rw section .near.bss,
                     rw section .near.data,
                     rw section .near_func.textrw,
                     rw section .tiny.bss,
                     rw section .tiny.data,
                     ro section .tiny.rodata };


do not initialize  { rw section .eeprom.noinit,
                     rw section .far.noinit,
                     rw section .huge.noinit,
                     rw section .near.noinit,
                     rw section .tiny.noinit,
                     rw section .vregs };


// Placement
place at start of TinyData      { rw section .vregs };
place in TinyData               { rw section .tiny.bss,
                                  rw section .tiny.data,
                                  rw section .tiny.noinit,
                                  rw section .tiny.rodata };


place at end of NearData        { block CSTACK };
place in NearData               { block HEAP,
                                  rw section .far.bss,
                                  rw section .far.data,
                                  rw section .far.noinit,
                                  rw section .far_func.textrw,
                                  rw section .huge.bss,
                                  rw section .huge.data,
                                  rw section .huge.noinit,
                                  rw section .huge_func.textrw,
                                  rw section .iar.dynexit,
                                  rw section .near.bss,
                                  rw section .near.data,
                                  rw section .near.noinit,
                                  rw section .near_func.textrw };


place at start of NearFuncCode  { block INTVEC };
place in NearFuncCode           { ro section .far.data_init,
                                  ro section .far_func.textrw_init,
       ro section .huge.data_init,
                                  ro section .huge_func.textrw_init,
 ro section .iar.init_table,
 ro section .init_array,
                                  ro section .near.data_init,
                                  ro section .near.rodata,
 ro section .near_func.text,
 ro section .near_func.textrw_init,
                                  ro section .tiny.data_init,
                                  ro section .tiny.rodata_init };


place in FarFuncCode            { ro section .far.rodata,
                                  ro section .far_func.text };


place in HugeFuncCode           { ro section .huge.rodata,
                                  ro section .huge_func.text };


place in Eeprom                 { rw section .eeprom.noinit };


/////////////////////////////////////////////////////////////////




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325807574&siteId=291194637