[英]How can I easily generate a list of symbols with static storage?
We have a large C++ project that we're building with both GCC and MSVC, and we've encountered the static initialization order fiasco . 我们有一个大型C ++项目,我们正在用GCC和MSVC构建,我们遇到了静态初始化命令fiasco 。 Is there a way to generate a list of symbols that take part in static initialization so I can generate a plan to resolve the problem? 有没有办法生成参与静态初始化的符号列表,以便生成解决问题的计划?
I've created a map file from both GCC and MSVC. 我已经从GCC和MSVC创建了一个地图文件。 MSVC's output didn't look very useful. MSVC的输出看起来不太有用。 It appears that GCC's map file could be used - I extracted everything related to the bss
section. 似乎可以使用GCC的地图文件 - 我提取了与bss
部分相关的所有内容。 However, many of the symbols come from libraries and just add noise to the information. 但是,许多符号来自库,只是为信息添加噪声。
Is there a trick or some other convenient way to obtain the information I'm looking for (short of reading every source file manually)? 是否有技巧或其他方便的方法来获取我正在寻找的信息(手动读取每个源文件)?
For Visual C++: Sort the lines of the .map file. 对于Visual C ++:对.map文件的行进行排序。 This will ensure the symbols are ordered by address. 这将确保符号按地址排序。
Search for symbols __xc_a
and __xc_z
. 搜索符号__xc_a
和__xc_z
。 The symbols that appear between those two symbols are all of the dynamic initializers for objects with static storage duration. 这两个符号之间出现的符号是具有静态存储持续时间的对象的所有动态初始化器。 The initializers will be executed in the order they appear in the list. 初始化程序将按它们在列表中出现的顺序执行。
Each entry in the .map file includes both .map文件中的每个条目都包含两者
fred
will be fred$initializer$
, plus the required C++ name decoration), and 全局变量的名称(例如,全局变量fred
的初始化程序将为fred$initializer$
,加上所需的C ++名称修饰),以及 fred.obj
). 包含全局变量的目标文件(例如fred.obj
)。 If the symbol came from a static library, the static library will be listed (eg libfred:fred.obj
). 如果符号来自静态库,则将列出静态库(例如libfred:fred.obj
)。 (I don't know enough about GCC to answer how to do this with their tools.) (我不太了解GCC如何用他们的工具来解决这个问题。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.