TI compiler V8.2.4
The customer has implemented a mechanism similar to linux driver registration, the code is as follows：
typedef int (*func_t)(void);
#define D_PRAGMA(x) _Pragma(#x)
func_t func_test = vfs_yaffs2_init;
D_PRAGMA( DATA_SECTION(func_test, ".env_reg") );
D_PRAGMA( RETAIN ( func_test ) );
Customer expects to put the pointer of the vfs_yaffs2_init function into the func_test variable, and use the RETAIN instruction to force the variable into the ".env_reg" data segment. He only needs to take out the pointer from the data segment to access the function.
When vfs_yaffs2_init is called in an external function, there is a func_test symbol in the map file. On the contrary, there is no func_test symbol in the map file.
Is it possible that when the function is not called externally, the compiler finds that in the above c file, no symbols are called externally, it ignores the RETAIN compilation instruction and directly optimizes the entire c file？
But even turning the optimization off will not solve the problem.
How to solve the problem?