C++ global object with destructor link error: __dso_handle

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
vitaly
Posts: 8
Joined: Mon Jan 02, 2012 11:24 am

C++ global object with destructor link error: __dso_handle

Post by vitaly »

Hello!

I try to compile simple C++ program. Eventually I reduced it to:

Code: Select all

class CD {
public:
    ~CD(){x=0;}
    int x;
};

CD cd;

which gives me the error:
Compiling ../tmp/1.cpp
Linking build/ch.elf
build/obj/1.o: In function `__static_initialization_and_destruction_0':
.../chibios/../tmp/1.cpp:7: undefined reference to `__dso_handle'
collect2: ld returned 1 exit status
make: *** [build/ch.elf] Error 1

I use ChibiOS 2.4.0 and code sourcery light 2011.03

Any ideas?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: C++ global object with destructor link error: __dso_hand

Post by Giovanni »

Are you using the arm-none-eabi compiler?

I never hit this problem because static destructors do no make much sense in an embedded system. Anyway try to Google those symbols, there are a lot of hits.

Giovanni
vitaly
Posts: 8
Joined: Mon Jan 02, 2012 11:24 am

Re: C++ global object with destructor link error: __dso_hand

Post by vitaly »

yes, I'm using the arm-none-eabi compiler.

I agree on little sense of static destructor, but anyway...
vitaly
Posts: 8
Joined: Mon Jan 02, 2012 11:24 am

Re: C++ global object with destructor link error: __dso_hand

Post by vitaly »

After a bit of surfing I see that it's related to dynamic libraries termination. (I don't plan to use embedded dynamic libraries for some time ;) http://sourcery.mentor.com/public/cxx-abi/abi.html#dso-dtor

Now my question boils down to: is it enough to add this line to feel safe? ;)

Code: Select all

extern "C" void *__dso_handle = 0;
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: C++ global object with destructor link error: __dso_hand

Post by Giovanni »

Probably yes, do you plan to actually execute destructors or just to silence the error?

Giovanni
vitaly
Posts: 8
Joined: Mon Jan 02, 2012 11:24 am

Re: C++ global object with destructor link error: __dso_hand

Post by vitaly »

I'd like to conceit myself they are executed ;)
Seriously, I have 2 valid imho arguments:
  • the same class may have both static and dynamic instances
  • it's not uncommon to use destructors to free resources in the spirit of RAII
Anyway, from ChibiOS/RT crt0.c I believe that static destructors are called, aren't they?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: C++ global object with destructor link error: __dso_hand

Post by Giovanni »

They are supposed to be called.

Giovanni
Post Reply