Go forward to ld Sections.
Go backward to Sections.
Go up to Sections.

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' will assign the final addresses the partial program occupies, so
that different partial programs don't overlap.  This is actually an
over-simplification, but it will suffice 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, `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 output, `as' can also generate whatever other
named sections you specify using the `.section' directive (
see `.section': Section.).  If you don't use any directives that place
output in the `.text' or `.data' sections, these sections will still
exist, but will be empty.

   Within the object file, the text section starts at address `0', the
data section follows, and the bss section follows the data section.

   To let `ld' know which data will change 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)

Further, every expression `as' computes is of this section-relative
nature.  "Absolute expression" means an expression with section
"absolute" (see ld Sections.).  A "pass1 expression" means an
expression with section "pass1" (see as Internal Sections: as Sections.).  In this manual we use the notation {SECNAME N} to mean
"offset N into section SECNAME".

   Apart from text, data and bss sections you need to know about the
"absolute" section.  When `ld' mixes partial programs, addresses in the
absolute section remain unchanged.  For example, address `{absolute 0}'
is "relocated" to run-time address 0 by `ld'.  Although two partial
programs' data sections will not overlap addresses after linking, *by
definition* their absolute sections will overlap.  Address `{absolute
239}' in one partial program will always be the same address when the
program is running as address `{absolute 239}' in any other partial
program.

   The idea of sections is extended to the "undefined" section.  Any
address whose section is unknown at assembly time is by definition
rendered {undefined U}--where U will be 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 *undefined*.

   By analogy the word *section* is used to describe groups of sections
in the linked program.  `ld' puts all partial programs' text sections
in contiguous addresses in the linked program.  It is customary to
refer to the *text section* of a program, meaning all the addresses of
all partial program's text sections.  Likewise for data and bss
sections.

   Some sections are manipulated by `ld'; others are invented for use
of `as' and have no meaning except during assembly.