Copyright (C) 2000-2012 |
GNU Info (ld.info)Builtin FunctionsBuiltin Functions ----------------- The linker script language includes a number of builtin functions for use in linker script expressions. `ABSOLUTE(EXP)' Return the absolute (non-relocatable, as opposed to non-negative) value of the expression EXP. Primarily useful to assign an absolute value to a symbol within a section definition, where symbol values are normally section relative. Note: Expression Section. `ADDR(SECTION)' Return the absolute address (the VMA) of the named SECTION. Your script must previously have defined the location of that section. In the following example, `symbol_1' and `symbol_2' are assigned identical values: SECTIONS { ... .output1 : { start_of_output_1 = ABSOLUTE(.); ... } .output : { symbol_1 = ADDR(.output1); symbol_2 = start_of_output_1; } ... } `ALIGN(EXP)' Return the location counter (`.') aligned to the next EXP boundary. EXP must be an expression whose value is a power of two. This is equivalent to (. + EXP - 1) & ~(EXP - 1) `ALIGN' doesn't change the value of the location counter--it just does arithmetic on it. Here is an example which aligns the output `.data' section to the next `0x2000' byte boundary after the preceding section and sets a variable within the section to the next `0x8000' boundary after the input sections: SECTIONS { ... .data ALIGN(0x2000): { *(.data) variable = ALIGN(0x8000); } ... } The first use of `ALIGN' in this example specifies the location of a section because it is used as the optional ADDRESS attribute of a section definition (Note: Output Section Address). The second use of `ALIGN' is used to defines the value of a symbol. The builtin function `NEXT' is closely related to `ALIGN'. `BLOCK(EXP)' This is a synonym for `ALIGN', for compatibility with older linker scripts. It is most often seen when setting the address of an output section. `DATA_SEGMENT_ALIGN(MAXPAGESIZE, COMMONPAGESIZE)' This is equivalent to either (ALIGN(MAXPAGESIZE) + (. & (MAXPAGESIZE - 1))) or (ALIGN(MAXPAGESIZE) + (. & (MAXPAGESIZE - COMMONPAGESIZE))) depending on whether the latter uses fewer COMMONPAGESIZE sized pages for the data segment (area between the result of this expression and `DATA_SEGMENT_END') than the former or not. If the latter form is used, it means COMMONPAGESIZE bytes of runtime memory will be saved at the expense of up to COMMONPAGESIZE wasted bytes in the on-disk file. This expression can only be used directly in `SECTIONS' commands, not in any output section descriptions and only once in the linker script. COMMONPAGESIZE should be less or equal to MAXPAGESIZE and should be the system page size the object wants to be optimized for (while still working on system page sizes up to MAXPAGESIZE). Example: . = DATA_SEGMENT_ALIGN(0x10000, 0x2000); `DATA_SEGMENT_END(EXP)' This defines the end of data segment for `DATA_SEGMENT_ALIGN' evaluation purposes. . = DATA_SEGMENT_END(.); `DEFINED(SYMBOL)' Return 1 if SYMBOL is in the linker global symbol table and is defined, otherwise return 0. You can use this function to provide default values for symbols. For example, the following script fragment shows how to set a global symbol `begin' to the first location in the `.text' section--but if a symbol called `begin' already existed, its value is preserved: SECTIONS { ... .text : { begin = DEFINED(begin) ? begin : . ; ... } ... } `LOADADDR(SECTION)' Return the absolute LMA of the named SECTION. This is normally the same as `ADDR', but it may be different if the `AT' attribute is used in the output section definition (Note: Output Section LMA). `MAX(EXP1, EXP2)' Returns the maximum of EXP1 and EXP2. `MIN(EXP1, EXP2)' Returns the minimum of EXP1 and EXP2. `NEXT(EXP)' Return the next unallocated address that is a multiple of EXP. This function is closely related to `ALIGN(EXP)'; unless you use the `MEMORY' command to define discontinuous memory for the output file, the two functions are equivalent. `SIZEOF(SECTION)' Return the size in bytes of the named SECTION, if that section has been allocated. If the section has not been allocated when this is evaluated, the linker will report an error. In the following example, `symbol_1' and `symbol_2' are assigned identical values: SECTIONS{ ... .output { .start = . ; ... .end = . ; } symbol_1 = .end - .start ; symbol_2 = SIZEOF(.output); ... } `SIZEOF_HEADERS' `sizeof_headers' Return the size in bytes of the output file's headers. This is information which appears at the start of the output file. You can use this number when setting the start address of the first section, if you choose, to facilitate paging. When producing an ELF output file, if the linker script uses the `SIZEOF_HEADERS' builtin function, the linker must compute the number of program headers before it has determined all the section addresses and sizes. If the linker later discovers that it needs additional program headers, it will report an error `not enough room for program headers'. To avoid this error, you must avoid using the `SIZEOF_HEADERS' function, or you must rework your linker script to avoid forcing the linker to use additional program headers, or you must define the program headers yourself using the `PHDRS' command (Note: PHDRS). automatically generated by info2www version 1.2.2.9 |