Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The GNU linker. - <b>elf program headers</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
ELF Program Headers
===================

   The ELF object file format uses "program headers", which are read by
the system loader and describe how the program should be loaded into
memory.  These program headers must be set correctly in order to run the
program on a native ELF system.  The linker will create reasonable
program headers by default.  However, in some cases, it is desirable to
specify the program headers more precisely; the `PHDRS' command may be
used for this purpose.  When the `PHDRS' command is used, the linker
will not generate any program headers itself.

   The `PHDRS' command is only meaningful when generating an ELF output
file.  It is ignored in other cases.  This manual does not describe the
details of how the system loader interprets program headers; for more
information, see the ELF ABI.  The program headers of an ELF file may
be displayed using the `-p' option of the `objdump' command.

   This is the syntax of the `PHDRS' command.  The words `PHDRS',
`FILEHDR', `AT', and `FLAGS' are keywords.

     PHDRS
     {
       NAME TYPE [ FILEHDR ] [ PHDRS ] [ AT ( ADDRESS ) ]
             [ FLAGS ( FLAGS ) ] ;
     }

   The NAME is used only for reference in the `SECTIONS' command of the
linker script.  It does not get put into the output file.

   Certain program header types describe segments of memory which are
loaded from the file by the system loader.  In the linker script, the
contents of these segments are specified by directing allocated output
sections to be placed in the segment.  To do this, the command
describing the output section in the `SECTIONS' command should use
`:NAME', where NAME is the name of the program header as it appears in
the `PHDRS' command.  Section Options:.   

   It is normal for certain sections to appear in more than one segment.
This merely implies that one segment of memory contains another.  This
is specified by repeating `:NAME', using it once for each program
header in which the section is to appear.

   If a section is placed in one or more segments using `:NAME', then
all subsequent allocated sections which do not specify `:NAME' are
placed in the same segments.  This is for convenience, since generally
a whole set of contiguous sections will be placed in a single segment.
To prevent a section from being assigned to a segment when it would
normally default to one, use `:NONE'.

   The `FILEHDR' and `PHDRS' keywords which may appear after the
program header type also indicate contents of the segment of memory.
The `FILEHDR' keyword means that the segment should include the ELF
file header.  The `PHDRS' keyword means that the segment should include
the ELF program headers themselves.

   The TYPE may be one of the following.  The numbers indicate the
value of the keyword.

`PT_NULL' (0)
     Indicates an unused program header.

`PT_LOAD' (1)
     Indicates that this program header describes a segment to be
     loaded from the file.

`PT_DYNAMIC' (2)
     Indicates a segment where dynamic linking information can be found.

`PT_INTERP' (3)
     Indicates a segment where the name of the program interpreter may
     be found.

`PT_NOTE' (4)
     Indicates a segment holding note information.

`PT_SHLIB' (5)
     A reserved program header type, defined but not specified by the
     ELF ABI.

`PT_PHDR' (6)
     Indicates a segment where the program headers may be found.

EXPRESSION
     An expression giving the numeric type of the program header.  This
     may be used for types not defined above.

   It is possible to specify that a segment should be loaded at a
particular address in memory.  This is done using an `AT' expression.
This is identical to the `AT' command used in the `SECTIONS' command
(Section Options:.).  Using the `AT' command for a program   
header overrides any information in the `SECTIONS' command.

   Normally the segment flags are set based on the sections.  The
`FLAGS' keyword may be used to explicitly specify the segment flags.
The value of FLAGS must be an integer.  It is used to set the `p_flags'
field of the program header.

   Here is an example of the use of `PHDRS'.  This shows a typical set
of program headers used on a native ELF system.

     PHDRS
     {
       headers PT_PHDR PHDRS ;
       interp PT_INTERP ;
       text PT_LOAD FILEHDR PHDRS ;
       data PT_LOAD ;
       dynamic PT_DYNAMIC ;
     }
     
     SECTIONS
     {
       . = SIZEOF_HEADERS;
       .interp : { *(.interp) } :text :interp
       .text : { *(.text) } :text
       .rodata : { *(.rodata) } /* defaults to :text */
       ...
       . = . + 0x1000; /* move to a new page in memory */
       .data : { *(.data) } :data
       .dynamic : { *(.dynamic) } :data :dynamic
       ...
     }


See Also: Section Options Section Options

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson