11. The expression syntax in the expression lDs is the same as that in the C language. The expression value is an integer. If the host running the LD and the target machine generating the file are both 32-bit, the expression is a 32-bit data, otherwise it is a 64-bit data. The following are common expressions: _ fourk_1 = 4 K;/* K, M Unit */_ fourk_2 = 4096;/* integer */_ fourk_3 = 0 × 1000; /* 16 carry */_ fourk_4 = 01000;/* 8 Carry */Note: 1 k = 1024 1 m = 1024*102411.1, the symbol name is not enclosed by quotation marks "", with letters, underscores or '. ', can contain letters, underscores ,'. 'and '-'. When the symbol name is enclosed by quotation marks, the symbol name can be the same as the keyword. For example, "Section" = 9; "with a space" = "also with a space" + 10; 11.2. Positioning symbol '. 'Only valid in the sections command, representing the address in the address space of a program. Note: When the locator is used in the output section description of the sections command during connection, it indicates the current ** offset ** of the Section **, instead of the absolute address of the program address space. Of course, after the program is loaded, the final address of the symbol is the absolute address of the program address space. Example 11.2_1: Sections {output: {file1 (. Text). =. +
1000; file2 (. text ). ++ = 1000; file3 (. text)} = 0x1234;} The gap generated by the assignment of the locator is filled by 0x1234. Other content should be easy to understand. Example 11.2_2: Sections {. = 0 × 100. text :{*(. text ). = 0 × 200 }. = 0 × 500. data :{*(. data ). + = 0x600 }}. the starting position of the text section in the program address space is 0x100. Example 11.2 _ 3 File SRC \. C # include <stdio. h> int A = 100; int B = 0; int C = 0; int d = 1; int main () {printf ("& A = % P \ n ", & A); printf ("& B = % P \ n", & B); printf ("& C = % P \ n", & C ); printf ("& D = % P \ n", & D); Return 0;} file lDs \. ldsa = 10;/* Global Position */sections {B = 11 ;. text :{*(. text) C = .; /* Section Description */. = 100 00; D =. ;}_ bdata = (. + 3 )&~ 4;/* Sections command */. data :{*(. data)} is not using. compiling gcc-wall-O a-without-lds.exe in case of LDS. /src/. c run. /a-without-lds.exe results: & A = 0x601020 & B = 0x601038 & C = 0x60103c & D = 0x601024 in the Use of. compiling gcc-wall-O a-with-lds.exe in case of LDS. /src/. c. /lDs/. LDS run. /a-with-lds.exe results: & A = 0xa & B = 0xb & C = 0x400638 & D = 0x402b2010. 3. The expression operator is in LDs, and the expression operator is the same as that in C language. Priority is combined with the sequence operator 1 left! -~ (1) 2 left */% 3 left +-4 left> = 5 left & 6 left | 7 left & 8 left | 9 right?: 10 right & = + =-= * =/= (2) (1) indicates the prefix, and (2) indicates the value assignment. 10.4. Expression calculation connector latency calculates the value of most expressions. However, for expressions closely related to the connection process, the connector immediately calculates the expression. If the expression cannot be calculated, an error is returned. For example, for the section VMA address, the start address and size of the memory area block, the expressions related to the Section should be calculated immediately. Example: Sections {. text 9 + this_isnt_constant :{*(. text)} in this example, the value of the 9 + this_isnt_constant expression is used for setting. because the value of the this_isnt_constant variable is uncertain, the connector cannot establish the expression value. In this case, the connector reports an error. 10.5 The expression of the Relative Value and absolute value in the description of the output section. The connector obtains the relative value, the relative offset from the start position of the section is in the expressions in the sections command and not in the description of the output section. The absolute value of the connector can be converted to the absolute value by using the absolute keyword, add the VMA value of the section where the expression is located on the basis of the original value. Example sections {. Data: {* (. data); _ edata = absolute (.);
} In this example, the value of the _ edata symbol is the end position of the. Data Section (absolute value, within the program address space ). 10.6. the built-in function LDS has the following built-in functions: absolute (exp): Convert to absolute value ADDR (Section): return the VMA value of a section. Align (exp): returns the adjusted value of the positioning character '.' After align is aligned according to exp. The adjusted value algorithm is :(.
+ Exp-1 )&~ (Exp-1 ). Block (exp): Like align (exp), for forward compatibility. Defined (Symbol): If the symbol is in the global symbol table and is defined, 1 is returned; otherwise, 0 is returned. Example: Sections {.... Text: {begin = defined (BEGIN)
? Begin :.;...}...} Loadaddr (Section): returns lmamax (exp1, exp2) of the three sections. Returns min (exp1, exp2): returns next (exp): returns the next address that can be used, this address is a multiple of exp, similar to align (exp ). Unless some discontinuous memory blocks are defined using the memory command, next (exp) must be the same as alweigh (exp. Sizeof (Section): returns the size of a section. When the section is not allocated, the connector reports an error when the section size is uncertain. Sizeof_headers: number of bytes in the output file header. This information appears at the beginning of the output file. You can use this number when setting the start address of the first segment. If you select accelerated pagination and an elf output file is generated, if the linker script uses the sizeof_headers built-in function, the connector must calculate the value of the program header before it calculates the address and length of all segments. If the connector later finds that it requires an additional program header, it will report a "not enough room for program headers" error. To avoid such errors, you must avoid using the sizeof_headers function, or you must modify your connector script to avoid forcing the connector to use additional program headers, or you must use the phdrs command to define your own program header 12. The input file of the implicit connection script can be the target file or the connection script, the connection script is called an implicit connection script. If the connector does not recognize an input file, the file is parsed as a connection script. Furthermore, if it is found that its format is not the format of the connection script, the connector reports an error. An implicit connection script does not replace the default connection script, but simply adds new connections. Generally, the implicit connection script symbol distribution command, or the input, group, and version commands. In the connection command line, the order of each input file is fixed, and the implied connection script occupies a location in the connection command line, this location determines the order of input files specified by the connection script in the connection process. The typical implicit connection script is the libc. So file, which usually exists in the/usr/lib directory in GNU/Linux.