c++ - '_GLOBAL__sub_I_' 在 nm 输出中是什么意思?

标签 c++ name-mangling nm

当我尝试解决静态链接中的问题时,我在符号名称前遇到了几个 _GLOBAL__sub_I_ 前缀。尽管我使用了 nm --demangle(-C),但它以那种形式出现。

我偶然发现了这个答案 (How to find global static initializations)。查看我的源代码,它确实看起来像是全局静态变量的初始化。

我想知道的是,我在哪里可以获取有关 __sub_ 和其他错误名称(例如 __cxxabiv1)的更多信息?

最佳答案

我收到了 _GLOBAL__sub_I_我需要删除的符号中的前缀。

然后发现:https://llvm.org/docs/FAQ.html :

What is this llvm.global_ctors and _GLOBAL__I_a... stuff that happens when I #include <iostream>?

If you #include the <iostream> header into a C++ translation unit, the file will probably use the std::cin/std::cout/… global objects. However, C++ does not guarantee an order of initialization between static objects in different translation units, so if a static ctor/dtor in your .cpp file used std::cout, for example, the object would not necessarily be automatically initialized before your use.

To make std::cout and friends work correctly in these scenarios, the STL that we use declares a static object that gets created in every translation unit that includes <iostream>. This object has a static constructor and destructor that initializes and destroys the global iostream objects before they could possibly be used in the file. The code that you see in the .ll file corresponds to the constructor and destructor registration code.

我将我的函数移到了没有 <fstream> 的翻译单元中, 现在导出符号时没有 _GLOBAL__sub_I_ .

关于c++ - '_GLOBAL__sub_I_' 在 nm 输出中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31691280/

相关文章:

c - C中的手动名称修改

c++ - Variadic 模板在目标文件中有重复的符号?

linux - 给定两个 Linux 静态库,如何判断一个是否依赖于另一个?

ios - 如何在 `nm` 工具中搜索公共(public)或私有(private) API 以查找二进制 .ipa 中的所有库

c++ - 为什么不满足我的 "while"条件?

c++ - 使用 const 数组元素初始化

c++ - 派生类的高效交换方法

c++ - 使用 GDB 获取 lambda 的行号

c++ - 仅存在于 RAM 中的临时文件?

c - 在 x64 DLL 中强制进行名称修改