Monday, June 3, 2013

LDS file format analysis


When you look at the recent Linux kernel, and the connection is always encounter some scripts related stuff, and made people confused, finally decided to thoroughly understand it, write a little experience, and want to help people like me ! 
    
Connection script format 
====================
Connection script is a text file.

You wrote a series of commands as a linker script. Every command with parameters is a keyword, or one pair of symbolic assignment you can 
use a semicolon to separate the commands. spaces are generally ignored.


File name or format name of the class string can generally be typed directly if the file name contains special characters, such as generally used as a comma delimited file name 
number, you can put the file name into double quotes. intermediate file name can not be used double quotes.

You can, as in the C language, as in linker script using annotations, using the '/ *' and '* /' separated, just like in C, comments are syntactically equivalent to whitespace.

Simple connection script example 
============================
Many scripts are fairly simple.
The most simple script may contain only one command: 'SECTIONS'. You can use the 'SECTIONS' to describe the memory layout of the output file.

'SECTIONS' is a very powerful command here which we will describe a very simple to use, let us assume that your program is only a code section, 
initialized data section, and uninitialized data section. these will exist in '. text', '. data' and '. bss' section, in addition, let us into a 
further assume that in your input file only those sections.


For this example, we say that the code should be loaded into the address '0 x10000 'office, and the data should be from the beginning at 0x8000000 The following is a realization of 
this function script:

    SECTIONS
    {
      . = 0x10000;
      . text: {* (. text)}
      . = 0x8000000;
      . Data: {* (. Data)}
      . BSS: {* (. BSS)}
    }
You use the keyword 'SECTIONS' wrote the SECTIONS command, followed by a string of symbols in braces assignment and output section describes the contents of the.

The above example, the 'SECTIONS' command in the first line is a special symbol '.' Assignment, which is a location counter if you do not have in its 
way it specifies the address of the output section (in the back would otherwise description), that value will be set to the address of the location counter existing value. location counter 
and the size of the output section is added in 'SECTIONS' command at the beginning of the location counter has the value '0 '.


The second line defines an output section, '. Text'. Colon is required syntax can now be ignored. Section name behind the curly braces, you list all should be 
placed into the output section of the input section name. '*' is a wildcard matching any file name. expressions '* (. text)' means that all the input 
into the file '. text' input sections.


Because when the output section '. Text' definition, positioning counter value is '0 x10000 ', the connector will output file'. Text 'section of the address set 
to '0 x10000 '.


The remaining contents of the definition of the output file '. Data' section and '. Bss' section. Connector will'. Data 'output section into the address '0 x8000000' office. Connection 
is put away '. data' output section after positioning counter value is '0 x8000000 'plus'. data' output section length. obtained result is the connector will 
put '. bss' output section is placed immediately '. data' section of the back position.


Connector necessary by increasing the value of the location counter to ensure that each section has its output aligned with the desired, in this case, in order to '. Text' 
and '. data' section specified address alignment constraints satisfied, but the Connector may need to '. data' and '. bss' section to create a small gap between.

In this way, it is a simple but complete connection script.
Simple connection script commands. 
=============================
In this chapter, we will describe some simple scripting commands.
Set the entry point.
-----------------------
When you run a program to be executed first instruction called "entry point." You can use the 'ENTRY' connection script command to set the entry point. Argument
is a symbol name:
    ENTRY (SYMBOL)
There are many different ways to set the entry point. Connector by sequentially try the following methods to set the entry point, if successful, will stop.
  * `-E 'entry command-line option;
  * Connect the script `ENTRY (SYMBOL) 'command;
  * If you define the start, on the use of start values;
  * If there is, use '. Text' section of the first address;
  * Address `0 '.
Document processing commands. 
---------------------------
There are several processing documents linking script commands.
`INCLUDE FILENAME '
in the current script file that contains the connection point FILENAME. in the current path or use the '-L' option specifies the path to search for all the files,
you can nest 'INCLUDE' up to 10 layers.
`INPUT (FILE, FILE, ...) '
`INPUT (FILE FILE ...) '
'INPUT' command instructs the connector connection include file, as they are the same as specified on the command line.
For example, if you connect it always contains the file 'subr.o', but every time you connect to the command line, enter bored
, you can connect to your script, enter 'INPUT (subr. o).
In fact, if you like, you can put all your input files listed in the linker script, and then when the connection does not need anything,
as long as a '-T' option is enough.
In a 'system root prefix' is configured in the case, if a file name with a '/' character starts, and the script is also stored in the system root
prefix a subdirectory, the file name will be in the system root prefix search under. Otherwise, the connector will attempt to open the file in the current directory
pieces, if not found, the connector through the archives library search path to search.
If you use a 'INPUT (-lFILE)', 'ld' will convert the file name 'libFILE.a', like a command line parameter '-l' the same.
When you are in an implicit connection scripts 'INPUT' command, the file will be connected to the connection point of the script file to be included on
is included in. This will affect the file search.
`GROUP (FILE, FILE, ...) '
`GROUP (FILE FILE ...) '
In addition to the archive file must all be outside, 'GROUP' command with 'INPUT' similar, they will be repeated searches, until there is no undefined
references are created.
`OUTPUT (FILENAME) '
'OUTPUT' command names the output file in connection scripts' OUTPUT (FILENAME) 'command with the command line using the'-O
FILENAME 'commands are equivalent if the two are used that command line option takes precedence.
You can use the 'OUTPUT' command to create a default output file name of the file, instead of the usual 'a.out'.
`SEARCH_DIR (PATH) '
`SEARCH_DIR 'command to the' ld 'is used to search for the file path of the file to add the new path. use` SEARCH_DIR (PATH)' with the
command line using the '-L PATH' option is a completely other effective if two are used, and that all connectors are two paths to search. Yongming
command line option to specify the path is searched first.
`STARTUP (FILENAME) '
Apart FILENAME will be the first to be connected to the input file, 'STARTUP' command with 'INPUT' command exactly alike, as this text
piece is the first one on the command line is the same as the specified file. If in a system, the entry point is always present in the first file, then
this is useful.
Processing object file format commands. 
-----------------------------------------
There are two processing object file format linker script command.
`OUTPUT_FORMAT (bfdname) '
`OUTPUT_FORMAT (DEFAULT, BIG, LITTLE) '
`OUTPUT_FORMAT 'command for the output file format used by BFD named using` OUTPUT_formAT (BFDNAME)' with the command line
using the '-oformat BFDNAME' is entirely etc. effective if two are used, the command line option takes precedence.
You can use the `OUTPUT_formAT 'with three parameters to use when different based'-EB 'and'-EL 'command line option format.
If the '-EB' and '-EL' are not used, then the output format will be the first argument DEFAULT, if you use the '-EB', the output format will be the
second parameter BIG, if you use the '-EL' The output format will be the third parameter, LITTLE.
For example, the default platform based on MIPS ELF linker script using the following command:
        OUTPUT_formAT (elf32-bigmips, elf32-bigmips, elf32-littlemips)
    This means that the default output file format is 'elf32-bigmips', but when the user uses '-EL' command line option, the output file will
    be in ` elf32-littlemips' format to create.
