This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Segger Embedded Studio Link Errors - Undefined References

First - thanks to those who answered my question about the Segger Embedded Studio code size limit.  It appears to have be fixed when I switch the build configuration from "Internal and External" to just "Internal".  

This question may relate to the SDK rather than the Segger Embedded Studio, but my project did compile, link, and run with IAR and now I am getting these link errors with SES.  

Linking hm_chair.elf

_build/nrf_sdh.o:(.rodata.sdh_req_observers+0x0): undefined reference to `__start_sdh_req_observers'

_build/nrf_sdh.o:(.rodata.sdh_req_observers+0x4): undefined reference to `__stop_sdh_req_observers'

_build/nrf_sdh.o:(.rodata.sdh_state_observers+0x0): undefined reference to `__start_sdh_state_observers'

_build/nrf_sdh.o:(.rodata.sdh_state_observers+0x4): undefined reference to `__stop_sdh_state_observers'

Parents
  • put "section variables segger embedded" into the search box and that will give you a mixed bag of posts, some of which explain how section variables work and how you need to add extra sections to the linker script and load code. 

    Regrettably section variables are one of those things which IAR's auto-section-creation makes work out of the box so someone used them a couple of years ago. They are a pain however under gcc and other non IAR  toolchains which require them added to the ld script (for gcc) or the xml file which generates the ld script for SES/crossworks and also, since they have defined initial values, a chunk of code to the loader stub to populate them. 

    I haven't seen nor thought up a better solution to this for SES. 

  • Would adding sections using Project Edit Option -> Linker -> Section Placement Segments have the same effect as modifying the XML file you mentioned?  Something tells me the issue involves the SDK, but only because the symbols that aren't getting seen at the link are of the format "sdh_..._observers".  

    I did try adding one segment to the Section Placements Segments hoping it would at least eliminate the first of the link errors I listed, but it did not.   Thanks for the help; I feel like I'm beating my head up on this and it's taking way longer than it should to port a project that compiles successfully on IAR to SES.  Maybe I'm not finding the correct posts if this problem has occurred before.

Reply
  • Would adding sections using Project Edit Option -> Linker -> Section Placement Segments have the same effect as modifying the XML file you mentioned?  Something tells me the issue involves the SDK, but only because the symbols that aren't getting seen at the link are of the format "sdh_..._observers".  

    I did try adding one segment to the Section Placements Segments hoping it would at least eliminate the first of the link errors I listed, but it did not.   Thanks for the help; I feel like I'm beating my head up on this and it's taking way longer than it should to port a project that compiles successfully on IAR to SES.  Maybe I'm not finding the correct posts if this problem has occurred before.

Children
  • This https://devzone.nordicsemi.com/f/nordic-q-a/12029/segger-embedded-studio---unplaced_sections-problem is basically the canonical mail thread about fixing this, bringing flash_placement.xml into your project (ie copy it) and then modify to add the correct entries. Then also modify the assembler to do the copies. 

    I wish Nordic hadn't used the very IAR/Keil specific way of magically creating sections, but they did, and it means a ton of work for people not using them. 

  • RK - thanks for the help and referral to the previous email thread, which I have followed.  My question now is: There appears to be a flash_placement.xml which I believe I copied over from the Segger studio directory <targets/? and have modified slight to try and add the non-linking segments.  Per the email thread you mentioned above, I tried adding two lines that I thought would apply to the linker undefined references for "_start_sdh_req_observers", "_stop_sdh_req_observers", "_start_sdh_state_observers", and "_stop_sdh_state_observers",

    <ProgramSection alignment="4" keep="Yes" load="Yes" name=".sdh_req_observers" address_symbol="__start_sdh_req_observers" end_symbol="__stop_sdh_req_observers"/>


    <ProgramSection alignment="4" keep="Yes" load="Yes" name=".sdh_state_observers" address_symbol="__start_sdh_state_observers" end_symbol="__stop_sdh_state_observers"/>

    This did not cause the link errors to go away as I had hoped.  As a sanity check, to see if lines added to my flash_placement.xml would have any effect at all, I put in the intentionally wrong line "<Intentional error here>" to see if I would get an error from it and did not, making me question if the linker placement file is getting used.

    In the Project->Options I see a reference to a section placement file ($StudiuoDir)/targets/section_placement.xml), however when I search my Segger embedded studio file, I can't find it.  Is that file used or needed?  I feel like I'm close, but still missing something to get this project to link.

  • I just tried renaming the flash_placement.xml in my project directory to "Old_flash_placement.xml", expecting this to cause some sort of error such as "Can't find flash placement file".  I did not get any such error, but instead the link proceeds until the same four undefined reference errors from my initial post show up.  Does that imply that the flash_placement.xml file in my project directory is not getting used?

    At the risk of asking too many question, I am I correct in assuming that $(StudioDir) is the install directory for the Segger Embedded Studio and $(ProjectDir) is the directory where m y project source files live?

  • The one being used should be in the sidebar somewhere in all the project settings. Usually it starts as the 'generic' one and you can right click to import it locally into your project where it copies it and sets it as the one it's going to use, you can then edit it. 

    If you head far enough into the actual build transcript you should find the command which uses the flash placement and other files to generate the linker file. Then you can see what it's actually using. 

  • RK Thanks much for the help - I now have a build that links without errors. My confusion was coming from two places.  First, the flash_placement.xml I had copied to the code directory was not being used.  The Project->Options->Linker-> Section Placement File was actually pointing to a directory a couple layers down in my project source rather than where I might have expected.  Modifying that xml file with the two <Program Section...> lines in my post three above this one eliminated the four linker errors.  I can now happily build in Segger above the 32K IAR Kickstarter limit, which was my main motivation for evaluating this tool.

    A second confusion source that held me up longer that I would have liked is that the Project->Options->Section Placement File indicated actually changes once the Import is done.  The imported file line was showing a file named "section_placement.xml", and when I couldn't find a file by that name I got further confused.

Related