Menu

#118 Problem with standard c++ templates

Next release
closed-works-for-me
None
5
2015-02-19
2014-07-20
No

I am having difficulties using objects from the standard c++ template library. I get an "undefined reference to `__dso_handle'" linker error all the time. I just created a new STM32F405 Project and added a std::map object and used it in main, that's it.

Here is my configuration:
Eclipse: Kepler 2.0.2.20140224-0627
GNU ARM C/C++ Cross Compiler Support: 1.10.2.201407190854
GNU ARM C/C++ STM32Fx Project Templates: 2.2.1.201407120554
OS: Windows 8.1
Toolchain : GNU Tools ARM Embedded 4.8.2014q2

Related

Bugs: #120

Discussion

  • Liviu Ionescu (ilg)

    • status: open --> open-accepted
    • assigned_to: Liviu Ionescu (ilg)
     
  • Liviu Ionescu (ilg)

    I tried instantiating 'std::map<char,int> first;' and initialising several items like 'first['a']=10;' worked, both on release and debug.</char,int>

    Can you provide more details in order to reproduce the problem?

     
  • Henry Leinen

    Henry Leinen - 2014-07-20

    Sure, I created a new STM32F4xx Project, unchecked newlib nano.

    Then added the following in main.cpp

    #include <map>
    static std::map<uint8_t, uint32_t> myMap;

    Then added the following in the main function in main.cpp

    myMap[17] = 256;

    Now rebuild:
    I get a fault in _syscalls.c then, which requires me to add another include somewhere around line number 320 (I always get this fault btw).
    The include which is missing for me in _syscalls.c is

    #include <stdint.h>

    and is not related to my main Problem I believe.
    After this is fixed, I get the linker error 'undefined reference to....'.

     
    • Liviu Ionescu (ilg)

      I confirm the missing include in _syscalls.c, will be added to the next release

       
  • Henry Leinen

    Henry Leinen - 2014-07-20

    Just checked and it seems to work for release but not for debug ?!?

     
  • Henry Leinen

    Henry Leinen - 2014-07-20

    This is the linker Output btw :

    arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=soft -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -Wall -Wextra -g3 -T mem.ld -T libs.ld -T sections.ld -nostartfiles -Xlinker --gc-sections -L"../ldscripts" -Wl,-Map,"StdlibTest.map" -o "StdlibTest.elf" ./System/Src/stm32f4-hal/stm32f4xx_hal.o ./System/Src/stm32f4-hal/stm32f4xx_hal_cortex.o ./System/Src/stm32f4-hal/stm32f4xx_hal_flash.o ./System/Src/stm32f4-hal/stm32f4xx_hal_flash_ex.o ./System/Src/stm32f4-hal/stm32f4xx_hal_flash_ramfunc.o ./System/Src/stm32f4-hal/stm32f4xx_hal_gpio.o ./System/Src/stm32f4-hal/stm32f4xx_hal_iwdg.o ./System/Src/stm32f4-hal/stm32f4xx_hal_pcd_ex.o ./System/Src/stm32f4-hal/stm32f4xx_hal_pwr.o ./System/Src/stm32f4-hal/stm32f4xx_hal_pwr_ex.o ./System/Src/stm32f4-hal/stm32f4xx_hal_rcc.o ./System/Src/stm32f4-hal/stm32f4xx_hal_rcc_ex.o ./System/Src/newlib/_cxx.o ./System/Src/newlib/_exit.o ./System/Src/newlib/_sbrk.o ./System/Src/newlib/_startup.o ./System/Src/newlib/_syscalls.o ./System/Src/newlib/_write.o ./System/Src/newlib/assert.o ./System/Src/diag/Trace.o ./System/Src/diag/trace_impl.o ./System/Src/cortexm/_initialize_hardware.o ./System/Src/cortexm/_reset_hardware.o ./System/Src/cortexm/exception_handlers.o ./System/Src/cmsis/system_stm32f4xx.o ./System/Src/cmsis/vectors_stm32f4xx.o ./Src/_initialize_hardware.o ./Src/main.o
    c:/_tools/gnutools/gnu tools arm embedded/4.8.2014q2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m\libstdc++.a(system_error.o): In function "GLOBAL__sub_I__ZNSt14error_categoryC2Ev":
    system_error.cc:(.text.startup._GLOBAL__sub_I__ZNSt14error_categoryC2Ev+0x24): undefined reference to "_dsohandle"
    c:/_tools/gnutools/gnu tools arm embedded/4.8.2014q2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: StdlibTest.elf: hidden symbol "_dsohandle" isn't defined
    c:/_tools/gnutools/gnu tools arm embedded/4.8.2014q2/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: final link failed: Bad value
    collect2.exe: error: ld returned 1 exit status

     
  • Henry Leinen

    Henry Leinen - 2014-07-20

    the copied text is screwed due to the Markup... the actual Symbol is __dso_handle

     
  • Liviu Ionescu (ilg)

    nope, still does not reproduce.

    did the following:

    • upgrade toolchain to 4.8.2014q2
    • create a new workspace
    • create a new C++ project
    • select F405, Blinky, Semihosting, ARM ITM, check some warnings, check -Og, check exclude unused
    • added the include & static declaration after existing includes
    • added the assignment right at the beginning of main()
    • added the #include <stdint.h> in _syscalls</stdint.h>

    Debug:

    Invoking: Cross ARM GNU Print Size
    arm-none-eabi-size --format=berkeley "t2cppmap.elf"
    text data bss dec hex filename
    39604 2200 2844 44648 ae68 t2cppmap.elf
    Finished building: t2cppmap.siz

    Release:

    Invoking: Cross ARM GNU Print Size
    arm-none-eabi-size --format=berkeley "t2cppmap.elf"
    text data bss dec hex filename
    21608 2132 2712 26452 6754 t2cppmap.elf
    Finished building: t2cppmap.siz

    you probably have a different configuration, or did something differently.

     
  • Liviu Ionescu (ilg)

    any progress?

     
  • Liviu Ionescu (ilg)

    • status: open-accepted --> closed-works-for-me
     
  • Uditha Atukorala

    This seems to be an issue with g++ optimisations and '-fno-use-cxa-atexit' flag is suppose to fix it. But for some reason it didn't work for me all the time (sometimes changing -O0 to -O1 helped to get rid of the error).

    Defining the following fixed it for me:

    extern "C" void * __dso_handle;

    It'll be good to know why '-fno-use-cxa-atexit' doesn't seem to work all the time though.

     
  • Uditha Atukorala

    OK, having "--specs=nano.specs" option for "Other linker flags" also resolves the issue with __dso_handle.

     
  • Liviu Ionescu (ilg)

    the projects generated by the templates are supposed to use newlib-nano, otherwise several adjustments might be needed.