`TARGET (bfdname) '
'TARGET' command reads the input file name in the BFD format which does not affect the subsequent 'INPUT' and 'GROUP' command with the command
on the command line using the `-b BFDNAME 'similarity. If you use the 'TARGET' command but `OUTPUT_formAT 'is not specified, the last of
'TARGET' command can also be used to set the output file format.
Other connection script commands. 
----------------------------
There are some other connection script commands.
`ASSERT (EXP, MESSAGE) '
to ensure that EXP does not equal zero, if zero, the connector will return an error code to exit, and print out the MESSAGE.
`EXTERN (SYMBOL SYMBOL ...) '
mandatory SYMBOL as a non-defined symbols input to the output file. doing so may trigger a number of connections from the standard library
section outside the library, you can assign each EXTERN ' lists several symbols, but many times you can use the 'EXTERN'. this command with the '-u'
command line option has the same effect.
`FORCE_COMMON_ALLOCATION '
this command with the command line option '-d' has the same effect: Even if you specify a relocatable output file ('-r'), but also to 'ld'
as an ordinary symbol distribution space.
`INHIBIT_COMMON_ALLOCATION '
this command with the command line option `- no-define-common 'has the same effect: even if it is a non-weight-bit output file, and let
'ld' ignored as ordinary symbols allocated space.
`NOCROSSREFS (SECTION SECTION ...) '
This command is encountered in some specific reference to the time between sections will produce an error message.
In certain programs, especially in the use of overlay technology embedded systems, when a section is loaded into memory, another section
will not be in memory. Any direct references between the two sections will was a mistake. example, if a section of code calls another
a section of a function, which will generate an error.
`NOCROSSREFS 'command output section with a list of names and if' ld 'encounter any cross-references between these sections, it
will report an error and returns a non-zero exit code. attention, `NOCROSSREFS 'command use the output section name, not the input section name.
`OUTPUT_ARCH (BFDARCH) '
Specify a particular output machine architecture. This parameter is used in a BFD library name you can use with the '-f' option
of 'objdump' program to view an object file structure.
The symbol assigned. 
===========================
You can connect in a script as a symbol assigned a value, which will define a symbol as a global symbol.
Simple assignment. 
------------------
You can use all of the C assignment symbol is a symbol assignments.
`SYMBOL = EXPRESSION; '
`SYMBOL + = EXPRESSION; '
`SYMBOL - = EXPRESSION; '
`SYMBOL * = EXPRESSION; '
`SYMBOL / = EXPRESSION; '
`SYMBOL << = EXPRESSION; '
`SYMBOL >> = EXPRESSION; '
`SYMBOL & = EXPRESSION; '
`SYMBOL | = EXPRESSION; '
The first case is defined as the value will SYMBOL EXPRESSION. Other cases, SYMBOL must have been defined, and the value will be adjusted accordingly
whole.
Special symbol name '.' Denotes the location counter. You can only 'SECTIONS' command to use it.
EXPRESSION behind the semicolon is a must.
Expressions are defined below.
Value of the expression you write when you can use them as a separate part, or as a 'SECTIONS' command in a statement, or as
'SECTIONS' command to describe a part of the output section.
Symbol's section will be set to an expression where the festival.
Here is a place in the three examples of using symbolic assignment:
    floating_point = 0;
    SECTIONS
    {
      . text:
        {
          * (. text)
          _etext =.;
        }
      _bdata = (. + 3) & ~ 3;
      . Data: {* (. Data)}
    }
In this example, the symbol `floating_point 'is defined as zero. Symbol'-etext 'is defined as the previous one'. Text 'end of the address section.
and the symbol '_bdata' may be defined as '. text' output section behind an upwardly aligned on a 4-byte boundary address value.
PROVIDE
-------
In some cases, a symbol is referenced to the time the connection is only defined in the script, and not to be connected at any one of the object file specified incoming
defined This approach is more sensible for example, a conventional connector definition a symbol 'etext'. However, ANSI C requires the user to be able to
'etext' as a function uses without generating an error. 'PROVIDE' keyword can be used to define a symbol, such as 'etext', this
definition is only in its is referenced to the time valid and invalid when it is defined. syntax is `PROVIDE (SYMBOL = EXPRESSION) '.
Here is a use of 'PROVIDE' define 'etext' examples:
    SECTIONS
    {
      . text:
        {
          * (. text)
          _etext =.;
          PROVIDE (etext =.);
        }
    }
In this example, if the program defines a '_etext' (with a leading underscore), the connector will give a redefinition error if,
the program defines a 'etext' (without the leading underscore), the connector define default program if the program refers to 'etext' but does not
define it, the connector will use the connection script definition.
SECTIONS command 
================
'SECTIONS' command tells the linker how to map input sections into output section, and how the output sections into memory.
'SECTIONS' command format is as follows:
    SECTIONS
    {
      SECTIONS-COMMAND
      SECTIONS-COMMAND
      ...
    }
SECTIONS-COMMAND each one may be the following:
  * A 'ENTRY' command.
  * A symbol assignment.
  * An output section description.
  * An overlapping description.
'ENTRY' command and symbol assignments in the 'SECTIONS' command is allowed, it is for the convenience of the location counter used in these commands, which can also be
connected to the script to make it easier to understand, because you can use in place of more meaningful these commands to control the output file layout.
Output Section Descriptor and overlapping descriptions are described below.
If you do not use the connection script 'SECTIONS' command, the connector will be encountered in the input file according to the order of sections in the same place each input section
names in the output section if all input sections are in the first a file exists, then the output file will match the order of the first section of an input file in
the order of sections The first section will address the zero point.
Output section describes 
--------------------------
A complete description of the output section should look like this:
    SECTION [ADDRESS] [(TYPE)]: [AT (LMA)]
      {
        OUTPUT-SECTION-COMMAND
        OUTPUT-SECTION-COMMAND
        ...
      } [> REGION] [AT> LMA_REGION] [: PHDR: PHDR ...] [ = FILLEXP]
Most of the output section does not use an optional section attributes here.
SECTION edge of space is a must, so section name is clear. Colon with braces is also necessary. Line breaks, and other spaces are optional.
Each OUTPUT-SECTION-COMMAND situation might be as follows:
  * A symbol assignment.
  * An input section description.
  * Directly contain data values.
  * A specific output section keyword. output section name. -------------------
 

Output section name is SECTION. SECTION must satisfy the constraints of your output format in one section only supports an unlimited number of formats, such as
'a.out', the name must be a format supported in a section name (eg , 'a.out' Only '. text', '. data' or '. bss'). If the
output format supports any number of sections, but only to support figures, and no name (as in the case of Oasys), name should be enclosed in double quotes with a
numeric string form. a section name can consist of any number of characters, but with a very contain arbitrary characters (such as comma) the words must be
in double quotation marks.
Output section describes 
--------------------------
ADDRESS is the output section of the VMS on an expression, if you do not provide ADDRESS, connector based REGION (if it exists) to set it up, or
those based on the current value of the location counter.
If you provide ADDRESS, the address of that output section will be precisely set to this value if you do not provide neither provides ADDRESS REGION, then
the address of the output section will be set up the current location counter aligned to the output section requires the alignment of the boundary value output section alignment requirements are all inputs
into the section containing the most stringent alignment requirements a.
For example:
    . text.: {* (. text)}
