Solaris cc 是否在可执行文件中嵌入了针对不同编译的不同信息?
你好,
以前有人问过这个问题,但我对 Solaris 的答案很感兴趣。
我正在编译并链接以下简单的 C 代码:
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
使用命令:
cc -o hello1 hello.c
并执行此操作几次以获得可执行文件 hello2 和 hello3。这是在同一台机器上使用相同的编译器并在不同的时间在同一目录中完成的。
可执行文件的大小是相同的,但 diff 报告二进制文件不同,而 cmp -l 会因为一长串不同位置而变得疯狂。
有人知道 cc 在可执行文件中嵌入了什么以使它们有所不同吗?时间戳?
编辑:按照 Chris 下面的建议剥离可执行文件会使 diff 报告两个可执行文件相同。
干杯,
G'day,
This has been asked before for VC++ but I am interested in the answer for Solaris.
I'm compiling and linking the following trivial C code:
#include <stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
using the command:
cc -o hello1 hello.c
and doing this a couple of times to get executables hello2 and hello3. This is being done on the same machine with the same compiler and in the same directory just at different times.
The sizes of the executables are the same but diff reports the binaries as differing and cmp -l goes crazy with a long list of differing locations.
Anyone know what cc is embedding in the executables to make them differ? Timestamps?
Edit: Stripping the executables as Chris suggested below makes diff report the two executables as identical.
cheers,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对两个二进制文件使用“od -c”,然后使用并排比较程序,您可以了解差异是什么。过去当我研究Sun编译器时,它通常是一个日期字符串。您还可以尝试剥离可执行文件,看看是否删除了有差异的 ELF 部分。
If you use "od -c" on the two binaries, and then use a side-by-side diff program, you can get an idea what the differences are. In the past when I have investigated the Sun compilers, it's usually a date string. You can also try stripping the executable to see if that removes the ELF section that has the difference in it.
如果您采用完全相同的源代码并使用 Sun 的编译器将其编译两次,您将不会获得两个完全相同的二进制重复文件。会有细微的差别。据我所知,这主要归结为日期/时间问题。
If you take the exact same source code and compile it twice with Sun's compiler you will not get two exact-binary-duplicate files. There will be minor differences. As far as I know, it mostly just comes down to date/time issues.