What does '_GLOBAL__sub_I_' mean in nm output?

雨燕双飞 提交于 2020-05-12 11:16:29

问题


While I was trying to resolve a problem in static linking, I encounter a couple of _GLOBAL__sub_I_ prefixes in front of symbol names. It appears in that form although I used nm --demangle(-C).

I stumbled upon this answer (How to find global static initializations). Looking at my source code, it indeed looks like initialization of a global static variable.

What I'm wondering is, where can I more information on __sub_ and other mangled names, like __cxxabiv1?


回答1:


To prevent link rot i will answer here, although it is Chris Britt who should be credited with finding the information in the first place (see comments to the question).

If we look at "cxxabi.h File Reference" (2013) we see that the header defines two namespaces: __gnu_cxx and abi. So this is the header we are looking for "cxxabi.h File Reference" (2019) states that it was generated in 2009 and is almost identical, except that there is only abi namespace that is mentioned.

The difference is superficial, the header code itself defines the namespace __cxxabiv1 and then sets namespace abi = __cxxabiv1; so we can be sure that this header is still what we are looking for.

The following is declared in the header:

typedef __cxa_cdtor_return_type (*__cxa_cdtor_type)(void *);

int __cxxabiv1::__cxa_atexit (void(*)(void *), void *, void *) throw ();
void __cxxabiv1::__cxa_bad_cast ();
void __cxxabiv1::__cxa_bad_typeid ();
std::type_info * __cxxabiv1::__cxa_current_exception_type ();
char * __cxxabiv1::__cxa_demangle (const char *__mangled_name, char *__output_buffer, size_t *__length, int *__status);
int __cxxabiv1::__cxa_finalize (void *);
void __cxxabiv1::__cxa_guard_abort (__guard *);
int __cxxabiv1::__cxa_guard_acquire (__guard *);
void __cxxabiv1::__cxa_guard_release (__guard *);
void __cxxabiv1::__cxa_pure_virtual (void);
__cxa_vec_ctor_return_type __cxxabiv1::__cxa_vec_cctor (void *dest_array, void *src_array, size_t element_count, size_t element_size, __cxa_cdtor_return_type(*constructor)(void *, void *), __cxa_cdtor_type destructor);
void __cxxabiv1::__cxa_vec_cleanup (void *__array_address, size_t __element_count, size_t __element_size, __cxa_cdtor_type destructor);
__cxa_vec_ctor_return_type __cxxabiv1::__cxa_vec_ctor (void *__array_address, size_t __element_count, size_t __element_size, __cxa_cdtor_type constructor, __cxa_cdtor_type destructor);
void __cxxabiv1::__cxa_vec_delete (void *__array_address, size_t __element_size, size_t __padding_size, __cxa_cdtor_type destructor);
void __cxxabiv1::__cxa_vec_delete2 (void *__array_address, size_t __element_size, size_t __padding_size, __cxa_cdtor_type destructor, void(*__dealloc)(void *));
void __cxxabiv1::__cxa_vec_delete3 (void *__array_address, size_t __element_size, size_t __padding_size, __cxa_cdtor_type destructor, void(*__dealloc)(void *, size_t));
void __cxxabiv1::__cxa_vec_dtor (void *__array_address, size_t __element_count, size_t __element_size, __cxa_cdtor_type destructor);
void * __cxxabiv1::__cxa_vec_new (size_t __element_count, size_t __element_size, size_t __padding_size, __cxa_cdtor_type constructor, __cxa_cdtor_type destructor);
void * __cxxabiv1::__cxa_vec_new2 (size_t __element_count, size_t __element_size, size_t __padding_size, __cxa_cdtor_type constructor, __cxa_cdtor_type destructor, void *(*__alloc)(size_t), void(*__dealloc)(void *));
void * __cxxabiv1::__cxa_vec_new3 (size_t __element_count, size_t __element_size, size_t __padding_size, __cxa_cdtor_type constructor, __cxa_cdtor_type destructor, void *(*__alloc)(size_t), void(*__dealloc)(void *, size_t));
void * __cxxabiv1::__dynamic_cast (const void *__src_ptr, const __class_type_info *__src_type, const __class_type_info *__dst_type, ptrdiff_t __src2dst);

class __cxxabiv1::__fundamental_type_info : public std::type_info;
class __enum_type_info : public std::type_info;
class __pointer_type_info : public __pbase_type_info;
class __class_type_info : public std::type_info;
class __pointer_to_member_type_info : public __pbase_type_info;
class __base_class_type_info;
class __si_class_type_info : public __class_type_info;
class __vmi_class_type_info : public __class_type_info;

The header also includes:

#include <bits/cxxabi_tweaks.h>
#include <cxxabi-forced.h>

So it may be useful to take a look at them.



来源:https://stackoverflow.com/questions/31691280/what-does-global-sub-i-mean-in-nm-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!