And
    . text: {* (. text)}
There are subtle differences. First one will '. Text' output section address is set to the current value of the location counter The second will set it to the location counter
aligned to the current value of upwards '. text' input sections aligned most demanding a border.
ADDRESS can be any expression; For example, if you need to put on the 0x10 byte boundary alignment sections, so you can make the low four-byte node address is
zero, you can do this:
    . Text ALIGN (0x10): {* (. Text)}
This statement can work because the 'ALIGN' returns the current location counter, and to align to the specified value.
Specify the address of a section will change the value of the location counter.
Input section description 
-------------------------
The most common output section command is an input section description.
Input section description is the most basic connection script actions you use to tell the linker output sections in memory layout of your program how you use the input section
to tell the linker how to map the input files to your memory.
Input section based 
---------------------------
An input section description consists of a file name followed by an optional bracketed section name lists.
File names and section names can appear as a wildcard, which we introduce later.
The most common input section description is included in the output section all input sections with a specific name, eg, containing all the input '. Text' section, you can
write:
    * (. Text)
Here, '*' is a wildcard, matches all filenames order to exclude the part of the file name wildcard matching outside, EXCLUDE_FILE can
be used to match all except in EXCLUDE_FILE file specified in the list, such as:
    (* (EXCLUDE_FILE (* crtend.o * otherfile.o). Ctors))
Let Apart `crtend.o 'files and` otherfile.o' files outside of all the documents in all. Ctors section is included.
There are two ways to include more than one sections:
    * (. Text. RDATA)
    * (. text) * (. RDATA)
The difference between the above two '. Text' and '. Rdata' input sections appear in the output section of a different order in the first example, the two sections alternately 
appear and to connect the input of the order of arrangement. In the second example, all '. text' input sections will appear first, followed by all '. rdata' section.
You can specify a file name from the file that contains a specific section if one or more of your files contain special data in memory, requiring special
special position, you can do this, such as:
    data.o (. data)
If you do not use a file name with a section of the list, and that all of the input file section will be included in the output section. Normally would not do, but
in some cases this can be very useful, such as:
    data.o When you use a wildcard does not contain any file name, the connector will first check whether you are connected to the command line specifies the file name or in the 'INPUT' command. If you do not, the connector will try to put this file as an input file to open, just as it appears on the same command line. attention to this with 'INPUT' command is not the same as the connector in the file search file search path.
   
Input section wildcard 
---------------------------------
In an input section description, file name or section name, or both can be a wildcard in the form.
File name wildcard '*' in many cases you can see, this is a simple file name wildcard form.
Wildcard forms used with Unix Shell same.
`* '
matches any number of characters.
`? '
match a single character.
`[CHARS] '
matches any single character in CHARS; character '-' can be used to specify a square Hong characters, such as [az] matches any small print characters.
`\ '
escapes the subsequent characters.
When a file name with a wildcard match, the wildcard characters will not match a '/' character (on UNIX systems used to separate directory names), one
containing a single '*' character in the form of an exception; it will always match any documents name, regardless of whether it contains a '/' in a section name, the wildcard character
character will match '/' character.
Filename wildcards only match those on the command line or in the 'INPUT' explicitly specified on the command file. Connector does not search directories to expand through the wildcard
character.
If a file name matches more than one wildcard, or if a file name appear explicitly while matching a wildcard, the connector will use the
first match to the connection script for example, the following section describes the input sequence is likely to be wrong , because 'data.o' rule is not being used:
    . Data: {* (. Data)}
    . DATA1: {data.o (. Data)}
Typically, the connector will match the wildcard file and the festival was seen by the connection placed in the order you can 'SORT' key to change it, it
appears in parentheses before the wildcard (eg, 'SORT (. text *) ') when' SORT 'keyword is used, the connector section in the file and put
the output file in the order prior to rearrange them by name.
If you enter the section is placed for where to go was very confused, then you can use the '-M' connection option to generate a bitmap file. Bitmap file will
accurately show how input sections are mapped to the output section.
This example shows how wildcard is used to distinguish file This connector connection script indicates all the '. Text' section into '. Text' in all the '. Bss' section into '. Bss' Connectors will put all the file names from the beginning with a capital letter in the file '. data' section into '. DATA' section; For all other files, the connector will '. data' section into ' . data 'section.
    SECTIONS {
      . text: {* (. text)}
      . DATA: {[AZ] * (. Data)}
      . Data: {* (. Data)}
      . BSS: {* (. BSS)}
    }
Input section ordinary symbols.
-----------------------------------
For ordinary symbol, require a special logo, because in many target format, the common symbol is not a particular input section. Connector will
handle normal symbols as if they are called 'COMMON' in a section.
You might like to use other input sections with the same file name to use with the 'COMMON' section of the file name. You can use this to come from a specific input
into the file into a common symbol section, while the input files from other common symbols into another section.
In most cases, the input file will be placed in ordinary symbols output file '. Bss' section. For example:
    . Bss {* (. Bss) * (COMMON)}
Some object file formats have more than one common symbols. For example, MIPS ELF object file format distinguishes standard common symbols and small common symbols.
In this case, the connector is common to other types of special symbols using a different section names. In the case of MIPS ELF, the connector
used for the standard normal symbols 'COMMON', and the general use of symbols for the small '. common'.This allows you to put different types of common symbols mapped to
different memory locations.
In some old connection script, you sometimes see '[COMMON]'. This symbol is now obsolete, and it is equivalent to '* (COMMON)'.
Input section and garbage collection 
---------------------------------------
When the connection is garbage collection is in use ('- gc-sections'), which identifies those who should not be excluded section is very useful. This
is achieved by a wildcard in the input section outside the entrance plus' KEEP () 'to achieve, such as' KEEP (* (. init))' or 'KEEP (SORT (*) (. sorts)) '
.
Sample input section 
---------------------
The following example is a complete linker script. It tells the linker to read the file 'all.o' in all sections, and put them in the output section
'outputa' at the beginning of the output section is from the position '0 x10000 'at the beginning. From the file 'foo.o' to all of the sections in '. Input1'
in the same output section closely packed. From the file 'foo.o' to all of the sections in '. Input2' all fit into output section 'outputb' in the back
to keep from 'foo1.o' in the coming festival '. input1'. All files from any remaining '. Input1' and '. Input2' section is written to the output section
'outputc' in.
    SECTIONS {
      outputa 0x10000:
        {
        all.o
        foo.o (. INPUT1)
        }
      outputb:
        {
        foo.o (. INPUT2)
        foo1.o (. INPUT1)
        }
      outputc:
        {
        * (. INPUT1)
        * (. INPUT2)
        }
    }
Data output section
-------------------
You can use the output section command 'BYTE', 'SHORT', 'LONG', 'QUAD', or 'SQUAD' explicitly in the output section contains several bytes of data
each keyword is followed by a round in brackets the value to be stored. Value of the expression is stored in the current value of the location counter at.
'BYTE', 'SHORT', 'LONG'' QUAD' command to store one, two, four, eight bytes. Into the byte, the potentiometer
plus the value of the count is stored in bytes.
For example, the following command will be credited to the contents of a one-byte, followed by four bytes, and its content is the symbol 'addr' value.
    BYTE (1)
    LONG (addr)
