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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
3,009 Views
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 Kudos
Reply
1 Solution
2,819 Views
BlackNight
NXP Employee
NXP Employee
0 Kudos
Reply
4 Replies
2,820 Views
BlackNight
NXP Employee
NXP Employee
0 Kudos
Reply
2,819 Views
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 Kudos
Reply
2,819 Views
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,819 Views
juliusjai
Contributor II

Hi Erich,

Thank you very much. This is now clear.

Julius

0 Kudos
Reply