Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
MPLAB
®
XC16 C Compiler Users Guide
DS50002071C-page 184 2012-2013 Microchip Technology Inc.
13.3 FUNCTION SIZE LIMITS
For all devices, the code generated for a function may become larger than one page in
size, limited only by the available program memory. However, functions that yield code
larger than a page may not be as efficient due to longer call sequences to jump to and
call destinations in other pages. See 13.4 Allocation of Function Code for more
details.
13.4 ALLOCATION OF FUNCTION CODE
Code associated with functions is always placed in the program memory of the target
device. As described in Section 10.2 Address Spaces, the compiler arranges for
code to be placed in the .text section, depending on the memory model used and
whether or not the data is initialized. When modules are combined at link time, the
linker determines the starting addresses of the various sections based on their attri-
butes.
13.5 CHANGING THE DEFAULT FUNCTION ALLOCATION
Cases may arise when a specific function must be located at a specific address, or
within some range of addresses. The easiest way to accomplish this is by using the
address attribute, described in Section 13.2.1 Function Specifiers. For example,
to locate function PrintString at address 0x8000 in program memory:
int __attribute__ ((address(0x8000))) PrintString (const char *s);
Another way to locate code is by placing the function into a user-defined section, and
specifying the starting address of that section in a custom linker script. This is done as
follows:
1. Modify the code declaration in the C source to specify a user-defined section.
2. Add the user-defined section to a custom linker script file to specify the starting
address of the section.
For example, to locate the function PrintString at address 0x8000 in program
memory, first declare the function as follows in the C source:
int __attribute__((__section__(".myTextSection")))
PrintString(const char *s);
The section attribute specifies that the function should be placed in a section named
.myTextSection, rather than the default .text section. It does not specify where
the user-defined section is to be located. That must be done in a custom linker script,
as follows. Using the device-specific linker script as a base, add the following section
definition:
.myTextSection 0x8000 :
{
*(.myTextSection);
} >program
This specifies that the output file should contain a section named .myTextSection
starting at location 0x8000 and containing all input sections named.myTextSection.
Since, in this example, there is a single function PrintString in that section, then the
function will be located at address 0x8000 in program memory.
Protego_Release_01_05-Related-OEM-Documentation-MPLAB-XC16-C-Compiler.pdf