When using a 64-bit system, 'QUAD' and 'SQUAD' is the same; they are stored 8 bytes, or a 64-bit value. And if the hardware and software
systems are 32-bit, an expression will be calculated as 32. In this case, 'QUAD' store a 32-bit value, and it is zero-extended
to 64 bits, while 'SQUAD' 32-bit value will sign extended to 64 bits.
If the output destination of the file format has an explicit endianness, which in normal circumstances, the value will be stored in this endianness
when an object file format does not have an explicit endianness, the value will be the first endianness of input target file storage.
Note that these commands only in one section describes the interior to be effective, rather than between them, therefore, the following code will generate an error connector
error message:
    SECTIONS {. Text: {* (. Text)} LONG (1). Data: {* (. Data)}}
And this is valid:
    SECTIONS {. Text: {* (. Text); LONG (1)}. Data: {* (. Data)}}
You may use the 'FILL' command to set the fill pattern for the current section. It is followed by an expression in parentheses. Any section of unspecified memory
area (for example, because the input section alignment requirements caused cracks) will be populated with the value of the expression. A 'FILL' statement to cover
itself in the position defined in section appears behind all memory areas; through the introduction of more 'FILL' statement, you can at different locations in the output section
has a different fill styles.
This example shows how to specify the memory area is not filled with '0 x90 ':
    FILL (0x90909090)
'FILL' command with the output section '= FILLEXP' attributes are similar, but it only affects the section following the 'FILL' command back part, rather than the
entire section. If both are used, and that 'FILL' command takes precedence.
Output section keyword
-----------------------
There are two key as the output section of the form of the command.
`CREATE_OBJECT_SYMBOLS '
This command tells the linker to create an input file for each symbol. The name of the symbol just input the file name is associated.
The section of each symbol is `CREATE_OBJECT_SYMBOLS 'command appears that section.
This command has the a.out object file format specific. It is generally not the object file format for other use.
`CONSTRUCTORS '
when using the a.out object file format when connected to the connector using a set of unusual structures to support the C + + global constructors
and destructors number. When the connection does not support the objectives section proprietary file format, such as ECOFF and XCOFF, the connector will automatically identification C + +
global constructors and destructors name. For these object file format, 'CONSTRUCTORS' command tells the linker to construct
the function information into 'CONSTRUCTORS' command appears that the output section. For other object file format, 'CONSTRUCTORS'
command is ignored.
Symbol `__CTOR_LIST__ 'logo global constructors start, and the symbol` __DTOR_LIST' identity ends. The first in the list
is the entrance WORD number, followed by one in the back of every constructor and destructor address, then to a zero WORD. Compiler
must arrange how to actually run the code. For these object file format, GNU C + + is usually from a `__main 'subroutine calls
the constructor, while the `__main 'call is automatically inserted into the` main' boot code. GNU C + + typically use 'atexit' run
destructors, or directly from the function 'exit' to run.
For like 'COFF' or 'ELF' section name, that support proprietary object file format, GNU C + + will usually global constructors and destructors
function address value into '. ctors' and '. dtors' section. The following code sequence into your linker script to go, it will build
the GNU C + + runtime code would like to see table type.
              __CTOR_LIST__ =.;
              LONG ((__CTOR_END__ - __ CTOR_LIST__) / 4 - 2)
              * (. ctors)
              LONG (0)
              __CTOR_END__ =.;
              __DTOR_LIST__ =.;
              LONG ((__DTOR_END__ - __ DTOR_LIST__) / 4 - 2)
              * (. dtors)
              LONG (0)
              __DTOR_END__ =.;
If you are using GNU C + + support for initialization priority, then it can provide some control of the situation in order to run the constructor function,
you must connect to the constructor sorted to ensure that they are executed in the correct order. When using 'CONSTRUCTORS' command,
replaced by `SORT (CONSTRUCTORS) '. When using '. Ctors' and' dtors' section, use `* (SORT (. Ctors)) 'and
`* (SORT (. dtors)) 'instead of` * (. ctors)' and `* (. dtors ) '.
Normally, the compiler and linker will automatically handle these things, and you do not personally care about these things. However, when you're using
C + +, and write your own connection script, you might want to consider these things.
Output section discarded. 
-------------------------
Connector does not create content that do not contain any output section. This is to cite those that may arise or not present any input file input
section of convenience. For example:
    . Foo {* (. Foo)}
If at least one input file has '. Foo' section in the output file it will create a '. Foo' section
If you use other than an input section description as an output section commands, such as a symbol assignment, then the output section is always
created, even if no matching input sections will be created.
A special output section name `/ DISCARD / 'can be used to discard input sections. Be assigned to any named `/ DISCARD / 'output section of the input
section is not included in the output file.
Output section attribute 
-------------------------
Above, we have demonstrated a complete description of the output section, looks like this:
    SECTION [ADDRESS] [(TYPE)]: [AT (LMA)]
      {
        OUTPUT-SECTION-COMMAND
        OUTPUT-SECTION-COMMAND
        ...
      } [> REGION] [AT> LMA_REGION] [: PHDR: PHDR ...] [ = FILLEXP]
We have introduced SECTION, ADDRESS, and OUTPUT-SECTION-COMMAND. In this section, we will introduce the rest of the section attributes.
Output section type 
...................
Each output section may have a type. Type is a keyword in parentheses, the defined types are as follows:
`NOLOAD '
This section should be iconic Ju can not load, so when the program is run, it will not be loaded into memory.
DSECT `'
`COPY '
`INFO '
`OVERLAY '
support for these types of names only for backwards compatibility, they are rarely used. They all have the same effect: This section should be iconic Ju not
be assigned, so when the program is running, there is no memory allocated for this section.
Connector typically mapped to the output section based on the input section to set the output section of the property. You can use the section type to reset this attribute,
for example, in the following script example, 'ROM' section is addressed at memory address zero point, and does not need to be loaded when the program is running.
'ROM' section of the content appears correctly in the connection output file.
    SECTIONS {
      ROM 0 (NOLOAD): {...}
      ...
    }
Output section LMA 
..................
Each section has a virtual address (VMA) and a load address (LMA); appear in the output section describes the settings in the address expression VMS
Connectors usually set to be equal LMA with VMA. You can use the 'AT' key to change this. With the keyword 'AT' behind the expression
LMA designated section load address. Or, `AT> LMA_REGION 'expressions, you can specify a section load address memory area.
This feature is to facilitate the establishment of the ROM image and design. For example, the following connection script creates three output sections: one called '. Text'
from address '0 x1000 'at the beginning, one called'. mdata ', despite its VMA is '0 x2000', it will be loaded into ' . text 'section behind the
rear one is called '. bss' is used to place uninitialized data, and its address from '0 x3000' at the beginning.Symbol '_data' is defined as a value
'0 x2000 ', which represents the value of the location counter value VMA instead LMA.
    SECTIONS
      {
      . text 0x1000: {* (. text) _etext =.;}
      . mdata 0x2000:
        AT (ADDR (. text) + SIZEOF (. text))
        {_data =.; * (. Data); _edata =.; }
      . BSS 0x3000:
        {_bstart =.; * (. BSS) * (COMMON); _bend =.;}
    }
