Linker script ASSERT syntax errors

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

Linker script ASSERT syntax errors

3,470 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldManVimes on Sun Feb 01 08:51:45 MST 2015
Hello Support,

I think I have found a small issue with the managed linker scripts. I was trying to use the ASSERT statement using the one from the CRP as an example. Here's the CRP snippet that LPCXpresso 7.4 generates.

        
/* Code Read Protect data */
. = 0x000002FC ;
PROVIDE(__CRP_WORD_START__ = .) ;
KEEP(*(.crp))
PROVIDE(__CRP_WORD_END__ = .) ;
ASSERT(!(__CRP_WORD_START__ == __CRP_WORD_END__), "Linker CRP Enabled, but no CRP_WORD provided within application");
/* End of Code Read Protect */


Note the semi colon at the rear of the ASSERT. So I copied that line into my non managed linker script in order to create a check for clashes in the heap and stack, like so:

    
PROVIDE(_pvHeapStart = .);
PROVIDE(_pvHeapLimit = __top_local_sram - 0x2000);
ASSERT(_pvHeapStart <= (_pvHeapLimit - 0x1000), "Not enough ram for specified heap and stack")
PROVIDE(_vStackTop = __top_local_sram - 32);


Note that the ASSERT has no semi colon. The reason being that I kept getting syntax errors from ld when one was there. I guess the difference is caused by the fact that the CRP one is at the end of a section, whereas mine has an additional PROVIDE statement following the ASSERT. The GNU ld manual states that ASSERT has no semi colon, but a PROVIDE does.

So if you agree then you can improve the managed script generation by not appending a semi colon behind ASSERT statements. It would have saved me a good 15 minutes of not understanding why my ASSERT did not parse as valid.

Kind regards,
Vimes
0 Kudos
Reply
3 Replies

2,479 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldManVimes on Mon Feb 02 09:16:37 MST 2015
Hello Support and Wolfgang,

Cool. I was not aware of these ld syntax details. Thanks to you both. I've changed the title of the post so the next poor chap who runs into this issue may find a solution more quickly.

Regards,
Vimes
0 Kudos
Reply

2,479 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Mon Feb 02 08:39:21 MST 2015
Is your "ASSERT(_pvHeapStart <= (_pvHeapLimit - 0x1000)" inside a section? If yes, then your assert is WRONG.

Inside the section, the value of _pvHeapStart is NOT the absolute address, but the RELATIVE address from the start of the section. If you want to calculate or compare the ABSOLUTE value of _pvHeapStart, please place your ASSERT statement AFTER the section.

Hint: gnu ld has a nice manual about linker scripts...

http://www.scoberlin.de/content/media/http/informatik/gcc_docs/ld_3.html#SEC46

regard
Wolfgang
0 Kudos
Reply

2,479 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Feb 02 07:15:18 MST 2015
I agree that the GNU linker script format can be somewhat "interesting" at times, and can trigger linker errors that are not particular helpful if you get things wrong.

Unfortunately, the use of ASSERT for the CRP check within the main flash .text section does require a semicolon character at the end of the line - even though the one that you have added at the end of the script does not. Thus we can't make the modification that you are requesting.

Regards,
LPCXpresso Support
0 Kudos
Reply