110 lines
		
	
	
	
		
			5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
		
		
			
		
	
	
			110 lines
		
	
	
	
		
			5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| 
								 | 
							
								<html lang="en">
							 | 
						||
| 
								 | 
							
								<head>
							 | 
						||
| 
								 | 
							
								<title>Ld Sections - Using as</title>
							 | 
						||
| 
								 | 
							
								<meta http-equiv="Content-Type" content="text/html">
							 | 
						||
| 
								 | 
							
								<meta name="description" content="Using as">
							 | 
						||
| 
								 | 
							
								<meta name="generator" content="makeinfo 4.7">
							 | 
						||
| 
								 | 
							
								<link title="Top" rel="start" href="index.html#Top">
							 | 
						||
| 
								 | 
							
								<link rel="up" href="Sections.html#Sections" title="Sections">
							 | 
						||
| 
								 | 
							
								<link rel="prev" href="Secs-Background.html#Secs-Background" title="Secs Background">
							 | 
						||
| 
								 | 
							
								<link rel="next" href="As-Sections.html#As-Sections" title="As Sections">
							 | 
						||
| 
								 | 
							
								<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
							 | 
						||
| 
								 | 
							
								<!--
							 | 
						||
| 
								 | 
							
								This file documents the GNU Assembler "as".
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002,
							 | 
						||
| 
								 | 
							
								2006, 2007 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.1
							 | 
						||
| 
								 | 
							
								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''.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								man end-->
							 | 
						||
| 
								 | 
							
								<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; } 
							 | 
						||
| 
								 | 
							
								--></style>
							 | 
						||
| 
								 | 
							
								</head>
							 | 
						||
| 
								 | 
							
								<body>
							 | 
						||
| 
								 | 
							
								<div class="node">
							 | 
						||
| 
								 | 
							
								<p>
							 | 
						||
| 
								 | 
							
								<a name="Ld-Sections"></a>Next: <a rel="next" accesskey="n" href="As-Sections.html#As-Sections">As Sections</a>,
							 | 
						||
| 
								 | 
							
								Previous: <a rel="previous" accesskey="p" href="Secs-Background.html#Secs-Background">Secs Background</a>,
							 | 
						||
| 
								 | 
							
								Up: <a rel="up" accesskey="u" href="Sections.html#Sections">Sections</a>
							 | 
						||
| 
								 | 
							
								<hr><br>
							 | 
						||
| 
								 | 
							
								</div>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								<h3 class="section">4.2 Linker Sections</h3>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								<p><code>ld</code> deals with just four kinds of sections, summarized below.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								     
							 | 
						||
| 
								 | 
							
								<a name="index-named-sections-192"></a>
							 | 
						||
| 
								 | 
							
								<a name="index-sections_002c-named-193"></a>
							 | 
						||
| 
								 | 
							
								<dl><dt><strong>named sections</strong><dd><a name="index-text-section-194"></a><a name="index-data-section-195"></a><dt><strong>text section</strong><dt><strong>data section</strong><dd>These sections hold your program.  <span class="command">as</span> and <code>ld</code> treat them as
							 | 
						||
| 
								 | 
							
								separate but equal sections.  Anything you can say of one section is
							 | 
						||
| 
								 | 
							
								true of another. 
							 | 
						||
| 
								 | 
							
								<!-- @ifset aout-bout -->
							 | 
						||
| 
								 | 
							
								When the program is running, however, it is
							 | 
						||
| 
								 | 
							
								customary for the text section to be unalterable.  The
							 | 
						||
| 
								 | 
							
								text section is often shared among processes: it contains
							 | 
						||
| 
								 | 
							
								instructions, constants and the like.  The data section of a running
							 | 
						||
| 
								 | 
							
								program is usually alterable: for example, C variables would be stored
							 | 
						||
| 
								 | 
							
								in the data section. 
							 | 
						||
| 
								 | 
							
								<!-- @end ifset -->
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								     <p><a name="index-bss-section-196"></a><br><dt><strong>bss section</strong><dd>This section contains zeroed bytes when your program begins running.  It
							 | 
						||
| 
								 | 
							
								is used to hold uninitialized variables or common storage.  The length of
							 | 
						||
| 
								 | 
							
								each partial program's bss section is important, but because it starts
							 | 
						||
| 
								 | 
							
								out containing zeroed bytes there is no need to store explicit zero
							 | 
						||
| 
								 | 
							
								bytes in the object file.  The bss section was invented to eliminate
							 | 
						||
| 
								 | 
							
								those explicit zeros from object files.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								     <p><a name="index-absolute-section-197"></a><br><dt><strong>absolute section</strong><dd>Address 0 of this section is always “relocated” to runtime address 0. 
							 | 
						||
| 
								 | 
							
								This is useful if you want to refer to an address that <code>ld</code> must
							 | 
						||
| 
								 | 
							
								not change when relocating.  In this sense we speak of absolute
							 | 
						||
| 
								 | 
							
								addresses being “unrelocatable”: they do not change during relocation.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								     <p><a name="index-undefined-section-198"></a><br><dt><strong>undefined section</strong><dd>This “section” is a catch-all for address references to objects not in
							 | 
						||
| 
								 | 
							
								the preceding sections. 
							 | 
						||
| 
								 | 
							
								<!-- FIXME: ref to some other doc on obj-file formats could go here. -->
							 | 
						||
| 
								 | 
							
								</dl>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								   <p><a name="index-relocation-example-199"></a>An idealized example of three relocatable sections follows. 
							 | 
						||
| 
								 | 
							
								The example uses the traditional section names <span class="samp">.text</span> and <span class="samp">.data</span>. 
							 | 
						||
| 
								 | 
							
								Memory addresses are on the horizontal axis.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								<!-- TEXI2ROFF-KILL -->
							 | 
						||
| 
								 | 
							
								<!-- END TEXI2ROFF-KILL -->
							 | 
						||
| 
								 | 
							
								<pre class="smallexample">                           +-----+----+--+
							 | 
						||
| 
								 | 
							
								     partial program # 1:  |ttttt|dddd|00|
							 | 
						||
| 
								 | 
							
								                           +-----+----+--+
							 | 
						||
| 
								 | 
							
								     
							 | 
						||
| 
								 | 
							
								                           text   data bss
							 | 
						||
| 
								 | 
							
								                           seg.   seg. seg.
							 | 
						||
| 
								 | 
							
								     
							 | 
						||
| 
								 | 
							
								                           +---+---+---+
							 | 
						||
| 
								 | 
							
								     partial program # 2:  |TTT|DDD|000|
							 | 
						||
| 
								 | 
							
								                           +---+---+---+
							 | 
						||
| 
								 | 
							
								     
							 | 
						||
| 
								 | 
							
								                           +--+---+-----+--+----+---+-----+~~
							 | 
						||
| 
								 | 
							
								     linked program:       |  |TTT|ttttt|  |dddd|DDD|00000|
							 | 
						||
| 
								 | 
							
								                           +--+---+-----+--+----+---+-----+~~
							 | 
						||
| 
								 | 
							
								     
							 | 
						||
| 
								 | 
							
								         addresses:        0 ...
							 | 
						||
| 
								 | 
							
								</pre>
							 | 
						||
| 
								 | 
							
								   <!-- TEXI2ROFF-KILL -->
							 | 
						||
| 
								 | 
							
								<!-- END TEXI2ROFF-KILL -->
							 | 
						||
| 
								 | 
							
								</body></html>
							 | 
						||
| 
								 | 
							
								
							 |