This connection uses the generated script runtime initialization code will contain something like shown below to the initialization data from ROM
image to its runtime copy the address to go. Note that this section of code is how to make good use of the symbols defined in connection script.
    extern char _etext, _data, _edata, _bstart, _bend;
    char * src = & _etext;
    char * dst = & _data;     / * ROM has Data at End of text; Copy it. * /     while (dst <& _edata) {       * dst + + = * src + +;     }     / * Zero BSS * /     for (dst = & _bstart; dst <& _bend; dst + +)       * dst = 0;
   
Output section area 
.....................
You can use the `> REGION 'is assigned to a section of a previously defined region of memory.
Here's a simple example:
    MEMORY {ROM: ORIGIN = 0x1000, LENGTH = 0x1000}
    SECTIONS {ROM: {* (. text)}> ROM}
Output section Phdr 
...................
You can use the `: PHDR 'assigned to a section of a previously defined block. If a node is assigned one or more segments, it was sub-
sections will be assigned with these segments, unless they are explicitly spent ': PHDR' modifier. You can use the ': NONE' to tell the linker not to section
into any one segment.
Here is a simple example:
    PHDRS {text PT_LOAD;}
    SECTIONS {. text: {* (. text)}: text}
Output section filled 
...................
You can use the '= FILLEXP' set the fill pattern for the entire festival. FILLEXP is an expression. Any output is not specified memory segment
area (for example, because the input section of the alignment of cracks) the value that will be filled. If the fill expression is a simple hexadecimal
value, for example, a '0 x 'began a string of hexadecimal digits, and the tail is not a' k 'or' M ', then an arbitrary sixteen hexadecimal number
word sequence can be used to specify the fill style; leading zeros also becomes part of the style. For all other cases, including an additional brackets
or unary operator '+' is an expression that fill styles lowest four-byte value. In all cases, the value is big-endian.
You can also use commands in the output section 'FILL' command to change the fill value.
Here is a simple example:
    SECTIONS {. text: {* (. text)} = 0x90909090}
Cover description 
-------------------
An overlay description provides a simple description of ways to describe those who want to be as a separate part of the memory image loaded into memory, but have to
run in the same memory address section. At run time, a number of management mechanism will cover the section to be covered copied in or out as needed runtime memory address,
and is mostly handled by a simple memory bits. This approach might be useful, for example, in a particular memory area is faster than the other.
Covered by 'OVERLAY' command description. 'OVERLAY' command in the 'SECTIONS' command to use the same description as the output section.
'OVERLAY' complete syntax for the command is as follows:
    OVERLAY [START]: [NOCROSSREFS] [AT (LDADDR)]
      {
        SECNAME1
          {
            OUTPUT-SECTION-COMMAND
            OUTPUT-SECTION-COMMAND
            ...
          } [: PHDR ...] [= FILL]
        SECNAME2
          {
            OUTPUT-SECTION-COMMAND
            OUTPUT -SECTION-COMMAND
            ...
          } [: PHDR ...] [= FILL]
        ...
      } [> REGION] [: PHDR ...] [= FILL]
In addition to 'OVERLAY' keyword, all of which are optional, each section must have a name (above SECNAME1 and SECNAME2). In
'OVERLAY' structure defined in section with the usual 'SECTIONS' structure defined in section are identical, except for one thing, that is, 'OVERLAY'
does not address the definition with the memory region.
Sections are defined for the same start address. Load address all sections are arranged so that they are in memory from the entire 'OVERLAY' load address to open
the beginning are continuous (as defined in Section ordinary, load address is optional, the default is the start address; starting address is optional, the default
is the current location counter value.)
If you use the keyword `NOCROSSREFS ', and in between there is a reference section, the connector will report an error. Because section runs in the same
address, so a direct reference to another section of the section content is wrong.
For 'OVERLAY' in each section, the connector automatically defines two symbols. Symbol `__load_start_SECNAME 'is defined as the beginning of the section contained
into the address. Symbol `__load_stop_SECNAME 'is defined as the last section load address. SECNAME C does not meet the provisions of any character will
be deleted. C (or assembly language) code may use these symbols in the time necessary to move the overlay code.
The coverage area of ​​the final positioning of the counter value is set to the start address of the area covered plus the maximum length of the section.
Here is an example. Remember that this will only appear in the 'SECTIONS' internal structure.
      OVERLAY 0x1000: AT (0x4000)
      {
        . text0 {o1 / *. O (. text)}
        . text1 {O2 / *. O (. text)}
      }
This code defines '. Text0' and '. Text1', they all start from address 0x1000. '. Text0' will be loaded into the address 0x4000 place, while
'. text1' will be loaded to immediately '. text0' after location. Here's a few symbols will be defined: `__load_start_text0 ',
`__load_stop_text0 ',` __load_start_text1', `__load_stop_text1 '.
Copy '. Text1' to the coverage area of ​​the C code might look like the following:
      load_start_text1 extern char __, __ load_stop_text1;
      memcpy ((char *) 0x1000, & __load_start_text1,
              & __load_stop_text1 - & __load_start_text1);
Note that 'OVERLAY' command only for syntactic convenience, because it does all the things that can be used to replace the more basic commands. The above
example can complete with the following wording effects:
      . Text0 0x1000: AT (0x4000) {o1 / *. O (. Text)}
      __load_start_text0 = LOADADDR (. text0);
      __load_stop_text0 = LOADADDR (. text0) + SIZEOF (. text0);
      . text1 0x1000: AT (0x4000 + SIZEOF (. text0)) {O2 / *. O (. text)}
      __load_start_text1 = LOADADDR (. text1);
      __load_stop_text1 = LOADADDR (. text1) + SIZEOF (. text1);
      . = 0x1000 + MAX (SIZEOF (. text0), SIZEOF (. text1));
 
============
Connectors by default is configured to allow all of the available memory blocks allocated. You can use the 'MEMORY' command to reconfigure the settings.
'MEMORY' command descriptor block of memory on the target platform location and length. You can use it to describe which memory regions can be connected using,
which is to avoid the area of memory used. Then you can put the section assigned to a specific area of memory. Connector memory-based locale section
addresses the area for too full, it will display a warning message. Connectors are available in order to meet the area will not be disturbed while section.
A connection script can contain up to a 'MEMORY' command. However, you can define as many commands arbitrary block of memory, the syntax
is as follows:
    MEMORY
      {
        NAME [(ATTR)]: ORIGIN = ORIGIN, LENGTH = LEN
        ...
      }
NAME is used in the connection memory area referenced in the script's name. A connection script, zone name would be no practical significance. Area name is stored in a
separate namespace, it does not and symbol name, file name, section name conflict, each a memory region must have a unique name.
ATTR string is an optional attribute list, which indicates whether a connection is not in the script explicitly mapped to an input section using a specific
memory area. If you do not specify an input section for some output section, the connector creates an input section with the same name as the output section. If you set
a defined area attribute, the connector will use them to create output for its segment selector memory area.
ATTR string must contain one of the following characters, and must contain only one:
`R '
read-only sections.
`W '
    can be read below.
`X '
executable section.
`A '
can be assigned section.
`I '
is initialized section.
`L '
    with 'I'
`! '
right before an attribute value negated.
If an unmapped section matches the above except '!' Outside of a property, it will be placed in the memory region. '!' Attribute negated the test, so
only if it does not match any properties listed above the line when an unmapped section will be placed into the memory area.
ORIGIN is a place on the starting address of the memory area of expression. In the memory allocation before the execution, the expression must be evaluated to produce a constant,
which means you can not use any Section-related symbols. Keyword 'ORIGIN' can be abbreviated as 'org' or 'o' (but not write to, than
as 'ORG')
LEN is a charge on the long memory area (in bytes) of the expression. Like ORIGIN expression that is assigned before executing it
must be determined as a constant value. Keyword 'LENGTH' can be abbreviated to 'len' or 'l'.
In the following example, we specify the two can be used to allocate memory area: one starting at 0, with 256kb length, and the other from 0x4000000
begin with 4mb length. Connector will be those who do not explicitly mapped and is a read-only or executable sections into 'rom' memory region. And the other will
not explicitly outside mapped to section put into 'ram' memory region.
    MEMORY
      {
        ROM (RX): ORIGIN = 0, LENGTH = 256K
        RAM (! RX): ORG = 0x40000000, L = 4M
      }
Once you have defined a region of memory, you can also instruct the connector to the specified output sections into to this memory area, which can be used
'> REGION' output section attribute. For example, if you have a file called 'mem' area of memory, you can use the output section definition '> mem'. If
fruit is not specified address for an output section, the connector will be set to the address of the memory area to the next available address. If the total is mapped to an
output stage of a memory area is too large for the area, the connector will prompt an error message.
PHDRS command 
=============
ELF object file format using the "Program Header", which is what people known as the "festival." Program header describes how the program should be loaded into memory.
You can use with the '-p' option 'objdump' command to print out the program header.
When you are in a pure ELF ELF program running on the system, the system loader reads the file header is calculated through how to load the file. It
is only in the program header is set correctly circumstances will work properly. This manual does not describe how to interpret the file system loader header details
issues; For more information, see the ELF ABI.
Connection will be in default under shun create yourself an available program header. However, in some cases, you might need to more precisely specify the program header.
You can use the command 'PHDRS' for this purpose. When the connector in the connection script to see 'PHDRS' command, it will create is assigned a
program header.
Connectors ELF output file is generated only when care 'PHDRS' command. In other cases, the connector is simply ignored 'PHDRS'.
Here is 'PHDRS' command syntax. Word 'PHDRS', 'FILEHDR', 'AT' and 'FLAGS' are keywords.
    PHDRS
    {
      NAME TYPE [filehdr] [PHDRS] [AT (ADDRESS)]
            [FLAGS (FLAGS)];
    }
NAME only in connection script 'SECTIONS' command is used when referenced. It will not be placed in the output file. Program header name will be stored in a separate
name space. Each program header must have a unique name.
Certain types of program header file describing the system loader to load into memory from the festival. In connection script, you can load through the output section put
into a segment to specify the content of these segments. You can use the ': PHDR' output section attribute to a section into a particular segment.
That certain sections into a plurality of segments is normal. This implies that only one segment of memory contains another segment. You can reuse ': PHDR', in each
section of a segment should contain this use it once.
If you use ': PHDR' put a section into a plurality of segments, and that the connector is not specified, all the subsequent ': PHDR' section are available for distribution into the same
segment. This is for convenience, because usually a string of consecutive sections will be placed in a separate section. You can use the ': NONE' to override the default segment,
tells the linker not to put any one segment section.
You might use later in the program header type 'FILEHDR' and 'PHDRS' keywords to further describe the contents of paragraph. 'FILEHDR' keyword indicates that the paragraph should
include the ELF file header when. 'PHDRS' keyword indicates that the paragraph should contain an ELF program header itself.
TYPE may be one of the following. Numbers indicate the value of the keyword.
`PT_NULL '(0)
indicates an unused program header.
`PT_LOAD '(1)
indicates that the program header describes a file is loaded from the segment.
`PT_DYNAMIC '(2)
    represents a dynamic linking information can find the segment.
`PT_INTERP '(3)
  represents one can find explanations about the name of the program segment.
`PT_NOTE '(4)
represents a segment exists Remarks.
`PT_SHLIB '(5)
  a reserved program header type is defined, but has not been designated ELF ABI.
`PT_PHDR '(6)
means that a can find the program header segment.
EXPRESSION
a given type of program header value expression. This can be defined using the above type of use.
You can use the 'AT' expression specifies a paragraph should be loaded into memory at a specific address.This is now
used in the output section attribute 'AT' commands are exactly the same. Program header 'AT' command overwrites the output section is
of the.
The connectors generally composed segment based on section to set the segment attributes. You can use the 'FLAGS' keyword to explicitly refer to
a given segment flags. FLAGS value must be an integer value. It is used to set the program header 'p_flags' domains.
This is one of the 'PHDRS' examples. It shows a pure ELF systems in a standard program header settings.
    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       ...     }
   
VERSION command 
===============
When using ELF, the linker supports symbol versions. Symbol version only useful when using shared libraries.Dynamic linker run a
possibility with an earlier version of the shared library linking program, you can use the symbol versions to select a specific version of a function.
You can connect directly to the main script contains a version of the script, or you can connect to an implicit form of the script
version of the script. You can also use the '- version-script' linker option.
'VERSION' command syntax is very simple:
    VERSION {version-script-commands}
The format of the version script commands available in Solaris 2.5 with Sun connector format is exactly the same. Version script defines a version of the
node tree. You can specify the version of the script node name and dependencies. You can specify which symbols are bound to which version of the node
, you can also put a limit specified set of symbols to local scope, so they shared libraries are not globally visible outside of it.
The demo version of the easiest method is to produce a scripting language a few small examples:
    VERS_1.1 {
    global:
    foo1;
    local:
    Old *;
    Original *;
    new *;
    };     VERS_1.2 {     foo2;     } VERS_1.1;     VERS_2.0 {     bar1; bar2;     } VERS_1.2;
   
This example version script defines three version nodes. The first version of the node is defined as 'VERS_1.1' it has no other dependencies.
Scripting the symbol 'foo1' bound to 'VERS_1.1'. It put some limited number of symbols to local scope, so they were
not visible outside of the shared library of; This is accomplished through a wildcard, so any name to 'old', 'original' or
'new' at the beginning of the sign will be matched. Available now in the shell wildcard matching file name the same.
Here, the version script defines a node 'VER_1.2'. This node dependency 'VER_1.1'. Scripting the symbol 'foo2' tied
to a node set 'VERS_1.2'.
Finally, the version script defines node 'VERS_2.0'. This node dependency 'VERS_1.2'. Scripting the symbol 'bar1' and
'bar2' bound to the version node 'VERS_2.0'.
When the connector finds a symbol defined in the library are not bound to a version of the specified node, it will mean that it is not bound to a
fixed base version of the library. You can use the 'global: *;' all unspecified symbols bound to a given version of the section
points.
Version node name does not have any special meaning only to facilitate people to read. Version '2 .0 'can appear in '1 .1' and
'1 .2 'between. However, in the version of the script writing, it would be a confusing way.
If the version of the script, which is a unique version of the node, the node name can be omitted. This version of the script is not assigned to the symbol
any version, just choose which symbols are globally visible and which are not.
    {Global: foo; bar; local: *;};
