Chapter 5.
Sections and Relocation
5.1. Background
Roughly, a section is a range of addresses, with no gaps; all data "in" those addresses is treated the
same for some particular purpose. For example there may be a "read only" section.
The linker
ld
reads many object files (partial programs) and combines their contents to form a
runnable program. When
as
emits an object file, the partial program is assumed to start at address
0.
ld
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
as
uses sections.
ld
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 section. Assigning run time addresses to sections is called
relocation. 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 H8/500, and for the Renesas / SuperH SH,
as
pads sections
if needed to ensure they end on a word (sixteen bit) boundary.
An object file written by
as
has at least three sections, any of which may be empty. These are named
text, data and bss sections.
When it generates COFF or ELF output,
as
can also generate whatever other named sections you
specify using the
.section
directive (Section 8.78
.section name
). If you do not use any directives
that place output in the
.text
or
.data
sections, these sections still exist, but are empty.
When
as
generates SOM or ELF output for the HPPA,
as
can also generate whatever other named
sections you specify using the
.space
and
.subspace
directives. See [HP9000 Series 800 Assembly
Language Reference Manual] (HP 92432 90001) for details on the
.space
and
.subspace
assem
bler directives.
Additionally,
as
uses different names for the standard text, data, and bss sections when generating
SOM output. Program text is placed into the
$CODE$
section, data into
$DATA$
, and BSS into
$BSS$
.
Within the object file, the text section starts at address
0
, the data section follows, and the bss section
follows the data section.
When generating either SOM or ELF output files on the HPPA, the text section starts at address
0
, the
data section at address
0x4000000
, and the bss section follows the data section.
To let
ld
know which data changes when the sections are relocated, and how to change that data,
as
also writes to the object file details of the relocation needed. To perform relocation
ld
must know,
each time an address in the object file is mentioned:
Where in the object file is the beginning of this reference to an address?
How long (in bytes) is this reference?
Which section does the address refer to? What is the numeric value of
(address) (start address of section)?
Is the reference to an address "Program Counter relative"?
In fact, every address
as
ever uses is expressed as
(section) + (offset into section)
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved