How can I access linker file keywords in my C code?

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

How can I access linker file keywords in my C code?

跳至解决方案
3,142 次查看
juliusjai
Contributor II

Hi,

I'm using MPC5744P MCU and S32DS IDE.

I need to access the range of allocated Stack memory after compilation.

My linker file includes the keywords:

.stack (NOLOAD) : ALIGN(16)
{
_stack_end = . ;
. += __STACK_SIZE ;
_stack_addr = . ;
__SP_INIT = . ;
. += 4;
} > m_data

How can I access _stack_end and _stack_addr in my C source code?

I will be using these addresses to monitor stack overflow/underflow during runtime.

Thanks in advance.

Julius

0 项奖励
回复
1 解答
2,952 次查看
BlackNight
NXP Employee
NXP Employee
0 项奖励
回复
4 回复数
2,953 次查看
BlackNight
NXP Employee
NXP Employee
0 项奖励
回复
2,952 次查看
juliusjai
Contributor II

Hi Erich,

Thank you very much. This is very helpful.

By the way, I'm using a 32-bit MPC5744P MCU.

Which should be the correct type of extern?

extern unsigned int _stack_end?

Or

extern unsigned long _stack_end?

Thanks again!

Julius

0 项奖励
回复
2,952 次查看
BlackNight
NXP Employee
NXP Employee

Hi Julius,

the type really does not matter, because the linker does not know about types. All what the linker knows and provides you is an address (or to the essence a number). So you can use whatever makes sense in your application.

Because your stack entries are 32bit, you probably want to use uint32_t as you don't know how many bits int or long can have.

I hope this helps,

Erich

2,952 次查看
juliusjai
Contributor II

Hi Erich,

Thank you very much. This is now clear.

Julius

0 项奖励
回复