When you put a program with a version with a symbol of shared library, the program itself to know which version of each symbol is that it needs
to be, and it knows it is connected to each section of the shared library version of the node in which it needs.Thus, at run time, dynamic
state loader can do a quick confirmation, to ensure that your library does provide a connection all the procedures needed to resolve all
versions of dynamic symbol node. In this way, it is possible for each dynamic connector that does not require all external symbols through
a search through each of the symbol reference can be resolved.
Symbol versions on SunOS doing minor version is a very mature recognition method. One was presented to the basic problem is that the external
function when required standard references are bound to the correct version, but not all the time the program starts to be binding. If a
shared library months expired, a required interface may not exist; when a program needs to use this interface, it may
suddenly and unexpectedly fail. With the symbolic version, when a user starts their program, if you want to use shared libraries too old, then
the user will get a warning message.
Sun's version of GNU recognized approach has some extensions. The first is the symbol defined in the source file to a symbol bound to a
version node rather than a version of the script. This is mainly to reduce the workload of database maintenance. You can use something like the following
code to achieve this:
    __asm__ (". symver original_foo, foo@VERS_1.1");
In the C source file. Phrase will function 'original_foo' an alias' foo ', and bound to the version node `VERS_1.1'.
Operators 'local:' can be used to prevent the symbol 'original_foo' be exported. Operator '. Symver' version of the phrase take precedence over
the script.
The second GNU extension is given in a shared library to allow multiple versions of the same function. In this way, you can
not increase the shared library major version number and the right interface to do totally incompatible changes.
To achieve this, you must be in a source file repeatedly used '. Symver' operator. Here is an example:
    __ asm__ (. "symver original_foo, foo @");
    __ asm__ (. "symver old_foo, foo@VERS_1.1");
    __ asm__ (. "symver old_foo1, foo@VERS_1.2");
    __ asm__ (. "symver new_foo, foo @ @ VERS_2.0 ");
In this example, 'foo @' represents the symbol 'foo' refers to the base is not bound to a version of the symbol.This example contains the source
files must define 4 C functions: `original_foo ',` old_foo', `old_foo1 ', and` new_foo'.
When you have more than a given symbol defined, it is necessary to have a way to specify a default version of this symbol for
external references can be found on this version. In this way, you can just declare a symbol of a version as the default version,
otherwise you will have multiple definitions of the same symbol.
If you want to bind a reference to the shared library symbols a specified version, you can easily use an alias (eg,
old_foo), or you can use '. symver' operator to specify the binding to an external specific version of the function.
You can also specify the language versions of the script.
    VERSION extern "lang" {version-script-commands}
Supported 'lang' a 'C', 'C + +' and 'Java'.
Connection script expressions 
=============================
Connect scripting language expression syntax with C expression is entirely consistent. All expressions are evaluated as an integer value. All
expressions have been evaluated with the same width. In the 32-bit system is that it is 32, otherwise it is 64.You can use in an expression and set symbol values.
    
Connector in order to use the expression that defines several built-in functions with special purpose.
Constant
---------
All constants are integer values.
As in C, the connector put to '0 'at the beginning of integers as octal numbers put to '0 x' or '0 X 'beginning as hexadecimal. Connector
to the other as a decimal integer.
In addition, you can use the 'K' and 'M' suffix as a constant unit of measurement, namely '1024 'and '1024 * 1024'. For example, the following three
constants represent the same value.
    _fourk_1 = 4K;
    _fourk_2 = 4096;
    _fourk_3 = 0x1000;
Symbolic names
------------
In addition to references to a symbol name are letters, underscores, or periods and may contain letters, numbers, underscores, periods, and hyphens.
Not being referenced symbol names must not conflict with any keywords. You can specify a number of characters it contains is not fixed with the keyword with the same name or
word but symbolic name must be in double quotes:
    "SECTION" = 9;
    "with a space" = "also with a space" + 10;
Because symbols can contain many non-alphanumeric characters, symbols separated by spaces so it is very safe. For example, 'A-B' is a symbol, and 'A - B'
is an expression for subtraction.
Location counter 
--------------------
A special connector variable "dot" '.' Always contains the current output location counter. Since the '.' Total output section in a reference position, it
can only appear in the 'SECTIONS' command in the expression. '.' Symbol can appear in the expression a universal symbol can appear in any position allowed
home.
Assign a value to '.' Location counter will generate movement. This will produce voids in the output section.Location counter never move forward.
    SECTIONS
    {
      output:
        {
          file1 (. text)
          . =. + 1000;
          file2 (. text)
          . + = 1000;
          file3 (. text)
        } = 0x12345678;
    }
In the previous example, from 'file1' a '. Text' section is positioned in the output section 'output' of the starting position. It followed 1000byte of
voids. Then from 'file2' the '. Text' section, the same is followed 1000byte gap, and finally from the 'file3' the '. Text'
section. Symbol '= 0x12345678' specifies what kind of void fill data.
Note: '.' Actually refers to the current objectives contained in the byte offset from the beginning. Typically, it is the 'SECTIONS' statement, whose starting address
is the address 0, because the '.' can be used as an absolute address. However, if the '.' Is used in a section of the description, it refers to this section from the start at the beginning
of the shift, rather than an absolute address. Thus, such a script in the following:
    SECTIONS
    {
        . = 0x100
        . text: {
          * (. text)
          . = 0x200
        }
        . = 0x500
        . Data: {
          * (. Data)
          . + = 0x600
        }
    }
'. Text' section is assigned starting address 0x100, although in '. Text' input sections do not have enough data to fill this area, but its length
degrees or 0x200bytes. (If too much data, it will generate an error message, because it would try to '.' To move forward). '. Data'
section from the 0x500 at the beginning, and it will have at the end of extra space 0x600.
Operators 
---------
Connectors can identify the standard C arithmetic operators set, and their priority set.
    Priorities set associative operator Remarks
    (Highest)
    1 Left! - ~ (1)
    2 Left * /%
    3 Left + -
    4 Left >> <<
    5 Left ==! => << => =
    6 Left &
    7 Left |
    8 Left &&
    9 Left | |
    10 right?:
    11 right & = + = - = * = / = (2)
    (Lowest)
  Note: (1) prefix operator (2) * Note Assignments ::.
Evaluation 
----------
Connectors are lazy to evaluate the expression. It is only when you really need to seek an expression.
Connector requires some information, such as the first section of the start address value, as well as the starting point and length of the memory area, make any connections at
this time are needed. Connect the connector reads the script, when possible, these values ​​were calculated.
However, other values ​​(such as symbol values) until the memory is allocated only after knowing or needs. This value until the additional information (than
if the output section length) can be used for symbolic assignment was only when calculated.
Until the memory assignment, the length of the section will be known, so the length of the assignment depends on the section only to the memory allocation will be executed after.
Some expressions, such as those dependent on the location counter '.', Must be evaluated in the course of time allocation is calculated.
If the result of an expression is now needed, but now can not get this value, this will cause an error. For example, like below this
kind of a script:
    SECTIONS
      {
        . text 9 + this_isnt_constant:
          {* (. text)}
      }
