as: Secs Background

1 
1 4.1 Background
1 ==============
1 
1 Roughly, a section is a range of addresses, with no gaps; all data "in"
1 those addresses is treated the same for some particular purpose.  For
1 example there may be a "read only" section.
1 
1    The linker 'ld' reads many object files (partial programs) and
1 combines their contents to form a runnable program.  When 'as' emits an
1 object file, the partial program is assumed to start at address 0.  'ld'
1 assigns the final addresses for the partial program, so that different
1 partial programs do not overlap.  This is actually an
1 oversimplification, but it suffices to explain how 'as' uses sections.
1 
1    'ld' moves blocks of bytes of your program to their run-time
1 addresses.  These blocks slide to their run-time addresses as rigid
1 units; their length does not change and neither does the order of bytes
1 within them.  Such a rigid unit is called a _section_.  Assigning
1 run-time addresses to sections is called "relocation".  It includes the
1 task of adjusting mentions of object-file addresses so they refer to the
1 proper run-time addresses.  For the H8/300, and for the Renesas / SuperH
1 SH, 'as' pads sections if needed to ensure they end on a word (sixteen
1 bit) boundary.
1 
1    An object file written by 'as' has at least three sections, any of
1 which may be empty.  These are named "text", "data" and "bss" sections.
1 
1    When it generates COFF or ELF output, 'as' can also generate whatever
11 other named sections you specify using the '.section' directive (⇒
 '.section' Section.).  If you do not use any directives that place
1 output in the '.text' or '.data' sections, these sections still exist,
1 but are empty.
1 
1    When 'as' generates SOM or ELF output for the HPPA, 'as' can also
1 generate whatever other named sections you specify using the '.space'
1 and '.subspace' directives.  See 'HP9000 Series 800 Assembly Language
1 Reference Manual' (HP 92432-90001) for details on the '.space' and
1 '.subspace' assembler directives.
1 
1    Additionally, 'as' uses different names for the standard text, data,
1 and bss sections when generating SOM output.  Program text is placed
1 into the '$CODE$' section, data into '$DATA$', and BSS into '$BSS$'.
1 
1    Within the object file, the text section starts at address '0', the
1 data section follows, and the bss section follows the data section.
1 
1    When generating either SOM or ELF output files on the HPPA, the text
1 section starts at address '0', the data section at address '0x4000000',
1 and the bss section follows the data section.
1 
1    To let 'ld' know which data changes when the sections are relocated,
1 and how to change that data, 'as' also writes to the object file details
1 of the relocation needed.  To perform relocation 'ld' must know, each
1 time an address in the object file is mentioned:
1    * Where in the object file is the beginning of this reference to an
1      address?
1    * How long (in bytes) is this reference?
1    * Which section does the address refer to?  What is the numeric value
1      of
1           (ADDRESS) - (START-ADDRESS OF SECTION)?
1    * Is the reference to an address "Program-Counter relative"?
1 
1    In fact, every address 'as' ever uses is expressed as
1      (SECTION) + (OFFSET INTO SECTION)
1 Further, most expressions 'as' computes have this section-relative
1 nature.  (For some object formats, such as SOM for the HPPA, some
1 expressions are symbol-relative instead.)
1 
1    In this manual we use the notation {SECNAME N} to mean "offset N into
1 section SECNAME."
1 
1    Apart from text, data and bss sections you need to know about the
1 "absolute" section.  When 'ld' mixes partial programs, addresses in the
1 absolute section remain unchanged.  For example, address '{absolute 0}'
1 is "relocated" to run-time address 0 by 'ld'.  Although the linker never
1 arranges two partial programs' data sections with overlapping addresses
1 after linking, _by definition_ their absolute sections must overlap.
1 Address '{absolute 239}' in one part of a program is always the same
1 address when the program is running as address '{absolute 239}' in any
1 other part of the program.
1 
1    The idea of sections is extended to the "undefined" section.  Any
1 address whose section is unknown at assembly time is by definition
1 rendered {undefined U}--where U is filled in later.  Since numbers are
1 always defined, the only way to generate an undefined address is to
1 mention an undefined symbol.  A reference to a named common block would
1 be such a symbol: its value is unknown at assembly time so it has
1 section _undefined_.
1 
1    By analogy the word _section_ is used to describe groups of sections
1 in the linked program.  'ld' puts all partial programs' text sections in
1 contiguous addresses in the linked program.  It is customary to refer to
1 the _text section_ of a program, meaning all the addresses of all
1 partial programs' text sections.  Likewise for data and bss sections.
1 
1    Some sections are manipulated by 'ld'; others are invented for use of
1 'as' and have no meaning except during assembly.
1