Keil Logo

Theory of Operation

The system the linker uses to determine which function arguments (or parameters) and variables may be overlaid is quite sophisticated. It begins when the compiler generates the object code for a function.

The compiler stores all function parameters and local variables in overlayable bit, data, pdata, or xdata segments. The segment names generated by the compiler for Parameters and Local Variables are well-defined. They are used by the compiler to access parameters and local variables.

As the linker resolves references between functions, it builds a call tree based on where those references appear. For instance, if function_a calls function_b, the compiler inserts a reference to function_b in the object code generated for function_a. When the linker resolves this reference, it inserts the address of function_b and adds a call from function_a to function_b in the call tree.

The local variables and parameters of function_a are overlaid with the variables and parameters of function_b only under the following conditions:

  1. No call references of any kind may exist between function_a and function_b. This includes direct calls between A and B as well as calls from other functions on the A branch to B and calls from functions on the B branch to A.
  2. The functions A and B may be invoked by only one program event or root: either the main root or an interrupt but not both. It is impossible to overlay variables and parameters if a function is called by an interrupt and the main program or by two interrupts.
  3. The segment definitions of functions A and B must conform to the rules for segment names described in the compiler manual.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.