4.2.6.1
Allocation of function and data to section
The CC-RH controls allocation to memory or the access method by allocating functions or data to sections.
Table 4.11 | Types of Sections for Functions |
|
|
|
|
text
|
.text
|
32-bit relative mode from r0
|
2
|
pctext
|
.pctext
|
32-bit relative mode from PC
|
- | The .text section is used by default. |
This section cannot be used by the PIC facility.
- | The .pctext section is a section to be used by the PIC facility. |
- | R0-relative sections for data |
Table 4.12 | Types of R0-Relative Sections for Data |
|
|
|
|
|
zdata
|
.zdata
|
Variables with initial value
|
16-bit relative mode from r0
|
4
|
zbss
|
.zbss
|
Variables with no initial value
|
zdata23
|
.zdata23
|
Variables with initial value
|
23-bit relative mode from r0
|
zbss23
|
.zbss23
|
Variables with no initial value
|
data
|
.data
|
Variables with initial value
|
32-bit relative mode from r0
|
bss
|
.bss
|
Variables with no initial value
|
- | The .data and .bss sections are used by default. |
- | The .zdata, .zbss, .zdata23, and .zbss23 sections are used for access in a short instruction length. |
- | Any of the R0-relative sections cannot be used by the PID facility. |
- | EP-relative sections for data |
Table 4.13 | Types of EP-Relative Sections for Data |
|
|
|
|
|
tdata4
|
.tdata4
|
Variables with initial value
|
4-bit relative mode from r30 (EP)
The sld or sst instruction can be used.
|
4
|
tbss4
|
.tbss4
|
Variables with no initial value
|
tdata5
|
.tdata5
|
Variables with initial value
|
5-bit relative mode from r30 (EP)
The sld or sst instruction can be used.
|
tbss5
|
.tbss5
|
Variables with no initial value
|
tdata7
|
.tdata7
|
Variables with initial value
|
7-bit relative mode from r30 (EP)
The sld or sst instruction can be used.
|
tbss7
|
.tbss7
|
Variables with no initial value
|
tdata8
|
.tdata8
|
Variables with initial value
|
8-bit relative mode from r30 (EP)
The sld or sst instruction can be used.
|
tbss8
|
.tbss8
|
Variables with no initial value
|
edata
|
.edata
|
Variables with initial value
|
16-bit relative mode from r30 (EP)
|
ebss
|
.ebss
|
Variables with no initial value
|
edata23
|
.edata23
|
Variables with initial value
|
23-bit relative mode from r30 (EP)
|
ebss23
|
.ebss23
|
Variables with no initial value
|
edata32
|
.edata32
|
Variables with initial value
|
32-bit relative mode from r30 (EP)
|
ebss32
|
.ebss32
|
Variables with no initial value
|
- | The .tdata* and .tbss* sections are used for access in a short instruction length. |
The sld or sst instruction which is even shorter can be used.
These sections can be used even by the PID facility.
- | The .edata, .ebss, .edata23, and .ebss23 sections are used for access in a short instruction length. |
These sections can be used even by the PID facility.
- | The .edata32 and .ebss32 sections are sections to be used by the PID facility. |
- | GP-relative sections for data |
Table 4.14 | Types of GP-Relative Sections for Data |
|
|
|
|
|
sdata
|
.sdata
|
Variables with initial value
|
16-bit relative mode from r4 (GP)
|
4
|
sbss
|
.sbss
|
Variables with no initial value
|
sdata23
|
.sdata23
|
Variables with initial value
|
23-bit relative mode from r4 (GP)
|
sbss23
|
.sbss23
|
Variables with no initial value
|
sdata32
|
.sdata32
|
Variables with initial value
|
32-bit relative mode from r4 (GP)
|
sbss32
|
.sbss32
|
Variables with no initial value
|
- | The .sdata, .sbss, .sdata23, and .sbss23 sections are used for access in a short instruction length. |
These sections can be used even by the PID facility.
- | The .sdata32 and .sbss32 sections are sections to be used by the PID facility. |
- | Sections for constant data |
Table 4.15 | Types of Sections for Constant Data |
|
|
|
|
|
zconst
|
.zconst
|
const variables
String literal
Initial values of auto variablesNote 1
|
16-bit relative mode from r0
|
4
|
zconst23
|
.zconst23
|
23-bit relative mode from r0
|
const
|
.const
|
32-bit relative mode from r0
|
pcconst16
|
.pcconst16
|
16-bit relative mode from the __pc_data symbol
|
pcconst23
|
.pcconst23
|
23-bit relative mode from the __pc_data symbol
|
pcconst32
|
.pcconst32
|
32-bit relative mode from the __pc_data symbol
|
Note 1. | The initial values of auto variables are in the .const section when the PIROD facility is not used and are in the .pcconst32 section when the PIROD facility is used. In either case, they cannot be changed. |
- | The .const section is used by default. |
This section cannot be used by the PIROD facility.
- | The .zconst and .zconst23 sections are used for access in a short instruction length. |
These sections cannot be used by the PIROD facility.
- | The .pcconst16, .pcconst23, and .pconst32 sections are sections to be used by the PIROD facility. |
The sections to which the CC-RH allocates functions or data are the four sections .text, .data, .bss, and .const, by default.
The longer the relative distance at access is, the access is in a long instruction length and the code size is increased.
The CC-RH can allocate functions and data to desired sections using the extended facilities. This makes it possible to generate code using the relocation attribute characteristics of each section.
(1) | #pragma section directive |
Describe the #pragma section directive in the following format.
#pragma section attribute-strings "user-defined-name"
|
#pragma section attribute-strings
|
#pragma section user-defined-name
|
#pragma section default
or
#pragma section
|
Section relocation attributes are specified using "attribute strings", and section names are specified using "user-defined names". The usable attribute strings vary depending on the specified options.
The relationship between specifiable attribute strings, corresponding section relocation attributes, and options that can be specified as conditions is shown in Table 4.16.
Attribute strings are case-sensitive.
Table 4.16 | Relationship between Attribute Strings and Section Relocation Attributes |
|
|
|
text
|
text
|
When -pic is not specified
|
pctext [V1.07.00 or later]
|
pctext
|
When -pic is specified
|
r0_disp16
|
zdata/zbss
|
When -pid is not specified
|
r0_disp23
|
zdata23/zbss23
|
r0_disp32
|
data/bss
|
ep_disp4
|
tdata4/tbss4
|
When -Xep=fix is specified
|
ep_disp5
|
tdata5/tbss5
|
ep_disp7
|
tdata7/tbss7
|
ep_disp8
|
tdata8/tbss8
|
ep_disp16
|
edata/ebss
|
ep_disp23
|
edata23/ebss23
|
ep_disp32 [V1.07.00 or later]
|
edata32/ebss32
|
When -Xep=fix and -pid are both specified
|
gp_disp16
|
sdata/sbss
|
When -r4=fix is specified
|
gp_disp23
|
sdata23/sbss23
|
gp_disp32 [V1.07.00 or later]
|
sdata32/sbss32
|
When -r4=fix and -pid are both specified
|
zconst
|
zconst
|
When -pirod is not specified
|
zconst23
|
zconst23
|
const
|
const
|
pcconst16 [V1.07.00 or later]
|
pcconst16
|
When -pirod is specified
|
pcconst23 [V1.07.00 or later]
|
pcconst23
|
pcconst32 [V1.07.00 or later]
|
pcconst32
|
The following characters are usable in user-defined names.
The allocation section of functions or data written after a #pragma section directive is determined in accordance with the following rules.
1. The relocation attribute is determined from the "attribute string".
(1) For data, *data* or *bss* is automatically selected depending on whether there is an initial value.
(2) A format with no attribute string has an effect on both functions and data, and the default relocation attribute of the compiler is used.
2. A string representing the relocation attribute is linked after the "user-defined name"Note.
(1) If the user-defined name starts with a number from 0 to 9, "_" is added to the beginning.
(2) If there is no user-defined name, the default section name is used without change.
Note | This is to prevent sections with different section relocation attributes from having the same section name. |
3. When the format of #pragma section default or #pragma section is specified, it has an effect on both functions and data, and the default relocation attribute of the compiler and the default section name are used.
A #pragma section directive is valid from the position where it was written up to the position where the next #pragma section directive appears or up to the end of the source file.
#pragma section gp_disp16 "foo"
int a = 1; /* foo.sdata */
int b; /* foo.sbss */
#pragma section zconst23 "bar"
const int c = 2; /* bar.zconst23 */
#pragma section text "123"
void func() {} /* _123.text */
#pragma section baz
int d = 3; /* baz.data */
int e; /* baz.bss */
const int f = 4; /* baz.const */
void func2() {} /* baz.text */
#pragma section default
int g = 3; /* .data */
int h; /* .bss */
const int i = 4; /* .const */
void func3() {} /* .text */
|
The effect of a #pragma section directive differs between variables and functions.
If there are multiple declarations and definitions for a variable and a different #pragma section directive is specified for each, the #pragma section directive that appears first is valid.
int x = 1; /* Variable x is allocated to foo.data */
int y = 2; /* Variable y is allocated to bar.data */
#pragma section foo
extern int x;
#pragma section bar
extern int x;
extern int y;
|
When the -pic option is not specified, #pragma section is valid only for function definitions.
When the -pic option is specified, similar as to variables, #pragma section is valid for both declarations and definitions.
[V2.02.00 or later] #pragma section can also be described within a function.
Therefore, #pragma section within a function is now valid, which was ignored and caused W0520609 to be output in V2.01.00 or earlier.
Due to this specification change, if there are multiple static variables within the function or multiple string literals, each value can be allocated to separate sections.
void func() {
#pragma section AAA
static int aaa; /* AAA.bss */
#pragma section BBB
static int bbb; /* BBB.bss */
#pragma section
;
}
static int ccc; /* .bss */
|