1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- This file documents the GNU linker LD
4(GNU Toolchain for the A-profile Architecture 10.3-2021.07 (arm-10.29))
5version 2.36.1.
6
7Copyright (C) 1991-2021 Free Software Foundation, Inc.
8
9Permission is granted to copy, distribute and/or modify this document
10under the terms of the GNU Free Documentation License, Version 1.3
11or any later version published by the Free Software Foundation;
12with no Invariant Sections, with no Front-Cover Texts, and with no
13Back-Cover Texts.  A copy of the license is included in the
14section entitled "GNU Free Documentation License". -->
15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
16<head>
17<title>LD: Output Section Address</title>
18
19<meta name="description" content="LD: Output Section Address">
20<meta name="keywords" content="LD: Output Section Address">
21<meta name="resource-type" content="document">
22<meta name="distribution" content="global">
23<meta name="Generator" content="makeinfo">
24<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
25<link href="index.html#Top" rel="start" title="Top">
26<link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
28<link href="SECTIONS.html#SECTIONS" rel="up" title="SECTIONS">
29<link href="Input-Section.html#Input-Section" rel="next" title="Input Section">
30<link href="Output-Section-Name.html#Output-Section-Name" rel="previous" title="Output Section Name">
31<style type="text/css">
32<!--
33a.summary-letter {text-decoration: none}
34blockquote.smallquotation {font-size: smaller}
35div.display {margin-left: 3.2em}
36div.example {margin-left: 3.2em}
37div.indentedblock {margin-left: 3.2em}
38div.lisp {margin-left: 3.2em}
39div.smalldisplay {margin-left: 3.2em}
40div.smallexample {margin-left: 3.2em}
41div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
42div.smalllisp {margin-left: 3.2em}
43kbd {font-style:oblique}
44pre.display {font-family: inherit}
45pre.format {font-family: inherit}
46pre.menu-comment {font-family: serif}
47pre.menu-preformatted {font-family: serif}
48pre.smalldisplay {font-family: inherit; font-size: smaller}
49pre.smallexample {font-size: smaller}
50pre.smallformat {font-family: inherit; font-size: smaller}
51pre.smalllisp {font-size: smaller}
52span.nocodebreak {white-space:nowrap}
53span.nolinebreak {white-space:nowrap}
54span.roman {font-family:serif; font-weight:normal}
55span.sansserif {font-family:sans-serif; font-weight:normal}
56ul.no-bullet {list-style: none}
57-->
58</style>
59
60
61</head>
62
63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
64<a name="Output-Section-Address"></a>
65<div class="header">
66<p>
67Next: <a href="Input-Section.html#Input-Section" accesskey="n" rel="next">Input Section</a>, Previous: <a href="Output-Section-Name.html#Output-Section-Name" accesskey="p" rel="previous">Output Section Name</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
68</div>
69<hr>
70<a name="Output-Section-Address-1"></a>
71<h4 class="subsection">3.6.3 Output Section Address</h4>
72<a name="index-address_002c-section"></a>
73<a name="index-section-address"></a>
74<p>The <var>address</var> is an expression for the VMA (the virtual memory
75address) of the output section.  This address is optional, but if it
76is provided then the output address will be set exactly as specified.
77</p>
78<p>If the output address is not specified then one will be chosen for the
79section, based on the heuristic below.  This address will be adjusted
80to fit the alignment requirement of the output section.  The
81alignment requirement is the strictest alignment of any input section
82contained within the output section.
83</p>
84<p>The output section address heuristic is as follows:
85</p>
86<ul>
87<li> If an output memory <var>region</var> is set for the section then it
88is added to this region and its address will be the next free address
89in that region.
90
91</li><li> If the MEMORY command has been used to create a list of memory
92regions then the first region which has attributes compatible with the
93section is selected to contain it.  The section&rsquo;s output address will
94be the next free address in that region; <a href="MEMORY.html#MEMORY">MEMORY</a>.
95
96</li><li> If no memory regions were specified, or none match the section then
97the output address will be based on the current value of the location
98counter.
99</li></ul>
100
101<p>For example:
102</p>
103<div class="smallexample">
104<pre class="smallexample">.text . : { *(.text) }
105</pre></div>
106
107<p>and
108</p>
109<div class="smallexample">
110<pre class="smallexample">.text : { *(.text) }
111</pre></div>
112
113<p>are subtly different.  The first will set the address of the
114&lsquo;<samp>.text</samp>&rsquo; output section to the current value of the location
115counter.  The second will set it to the current value of the location
116counter aligned to the strictest alignment of any of the &lsquo;<samp>.text</samp>&rsquo;
117input sections.
118</p>
119<p>The <var>address</var> may be an arbitrary expression; <a href="Expressions.html#Expressions">Expressions</a>.
120For example, if you want to align the section on a 0x10 byte boundary,
121so that the lowest four bits of the section address are zero, you could
122do something like this:
123</p><div class="smallexample">
124<pre class="smallexample">.text ALIGN(0x10) : { *(.text) }
125</pre></div>
126<p>This works because <code>ALIGN</code> returns the current location counter
127aligned upward to the specified value.
128</p>
129<p>Specifying <var>address</var> for a section will change the value of the
130location counter, provided that the section is non-empty.  (Empty
131sections are ignored).
132</p>
133<hr>
134<div class="header">
135<p>
136Next: <a href="Input-Section.html#Input-Section" accesskey="n" rel="next">Input Section</a>, Previous: <a href="Output-Section-Name.html#Output-Section-Name" accesskey="p" rel="previous">Output Section Name</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
137</div>
138
139
140
141</body>
142</html>
143