You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
9.5 KiB
HTML
212 lines
9.5 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!-- This file documents the GNU linker LD
|
|
(SiFive Binutils 2.32.0-2020.04.1)
|
|
version 2.32.
|
|
|
|
Copyright (C) 1991-2019 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3
|
|
or any later version published by the Free Software Foundation;
|
|
with no Invariant Sections, with no Front-Cover Texts, and with no
|
|
Back-Cover Texts. A copy of the license is included in the
|
|
section entitled "GNU Free Documentation License". -->
|
|
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<title>MEMORY (LD)</title>
|
|
|
|
<meta name="description" content="MEMORY (LD)">
|
|
<meta name="keywords" content="MEMORY (LD)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content="makeinfo">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link href="index.html#Top" rel="start" title="Top">
|
|
<link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="Scripts.html#Scripts" rel="up" title="Scripts">
|
|
<link href="PHDRS.html#PHDRS" rel="next" title="PHDRS">
|
|
<link href="Overlay-Description.html#Overlay-Description" rel="prev" title="Overlay Description">
|
|
<style type="text/css">
|
|
<!--
|
|
a.summary-letter {text-decoration: none}
|
|
blockquote.indentedblock {margin-right: 0em}
|
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
|
blockquote.smallquotation {font-size: smaller}
|
|
div.display {margin-left: 3.2em}
|
|
div.example {margin-left: 3.2em}
|
|
div.lisp {margin-left: 3.2em}
|
|
div.smalldisplay {margin-left: 3.2em}
|
|
div.smallexample {margin-left: 3.2em}
|
|
div.smalllisp {margin-left: 3.2em}
|
|
kbd {font-style: oblique}
|
|
pre.display {font-family: inherit}
|
|
pre.format {font-family: inherit}
|
|
pre.menu-comment {font-family: serif}
|
|
pre.menu-preformatted {font-family: serif}
|
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
|
pre.smallexample {font-size: smaller}
|
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
|
pre.smalllisp {font-size: smaller}
|
|
span.nolinebreak {white-space: nowrap}
|
|
span.roman {font-family: initial; font-weight: normal}
|
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
|
ul.no-bullet {list-style: none}
|
|
-->
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<a name="MEMORY"></a>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="PHDRS.html#PHDRS" accesskey="n" rel="next">PHDRS</a>, Previous: <a href="SECTIONS.html#SECTIONS" accesskey="p" rel="prev">SECTIONS</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</a> [<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>
|
|
</div>
|
|
<hr>
|
|
<a name="MEMORY-Command"></a>
|
|
<h3 class="section">3.7 MEMORY Command</h3>
|
|
<a name="index-MEMORY"></a>
|
|
<a name="index-memory-regions"></a>
|
|
<a name="index-regions-of-memory"></a>
|
|
<a name="index-allocating-memory"></a>
|
|
<a name="index-discontinuous-memory"></a>
|
|
<p>The linker’s default configuration permits allocation of all available
|
|
memory. You can override this by using the <code>MEMORY</code> command.
|
|
</p>
|
|
<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>
|
|
<p>A linker script may contain many uses of the <code>MEMORY</code> command,
|
|
however, all memory blocks defined are treated as if they were
|
|
specified inside a single <code>MEMORY</code> command. The syntax for
|
|
<code>MEMORY</code> is:
|
|
</p><div class="smallexample">
|
|
<pre class="smallexample">MEMORY
|
|
{
|
|
<var>name</var> [(<var>attr</var>)] : ORIGIN = <var>origin</var>, LENGTH = <var>len</var>
|
|
…
|
|
}
|
|
</pre></div>
|
|
|
|
<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 within the <code>MEMORY</code> command. However you can
|
|
add later alias names to existing memory regions with the <a href="REGION_005fALIAS.html#REGION_005fALIAS">REGION_ALIAS</a>
|
|
command.
|
|
</p>
|
|
<a name="index-memory-region-attributes"></a>
|
|
<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>
|
|
<p>The <var>attr</var> string must consist only of the following characters:
|
|
</p><dl compact="compact">
|
|
<dt>‘<samp>R</samp>’</dt>
|
|
<dd><p>Read-only section
|
|
</p></dd>
|
|
<dt>‘<samp>W</samp>’</dt>
|
|
<dd><p>Read/write section
|
|
</p></dd>
|
|
<dt>‘<samp>X</samp>’</dt>
|
|
<dd><p>Executable section
|
|
</p></dd>
|
|
<dt>‘<samp>A</samp>’</dt>
|
|
<dd><p>Allocatable section
|
|
</p></dd>
|
|
<dt>‘<samp>I</samp>’</dt>
|
|
<dd><p>Initialized section
|
|
</p></dd>
|
|
<dt>‘<samp>L</samp>’</dt>
|
|
<dd><p>Same as ‘<samp>I</samp>’
|
|
</p></dd>
|
|
<dt>‘<samp>!</samp>’</dt>
|
|
<dd><p>Invert the sense of any of the attributes that follow
|
|
</p></dd>
|
|
</dl>
|
|
|
|
<p>If an unmapped section matches any of the listed attributes other than
|
|
‘<samp>!</samp>’, it will be placed in the memory region. The ‘<samp>!</samp>’
|
|
attribute reverses the test for the characters that follow, so that an
|
|
unmapped section will be placed in the memory region only if it does
|
|
not match any of the attributes listed afterwards. Thus an attribute
|
|
string of ‘<samp>RW!X</samp>’ will match any unmapped section that has either
|
|
or both of the ‘<samp>R</samp>’ and ‘<samp>W</samp>’ attributes, but only as long as
|
|
the section does not also have the ‘<samp>X</samp>’ attribute.
|
|
</p>
|
|
<a name="index-ORIGIN-_003d"></a>
|
|
<a name="index-o-_003d"></a>
|
|
<a name="index-org-_003d"></a>
|
|
<p>The <var>origin</var> is an numerical expression for the start address of
|
|
the memory region. The expression must evaluate to a constant and it
|
|
cannot involve any 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>
|
|
<a name="index-LENGTH-_003d"></a>
|
|
<a name="index-len-_003d"></a>
|
|
<a name="index-l-_003d"></a>
|
|
<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
|
|
be numerical only and must evaluate to a constant. The keyword
|
|
<code>LENGTH</code> may be abbreviated to <code>len</code> or <code>l</code>.
|
|
</p>
|
|
<p>In the following example, we specify that there are two memory regions
|
|
available for allocation: one starting at ‘<samp>0</samp>’ for 256 kilobytes,
|
|
and the other starting at ‘<samp>0x40000000</samp>’ for four megabytes. The
|
|
linker will place into the ‘<samp>rom</samp>’ 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 ‘<samp>ram</samp>’ memory
|
|
region.
|
|
</p>
|
|
<div class="smallexample">
|
|
<pre class="smallexample">MEMORY
|
|
{
|
|
rom (rx) : ORIGIN = 0, LENGTH = 256K
|
|
ram (!rx) : org = 0x40000000, l = 4M
|
|
}
|
|
</pre></div>
|
|
|
|
<p>Once you define a memory region, you can direct the linker to place
|
|
specific output sections into that memory region by using the
|
|
‘<samp>><var>region</var></samp>’ output section attribute. For example, if you have
|
|
a memory region named ‘<samp>mem</samp>’, you would use ‘<samp>>mem</samp>’ in the
|
|
output section definition. See <a href="Output-Section-Region.html#Output-Section-Region">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.
|
|
</p>
|
|
<p>It is possible to access the origin and length of a memory in an
|
|
expression via the <code>ORIGIN(<var>memory</var>)</code> and
|
|
<code>LENGTH(<var>memory</var>)</code> functions:
|
|
</p>
|
|
<div class="smallexample">
|
|
<pre class="smallexample"> _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
|
|
</pre></div>
|
|
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
Next: <a href="PHDRS.html#PHDRS" accesskey="n" rel="next">PHDRS</a>, Previous: <a href="SECTIONS.html#SECTIONS" accesskey="p" rel="prev">SECTIONS</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</a> [<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>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|