AnsweredAssumed Answered

Using your own linker scripts

Question asked by LPCware Support on Mar 31, 2016

Managed Linker scripts

 

The underlying GNU build tools within LPCXpresso IDE use linker scripts to define how the linker creates an executable image from your sources. By default the LPCXpresso IDE use a "managed linker script" mechanism to automatically create a script for each Build configuration that is suitable for the MCU selected for the project, and the C libraries being used. It will create (and at times modify) three linker script files for each build configuration of your project:

<projname>_<buildconfig>_lib.ld 
<projname>_<buildconfig>_mem.ld
<projname>_<buildconfig>.ld

 

This set of hierarchical files are used to define the C libraries being used, the memory map of the system and the way your code and data is placed in memory. These files will be located in the build configuration subdirectories of your project (typically - Debug and Release).

 

Tweaking the managed linker scripts

 

The following FAQs describe some of the ways that it is possible to modify the behaviour of the managed linker script mechanism. These allow you, in many cases, to avoid the need to bypass the managed linker scripts and manage the linker scripts by hand (as described later in this FAQ). Some examples of ways of modifying the behaviour of the managed linker script mechanism are given in the following FAQs:

 

 

Bypassing the managed linker script mechanism

 

In some circumstances, you might want to bypass the managed linker script mechanism and create your own bespoke linker scripts. In such cases you can either create your own linker script from scratch, or you can use the managed linker scripts as a starting point.

 

One very important point though is that you are advised not to simply modify the managed linker scripts in place, but instead to copy them to another location and modify them there. This will prevent any chance of the tools accidentally overwritting them if at some point in the future you turn the managed make script mechanism back on.To turn off the managed linker script mechanism, carry out the following steps:

 

  1. Open the Project properties. There are a number of ways of doing this. For example, make sure the Project is highlighted in the Project Explorer view then open the menu "Project -> Properties".

  2. In the left-hand list of the Properties window, open "C/C++ Build" and select "Settings" and then the "Tool Settings" tab.

  3. Now choose "MCU Linker - Target" and untick the Manage linker script box.

  4. Now enter the name of the your linker script into the "Linker script" field. Then enter the relative path information into the "Script path" field, so that the linker can find the script (relative to the current build configuration directory (i.e. Debug or Release). For example if your linker script is called myscript.ld and is located in the linkscripts subdirectory of your project, then you need to add "../linkscripts" to the linker script field and "myscript.ld" into the Linker script field.

 

Note that if your linker script includes additional files (as the managed linker scripts do), then you will also need to include the relative path information in the include.

 

Creating linker scripts

 

The GNU linker documentation contains a great deal of information on linker scripts. Please see the copy of the documentation included within the LPCXpresso IDE built-in help, or view online at: http://sourceware.org/binutils/docs-2.21/ld/index.html

 

There is also a good introduction to linker scripts available in Building Bare-Metal ARM Systems with GNU: Part 3 at:

 

http://www.embedded.com/design/mcus-processors-and-socs/4026080/Building-Bare-Metal-ARM-Systems-with-GNU-Part-3

 

Linker scripts and C (or C++) libraries

 

If you are providing your own linker script, you will need to add one of the following entries before the SECTION line in your linker script:

  • Redlib (None), add

[C project only]: GROUP(libcr_c.a libcr_eabihelpers.a)

  • Redlib (Nohost), add

[C projects only]: GROUP(libcr_nohost.a libcr_c.a libcr_eabihelpers.a)

  • Redlib (Semihost), add

[C projects only]: GROUP(libcr_semihost.a libcr_c.a libcr_eabihelpers.a)

  • Newlib (None), add

[C projects]: GROUP(libgcc.a libc.a libm.a)
               [C++ projects]: GROUP(libgcc.a libc.a libstdc++.a libm.a)

  • Newlib (Nohost), add

[C projects]: GROUP(libgcc.a libc.a libm.a libcr_newlib_nohost.a)
                 [C++ projects]: GROUP(libgcc.a libc.a libstdc++.a libm.a libcr_newlib_nohost.a)

  • Newlib (Semihost), add

[C projects]: GROUP(libgcc.a libc.a libm.a libcr_newlib_semihost.a)
                 [C++ projects]: GROUP(libgcc.a libc.a libstdc++.a libm.a libcr_newlib_semihost.a)

 

LPCXpresso v7 introduced support for Newlib-Nano, which can be accessed as follows:

 

  • LPCXpresso 7.6 and later
    • NewlibNano (None), add

[C projects]: GROUP(libgcc.a libc_nano.a libm.a)
                          [C++ projects]: GROUP(libgcc.a libc_nano.a libstdc++_nano.a libm.a)

    • NewlibNano (Nohost), add

[C projects]: GROUP(libgcc.a libc_nano.a libm.a libcr_newlib_nohost.a)
                           [C++ projects]: GROUP(libgcc.a libc_nano.a libstdc++_nano.a libm.a libcr_newlib_nohost.a)

    • NewlibNano (Semihost), add

[C projects]: GROUP(libgcc.a libc_nano.a libm.a libcr_newlib_semihost.a)
                          [C++ projects]: GROUP(libgcc.a libc_nano.a libstdc++_nano.a libm.a libcr_newlib_semihost.a)

  • LPCXpresso 7.5 and earlier
    • NewlibNano (None), add

[C projects]: GROUP(libgcc.a libc_s.a libm.a)
                           [C++ projects]: GROUP(libgcc.a libc_s.a libstdc++_s.a libm.a)

    • NewlibNano (Nohost), add

[C projects]: GROUP(libgcc.a libc_s.a libm.a libcr_newlib_nohost.a)
                           [C++ projects]: GROUP(libgcc.a libc_s.a libstdc++_s.a libm.a libcr_newlib_nohost.a)

    • NewlibNano (Semihost), add

[C projects]: GROUP(libgcc.a libc_s.a libm.a libcr_newlib_semihost.a)
                          [C++ projects]: GROUP(libgcc.a libc_s.a libstdc++_s.a libm.a libcr_newlib_semihost.a)


For more information on C library variants, please see the FAQ:

Outcomes