Difference between revisions of "Placing external library symbols at specific address"

From SEGGER Wiki
Jump to: navigation, search
Line 20: Line 20:
 
</pre>
 
</pre>
 
* Now everything should be set up and all libc function should be linked into region MEM_LIB.
 
* Now everything should be set up and all libc function should be linked into region MEM_LIB.
  +
* To make sure this stays valid after a reset/reboot of the device the library functions must be initialized during startup by copying them from Flash to RAM.
  +
* This can be done by adding the following line to the remaining "initialize by copy entries".
  +
<pre>
  +
initialize by copy { section .text.libc, section .text.libc.* };
  +
</pre>

Revision as of 11:24, 8 April 2020

One of the big benefits of the SEGGER Linker is its simple usage. In this scenario an external library will be placed in a specific memory location.

  • Usually everything is placed under .text section. Check your symbol browser or map file to locate how the subsection of the external library is called. For this example we will show how the libc library can be placed into a different memory region.
  • Open your projects linker script(.icf file) for editing.
  • Add a new placement for your particular library subsection into the desired region. e.g.
place in MEM_LIB                            { section .text.libc, section .text.libc.*};
  • In the general placement where other code sections are placed, add an exception for this subsection otherwise the linker will throw an error that the same symbols are linked twice.
place in FLASH with minimum size order      { section .init,   section .init.*,        // Init code section
                                              section .init_rodata, section .init_rodata.*, // Init read-only section
                                              section .text,   section .text.*,        // Code section
                                              section .rodata, section .rodata.*,      // Read-only data section
                                              section .segger.*,                       // Auto-generated initialization
                                              block exidx,                             // ARM exception unwinding block
                                              block ctors,                             // Constructors block
                                              block dtors }                            // Destructors block
                                     except { section .text.libc, section .text.libc.*};
  • Now everything should be set up and all libc function should be linked into region MEM_LIB.
  • To make sure this stays valid after a reset/reboot of the device the library functions must be initialized during startup by copying them from Flash to RAM.
  • This can be done by adding the following line to the remaining "initialize by copy entries".
initialize by copy                          { section .text.libc, section .text.libc.* };