Where is __dso_handle defined?

Where is __dso_handle defined?

来源  https://stackoverflow.com/questions/34308720/where-is-dso-handle-defined

 

__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:

 

 

__cxa_atexit and __dso_handle

https://lists.debian.org/debian-gcc/2003/07/msg00057.html  

https://wiki.osdev.org/C++#GCC 

 

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 SHARED
void *__dso_handle = &__dso_handle;
#else
void *__dso_handle = 0;
#endif

#if 0
#ifdef SHARED

extern 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 0
static 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 __cplusplus
extern "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

 

原文链接: https://www.cnblogs.com/lsgxeva/p/11040993.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    Where is __dso_handle defined?

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/297015

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月15日 下午6:20
下一篇 2023年2月15日 下午6:20

相关推荐