Where is __dso_handle defined?
来源
__dso_handle
is a "guard" that is .
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 for a source).
Sometimes, it is .
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:
__cxa_atexit and __dso_handle
crtbegin.c
/* Runtime support for C++ */typedef void (*func_ptr) (void);/* __dso_handle *//* Itanium C++ ABI requires that each shared object (*.so) should have its own __dso_handle, and when that shared object is unloaded, the __dso_handle is an argument that is passed to __cxa_finalize. For a shared object, __dso_handle is assigned itself, for the main executable, __dso_handle is 0*/#ifdef SHAREDvoid *__dso_handle = &__dso_handle;#elsevoid *__dso_handle = 0;#endif#if 0#ifdef SHAREDextern void __cxa_finalize (void *) __attribute__((weak));static void __attribute__((used))__do_global_dtors_aux(void) { static int completed; if (__builtin_expect (completed, 0)) return; if (__cxa_finalize) __cxa_finalize (__dso_handle); completed = 1;}__asm__ (".section .fini");__asm__ (".align 8, 0x90");__asm__ (".byte 0x0f, 0x1f, 0x00");__asm__ ("call __do_global_dtors_aux");#endif#endif/* The musl libc is responsible for init_array traversal so there is no need to keep __do_global_ctors_aux*/#if 0static void __attribute__((used))__do_global_ctors_aux(void) { static int completed; if (__builtin_expect (completed, 0)) return; completed = 1;}__asm__ (".section .init");__asm__ (".align 8, 0x90");__asm__ (".byte 0x0f, 0x1f, 0x00");__asm__ ("call __do_global_ctors_aux");#endif
#ifdef __cplusplusextern "C" {#endif // __cplusplus extern __attribute__((weak)) void *__dso_handle;#ifdef __cplusplus}#endif // __cplusplus
undefined reference to `__dso_handle' ?
If this is your use case then merely add the command line option to your compile/link command line: -fno-use-cxa-atexit
=============== End