反汇编 Microsoft Visual Studio 2003 编译器输出
我发现 Microsoft Visual Studio 2003 工具输出的对象文件出现了奇怪的行为。 file
实用程序告诉我:
asmfile.obj: 80386 COFF executable not stripped - version 30821
对于由汇编器创建的对象,但对于来自 C 文件的对象,我得到的只是:
cfile.obj: data
使用 Microsoft 的 dumpbin
实用程序和 objdump< /code> 我从 cygwin 获得,我可以反汇编汇编构建的文件,但我从 C 构建文件的任一实用程序中都没有得到有用的结果。
我有几个与此差异相关的问题:
- MSVC2003 编译器生成的目标文件格式是什么?
- 我如何反汇编该目标文件?
我对 AT&T 语法中的反汇编特别感兴趣 - 我正在做一个大型源库的移植,以使其与 GCC 一起工作,并且我想使用此方法作为一些内联汇编例程的快捷方式在项目中。
编辑:添加更多信息。
当我在这些文件之一上运行 dumpbin
时,没有给出任何结果:
C:\> dumpbin /disasm Func.obj
Microsoft (R) COFF/PE Dumper Version 7.10.6030
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file Func.obj
FileType: ANONYMOUS OBJECT
使用 objdump
时,它给出:
$ objdump -d Func.obj
objdump: Func.obj: File truncated
在从程序集构建的文件上,我得到了合理的结果。
再次编辑:添加命令行信息。
汇编文件是使用类似于以下内容的命令行构建的:
ml -nologo -W3 -WX -c -coff -FoAssemblyFile.obj -Zi -Cx AssemblyFile.asm
ml
当其自身执行时表示:
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000. All rights reserved.
C 文件是使用以下命令构建的:
cl -nologo -W4 -WX -Gs32768 -GX -Gy -c -FdCFile.pdb -FoCFile.obj -Zi
-Gm -O1 -Oy- -Gy -GL -X CFile.c
有一些 -I
和-D
选项传递给 ml
和 cl
,但为了简洁起见,我在这里省略了它们。 此处描述了 cl
选项。
I'm seeing what I think is strange behaviour from object files output by the Microsoft Visual Studio 2003 tools. The file
utility tells me:
asmfile.obj: 80386 COFF executable not stripped - version 30821
For objects created by the assembler, but for objects coming from C files, I get just:
cfile.obj: data
Using Microsoft's dumpbin
utility and the objdump
I got from cygwin, I can disassemble the assembly-built file, but I get no useful results from either utility for the C-built files.
I have a couple of questions related to this difference:
- What is the object file format generated by the MSVC2003 compiler?
- How can I disassemble that object file?
I am particularly interested in getting the disassembly in AT&T syntax - I'm doing a port of a large source base to make it work with GCC, and I would like to use this method as a shortcut for some of the inline assembly routines in the project.
Edit: Adding some more information.
When I run dumpbin
on one of these files gives me no results:
C:\> dumpbin /disasm Func.obj
Microsoft (R) COFF/PE Dumper Version 7.10.6030
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file Func.obj
FileType: ANONYMOUS OBJECT
With objdump
, it gives:
$ objdump -d Func.obj
objdump: Func.obj: File truncated
On the files built from assembly, I get reasonable results.
Edit again: Adding command line information.
The assembly files are built with a command line resembling the following:
ml -nologo -W3 -WX -c -coff -FoAssemblyFile.obj -Zi -Cx AssemblyFile.asm
ml
when executed by itself says:
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000. All rights reserved.
The C files are built with the following command:
cl -nologo -W4 -WX -Gs32768 -GX -Gy -c -FdCFile.pdb -FoCFile.obj -Zi
-Gm -O1 -Oy- -Gy -GL -X CFile.c
There are some -I
and -D
options passed to ml
and to cl
, but I've omitted them for brevity here. The cl
options are described here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据添加到问题中的 cl 命令行选项进行编辑:
我认为问题是使用
/GL
选项,该选项指定将完成链接时代码生成优化。从该选项的文档页面:使用此选项会导致编译器生成链接器可以执行程序范围优化的
.obj
文件 - 显然该文件格式是专有的(也许它已记录在某处,但我怀疑没有)。/GL
(也称为“整个程序优化”、“链接时代码生成”或 LTCG)的文档包含有关.obj
文件互操作性的多个警告或包含此类对象文件的库。原始答案:
您尝试反汇编的 .obj 文件的 C 源代码中到底有什么?对于简单的“hello world”程序,我使用
dumpbin /disasm test.obj
得到以下内容:注意:这是使用由
编译的
由 VS2005 提供,但我无法想象这个东西与 VS2003 相比会有多大变化。.obj
文件dumpbinEdit based on the cl command line options being added to the question:
I think the problem is the use of the
/GL
option, which specifies that link-time code generation optimization will be done. from a doc page on that option:Using this option causes the compiler to generate
.obj
files that the linker can perform program-wide optimization on - apparently the file format is proprietary (maybe it's documented somewhere, but I suspect not).The docs for
/GL
(also known as "whole program optimization", "link-time code generation", or LTCG) contain several warnings about interoperability of the.obj
files or libraries containing such objects files.Original answer:
What exactly is in the C source for the .obj file you're trying to disassemble? I get the following using
dumpbin /disasm test.obj
for a simple 'hello world' program:Note: this is using an
.obj
file compiled by and adumpbin
provided by VS2005, but I can't imagine this stuff would have changed much from VS2003.