📄 location-counter.html
字号:
<html lang="en">
<head>
<title>Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
</head>
<body>
<div class="node">
<p>
Node:<a name="Location%20Counter">Location Counter</a>,
Next:<a rel="next" accesskey="n" href="Operators.html#Operators">Operators</a>,
Previous:<a rel="previous" accesskey="p" href="Symbols.html#Symbols">Symbols</a>,
Up:<a rel="up" accesskey="u" href="Expressions.html#Expressions">Expressions</a>
<hr><br>
</div>
<h4 class="subsection">The Location Counter</h4>
<p>The special linker variable <dfn>dot</dfn> <code>.</code> always contains the
current output location counter. Since the <code>.</code> always refers to a
location in an output section, it may only appear in an expression
within a <code>SECTIONS</code> command. The <code>.</code> symbol may appear
anywhere that an ordinary symbol is allowed in an expression.
<p>Assigning a value to <code>.</code> will cause the location counter to be
moved. This may be used to create holes in the output section. The
location counter may never be moved backwards.
<pre class="smallexample"> SECTIONS
{
output :
{
file1(.text)
. = . + 1000;
file2(.text)
. += 1000;
file3(.text)
} = 0x12345678;
}
</pre>
<p>In the previous example, the <code>.text</code> section from <code>file1</code> is
located at the beginning of the output section <code>output</code>. It is
followed by a 1000 byte gap. Then the <code>.text</code> section from
<code>file2</code> appears, also with a 1000 byte gap following before the
<code>.text</code> section from <code>file3</code>. The notation <code>= 0x12345678</code>
specifies what data to write in the gaps (see <a href="Output-Section-Fill.html#Output%20Section%20Fill">Output Section Fill</a>).
<p>Note: <code>.</code> actually refers to the byte offset from the start of the
current containing object. Normally this is the <code>SECTIONS</code>
statement, whoes start address is 0, hence <code>.</code> can be used as an
absolute address. If <code>.</code> is used inside a section description
however, it refers to the byte offset from the start of that section,
not an absolute address. Thus in a script like this:
<pre class="smallexample"> SECTIONS
{
. = 0x100
.text: {
*(.text)
. = 0x200
}
. = 0x500
.data: {
*(.data)
. += 0x600
}
}
</pre>
<p>The <code>.text</code> section will be assigned a starting address of 0x100
and a size of exactly 0x200 bytes, even if there is not enough data in
the <code>.text</code> input sections to fill this area. (If there is too
much data, an error will be produced because this would be an attempt to
move <code>.</code> backwards). The <code>.data</code> section will start at 0x500
and it will have an extra 0x600 bytes worth of space after the end of
the values from the <code>.data</code> input sections and before the end of
the <code>.data</code> output section itself.
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -