toolchain/share/doc/ld.html/Simple-Assignments.html

94 lines
4.5 KiB
HTML
Raw Normal View History

2024-01-10 05:24:32 +00:00
<html lang="en">
<head>
<title>Simple Assignments - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Assignments.html#Assignments" title="Assignments">
<link rel="next" href="HIDDEN.html#HIDDEN" title="HIDDEN">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This file documents the GNU linker LD
(GNU Toolchain for the A-profile Architecture 9.2-2019.12 (arm-9.10))
version 2.33.1.
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''.-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Simple-Assignments"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="HIDDEN.html#HIDDEN">HIDDEN</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Assignments.html#Assignments">Assignments</a>
<hr>
</div>
<h4 class="subsection">3.5.1 Simple Assignments</h4>
<p>You may assign to a symbol using any of the C assignment operators:
<dl>
<dt><var>symbol</var><code> = </code><var>expression</var><code> ;</code><dt><var>symbol</var><code> += </code><var>expression</var><code> ;</code><dt><var>symbol</var><code> -= </code><var>expression</var><code> ;</code><dt><var>symbol</var><code> *= </code><var>expression</var><code> ;</code><dt><var>symbol</var><code> /= </code><var>expression</var><code> ;</code><dt><var>symbol</var><code> &lt;&lt;= </code><var>expression</var><code> ;</code><dt><var>symbol</var><code> &gt;&gt;= </code><var>expression</var><code> ;</code><dt><var>symbol</var><code> &amp;= </code><var>expression</var><code> ;</code><dt><var>symbol</var><code> |= </code><var>expression</var><code> ;</code><dd></dl>
<p>The first case will define <var>symbol</var> to the value of
<var>expression</var>. In the other cases, <var>symbol</var> must already be
defined, and the value will be adjusted accordingly.
<p>The special symbol name &lsquo;<samp><span class="samp">.</span></samp>&rsquo; indicates the location counter. You
may only use this within a <code>SECTIONS</code> command. See <a href="Location-Counter.html#Location-Counter">Location Counter</a>.
<p>The semicolon after <var>expression</var> is required.
<p>Expressions are defined below; see <a href="Expressions.html#Expressions">Expressions</a>.
<p>You may write symbol assignments as commands in their own right, or as
statements within a <code>SECTIONS</code> command, or as part of an output
section description in a <code>SECTIONS</code> command.
<p>The section of the symbol will be set from the section of the
expression; for more information, see <a href="Expression-Section.html#Expression-Section">Expression Section</a>.
<p>Here is an example showing the three different places that symbol
assignments may be used:
<pre class="smallexample"> floating_point = 0;
SECTIONS
{
.text :
{
*(.text)
_etext = .;
}
_bdata = (. + 3) &amp; ~ 3;
.data : { *(.data) }
}
</pre>
<p class="noindent">In this example, the symbol &lsquo;<samp><span class="samp">floating_point</span></samp>&rsquo; will be defined as
zero. The symbol &lsquo;<samp><span class="samp">_etext</span></samp>&rsquo; will be defined as the address following
the last &lsquo;<samp><span class="samp">.text</span></samp>&rsquo; input section. The symbol &lsquo;<samp><span class="samp">_bdata</span></samp>&rsquo; will be
defined as the address following the &lsquo;<samp><span class="samp">.text</span></samp>&rsquo; output section aligned
upward to a 4 byte boundary.
</body></html>