Functions and processes of a CCS linker
The assembler has added the source file (. ASM) is converted to the machine language target file (. (OBJ file), that is, the coff file, the main task of the connector is based on the connection command or connection command file (. CMD) connects one or more coff target files to generate a memory image file (. map) and executable output files (. out file), that is, the coff target module. The link process is as follows:
(1) Merge the target files and configure the segments of each file to the memory of the target system.
(2) relocate symbols and segments and specify a final address for them.
(3) Resolve undefined external references between input files.
2. Writing of the link command file
The coff (Common Object File Format) file format is based on the concept of block (section), that isProgramIt is broken down into a combination of various blocks, such as text blocks and data blocks. It has the following features:
(1) easy to implement modular program design
(2) For ManagementCodeBlock and target system memory provides more powerful and flexible methods
(3) programmers only need to design based on concepts such as code blocks and data blocks, and do not need to pay attention to each command or specific target address of each data. As to where they will eventually be stored, it will be arranged by the linker
(4) It provides great convenience for programming and porting.
1 Section
The smallest unit in the target file of section is block. A block is a piece of code or data that eventually occupies continuous space in the memory image. All sections can be divided:
(1) The default section of COFF (2) custom section can be divided into: (1) initialized section (2) uninitialized section. C and assembly may be somewhat different.
The default sections in the assembler are:
Section |
Function |
Normal location |
. Text |
Usually contains executable code |
Ram or EPROM |
. Data |
Usually contains initialized data |
Rom or EPROM |
. BSS |
Reserved for uninitialized variables |
Ram |
Custom modules in assembly can create named blocks with relocated addresses and uninitialized blocks using. sect.
The section in C can be distinguished as follows:
Section |
Function |
. Text |
Code and constant |
. Cinit |
Variable initial value table |
. Switch |
Jump table for large switch statements |
. Const |
Constants and strings |
|
|
. BSS |
Global and static variables |
. System |
Global heap (for memory allocation) |
. Stack |
Stack |
. Far |
Global and static variables declared with far |
. CIO |
Used for stdio Functions |
. Ebss |
Long-called. BSS (exceeds the 64 K address limit) |
. Esysmem |
Long call. sysmem (exceeds 64 K address limit) |
Econst |
Long. Const (can be located anywhere) |
Of course, segments can be customized in C Language
2. cmd
The linker can be quickly located in two ways, one is to use the default allocationAlgorithmThe assembly process is as follows:
(1) assume that the starting address of the memory is 0.
(2) Assume that 2 ^ 32 characters of memory can be used to allocate
(3) Allocate. Text to program memory with the starting address 0
(4) Distribute. Data to the program memory followed by. Text.
(5) Allocate. BSS to the program memory followed by. Data.
(6) Allocate custom sections.
The connector can also be connected to a command file. The CMD file consists of three parts::
(1) Input and Output definitions;
You can set this part through the "build option..." menu of CCS. It mainly includes the following parts:
Specific Commands include:
-A is an executable module that generates an absolute address (cannot be located again). If-A or-R is not specified, the default value is-.
-R generates a module that can be located and unexecutable
-Ar generates executable modules that can be located again
-Connector B will not merge any repeated symbol table items that may exist due to multiple files. The result of this option is that the connector runs faster, but the cost is that the output coff file is large.
-C uses the connection Convention defined by the TMS320C54x C/C ++ Compiler's Rom automatic initialization Model
-Cr uses the connection conventions defined by the C compiler's Ram automatic initialization Model
-E global_symbol defines the global symbol as the specified main entry point of the output module.
-F Fill value is the default fill value set for the holes in the output segment. Fill value is a 16-bit constant.
-H: Make all global symbols static variables
-G global_symbol indicates that the specified global_symbol is a global symbol, regardless of whether the-H option is used.
-Help ,-? Show all available connection command line options
-Head size: sets the stack size for dynamic memory allocation in C language, in the unit of words, and defines the global symbol of the specified stack size. The default size is 1 kb.
-I dir: Change the library search method to search for Dir before the default position. This item must appear before the-l (l) option.
-L filename: specifies that an archive library file is the connector input, and filename is the file name of the archive library. This option must appear after the-I option, and the directory or file name must comply with the operating system requirements.
-M filename generates a memory (Address) ing file with the output name filename. map. This file lists the addresses of the input and output segments (including holes ).
-O filename specifies the file name (filename) of the executable output module. The default value is a. Out. The directory or file name must comply with the operating system requirements.
-Q: The request for static run (quiet run), that is, the compression flag (banner) must be the first option on the command line.
-S: remove the symbol table information and row number from the output module.
-Stack size: sets the C system stack. The size is in the unit of words and defines the global symbol for the specified stack size. The default size is 1 K.
-U Symbol: puts unresolvable external symbols into the symbol table of the output module.
-The coff file format specified by VN is n, n = 0, 1, or 2. The default value is coff2.
-W: When an output segment is not defined, a warning is issued.
-X forces the database to be reread to distinguish references
(2) MEMORY command;
Memory: defines the memory images of the target system. You can name them and specify the starting address and length.
Usage: Memory {memory space name: O = hexadecimal memory start address L = hexadecimal Memory Length}
For example:
Memory {l2ram: O = 0x10800000 L = 0x00020000 DDR2: O = 0x80000000 L = 0x10000000}
(3) Section command.
Sections: specify how to combine each input block and where each output block is stored in the memory.
Usage:
Sections {segment name 1> memory space name 1 segment name 2> memory space name 2 ...}
Example:
Sections {. BSS> l2ram. cinit> l2ram. CIO> l2ram.Const> L2ram. Data> l2ram. Far> l2ram. Stack> l2ram.Switch> L2ram. sysmem> l2ram. Text> l2ram. DDR2> DDR2}
You can also customize the section in cmd. The usage is as follows:
# Pragma data_section (function name or global variable name, "user-defined segment name in data space ");
# Pragma code_section (function name or global variable name, "user-defined segment name in the program space ");
The usage is as follows:
Sections {segment name 1> memory space name 1 segment name 2> memory space name 2}
You can refer to the following url: cmd