SLAU131V October 2004 – February 2020
1 ** Generating Relocation Entries **
2
3 .ref X
4 .def Y
5
6 000000 .text
7 000000 5A0B ADD.W R10, R11
8 000002 4B82 MOV.W R11, &X
000004 0000!
9 000006 4030 BR #Y
000008 000A!
10
11 00000a 5B0C Y ADD.W R11, R12
In Example 3, both symbols X and Y are relocatable. Y is defined in the .text section of this module; X is defined in another module. When the code is assembled, X has a value of 0 (the assembler assumes all undefined external symbols have values of 0), and Y has a value of 8. The assembler generates two relocation entries: one for X and one for Y. The reference to X is an external reference and the reference to Y is to an internally defined relocatable symbol (both are indicated by the ! character in the listing).
After the code is linked, suppose that X is relocated to address 0x0800. Suppose also that the .text section is relocated to begin at address 0x0600; Y now has a relocated value of 0x0608. The linker uses the relocation entry for the reference to X to patch the branch instruction in the object code:
4B820000!
|
becomes |
4B820800
|