Placing Code in Sections with managed GNU Linker Scripts

Managed linker scripts are great on one side: the simplify the otherwise complex GNU linker script handling. On the other side it requires knowledge how to tweak them in case ‘non-standard’ behavior is needed.

I described the context in Putting Code of Files into Special Section with the GNU Linker.

This is very useful for example putting code or data into specific memory areas, for example if using position independent code or in the context of libraries and bootloaders.

The question is: how to do this with a managed linker script as in the NXP MCUXpresso IDE?

First, we need a memory section which we can use. I’m using here the NXP LPC55S16 which has one text/FLASH region, so I used the ‘Split’ button to have another section:

Text Sections

The next thing is that I have to specify which code I want to place into this section. There is an ‘extra linker script input section’ I can use:

Extra Linker Script Input Section
  • Input section description: The text used in the linker script. I can use wildcards (*) and specify the file name(s). After the file name I can specify the section names with wildcards too.
  • Region: The region name I have defined
  • Section Type: The linker script will be split into different areas like .text or .data. Specify for which section kind it shall be used.

What it does is creating an extra placement in the linker script file like this one:

With this, check the placement in the linker *.map file:

Code Placed in Linker Map File

The image below shows the full flow:

Placement Flow with Managed Linker Script

With this, I can place code (or data) into specific sections using managed linker scripts.

Happy placing 🙂

Links

5 thoughts on “Placing Code in Sections with managed GNU Linker Scripts

  1. just wanted to also point out the magic of “cr_section_macros.h”. You can get nice macros that are compatible with all of the MCUXPresso managed linker scripts. It has been a life saver for me!

    Liked by 1 person

    • Agreed, they are very useful. I’m only wondering why they are not part of the MCUXpresso SDK and why the file is labeled ‘NXP confidential’. I don’t see anything in there which would make it confidential.

      Like

      • That header dates back to Code Red days (hence the “cr” in its filename). Looks like someone decided to change the license inappropriately during 2020 – there is no way the file should be marked NXP Confidential given its been provided to users as part of Red Suite / LPCXpresso IDE / MCUXpresso IDE for well over 10 years!

        Liked by 1 person

  2. Pingback: Position-Independent Code with GCC for ARM Cortex-M | MCU on Eclipse

Leave a Reply to Erich Styger Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.