简体   繁体   English

如何使用静态存储轻松生成符号列表?

[英]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文件中的每个条目都包含两者

  1. the name of the global variable (eg, the initializer for global variable fred will be fred$initializer$ , plus the required C++ name decoration), and 全局变量的名称(例如,全局变量fred的初始化程序将为fred$initializer$ ,加上所需的C ++名称修饰),以及
  2. the object file that contained the global variable (eg 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.

相关问题 如何从特定的静态链接库生成构建产品使用的符号列表? - How can I generate a list of symbols used by a build product from a particular statically linked library? 如何使用脚本可以轻松修改的数据生成exe - How to generate an exe with data that can be easily modified by a script 如何轻松使用 char**? - How can I easily work with a char**? 如何链接(或解决)两个定义相同符号的第三方静态库? - How can I link with (or work around) two third-party static libraries that define the same symbols? 如何检查静态库以查看是否正在导出调试符号? - How can I inspect a static library to see if the debug symbols are being exported? 我可以让cmake始终生成调试符号吗? - Can I make cmake always generate debugging symbols? 如何列出 a.so 文件中的符号 - How do I list the symbols in a .so file 如何设计一个可以轻松返回数组长度的函数? - How can I design a function that can return the length of an array easily? 如何使用库的头文件生成libfoo.sym文件,以与libtool -export-symbols一起使用? - How can I use a library's header files to generate a libfoo.sym file for use with libtool -export-symbols? 如何使用Visual Studio轻松缩进标头声明 - How can I easily indent header declarations with Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM