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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

ソリューションへジャンプ
3,139件の閲覧回数
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,949件の閲覧回数
BlackNight
NXP Employee
NXP Employee
0 件の賞賛
返信
4 返答(返信)
2,950件の閲覧回数
BlackNight
NXP Employee
NXP Employee
0 件の賞賛
返信
2,949件の閲覧回数
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,949件の閲覧回数
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,949件の閲覧回数
juliusjai
Contributor II

Hi Erich,

Thank you very much. This is now clear.

Julius

0 件の賞賛
返信