1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- This file documents the GNU Assembler "as".
4
5Copyright (C) 1991-2021 Free Software Foundation, Inc.
6
7Permission is granted to copy, distribute and/or modify this document
8under the terms of the GNU Free Documentation License, Version 1.3
9or any later version published by the Free Software Foundation;
10with no Invariant Sections, with no Front-Cover Texts, and with no
11Back-Cover Texts.  A copy of the license is included in the
12section entitled "GNU Free Documentation License".
13 -->
14<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
15<head>
16<title>Using as: Ld Sections</title>
17
18<meta name="description" content="Using as: Ld Sections">
19<meta name="keywords" content="Using as: Ld Sections">
20<meta name="resource-type" content="document">
21<meta name="distribution" content="global">
22<meta name="Generator" content="makeinfo">
23<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
24<link href="index.html#Top" rel="start" title="Top">
25<link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
26<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
27<link href="Sections.html#Sections" rel="up" title="Sections">
28<link href="As-Sections.html#As-Sections" rel="next" title="As Sections">
29<link href="Secs-Background.html#Secs-Background" rel="previous" title="Secs Background">
30<style type="text/css">
31<!--
32a.summary-letter {text-decoration: none}
33blockquote.smallquotation {font-size: smaller}
34div.display {margin-left: 3.2em}
35div.example {margin-left: 3.2em}
36div.indentedblock {margin-left: 3.2em}
37div.lisp {margin-left: 3.2em}
38div.smalldisplay {margin-left: 3.2em}
39div.smallexample {margin-left: 3.2em}
40div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
41div.smalllisp {margin-left: 3.2em}
42kbd {font-style:oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47pre.smalldisplay {font-family: inherit; font-size: smaller}
48pre.smallexample {font-size: smaller}
49pre.smallformat {font-family: inherit; font-size: smaller}
50pre.smalllisp {font-size: smaller}
51span.nocodebreak {white-space:nowrap}
52span.nolinebreak {white-space:nowrap}
53span.roman {font-family:serif; font-weight:normal}
54span.sansserif {font-family:sans-serif; font-weight:normal}
55ul.no-bullet {list-style: none}
56-->
57</style>
58
59
60</head>
61
62<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
63<a name="Ld-Sections"></a>
64<div class="header">
65<p>
66Next: <a href="As-Sections.html#As-Sections" accesskey="n" rel="next">As Sections</a>, Previous: <a href="Secs-Background.html#Secs-Background" accesskey="p" rel="previous">Secs Background</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>
67</div>
68<hr>
69<a name="Linker-Sections"></a>
70<h3 class="section">4.2 Linker Sections</h3>
71<p><code>ld</code> deals with just four kinds of sections, summarized below.
72</p>
73<dl compact="compact">
74<dd>
75<a name="index-named-sections"></a>
76<a name="index-sections_002c-named"></a>
77</dd>
78<dt><strong>named sections</strong></dt>
79<dd><a name="index-text-section"></a>
80<a name="index-data-section"></a>
81</dd>
82<dt><strong>text section</strong></dt>
83<dt><strong>data section</strong></dt>
84<dd><p>These sections hold your program.  <code>as</code> and <code>ld</code> treat them as
85separate but equal sections.  Anything you can say of one section is
86true of another.
87When the program is running, however, it is
88customary for the text section to be unalterable.  The
89text section is often shared among processes: it contains
90instructions, constants and the like.  The data section of a running
91program is usually alterable: for example, C variables would be stored
92in the data section.
93</p>
94<a name="index-bss-section"></a>
95</dd>
96<dt><strong>bss section</strong></dt>
97<dd><p>This section contains zeroed bytes when your program begins running.  It
98is used to hold uninitialized variables or common storage.  The length of
99each partial program&rsquo;s bss section is important, but because it starts
100out containing zeroed bytes there is no need to store explicit zero
101bytes in the object file.  The bss section was invented to eliminate
102those explicit zeros from object files.
103</p>
104<a name="index-absolute-section"></a>
105</dd>
106<dt><strong>absolute section</strong></dt>
107<dd><p>Address 0 of this section is always &ldquo;relocated&rdquo; to runtime address 0.
108This is useful if you want to refer to an address that <code>ld</code> must
109not change when relocating.  In this sense we speak of absolute
110addresses being &ldquo;unrelocatable&rdquo;: they do not change during relocation.
111</p>
112<a name="index-undefined-section"></a>
113</dd>
114<dt><strong>undefined section</strong></dt>
115<dd><p>This &ldquo;section&rdquo; is a catch-all for address references to objects not in
116the preceding sections.
117</p></dd>
118</dl>
119
120<a name="index-relocation-example"></a>
121<p>An idealized example of three relocatable sections follows.
122The example uses the traditional section names &lsquo;<samp>.text</samp>&rsquo; and &lsquo;<samp>.data</samp>&rsquo;.
123Memory addresses are on the horizontal axis.
124</p>
125<div class="smallexample">
126<pre class="smallexample">                      +-----+----+--+
127partial program # 1:  |ttttt|dddd|00|
128                      +-----+----+--+
129
130                      text   data bss
131                      seg.   seg. seg.
132
133                      +---+---+---+
134partial program # 2:  |TTT|DDD|000|
135                      +---+---+---+
136
137                      +--+---+-----+--+----+---+-----+~~
138linked program:       |  |TTT|ttttt|  |dddd|DDD|00000|
139                      +--+---+-----+--+----+---+-----+~~
140
141    addresses:        0 &hellip;
142</pre></div>
143
144<hr>
145<div class="header">
146<p>
147Next: <a href="As-Sections.html#As-Sections" accesskey="n" rel="next">As Sections</a>, Previous: <a href="Secs-Background.html#Secs-Background" accesskey="p" rel="previous">Secs Background</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>
148</div>
149
150
151
152</body>
153</html>
154