Changing compiler output section name (#pragma section)
|
This changes a section name to be output by the compiler.
[Function]
- | This changes a section name to be output by the compiler.
For the section names output by the compiler and default allocation of the sections, see "6.1.1 Section name" |
- | This affects the declarations written after the #pragma directive. |
[Effect]
- | Assigning a new section name that differs from the default name to a specified set of data or functions allows this set of data or functions to be allocated to an address separate from that for other data or functions, and special processing can be applied in section units. |
[Usage]
#pragma section section-type new-section-name
section-type:{text|const|data|bss}
|
The section name of the specified type is changed.
#pragma section new-section-name
|
The section names of all types are changed.
The section names of all types are changed to their default section names.
- | The characters shown below can be used in a new section name.
The beginning of a name should be a character other than 0 to 9.
"." can be used only to specify the section type and it can be used only at the beginning. If it is used in a character string not at the beginning, a compilation error will occur. If "." is used when the section type is not specified, a compilation error will occur. |
- | When the section type is text, the section name for the functions defined after the #pragma declaration is changed.
Note that the start address of the interrupt handler should be a location that can be accessed in 16-bit addressing. |
- | When the section type is const, data, or bss, the name of the const, data, or bss section whose entity is defined after the #pragma declaration is changed. |
- | When both a section type and a new section name are specified, a character string is appended to the section name according to the following rules. |
- | near section (.text, .const, .data, .bss)
New section name + "_n" |
#pragma section data MyData
int __near ndata = 5; //Generated section name : MyData_n
|
- | far section (.textf, .constf, .dataf, .bssf)
New section name + "_f" |
#pragma section bss MyBss
int __far fdata; //Generated section name : MyBss_f
|
- | saddr section (.sdata, .sbss)
New section name + "_s" |
#pragma section bss MyBss
int __saddr sdata; //Generated section name : MyBss_s
|
|
#pragma section
text MyText
|
#pragma section
bss MyBss
|
#pragma section
data MyData
|
#pragma section
const MyConst
|
void __near func() { }
|
MyText_n
|
|
|
|
void __far func() { }
|
MyText_f
|
|
|
|
int __near i;
|
|
MyBss_n
|
|
|
int __far i;
|
|
MyBss_f
|
|
|
int __saddr i;
|
|
MyBss_s
|
|
|
int __near i = 5;
|
|
|
MyData_n
|
|
int __far i = 5;
|
|
|
MyData_f
|
|
int __saddr i = 5;
|
|
|
MyData_s
|
|
const int __near i = 5;
|
|
|
|
MyConst_n
|
const int __far i = 5;
|
|
|
|
MyConst_f
|
- | When only a new section name is specified, all section names for the program area, constant area, initialized data area, and uninitialized data area after the #pragma declaration are changed. In this case, each section name is created by appending the character string of the specified new section name at the end of the current section name and also post-fixing _s, _n, or _f. When the current section name is post-fixed with _n or _f, it is deleted. |
#pragma section bss XXX
int __near i; //The section name is XXX_n
#pragma section YYY
int __far j; //The section name is XXXYYY_f
//For bss, the section names change for both near and far.
//Therefore, XXX is added even for __far.
|
- | When neither a section type nor a new section name are specified, all section names for the program area, constant area, initialized data area, and uninitialized data area after the #pragma declaration are restored to their default section names. |
- | When #pragma section is specified for a function, the scope of its effectiveness is not limited to within the function but extends to all locations following the specification. When a change to a text section is placed within a function, the scope is valid from the next function. A switch table is allocated to the section of the const data which have been specified at the start of the given function. |
[Restrictions]
- | The section name for an interrupt vector table cannot be changed. |
[Example]
(1) | To specify section names and section types |
int __near ni_1; //.bss
int __far fi_1; //.bssf
#pragma section bss MyBss
int __near ni_2; //MyBss_n
int __far fi_2; //MyBss_f
#pragma section
int __near ni_3; //.bss
int __far fi_3; //.bssf
|
#pragma section abc
int __near na; //Allocated to the .bssabc_n section
int __far fa; //Allocated to the .bssfabc_f section
int __near ni=1; //Allocated to the .dataabc_n section
int __far fi=1; //Allocated to the .datafabc_f section
const int __near nc=1; //Allocated to the .constabc_n section
const int __far fc=1; //Allocated to the .constfabc_f section
void __near f(void) //Allocated to the .textabc_n section
{
na=nc;
}
#pragma section
int __near nb; //Allocated to the .bss section
void __near g(void) //Allocated to the .text section
{
nb=nc;
}
|
(3) | To use both specifications with a section type and without a section type |
int __near ni_1; //.bss
int __far fi_1; //.bssf
#pragma section bss MyBss
int __near ni_2; //MyBss_n
int __far fi_2; //MyBss_f
#pragma section XXX
int __near ni_3; //Allocated to the MyBssXXX_n section
int __far fi_3; //Allocated to the MyBssXXX_f section
#pragma section
int __near ni_4; //.bss
int __far fi_5; //.bssf
|