Where is __dso_handle defined?

I have an unresolved symbolic error while trying to compile my program that complains that it cannot find __dso_handle . Which library is this function commonly defined in?

Does the following result from nm on libstdc++.so.6 what does it contain?

I tried to link it, but the error is still happening.

 nm libstdc++.so.6 | grep dso 00000000002fc480 d __dso_handle 
+6
source share
2 answers

__dso_handle is a protector that is used to identify dynamic shared objects during global destruction .

Really, you should stop reading here. If you are trying to defeat the identity of an object by messing with __dso_handle , something is probably very wrong.

However, since you asked where it is defined: the answer is complex. To determine the location of its definition (for GCC), use iostream in a C ++ file and after that do extern int __dso_handle; . This should reflect the location of the ad due to type conflict (see this forum for source).

Sometimes this is determined manually .

Sometimes it is defined / provided by the "runtime" set by the compiler (in practice, a CRT is usually just a bunch of binary header / entry point code, as well as some defenders / exit handlers). In GCC (not sure if other compilers support it, if so, they will be in their sources):

Often it is defined in stdlib:

Further reading:

+8
source

I ran into this problem. Here are the conditions that seem to reliably create the problem:

  • g ++ without the standard C / C ++ library: -nostdlib (typical small built-in script).
  • Defining a statically assigned standard library object; for my case - std::vector . It used to be std::array statically distributed without any problems. Apparently, not all std:: statically allocated objects will cause a problem.
  • Please note that I do not use a shared library of any type.
  • uses the cross-compiler GCC / ARM .

If this is your use case, just add a command line parameter to your compilation / link command line: -fno-use-cxa-atexit

Here is a very good reference to __ using dso_handle as a descriptor for a dynamic shared object .

There is a typo on the page, but I have no idea who to contact to confirm:

After calling the destructors of the object constructor, GCC automatically calls the function ...

I think this should read "When all destructors called GCC calls a function" ...

One way to confirm this is to implement the __cxa_atexit function as mentioned, and then perform one step of the program and see where it is called. I will try it the other day, but not now.

0
source

All Articles