SPRUI03E June 2015 – January 2023
The syntax of assignment statements in the linker is similar to that of assignment statements in the C language:
symbol | = | expression; | assigns the value of expression to symbol |
symbol | + = | expression; | adds the value of expression to symbol |
symbol | - = | expression; | subtracts the value of expression from symbol |
symbol | * = | expression; | multiplies symbol by expression |
symbol | / = | expression; | divides symbol by expression |
The symbol should be defined externally. If it is not, the linker defines a new symbol and enters it into the symbol table. The expression must follow the rules defined in Section 9.6.10.3. Assignment statements must terminate with a semicolon.
The linker processes assignment statements after it allocates all the output sections. Therefore, if an expression contains a symbol, the address used for that symbol reflects the symbol's address in the executable output file.
For example, suppose a program reads data from one of two tables identified by two external symbols, Table1 and Table2. The program uses the symbol cur_tab as the address of the current table. The cur_tab symbol must point to either Table1 or Table2. You could accomplish this in the assembly code, but you would need to reassemble the program to change tables. Instead, you can use a linker assignment statement to assign cur_tab at link time:
prog.c.obj /* Input file */
cur_tab = Table1; /* Assign cur_tab to one of the tables */