You may assign a value to a symbol in a linker script. This will define the symbol and place it into the symbol table with a global scope.
Simple Assignments
--------------------------------------------------------
You may assign to a symbol using any of the C assignment operators:
symbol
=
expression ;
symbol +=
expression ;
symbol -=
expression ;
symbol *=
expression ;
symbol /=
expression ;
symbol <<=
expression ;
symbol >>=
expression ;
symbol &=
expression ;
symbol |=
expression ;
你可以使用C赋值操作的任何一种完成符号赋值.
symbol = expression ; symbol += expression ; symbol -= expression ; symbol *= expression ; symbol /= expression ; symbol <<= expression ; symbol >>= expression ; symbol &= expression ; symbol |= expression ;
The first case will define symbol to the value of expression. In the other cases, symbol must already be defined, and the value will be adjusted accordingly.
第一方式是定义符号为一个表达式的值. 在其它方式中,符号必须已经定义过了,并且它的值将被相应地调整.
The special symbol name ‘.’ indicates the location counter. You may only use this within a SECTIONS command. See Location Counter.
特殊的符号'.'表示位置计数.你可能仅仅在一个SECTIONS命令里使用它.
The semicolon after expression is required.
在表达式之后的必须要有分号
Expressions are defined below; see Expressions.
表达式被定义在后面;请看'表达式'这一节.
You may write symbol assignments as commands in their own right, or as statements within a SECTIONS command, or as part of an output section description in a SECTIONS command.
你可能把符号赋值作为有效的命令,或SECTION命令中的一个声明,又或者是SECTION命令中一个输出section描述.
The section of the symbol will be set from the section of the expression; for more information, see Expression Section.
在表达式的section中设置符号的section;详细的信息,可以参考'表达式'这一节.
Here is an example showing the three different places that symbol assignments may be used:
举一个使用在三个不同地方给符号赋值的例子:
floating_point = 0;
SECTIONS
{
.text :
{
*(.text)
_etext = .;
}
_bdata = (. + 3) & ~ 3;
.data : { *(.data) }
}
In this example, the symbol ‘floating_point’ will be defined as zero. The symbol ‘_etext’ will be defined as the address following the last ‘.text’ input section. The symbol ‘_bdata’ will be defined as the address following the ‘.text’ output section aligned upward to a 4 byte boundary.
在这个例子中,符号'floating_point'将被定义为0. 符号'_etext'将被设置为前一个'.text'输入section之后的地址.
符号'_bdata'将被设置为'.text'输出section之后对齐4字节的地址.