【问题标题】:Linker map file sometimes has mangled symbols but not always链接器映射文件有时具有损坏的符号,但并非总是如此
【发布时间】:2015-12-22 17:23:40
【问题描述】:

作为构建过程的一部分,我们在编译可执行文件时会生成一个映射文件。例如:

g++ -Wl,-Map,/tmp/foo.map -o foo foo.cpp

为了尝试从 GCC 4.3/4.4 迁移到 GCC 4.9,我们设置了一个新的构建服务器。 4.9 构建服务器生成的映射文件没有损坏的符号名称。由 4.3/4.4 构建服务器生成的映射文件。例如,用 4.3 运行上面的代码,我在地图文件中得到了这个片段:

 .plt           0x0000000000400700       0x90 /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crt1.o
                0x0000000000400710                _ZNSolsEi@@GLIBCXX_3.4
                0x0000000000400720                _ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4
                0x0000000000400730                __libc_start_main@@GLIBC_2.2.5

针对 4.9 运行相同的代码,我得到以下 sn-p:

 .plt           0x00000000004006e0       0x80 /usr/lib/../lib64/crt1.o
                0x00000000004006f0                std::ostream::operator<<(int)@@GLIBCXX_3.4
                0x0000000000400700                std::ios_base::Init::Init()@@GLIBCXX_3.4
                0x0000000000400710                __libc_start_main@@GLIBC_2.2.5
                0x0000000000400720                __cxa_atexit@@GLIBC_2.2.5

这种变化是预期的吗?有没有办法使用 gcc 4.9(某种向后兼容选项)生成损坏的输出?我问是因为我们构建中的后续工具使用符号文件并且被解构后的名称阻塞。

【问题讨论】:

    标签: c++ gcc ld gcc4.9


    【解决方案1】:

    有没有办法使用 gcc 4.9 生成损坏的输出

    地图文件生成nothing与 GCC 的版本有关,而 everything 与您使用的链接器版本有关(必须与旧的和新的构建服务器)。

    来自man ld

     --demangle[=style]
     --no-demangle
           These options control whether to demangle symbol names in error
           messages and other output.  When the linker is told to demangle,
           it tries to present symbol names in a readable fashion: it strips
           leading underscores if they are used by the object file format,
           and converts C++ mangled symbol names into user readable names.
           Different compilers have different mangling styles.  The optional
           demangling style argument can be used to choose an appropriate
           demangling style for your compiler.  The linker will demangle by
           default unless the environment variable COLLECT_NO_DEMANGLE is
           set.  These options may be used to override the default.
    

    我猜测旧的链接器在生成输出映射时没有注意--demangle,而新的链接器已经修复了这个问题。

    【讨论】:

      猜你喜欢
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-14
      相关资源
      最近更新 更多