⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memory.html

📁 gcc手册
💻 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="MEMORY">MEMORY</a>,

Next:<a rel="next" accesskey="n" href="PHDRS.html#PHDRS">PHDRS</a>,

Previous:<a rel="previous" accesskey="p" href="SECTIONS.html#SECTIONS">SECTIONS</a>,

Up:<a rel="up" accesskey="u" href="Scripts.html#Scripts">Scripts</a>

<hr><br>

</div>



<h3 class="section">MEMORY command</h3>



   <p>The linker's default configuration permits allocation of all available

memory.  You can override this by using the <code>MEMORY</code> command.



   <p>The <code>MEMORY</code> command describes the location and size of blocks of

memory in the target.  You can use it to describe which memory regions

may be used by the linker, and which memory regions it must avoid.  You

can then assign sections to particular memory regions.  The linker will

set section addresses based on the memory regions, and will warn about

regions that become too full.  The linker will not shuffle sections

around to fit into the available regions.



   <p>A linker script may contain at most one use of the <code>MEMORY</code>

command.  However, you can define as many blocks of memory within it as

you wish.  The syntax is:

<pre class="smallexample">     MEMORY

       {

         <var>name</var> [(<var>attr</var>)] : ORIGIN = <var>origin</var>, LENGTH = <var>len</var>

         ...

       }

     </pre>



   <p>The <var>name</var> is a name used in the linker script to refer to the

region.  The region name has no meaning outside of the linker script. 

Region names are stored in a separate name space, and will not conflict

with symbol names, file names, or section names.  Each memory region

must have a distinct name.



   <p>The <var>attr</var> string is an optional list of attributes that specify

whether to use a particular memory region for an input section which is

not explicitly mapped in the linker script.  As described in

<a href="SECTIONS.html#SECTIONS">SECTIONS</a>, if you do not specify an output section for some input

section, the linker will create an output section with the same name as

the input section.  If you define region attributes, the linker will use

them to select the memory region for the output section that it creates.



   <p>The <var>attr</var> string must consist only of the following characters:

     <dl>

<dt><code>R</code>

     <dd>Read-only section

<br><dt><code>W</code>

     <dd>Read/write section

<br><dt><code>X</code>

     <dd>Executable section

<br><dt><code>A</code>

     <dd>Allocatable section

<br><dt><code>I</code>

     <dd>Initialized section

<br><dt><code>L</code>

     <dd>Same as <code>I</code>

<br><dt><code>!</code>

     <dd>Invert the sense of any of the preceding attributes

</dl>



   <p>If a unmapped section matches any of the listed attributes other than

<code>!</code>, it will be placed in the memory region.  The <code>!</code>

attribute reverses this test, so that an unmapped section will be placed

in the memory region only if it does not match any of the listed

attributes.



   <p>The <var>origin</var> is an expression for the start address of the memory

region.  The expression must evaluate to a constant before memory

allocation is performed, which means that you may not use any section

relative symbols.  The keyword <code>ORIGIN</code> may be abbreviated to

<code>org</code> or <code>o</code> (but not, for example, <code>ORG</code>).



   <p>The <var>len</var> is an expression for the size in bytes of the memory

region.  As with the <var>origin</var> expression, the expression must

evaluate to a constant before memory allocation is performed.  The

keyword <code>LENGTH</code> may be abbreviated to <code>len</code> or <code>l</code>.



   <p>In the following example, we specify that there are two memory regions

available for allocation: one starting at <code>0</code> for 256 kilobytes,

and the other starting at <code>0x40000000</code> for four megabytes.  The

linker will place into the <code>rom</code> memory region every section which

is not explicitly mapped into a memory region, and is either read-only

or executable.  The linker will place other sections which are not

explicitly mapped into a memory region into the <code>ram</code> memory

region.



<pre class="smallexample">     MEMORY

       {

         rom (rx)  : ORIGIN = 0, LENGTH = 256K

         ram (!rx) : org = 0x40000000, l = 4M

       }

     </pre>



   <p>Once you define a memory region, you can direct the linker to place

specific output sections into that memory region by using the

<code>&gt;</code><var>region</var><code></code> output section attribute.  For example, if you have

a memory region named <code>mem</code>, you would use <code>&gt;mem</code> in the

output section definition.  See <a href="Output-Section-Region.html#Output%20Section%20Region">Output Section Region</a>.  If no address

was specified for the output section, the linker will set the address to

the next available address within the memory region.  If the combined

output sections directed to a memory region are too large for the

region, the linker will issue an error message.



   </body></html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -