1<html lang="en"> 2<head> 3<title>MEMORY - 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="Scripts.html#Scripts" title="Scripts"> 9<link rel="prev" href="SECTIONS.html#SECTIONS" title="SECTIONS"> 10<link rel="next" href="PHDRS.html#PHDRS" title="PHDRS"> 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="MEMORY"></a> 43<p> 44Next: <a rel="next" accesskey="n" href="PHDRS.html#PHDRS">PHDRS</a>, 45Previous: <a rel="previous" accesskey="p" href="SECTIONS.html#SECTIONS">SECTIONS</a>, 46Up: <a rel="up" accesskey="u" href="Scripts.html#Scripts">Scripts</a> 47<hr> 48</div> 49 50<h3 class="section">3.7 MEMORY Command</h3> 51 52<p><a name="index-MEMORY-474"></a><a name="index-memory-regions-475"></a><a name="index-regions-of-memory-476"></a><a name="index-allocating-memory-477"></a><a name="index-discontinuous-memory-478"></a>The linker's default configuration permits allocation of all available 53memory. You can override this by using the <code>MEMORY</code> command. 54 55 <p>The <code>MEMORY</code> command describes the location and size of blocks of 56memory in the target. You can use it to describe which memory regions 57may be used by the linker, and which memory regions it must avoid. You 58can then assign sections to particular memory regions. The linker will 59set section addresses based on the memory regions, and will warn about 60regions that become too full. The linker will not shuffle sections 61around to fit into the available regions. 62 63 <p>A linker script may contain at most one use of the <code>MEMORY</code> 64command. However, you can define as many blocks of memory within it as 65you wish. The syntax is: 66<pre class="smallexample"> MEMORY 67 { 68 <var>name</var> [(<var>attr</var>)] : ORIGIN = <var>origin</var>, LENGTH = <var>len</var> 69 ... 70 } 71</pre> 72 <p>The <var>name</var> is a name used in the linker script to refer to the 73region. The region name has no meaning outside of the linker script. 74Region names are stored in a separate name space, and will not conflict 75with symbol names, file names, or section names. Each memory region 76must have a distinct name within the <code>MEMORY</code> command. However you can 77add later alias names to existing memory regions with the <a href="REGION_005fALIAS.html#REGION_005fALIAS">REGION_ALIAS</a> 78command. 79 80 <p><a name="index-memory-region-attributes-479"></a>The <var>attr</var> string is an optional list of attributes that specify 81whether to use a particular memory region for an input section which is 82not explicitly mapped in the linker script. As described in 83<a href="SECTIONS.html#SECTIONS">SECTIONS</a>, if you do not specify an output section for some input 84section, the linker will create an output section with the same name as 85the input section. If you define region attributes, the linker will use 86them to select the memory region for the output section that it creates. 87 88 <p>The <var>attr</var> string must consist only of the following characters: 89 <dl> 90<dt>‘<samp><span class="samp">R</span></samp>’<dd>Read-only section 91<br><dt>‘<samp><span class="samp">W</span></samp>’<dd>Read/write section 92<br><dt>‘<samp><span class="samp">X</span></samp>’<dd>Executable section 93<br><dt>‘<samp><span class="samp">A</span></samp>’<dd>Allocatable section 94<br><dt>‘<samp><span class="samp">I</span></samp>’<dd>Initialized section 95<br><dt>‘<samp><span class="samp">L</span></samp>’<dd>Same as ‘<samp><span class="samp">I</span></samp>’ 96<br><dt>‘<samp><span class="samp">!</span></samp>’<dd>Invert the sense of any of the attributes that follow 97</dl> 98 99 <p>If a unmapped section matches any of the listed attributes other than 100‘<samp><span class="samp">!</span></samp>’, it will be placed in the memory region. The ‘<samp><span class="samp">!</span></samp>’ 101attribute reverses this test, so that an unmapped section will be placed 102in the memory region only if it does not match any of the listed 103attributes. 104 105 <p><a name="index-ORIGIN-_003d-480"></a><a name="index-o-_003d-481"></a><a name="index-org-_003d-482"></a>The <var>origin</var> is an numerical expression for the start address of 106the memory region. The expression must evaluate to a constant and it 107cannot involve any symbols. The keyword <code>ORIGIN</code> may be 108abbreviated to <code>org</code> or <code>o</code> (but not, for example, 109<code>ORG</code>). 110 111 <p><a name="index-LENGTH-_003d-483"></a><a name="index-len-_003d-484"></a><a name="index-l-_003d-485"></a>The <var>len</var> is an expression for the size in bytes of the memory 112region. As with the <var>origin</var> expression, the expression must 113be numerical only and must evaluate to a constant. The keyword 114<code>LENGTH</code> may be abbreviated to <code>len</code> or <code>l</code>. 115 116 <p>In the following example, we specify that there are two memory regions 117available for allocation: one starting at ‘<samp><span class="samp">0</span></samp>’ for 256 kilobytes, 118and the other starting at ‘<samp><span class="samp">0x40000000</span></samp>’ for four megabytes. The 119linker will place into the ‘<samp><span class="samp">rom</span></samp>’ memory region every section which 120is not explicitly mapped into a memory region, and is either read-only 121or executable. The linker will place other sections which are not 122explicitly mapped into a memory region into the ‘<samp><span class="samp">ram</span></samp>’ memory 123region. 124 125<pre class="smallexample"> MEMORY 126 { 127 rom (rx) : ORIGIN = 0, LENGTH = 256K 128 ram (!rx) : org = 0x40000000, l = 4M 129 } 130</pre> 131 <p>Once you define a memory region, you can direct the linker to place 132specific output sections into that memory region by using the 133‘<samp><span class="samp">></span><var>region</var></samp>’ output section attribute. For example, if you have 134a memory region named ‘<samp><span class="samp">mem</span></samp>’, you would use ‘<samp><span class="samp">>mem</span></samp>’ in the 135output section definition. See <a href="Output-Section-Region.html#Output-Section-Region">Output Section Region</a>. If no address 136was specified for the output section, the linker will set the address to 137the next available address within the memory region. If the combined 138output sections directed to a memory region are too large for the 139region, the linker will issue an error message. 140 141 <p>It is possible to access the origin and length of a memory in an 142expression via the <code>ORIGIN(</code><var>memory</var><code>)</code> and 143<code>LENGTH(</code><var>memory</var><code>)</code> functions: 144 145<pre class="smallexample"> _fstack = ORIGIN(ram) + LENGTH(ram) - 4; 146</pre> 147 </body></html> 148 149