当我尝试解决静态链接中的问题时,我在符号名称前遇到了几个 _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 thestd::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/