188 lines
8.6 KiB
HTML
188 lines
8.6 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
|
||
|
(Linaro_Binutils-2017.02)
|
||
|
version 2.27.0.
|
||
|
|
||
|
Copyright (C) 1991-2016 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 5.2, http://www.gnu.org/software/texinfo/ -->
|
||
|
<head>
|
||
|
<title>LD: Overlay Description</title>
|
||
|
|
||
|
<meta name="description" content="LD: Overlay Description">
|
||
|
<meta name="keywords" content="LD: Overlay Description">
|
||
|
<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="SECTIONS.html#SECTIONS" rel="up" title="SECTIONS">
|
||
|
<link href="MEMORY.html#MEMORY" rel="next" title="MEMORY">
|
||
|
<link href="Output-Section-Fill.html#Output-Section-Fill" rel="prev" title="Output Section Fill">
|
||
|
<style type="text/css">
|
||
|
<!--
|
||
|
a.summary-letter {text-decoration: none}
|
||
|
blockquote.smallquotation {font-size: smaller}
|
||
|
div.display {margin-left: 3.2em}
|
||
|
div.example {margin-left: 3.2em}
|
||
|
div.indentedblock {margin-left: 3.2em}
|
||
|
div.lisp {margin-left: 3.2em}
|
||
|
div.smalldisplay {margin-left: 3.2em}
|
||
|
div.smallexample {margin-left: 3.2em}
|
||
|
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
|
||
|
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.nocodebreak {white-space:nowrap}
|
||
|
span.nolinebreak {white-space:nowrap}
|
||
|
span.roman {font-family:serif; font-weight:normal}
|
||
|
span.sansserif {font-family:sans-serif; font-weight:normal}
|
||
|
ul.no-bullet {list-style: none}
|
||
|
-->
|
||
|
</style>
|
||
|
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
|
||
|
<a name="Overlay-Description"></a>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Previous: <a href="Output-Section-Attributes.html#Output-Section-Attributes" accesskey="p" rel="prev">Output Section Attributes</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</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="Overlay-Description-1"></a>
|
||
|
<h4 class="subsection">3.6.9 Overlay Description</h4>
|
||
|
<a name="index-OVERLAY"></a>
|
||
|
<a name="index-overlays"></a>
|
||
|
<p>An overlay description provides an easy way to describe sections which
|
||
|
are to be loaded as part of a single memory image but are to be run at
|
||
|
the same memory address. At run time, some sort of overlay manager will
|
||
|
copy the overlaid sections in and out of the runtime memory address as
|
||
|
required, perhaps by simply manipulating addressing bits. This approach
|
||
|
can be useful, for example, when a certain region of memory is faster
|
||
|
than another.
|
||
|
</p>
|
||
|
<p>Overlays are described using the <code>OVERLAY</code> command. The
|
||
|
<code>OVERLAY</code> command is used within a <code>SECTIONS</code> command, like an
|
||
|
output section description. The full syntax of the <code>OVERLAY</code>
|
||
|
command is as follows:
|
||
|
</p><div class="smallexample">
|
||
|
<pre class="smallexample">OVERLAY [<var>start</var>] : [NOCROSSREFS] [AT ( <var>ldaddr</var> )]
|
||
|
{
|
||
|
<var>secname1</var>
|
||
|
{
|
||
|
<var>output-section-command</var>
|
||
|
<var>output-section-command</var>
|
||
|
…
|
||
|
} [:<var>phdr</var>…] [=<var>fill</var>]
|
||
|
<var>secname2</var>
|
||
|
{
|
||
|
<var>output-section-command</var>
|
||
|
<var>output-section-command</var>
|
||
|
…
|
||
|
} [:<var>phdr</var>…] [=<var>fill</var>]
|
||
|
…
|
||
|
} [><var>region</var>] [:<var>phdr</var>…] [=<var>fill</var>] [,]
|
||
|
</pre></div>
|
||
|
|
||
|
<p>Everything is optional except <code>OVERLAY</code> (a keyword), and each
|
||
|
section must have a name (<var>secname1</var> and <var>secname2</var> above). The
|
||
|
section definitions within the <code>OVERLAY</code> construct are identical to
|
||
|
those within the general <code>SECTIONS</code> construct (see <a href="SECTIONS.html#SECTIONS">SECTIONS</a>),
|
||
|
except that no addresses and no memory regions may be defined for
|
||
|
sections within an <code>OVERLAY</code>.
|
||
|
</p>
|
||
|
<p>The comma at the end may be required if a <var>fill</var> is used and
|
||
|
the next <var>sections-command</var> looks like a continuation of the expression.
|
||
|
</p>
|
||
|
<p>The sections are all defined with the same starting address. The load
|
||
|
addresses of the sections are arranged such that they are consecutive in
|
||
|
memory starting at the load address used for the <code>OVERLAY</code> as a
|
||
|
whole (as with normal section definitions, the load address is optional,
|
||
|
and defaults to the start address; the start address is also optional,
|
||
|
and defaults to the current value of the location counter).
|
||
|
</p>
|
||
|
<p>If the <code>NOCROSSREFS</code> keyword is used, and there are any
|
||
|
references among the sections, the linker will report an error. Since
|
||
|
the sections all run at the same address, it normally does not make
|
||
|
sense for one section to refer directly to another.
|
||
|
See <a href="Miscellaneous-Commands.html#Miscellaneous-Commands">NOCROSSREFS</a>.
|
||
|
</p>
|
||
|
<p>For each section within the <code>OVERLAY</code>, the linker automatically
|
||
|
provides two symbols. The symbol <code>__load_start_<var>secname</var></code> is
|
||
|
defined as the starting load address of the section. The symbol
|
||
|
<code>__load_stop_<var>secname</var></code> is defined as the final load address of
|
||
|
the section. Any characters within <var>secname</var> which are not legal
|
||
|
within C identifiers are removed. C (or assembler) code may use these
|
||
|
symbols to move the overlaid sections around as necessary.
|
||
|
</p>
|
||
|
<p>At the end of the overlay, the value of the location counter is set to
|
||
|
the start address of the overlay plus the size of the largest section.
|
||
|
</p>
|
||
|
<p>Here is an example. Remember that this would appear inside a
|
||
|
<code>SECTIONS</code> construct.
|
||
|
</p><div class="smallexample">
|
||
|
<pre class="smallexample"> OVERLAY 0x1000 : AT (0x4000)
|
||
|
{
|
||
|
.text0 { o1/*.o(.text) }
|
||
|
.text1 { o2/*.o(.text) }
|
||
|
}
|
||
|
</pre></div>
|
||
|
<p>This will define both ‘<samp>.text0</samp>’ and ‘<samp>.text1</samp>’ to start at
|
||
|
address 0x1000. ‘<samp>.text0</samp>’ will be loaded at address 0x4000, and
|
||
|
‘<samp>.text1</samp>’ will be loaded immediately after ‘<samp>.text0</samp>’. The
|
||
|
following symbols will be defined if referenced: <code>__load_start_text0</code>,
|
||
|
<code>__load_stop_text0</code>, <code>__load_start_text1</code>,
|
||
|
<code>__load_stop_text1</code>.
|
||
|
</p>
|
||
|
<p>C code to copy overlay <code>.text1</code> into the overlay area might look
|
||
|
like the following.
|
||
|
</p>
|
||
|
<div class="smallexample">
|
||
|
<pre class="smallexample"> extern char __load_start_text1, __load_stop_text1;
|
||
|
memcpy ((char *) 0x1000, &__load_start_text1,
|
||
|
&__load_stop_text1 - &__load_start_text1);
|
||
|
</pre></div>
|
||
|
|
||
|
<p>Note that the <code>OVERLAY</code> command is just syntactic sugar, since
|
||
|
everything it does can be done using the more basic commands. The above
|
||
|
example could have been written identically as follows.
|
||
|
</p>
|
||
|
<div class="smallexample">
|
||
|
<pre class="smallexample"> .text0 0x1000 : AT (0x4000) { o1/*.o(.text) }
|
||
|
PROVIDE (__load_start_text0 = LOADADDR (.text0));
|
||
|
PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
|
||
|
.text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) { o2/*.o(.text) }
|
||
|
PROVIDE (__load_start_text1 = LOADADDR (.text1));
|
||
|
PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
|
||
|
. = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
|
||
|
</pre></div>
|
||
|
|
||
|
<hr>
|
||
|
<div class="header">
|
||
|
<p>
|
||
|
Previous: <a href="Output-Section-Attributes.html#Output-Section-Attributes" accesskey="p" rel="prev">Output Section Attributes</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</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>
|