How to make extern variable of a file stored into a section

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to make extern variable of a file stored into a section

1,782 次查看
yuehedeng
Contributor III

Hello,

 

   I know there is a way to store extern variables in a section defined in ld file as below:

__attribute__ ((section(".ccp_database1"))) struct  stDataCache stDataRamCacheA;

__attribute__ ((section(".ccp_database1"))) struct  stDataCache stDataRamCacheB;

....

 

But it is quite inconvenient if there are many extern variables in source files. Some compiler can do it by writing it in link file, for example TI CCS. Could S32 IDE  also have this feature?

 

My platform is: S32 IDE V1.1 + MPC574x

标签 (2)
标记 (3)
0 项奖励
回复
2 回复数

1,409 次查看
stanish
NXP Employee
NXP Employee

Hi,

You can e.g. replace an attribute with  shorter alias:

#define CCP_DATA1 __attribute__ ((section(".ccp_database1")))
CCP_DATA1  struct  stDataCache stDataRamCacheA;

You can also explicitly assign the object files into a custom section in the linker script command file (.ld).

First I'd suggest to turn off  function and data sections compiler flags since they might interfere with it.

pastedImage_1.png

SECTION
{
   .my_custom_section_consts : 
    {
    * source1.o (.rodata) 
   * source2.o (.rodata) 
   * source3.o (.rodata) 
    } > m_text

   .my_custom_text : 
   { INPUT_SECTION_FLAGS (SHF_PPC_VLE) 
   * source1.o (.text) 
   * source2.o (.text) 
   } > m_text
...‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hope it helps.

Stan

0 项奖励
回复

1,409 次查看
yuehedeng
Contributor III

Thanks very much. I will have a try as you provide.

0 项奖励
回复