Will generate an error message 'non constant expression for initial address'.

Expression festival 
----------------------------


When a connector calculate an expression, the result may be an absolute value, may also be associated with a section. A section related 
expression is a section from the base address of the beginning of the partial fixed nominal value.


Expressions in connection script determines its position is absolute or sections relevant. One appears at the output of the expression is defined in section with the output 
section of the base address. A expression in other places is absolute.


If you pass '-r' option specifies the need for re-bit output, it is assigned a section related to the expression for the symbol will be relocatable. Italian 
think is the next operation will change the connection value of this symbol. The festival is a symbolic expression of the section where the relevant section.


Is assigned a sign of the absolute expression further connecting operation of the back will always keep its value constant. Symbol is absolute, and 
does not have any particular relevant section.


If an expression may be related to the festival, you can use the built-in function 'ABSOLUTE' to force an expression is absolute. For example, 
to create an output section is assigned to '. data' at the end of the address of the absolute symbol:


    SECTIONS 
      {
        . Data: {* (. Data) _edata = ABSOLUTE (.);}
      }
If you do not use 'ABSOLUTE', '_edata' will follow section '. Data' related.

Built-in Functions 
-----------------

In order to use the connection script expression, connection scripting language contains a number of built-in functions.

`ABSOLUTE (EXP) ' 
returns the absolute value of the expression EXP (not relocatable, instead of non-negative). Mainly to an absolute value assigned to a section within the definition of 
useful symbols.


`ADDR (SECTION) ' 
returns the absolute address section SECTION (VMA). Your script must be defined before the address of this section. In the following example 
the, 'symbol_1' and 'symbol_2' is assigned to the same value.


        SECTIONS {... 
          . OUTPUT1: 
            { 
            start_of_output_1 = ABSOLUTE (.); 
            ... 
            } 
          . output: 
            { 
            Symbol_1 = ADDR (. OUTPUT1); 
            symbol_2 = start_of_output_1; 
            } 
        ...}


`ALIGN (EXP) ' 
Return the location counter '.' alignment to the next EXP specified boundary value. 'ALIGN' does not change the value of the location counter, it is only 
in the positioning counter top made ​​an arithmetic operation. Here is an example, it is in front of the section after the output section '. Data' alignment 
to the next '0 x2000 'byte boundary, and in the input section after section of a variable to be aligned to the next '0 x8000' word section of the border.


        SECTIONS {... 
          . Data ALIGN (0x2000): { 
            * (. Data) 
            variable = ALIGN (0x8000); 
          } 
        ...}


This case before a 'ALIGN' designated a section location because it is used as defined in section ADDRESS attribute options appear. Section 
two 'ALIGN' is used to define the value of a symbol.

Built-in function 'NEXT' Contact 'ALIGN' very similar.

`BLOCK (EXP) ' 
This is the 'ALIGN' is synonymous with the other in order to remain compatible connector. This is the address to set the output section is useful.


`DATA_SEGMENT_ALIGN (MAXPAGESIZE, COMMONPAGESIZE) ' 
    This is synonymous with the following two expressions: 
        (ALIGN (maxpagesize) + (. & (maxpagesize - 1))) 
    or: 
        (ALIGN (maxpagesize) + (. & (maxpagesize - COMMONPAGESIZE) ))


Implicit connection script 
=======================


If you specify an output file connector, and the connector does not recognize it is an object file or archive file, it will attempt to read it as 
a connection script. If the file can not be analyzed as a connection script, the connector will report an error.

An implicit linker script will not replace the default linker script.
Typically, an implicit linker script contains only a symbol assignment, or 'INPUT', 'GROUP' or 'VERSION' command.

BFD 
***


Connector on the target through the BFD library to manipulate files and archive files. These libraries allow the connector to ignore the use of the target file format associated 
routines to manipulate the target file. Simply create a new BFD back and add it to the library, a different object file formats will be 
supported. But in order to save runtime memory, connectors and related tools are generally configured to support only available target a subset of file formats, 
you can use 'objdump-i' to list you configured all supported formats.


Like most cases, BFD is a conflict with each other in a variety of a compromise between the needs, the impact of a major BFD design because 
factor is efficiency. Because BFD simplifies the procedures and the background, the more time and effort was put in to the pursuit of optimization algorithms faster.


BFD a byproduct of the solution is that you have to remember there is the potential for loss of information.When using BFD mechanism, where there are two useful information may 
be lost: the conversion and during output.

How it works: BFD summary. 
===============================

When a target file is opened, BFD subroutines automatically determine the format of the input object files.They are then used in memory pointer pointing to a subroutine 
to build a descriptor This descriptor is used to access the target file's data structure elements.


Because of the need different information from an object file, BFD from different sections of the file to read them, and processed. For example, a very common connector 
operation is to handle the symbol table. Each one offers a backstage BFD symbolic expression in the target file format specification with internal conversion between formats function 
as a connector requires an object file's symbol table, it calls through a memory pointer one from the corresponding BFD background subroutines, this 
sub-program reads the table and put it into a standardized form. Then, the connector writes the output file symbol table, another BFD back subroutine is called to 
create a new symbol table and put it into a selected output format.

Loss of information.
----------------

In the output process, the information may be lost. BFD supported output formats do not provide consistent feature, and in a certain format that can be 
described in a different format information may be put in no place. An example is the 'b.out' in the alignment information in a 'a.out' format 
file, no place to store alignment information, so when a file is from 'b.out' concatenated and produce a 'a.out' the 
file, alignment information will not be passed to the output file (or in the connector alignment information for internal use, so the connector is still correct execution)


Another example is COFF section names. COFF file can contain an unlimited number of sections, each with a text section name. If the connection destination is 
in an unsupported format section too (for example, 'a.out'), or does not contain a section name format (for example, Oasys format), the connector is not 
as easy to handle as usual it. You can put the desired input and output sections by connecting a scripting language for detailed mapping to solve the next problem.


In the process of normalization information will be lost. BFD internal specifications of the format corresponding to the external form of not exhaustive; some of the input format 
and the structure does not correspond to the internal representation. This means that BFD back in from the outside to the inside or from internal to external conversion process can not 
maintain all possible data.

This limit is only an application to read and write one format to another format it will be a problem. Every one has the responsibility to safeguard the background as BFD 
much data, the internal BFD canonical form has a pair of opaque BFD core structure, export only to the background. When reading a file in one format, the 
canonical format to whom it will generate. Meanwhile, the background of all the information stored may be lost.If these data are then written in the same format to write 
back, you can use BFD daemon provided by the kernel before the election preparations with the same canonical form. Because there is a lot in the background between the same things in 
the big endianCOFF copied into littile endian COFF, or 'a.out' to 'b.out' time, there will be no loss of information. While some hybrid cell 
type are connected together, only those formats with different file formats objective information will be lost.

No comments:

Post a Comment