Where is __dso_handle defined?

revit picture revit · Dec 16, 2015 · Viewed 14.5k times · Source

I have an unresolved symbol error when trying to compile my program which complains that it cannot find __dso_handle. Which library is this function usually defined in?

Does the following result from nm on libstdc++.so.6 mean it contains that?

I tried to link against it but the error still occurs.

nm libstdc++.so.6 | grep dso
00000000002fc480 d __dso_handle

Answer

Zac B picture Zac B · Sep 16, 2016

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

Realistically, you should stop reading here. If you're trying to defeat object identification by messing with __dso_handle, something is likely very wrong.

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

Sometimes, it is defined manually.

Sometimes, it is defined/supplied by the "runtime" installed by the compiler (in practice, the CRT is usually just a bunch of binary header/entry-point-management code, and some exit guards/handlers). In GCC (not sure if other compilers support this; if so, it'll be in their sources):

Often, it is defined in the stdlib:

Further reading: