【发布时间】:2014-04-15 00:10:01
【问题描述】:
我写了一个简单的程序,然后编译组装它。
tfc.cpp
int i = 0;
void f(int a)
{
i += a;
};
int main()
{
f(9);
return 0;
};
我通过运行得到了 tfc.o
$ g++ -c -O1 tfc.cpp
然后我使用gobjdump(objdump)来反汇编二进制文件。
$ gobjdump -d tfc.o
然后我得到了
0000000000000000 <__Z1fi>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 01 3d 00 00 00 00 add %edi,0x0(%rip) # a <__Z1fi+0xa>
a: 5d pop %rbp
b: c3 retq
c: 0f 1f 40 00 nopl 0x0(%rax)
0000000000000010 <_main>:
10: 55 push %rbp
11: 48 89 e5 mov %rsp,%rbp
14: bf 09 00 00 00 mov $0x9,%edi
19: e8 00 00 00 00 callq 1e <_main+0xe>
1e: 31 c0 xor %eax,%eax
20: 5d pop %rbp
21: c3 retq
奇怪的事情发生了,callq 指令后面跟着1e <_main+0xe>。不应该是<__Z1fi>的地址吗?如果不是,main 函数如何调用f 函数?
编辑 仅供参考:
$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
【问题讨论】:
-
试试
objdump -M intel -d tfc.o。 -
我想知道反汇编是否没有显示 callq -> 跳转到 0x00 <__z1fi> ?
-
@ooga 我还是得到了
19: e8 00 00 00 00 call 1e <_main+0xe> -
查看@GriffinG提供的答案,很有帮助!
标签: c++