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):
- Main definition
- Testing
__dso_handle
replacement/tracker example 1 - Testing
__dso_handle
replacement/tracker example 2
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
2018-06-17 Ddos攻击防护