• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2011.09/share/doc/arm-arm-none-eabi/html/ld.html/
1<html lang="en">
2<head>
3<title>Location Counter - Untitled</title>
4<meta http-equiv="Content-Type" content="text/html">
5<meta name="description" content="Untitled">
6<meta name="generator" content="makeinfo 4.13">
7<link title="Top" rel="start" href="index.html#Top">
8<link rel="up" href="Expressions.html#Expressions" title="Expressions">
9<link rel="prev" href="Orphan-Sections.html#Orphan-Sections" title="Orphan Sections">
10<link rel="next" href="Operators.html#Operators" title="Operators">
11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12<!--
13This file documents the GNU linker LD
14(Sourcery CodeBench Lite 2011.09-69)
15version 2.21.53.
16
17Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
182001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
19
20Permission is granted to copy, distribute and/or modify this document
21under the terms of the GNU Free Documentation License, Version 1.3
22or any later version published by the Free Software Foundation;
23with no Invariant Sections, with no Front-Cover Texts, and with no
24Back-Cover Texts.  A copy of the license is included in the
25section entitled ``GNU Free Documentation License''.-->
26<meta http-equiv="Content-Style-Type" content="text/css">
27<style type="text/css"><!--
28  pre.display { font-family:inherit }
29  pre.format  { font-family:inherit }
30  pre.smalldisplay { font-family:inherit; font-size:smaller }
31  pre.smallformat  { font-family:inherit; font-size:smaller }
32  pre.smallexample { font-size:smaller }
33  pre.smalllisp    { font-size:smaller }
34  span.sc    { font-variant:small-caps }
35  span.roman { font-family:serif; font-weight:normal; } 
36  span.sansserif { font-family:sans-serif; font-weight:normal; } 
37--></style>
38<link rel="stylesheet" type="text/css" href="../cs.css">
39</head>
40<body>
41<div class="node">
42<a name="Location-Counter"></a>
43<p>
44Next:&nbsp;<a rel="next" accesskey="n" href="Operators.html#Operators">Operators</a>,
45Previous:&nbsp;<a rel="previous" accesskey="p" href="Orphan-Sections.html#Orphan-Sections">Orphan Sections</a>,
46Up:&nbsp;<a rel="up" accesskey="u" href="Expressions.html#Expressions">Expressions</a>
47<hr>
48</div>
49
50<h4 class="subsection">3.10.5 The Location Counter</h4>
51
52<p><a name="index-g_t_002e-515"></a><a name="index-dot-516"></a><a name="index-location-counter-517"></a><a name="index-current-output-location-518"></a>The special linker variable <dfn>dot</dfn> &lsquo;<samp><span class="samp">.</span></samp>&rsquo; always contains the
53current output location counter.  Since the <code>.</code> always refers to a
54location in an output section, it may only appear in an expression
55within a <code>SECTIONS</code> command.  The <code>.</code> symbol may appear
56anywhere that an ordinary symbol is allowed in an expression.
57
58   <p><a name="index-holes-519"></a>Assigning a value to <code>.</code> will cause the location counter to be
59moved.  This may be used to create holes in the output section.  The
60location counter may not be moved backwards inside an output section,
61and may not be moved backwards outside of an output section if so
62doing creates areas with overlapping LMAs.
63
64<pre class="smallexample">     SECTIONS
65     {
66       output :
67         {
68           file1(.text)
69           . = . + 1000;
70           file2(.text)
71           . += 1000;
72           file3(.text)
73         } = 0x12345678;
74     }
75</pre>
76   <p class="noindent">In the previous example, the &lsquo;<samp><span class="samp">.text</span></samp>&rsquo; section from <samp><span class="file">file1</span></samp> is
77located at the beginning of the output section &lsquo;<samp><span class="samp">output</span></samp>&rsquo;.  It is
78followed by a 1000 byte gap.  Then the &lsquo;<samp><span class="samp">.text</span></samp>&rsquo; section from
79<samp><span class="file">file2</span></samp> appears, also with a 1000 byte gap following before the
80&lsquo;<samp><span class="samp">.text</span></samp>&rsquo; section from <samp><span class="file">file3</span></samp>.  The notation &lsquo;<samp><span class="samp">= 0x12345678</span></samp>&rsquo;
81specifies what data to write in the gaps (see <a href="Output-Section-Fill.html#Output-Section-Fill">Output Section Fill</a>).
82
83   <p><a name="index-dot-inside-sections-520"></a>Note: <code>.</code> actually refers to the byte offset from the start of the
84current containing object.  Normally this is the <code>SECTIONS</code>
85statement, whose start address is 0, hence <code>.</code> can be used as an
86absolute address.  If <code>.</code> is used inside a section description
87however, it refers to the byte offset from the start of that section,
88not an absolute address.  Thus in a script like this:
89
90<pre class="smallexample">     SECTIONS
91     {
92         . = 0x100
93         .text: {
94           *(.text)
95           . = 0x200
96         }
97         . = 0x500
98         .data: {
99           *(.data)
100           . += 0x600
101         }
102     }
103</pre>
104   <p>The &lsquo;<samp><span class="samp">.text</span></samp>&rsquo; section will be assigned a starting address of 0x100
105and a size of exactly 0x200 bytes, even if there is not enough data in
106the &lsquo;<samp><span class="samp">.text</span></samp>&rsquo; input sections to fill this area.  (If there is too
107much data, an error will be produced because this would be an attempt to
108move <code>.</code> backwards).  The &lsquo;<samp><span class="samp">.data</span></samp>&rsquo; section will start at 0x500
109and it will have an extra 0x600 bytes worth of space after the end of
110the values from the &lsquo;<samp><span class="samp">.data</span></samp>&rsquo; input sections and before the end of
111the &lsquo;<samp><span class="samp">.data</span></samp>&rsquo; output section itself.
112
113   <p><a name="index-dot-outside-sections-521"></a>Setting symbols to the value of the location counter outside of an
114output section statement can result in unexpected values if the linker
115needs to place orphan sections.  For example, given the following:
116
117<pre class="smallexample">     SECTIONS
118     {
119         start_of_text = . ;
120         .text: { *(.text) }
121         end_of_text = . ;
122     
123         start_of_data = . ;
124         .data: { *(.data) }
125         end_of_data = . ;
126     }
127</pre>
128   <p>If the linker needs to place some input section, e.g. <code>.rodata</code>,
129not mentioned in the script, it might choose to place that section
130between <code>.text</code> and <code>.data</code>.  You might think the linker
131should place <code>.rodata</code> on the blank line in the above script, but
132blank lines are of no particular significance to the linker.  As well,
133the linker doesn't associate the above symbol names with their
134sections.  Instead, it assumes that all assignments or other
135statements belong to the previous output section, except for the
136special case of an assignment to <code>.</code>.  I.e., the linker will
137place the orphan <code>.rodata</code> section as if the script was written
138as follows:
139
140<pre class="smallexample">     SECTIONS
141     {
142         start_of_text = . ;
143         .text: { *(.text) }
144         end_of_text = . ;
145     
146         start_of_data = . ;
147         .rodata: { *(.rodata) }
148         .data: { *(.data) }
149         end_of_data = . ;
150     }
151</pre>
152   <p>This may or may not be the script author's intention for the value of
153<code>start_of_data</code>.  One way to influence the orphan section
154placement is to assign the location counter to itself, as the linker
155assumes that an assignment to <code>.</code> is setting the start address of
156a following output section and thus should be grouped with that
157section.  So you could write:
158
159<pre class="smallexample">     SECTIONS
160     {
161         start_of_text = . ;
162         .text: { *(.text) }
163         end_of_text = . ;
164     
165         . = . ;
166         start_of_data = . ;
167         .data: { *(.data) }
168         end_of_data = . ;
169     }
170</pre>
171   <p>Now, the orphan <code>.rodata</code> section will be placed between
172<code>end_of_text</code> and <code>start_of_data</code>.
173
174   </body></html>
175
176