ld: PHDRS
1
1 3.8 PHDRS Command
1 =================
1
1 The ELF object file format uses "program headers", also knows as
1 "segments". The program headers describe how the program should be
1 loaded into memory. You can print them out by using the 'objdump'
1 program with the '-p' option.
1
1 When you run an ELF program on a native ELF system, the system loader
1 reads the program headers in order to figure out how to load the
1 program. This will only work if the program headers are set correctly.
1 This manual does not describe the details of how the system loader
1 interprets program headers; for more information, see the ELF ABI.
1
1 The linker will create reasonable program headers by default.
1 However, in some cases, you may need to specify the program headers more
1 precisely. You may use the 'PHDRS' command for this purpose. When the
1 linker sees the 'PHDRS' command in the linker script, it will not create
1 any program headers other than the ones specified.
1
1 The linker only pays attention to the 'PHDRS' command when generating
1 an ELF output file. In other cases, the linker will simply ignore
1 'PHDRS'.
1
1 This is the syntax of the 'PHDRS' command. The words 'PHDRS',
1 'FILEHDR', 'AT', and 'FLAGS' are keywords.
1
1 PHDRS
1 {
1 NAME TYPE [ FILEHDR ] [ PHDRS ] [ AT ( ADDRESS ) ]
1 [ FLAGS ( FLAGS ) ] ;
1 }
1
1 The NAME is used only for reference in the 'SECTIONS' command of the
1 linker script. It is not put into the output file. Program header
1 names are stored in a separate name space, and will not conflict with
1 symbol names, file names, or section names. Each program header must
1 have a distinct name. The headers are processed in order and it is
1 usual for them to map to sections in ascending load address order.
1
1 Certain program header types describe segments of memory which the
1 system loader will load from the file. In the linker script, you
1 specify the contents of these segments by placing allocatable output
1 sections in the segments. You use the ':PHDR' output section attribute
11 to place a section in a particular segment. ⇒Output Section
Phdr.
1
1 It is normal to put certain sections in more than one segment. This
1 merely implies that one segment of memory contains another. You may
1 repeat ':PHDR', using it once for each segment which should contain the
1 section.
1
1 If you place a section in one or more segments using ':PHDR', then
1 the linker will place all subsequent allocatable sections which do not
1 specify ':PHDR' in the same segments. This is for convenience, since
1 generally a whole set of contiguous sections will be placed in a single
1 segment. You can use ':NONE' to override the default segment and tell
1 the linker to not put the section in any segment at all.
1
1 You may use the 'FILEHDR' and 'PHDRS' keywords after the program
1 header type to further describe the contents of the segment. The
1 'FILEHDR' keyword means that the segment should include the ELF file
1 header. The 'PHDRS' keyword means that the segment should include the
1 ELF program headers themselves. If applied to a loadable segment
1 ('PT_LOAD'), all prior loadable segments must have one of these
1 keywords.
1
1 The TYPE may be one of the following. The numbers indicate the value
1 of the keyword.
1
1 'PT_NULL' (0)
1 Indicates an unused program header.
1
1 'PT_LOAD' (1)
1 Indicates that this program header describes a segment to be loaded
1 from the file.
1
1 'PT_DYNAMIC' (2)
1 Indicates a segment where dynamic linking information can be found.
1
1 'PT_INTERP' (3)
1 Indicates a segment where the name of the program interpreter may
1 be found.
1
1 'PT_NOTE' (4)
1 Indicates a segment holding note information.
1
1 'PT_SHLIB' (5)
1 A reserved program header type, defined but not specified by the
1 ELF ABI.
1
1 'PT_PHDR' (6)
1 Indicates a segment where the program headers may be found.
1
1 'PT_TLS' (7)
1 Indicates a segment containing thread local storage.
1
1 EXPRESSION
1 An expression giving the numeric type of the program header. This
1 may be used for types not defined above.
1
1 You can specify that a segment should be loaded at a particular
1 address in memory by using an 'AT' expression. This is identical to the
11 'AT' command used as an output section attribute (⇒Output Section
LMA). The 'AT' command for a program header overrides the output
1 section attribute.
1
1 The linker will normally set the segment flags based on the sections
1 which comprise the segment. You may use the 'FLAGS' keyword to
1 explicitly specify the segment flags. The value of FLAGS must be an
1 integer. It is used to set the 'p_flags' field of the program header.
1
1 Here is an example of 'PHDRS'. This shows a typical set of program
1 headers used on a native ELF system.
1
1 PHDRS
1 {
1 headers PT_PHDR PHDRS ;
1 interp PT_INTERP ;
1 text PT_LOAD FILEHDR PHDRS ;
1 data PT_LOAD ;
1 dynamic PT_DYNAMIC ;
1 }
1
1 SECTIONS
1 {
1 . = SIZEOF_HEADERS;
1 .interp : { *(.interp) } :text :interp
1 .text : { *(.text) } :text
1 .rodata : { *(.rodata) } /* defaults to :text */
1 ...
1 . = . + 0x1000; /* move to a new page in memory */
1 .data : { *(.data) } :data
1 .dynamic : { *(.dynamic) } :data :dynamic
1 ...
1 }
1