A.1.2.3 Change the allocated area using the -Xpreinclude option
You can use the -Xpreinclude option to allocate all variables declared or defined in a file into an arbitrary section, without changing the C source file. You can reduce the code size by allocating them in a section with efficient access.
(1) | Prepare a header file (.h) containing a #pragma section directive. |
Example | Allocating in .sdata/.sbss section [section.h] |
#pragma section gp_disp16
|
(2) | Use the -Xpreinclude option to include the header you created in (1) at the beginning of the compilation unit. |
Example | If the header file with the specified section is section.h |
>ccrh main.c -Xpreinclude=section.h
|
Compiled as if main.c starts with an include of "section.h".
However, a link-time error will be output if the variables do not fit in the section specified in (1). In this case, change the section of the variables in the C source file.
E0562330 : Relocation size overflow : "file"-"section"-"offset"
|
Example | Changing variables to .sdata23/.sbss23 section |
int a = 1; /*Allocated in section specified in (1)*/
int b; /*Allocated in section specified in (1)*/
#pragma section gp_disp23
int c = 1; /*Allocated in .sdata23 section*/
int d; /*Allocated in .sbss23 section*/
#pragma section default
int e = 1; /*Allocated in default .data section*/
int f; /*Allocated in default .bss section*/
|