8.4.1 __gp_data

The value of __gp_data is determined in the following order of precedence.

(1)

When __gp_data is defined in the application, that value is used.

Note

The compiler generates code based on the assumption that __gp_data is aligned at the 2-byte boundary. Therefore, make sure the defined value is a multiple of 2 when defining __gp_data in the application.

 

(2)

When there is only a reference to __gp_data in the application, the optimizing linker (rlink) automatically determines the __gp_data value in the following order of precedence.

(2-1) If there is an sdata or sbss attribute section, the value is the intermediate value of the minimum address

and maximum address of all of those sections.

(2-2) If there is an sdata23 or sbss23 attribute section, the value is the intermediate value of the minimum

address and maximum address of all of those sections.

(2-3) If there is an sdata32 or sbss32 attribute section, the value is the intermediate value of the minimum

address and maximum address of all of those sections.

(2-4) If none of the above sections exist and there is only a reference to __gp_data, the value is 0.

 

Note, however, that if the value attempted to be defined is an odd value, 1 is added to that value.

The compiler will not generate code to directly reference __gp_data. Normally, a reference to __gp_data indicates the processing to set the __gp_data value to the global pointer register (r4) in the startup routine.

 

(3)

When there is no definition or reference regarding __gp_data in the application, the optimizing linker (rlink) does not generate __gp_data. If there is code to reference a GP-relative section in this state, an error will occur at linkage.

Undefined external symbol "GP-symbol (__gp_data)" referenced in "FILE"