toolchain/gcc-linaro-6.3.1-2017.02-x8.../share/doc/as.html/Secs-Background.html

195 lines
9.4 KiB
HTML
Raw Normal View History

2024-03-22 05:10:17 +00:00
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This file documents the GNU Assembler "as".
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>Using as: Secs Background</title>
<meta name="description" content="Using as: Secs Background">
<meta name="keywords" content="Using as: Secs Background">
<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="AS-Index.html#AS-Index" rel="index" title="AS Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Sections.html#Sections" rel="up" title="Sections">
<link href="Ld-Sections.html#Ld-Sections" rel="next" title="Ld Sections">
<link href="Sections.html#Sections" rel="prev" title="Sections">
<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="Secs-Background"></a>
<div class="header">
<p>
Next: <a href="Ld-Sections.html#Ld-Sections" accesskey="n" rel="next">Ld Sections</a>, Up: <a href="Sections.html#Sections" accesskey="u" rel="up">Sections</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Background"></a>
<h3 class="section">4.1 Background</h3>
<p>Roughly, a section is a range of addresses, with no gaps; all data
&ldquo;in&rdquo; those addresses is treated the same for some particular purpose.
For example there may be a &ldquo;read only&rdquo; section.
</p>
<a name="index-linker_002c-and-assembler"></a>
<a name="index-assembler_002c-and-linker"></a>
<p>The linker <code>ld</code> reads many object files (partial programs) and
combines their contents to form a runnable program. When <code>as</code>
emits an object file, the partial program is assumed to start at address 0.
<code>ld</code> assigns the final addresses for the partial program, so that
different partial programs do not overlap. This is actually an
oversimplification, but it suffices to explain how <code>as</code> uses
sections.
</p>
<p><code>ld</code> moves blocks of bytes of your program to their run-time
addresses. These blocks slide to their run-time addresses as rigid
units; their length does not change and neither does the order of bytes
within them. Such a rigid unit is called a <em>section</em>. Assigning
run-time addresses to sections is called <em>relocation</em>. It includes
the task of adjusting mentions of object-file addresses so they refer to
the proper run-time addresses.
For the H8/300, and for the Renesas / SuperH SH,
<code>as</code> pads sections if needed to
ensure they end on a word (sixteen bit) boundary.
</p>
<a name="index-standard-assembler-sections"></a>
<p>An object file written by <code>as</code> has at least three sections, any
of which may be empty. These are named <em>text</em>, <em>data</em> and
<em>bss</em> sections.
</p>
<p>When it generates COFF or ELF output,
<code>as</code> can also generate whatever other named sections you specify
using the &lsquo;<samp>.section</samp>&rsquo; directive (see <a href="Section.html#Section"><code>.section</code></a>).
If you do not use any directives that place output in the &lsquo;<samp>.text</samp>&rsquo;
or &lsquo;<samp>.data</samp>&rsquo; sections, these sections still exist, but are empty.
</p>
<p>When <code>as</code> generates SOM or ELF output for the HPPA,
<code>as</code> can also generate whatever other named sections you
specify using the &lsquo;<samp>.space</samp>&rsquo; and &lsquo;<samp>.subspace</samp>&rsquo; directives. See
<cite>HP9000 Series 800 Assembly Language Reference Manual</cite>
(HP 92432-90001) for details on the &lsquo;<samp>.space</samp>&rsquo; and &lsquo;<samp>.subspace</samp>&rsquo;
assembler directives.
</p>
<p>Additionally, <code>as</code> uses different names for the standard
text, data, and bss sections when generating SOM output. Program text
is placed into the &lsquo;<samp>$CODE$</samp>&rsquo; section, data into &lsquo;<samp>$DATA$</samp>&rsquo;, and
BSS into &lsquo;<samp>$BSS$</samp>&rsquo;.
</p>
<p>Within the object file, the text section starts at address <code>0</code>, the
data section follows, and the bss section follows the data section.
</p>
<p>When generating either SOM or ELF output files on the HPPA, the text
section starts at address <code>0</code>, the data section at address
<code>0x4000000</code>, and the bss section follows the data section.
</p>
<p>To let <code>ld</code> know which data changes when the sections are
relocated, and how to change that data, <code>as</code> also writes to the
object file details of the relocation needed. To perform relocation
<code>ld</code> must know, each time an address in the object
file is mentioned:
</p><ul>
<li> Where in the object file is the beginning of this reference to
an address?
</li><li> How long (in bytes) is this reference?
</li><li> Which section does the address refer to? What is the numeric value of
<div class="display">
<pre class="display">(<var>address</var>) - (<var>start-address of section</var>)?
</pre></div>
</li><li> Is the reference to an address &ldquo;Program-Counter relative&rdquo;?
</li></ul>
<a name="index-addresses_002c-format-of"></a>
<a name="index-section_002drelative-addressing"></a>
<p>In fact, every address <code>as</code> ever uses is expressed as
</p><div class="display">
<pre class="display">(<var>section</var>) + (<var>offset into section</var>)
</pre></div>
<p>Further, most expressions <code>as</code> computes have this section-relative
nature.
(For some object formats, such as SOM for the HPPA, some expressions are
symbol-relative instead.)
</p>
<p>In this manual we use the notation {<var>secname</var> <var>N</var>} to mean &ldquo;offset
<var>N</var> into section <var>secname</var>.&rdquo;
</p>
<p>Apart from text, data and bss sections you need to know about the
<em>absolute</em> section. When <code>ld</code> mixes partial programs,
addresses in the absolute section remain unchanged. For example, address
<code>{absolute 0}</code> is &ldquo;relocated&rdquo; to run-time address 0 by
<code>ld</code>. Although the linker never arranges two partial programs&rsquo;
data sections with overlapping addresses after linking, <em>by definition</em>
their absolute sections must overlap. Address <code>{absolute&nbsp;239}</code> in one
part of a program is always the same address when the program is running as
address <code>{absolute&nbsp;239}</code> in any other part of the program.
</p>
<p>The idea of sections is extended to the <em>undefined</em> section. Any
address whose section is unknown at assembly time is by definition
rendered {undefined <var>U</var>}&mdash;where <var>U</var> is filled in later.
Since numbers are always defined, the only way to generate an undefined
address is to mention an undefined symbol. A reference to a named
common block would be such a symbol: its value is unknown at assembly
time so it has section <em>undefined</em>.
</p>
<p>By analogy the word <em>section</em> is used to describe groups of sections in
the linked program. <code>ld</code> puts all partial programs&rsquo; text
sections in contiguous addresses in the linked program. It is
customary to refer to the <em>text section</em> of a program, meaning all
the addresses of all partial programs&rsquo; text sections. Likewise for
data and bss sections.
</p>
<p>Some sections are manipulated by <code>ld</code>; others are invented for
use of <code>as</code> and have no meaning except during assembly.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Ld-Sections.html#Ld-Sections" accesskey="n" rel="next">Ld Sections</a>, Up: <a href="Sections.html#Sections" accesskey="u" rel="up">Sections</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>