【发布时间】:2017-02-21 15:32:19
【问题描述】:
我发现 file >=5.30 或 gcc >=6.3 改变了它的行为。当我编译像 hello-world 这样的基本程序时,file 的输出表明 elf 可执行文件包含某种“debug_info”。
来源:
#include <iostream>
using namespace std;
int main(int argc, char* argv []) {
cout << "Hello world.\n";
return 0;
}
编译:
$ g++ -o hello hello.cpp # notice, no option "-g"
检查:
$ file hello # please scroll to the right hand-side, it is at the very end
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=d03b68ed8618fcb97094b18157054f7cc2030f3c, not stripped, with debug_info
我不熟悉 readelf。 A readelf -S 你好 | grep -i debug 表示没有调试信息,编译时没有“-g”。如果使用选项“-g”编译,我会看到这个,这对我来说很好:
[27] .debug_aranges PROGBITS 0000000000000000 0000107c
[28] .debug_info PROGBITS 0000000000000000 000010ac
[29] .debug_abbrev PROGBITS 0000000000000000 000038ce
[30] .debug_line PROGBITS 0000000000000000 00003e54
[31] .debug_str PROGBITS 0000000000000000 00004186
我假设没有人在构建我的 gcc 版本期间使用隐藏的配置标志,以始终包含某种调试信息。所以可能 util file 的行为已经改变。 file 与“调试信息”是什么意思?
信息:
我在 X86_64 上运行 GNU/Linux (Archlinux),软件包都是最新的。
【问题讨论】:
-
友情提示:“包都是最新的。”并不意味着编译器是或提供任何关于编译器版本的提示。据我们所知,该发行版本可以在 3.3.4 停止更新 GCC。这将是极端的,但似乎不止几个主要发行版已停止在 4.8 和 4.9。最好运行
g++ -v并将版本添加到需要的未来问题中。 -
你说得对,但我已经在问题的顶部添加了版本信息。最后的注释应该只提供上下文信息。