1<html lang="en"> 2<head> 3<title>Output Section Address - 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="SECTIONS.html#SECTIONS" title="SECTIONS"> 9<link rel="prev" href="Output-Section-Name.html#Output-Section-Name" title="Output Section Name"> 10<link rel="next" href="Input-Section.html#Input-Section" title="Input Section"> 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="Output-Section-Address"></a> 43<p> 44Next: <a rel="next" accesskey="n" href="Input-Section.html#Input-Section">Input Section</a>, 45Previous: <a rel="previous" accesskey="p" href="Output-Section-Name.html#Output-Section-Name">Output Section Name</a>, 46Up: <a rel="up" accesskey="u" href="SECTIONS.html#SECTIONS">SECTIONS</a> 47<hr> 48</div> 49 50<h4 class="subsection">3.6.3 Output Section Address</h4> 51 52<p><a name="index-address_002c-section-403"></a><a name="index-section-address-404"></a>The <var>address</var> is an expression for the VMA (the virtual memory 53address) of the output section. This address is optional, but if it 54is provided then the output address will be set exactly as specified. 55 56 <p>If the output address is not specified then one will be chosen for the 57section, based on the heuristic below. This address will be adjusted 58to fit the alignment requirement of the output section. The 59alignment requirement is the strictest alignment of any input section 60contained within the output section. 61 62 <p>The output section address heuristic is as follows: 63 64 <ul> 65<li>If an output memory <var>region</var> is set for the section then it 66is added to this region and its address will be the next free address 67in that region. 68 69 <li>If the MEMORY command has been used to create a list of memory 70regions then the first region which has attributes compatible with the 71section is selected to contain it. The section's output address will 72be the next free address in that region; <a href="MEMORY.html#MEMORY">MEMORY</a>. 73 74 <li>If no memory regions were specified, or none match the section then 75the output address will be based on the current value of the location 76counter. 77</ul> 78 79<p class="noindent">For example: 80 81<pre class="smallexample"> .text . : { *(.text) } 82</pre> 83 <p class="noindent">and 84 85<pre class="smallexample"> .text : { *(.text) } 86</pre> 87 <p class="noindent">are subtly different. The first will set the address of the 88‘<samp><span class="samp">.text</span></samp>’ output section to the current value of the location 89counter. The second will set it to the current value of the location 90counter aligned to the strictest alignment of any of the ‘<samp><span class="samp">.text</span></samp>’ 91input sections. 92 93 <p>The <var>address</var> may be an arbitrary expression; <a href="Expressions.html#Expressions">Expressions</a>. 94For example, if you want to align the section on a 0x10 byte boundary, 95so that the lowest four bits of the section address are zero, you could 96do something like this: 97<pre class="smallexample"> .text ALIGN(0x10) : { *(.text) } 98</pre> 99 <p class="noindent">This works because <code>ALIGN</code> returns the current location counter 100aligned upward to the specified value. 101 102 <p>Specifying <var>address</var> for a section will change the value of the 103location counter, provided that the section is non-empty. (Empty 104sections are ignored). 105 106 </body></html> 107 108