A.1.2 Changing allocated section
The default allocation sections are as follows:
- | Variables with no initial value: .bss section |
- | Variables with initial value: .data section |
- | const constants: .const section |
To change the allocated section, specify the attribute strings using #pragma section directive.
The relationship between attribute strings and the section generated is as follows.
|
|
|
|
|
|
r0_disp16
|
Yes
|
.zdata
|
Possible
|
r0
|
ld/st 1 instruction
|
No
|
.zbss
|
Possible
|
r0
|
ld/st 1 instruction
|
r0_disp23
|
Yes
|
.zdata23
|
Possible
|
r0
|
ld23/st23 1 instruction
|
No
|
.zbss23
|
Possible
|
r0
|
ld23/st23 1 instruction
|
r0_disp32
|
Yes
|
.data
|
Possible
|
r0
|
movhi+ld/st 2 instruction
|
No
|
.bss
|
Possible
|
r0
|
movhi+ld/st 2 instruction
|
ep_auto
|
Yes/No
|
Automatically selected from among .tdata4, .tdata5, .tdata7, and .tdata8
|
Impossible
|
ep
|
sld/sst 1 instruction
|
ep_disp4
|
Yes
|
.tdata4
|
Possible
|
ep
|
sld/sst 1 instruction
|
No
|
.tbss4
|
Possible
|
ep
|
sld/sst 1 instruction
|
ep_disp5
|
Yes
|
.tdata5
|
Possible
|
ep
|
sld/sst 1 instruction
|
No
|
.tbss5
|
Possible
|
ep
|
sld/sst 1 instruction
|
ep_disp7
|
Yes
|
.tdata7
|
Possible
|
ep
|
sld/sst 1 instruction
|
No
|
.tbss7
|
Possible
|
ep
|
sld/sst 1 instruction
|
ep_disp8
|
Yes
|
.tdata8
|
Possible
|
ep
|
sld/sst 1 instruction
|
No
|
.tbss8
|
Possible
|
ep
|
sld/sst 1 instruction
|
ep_disp16
|
Yes
|
.edata
|
Possible
|
ep
|
ld/st 1 instruction
|
No
|
.ebss
|
Possible
|
ep
|
ld/st 1 instruction
|
ep_disp23
|
Yes
|
.edata23
|
Possible
|
ep
|
ld23/st23 1 instruction
|
No
|
.ebss23
|
Possible
|
ep
|
ld23/st23 1 instruction
|
gp_disp16
|
Yes
|
.sdata
|
Possible
|
gp
|
ld/st 1 instruction
|
No
|
.sbss
|
Possible
|
gp
|
ld/st 1 instruction
|
gp_disp23
|
Yes
|
.sdata23
|
Possible
|
gp
|
ld23/st23 1 instruction
|
No
|
.sbss23
|
Possible
|
gp
|
ld23/st23 1 instruction
|
const
|
Yes
|
.const
|
Possible
|
r0
|
movhi+ld/st 2 instruction
|
zconst
|
Yes
|
.zconst
|
Possible
|
r0
|
ld/st 1 instruction
|
zconst23
|
Yes
|
.zconst23
|
Possible
|
r0
|
ld23/st23 1 instruction
|
default
|
After this statement, any previous #pragma section will be ignored, and the default allocation will be used.
|
Example | #pragma section directive description |
#pragma section gp_disp16 "mysdata"
int a = 1; /*allocated to mysdata.sdata attribute section*/
int b; /*allocated to mysdata.sbss attribute section*/
#pragma section default
|
When referencing a variable using the #pragma section directive from a function in another file (i.e. reference file), it is necessary to also specify the #pragma section directive in the reference file and to define the affected variable as extern format.
Unlike when specifying a variable by means of a definition or declaration, it outputs the following error if the variable cannot be accessed with the specified section attribute.
E0562330 : Relocation size overflow : "file"-"section"-"offset"
|
Example 1. | File that defines a table |
#pragma section zconst
const unsigned char table_data[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; /*allocated to .zconst section*/
#pragma section default
|
Example 2. | File that references a table |
#pragma section zconst
extern const unsigned char table_data[]; /*allocated to .zconst section*/
#pragma section default
|
Code such as the following can be used if portability of C source to the SH family of compilers is a concern.
Example | #pragma section directive description |
#pragma section mydata
int a = 1; /*allocated to mydata.data section*/
int b; /*allocated to mydata.bss section*/
#pragma section default
|