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'

  • When I search the project directory, I find several instances of Makefile, as well as makefiles with the extension .common, .posix, and .windows.  I assume the relevant makefiles when I use the internal build configuration are those in the /components/toolchain/gcc directory. 

    The issue I'm having is probably related to section variables.  In the Nordic-supplied source file, I notice the following lines:

    // Create section "sdh_req_observers".
    NRF_SECTION_SET_DEF(sdh_req_observers, nrf_sdh_req_observer_t, NRF_SDH_REQ_OBSERVER_PRIO_LEVELS);

    This somehow creates a section sdh_req_observers, which does indeed show up in the map file after building externally with the IAR.  When I try building internally, the link errors listed in my initial question above show up, and I assume that no map file gets created because these are linker errors and the linker therefore never completes successfully.

  • 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.

  • 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?

Related