Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gcc生成对下一条指令地址的'call'_Gcc_Assembly_X86_Disassembly - Fatal编程技术网

gcc生成对下一条指令地址的'call'

gcc生成对下一条指令地址的'call',gcc,assembly,x86,disassembly,Gcc,Assembly,X86,Disassembly,我正在使用cc-g-O0-m32编译下一个代码: void f() { int l; short s; char c; l = 0xdeadbeef; s = l; c = l; printf("l = 0x%x (%d bits)\n", l, sizeof(l) * 8); printf("s = 0x%x (%d bits)\n", s, sizeof(s) * 8); printf("c = 0x%x (%d b

我正在使用cc-g-O0-m32编译下一个代码:

void f() {
    int l;
    short s;
    char c;

    l = 0xdeadbeef;
    s = l;
    c = l;

    printf("l = 0x%x (%d bits)\n", l, sizeof(l) * 8);
    printf("s = 0x%x (%d bits)\n", s, sizeof(s) * 8);
    printf("c = 0x%x (%d bits)\n", c, sizeof(c) * 8);
}
下面几行的目的是什么

   0x00001e89 <+9>: call   0x1e8e <f+14>
   0x00001e8e <+14>:    pop    %eax
   0x00001e8f <+15>:    lea    0xe8(%eax),%ecx
0x00001e89:调用0x1e8e
0x00001e8e:弹出%eax
0x00001e8f:lea 0xe8(%eax),%ecx
当我使用gdb进行反汇编时

(gdb) disassemble f
Dump of assembler code for function f:
   0x00001e80 <+0>: push   %ebp
   0x00001e81 <+1>: mov    %esp,%ebp
   0x00001e83 <+3>: push   %ebx
   0x00001e84 <+4>: push   %edi
   0x00001e85 <+5>: push   %esi
   0x00001e86 <+6>: sub    $0x3c,%esp
   0x00001e89 <+9>: call   0x1e8e <f+14>
   0x00001e8e <+14>:    pop    %eax
   0x00001e8f <+15>:    lea    0xe8(%eax),%ecx
   0x00001e95 <+21>:    mov    $0x20,%edx
   0x00001e9a <+26>:    movl   $0xdeadbeef,-0x10(%ebp)
   0x00001ea1 <+33>:    mov    -0x10(%ebp),%esi
   0x00001ea4 <+36>:    mov    %si,%di
   0x00001ea7 <+39>:    mov    %di,-0x12(%ebp)
   0x00001eab <+43>:    mov    -0x10(%ebp),%esi
   0x00001eae <+46>:    mov    %esi,%ebx
   0x00001eb0 <+48>:    mov    %bl,-0x13(%ebp)
   0x00001eb3 <+51>:    mov    -0x10(%ebp),%esi
   0x00001eb6 <+54>:    mov    %ecx,(%esp)
   0x00001eb9 <+57>:    mov    %esi,0x4(%esp)
   0x00001ebd <+61>:    movl   $0x20,0x8(%esp)
   0x00001ec5 <+69>:    mov    %eax,-0x18(%ebp)
   0x00001ec8 <+72>:    mov    %edx,-0x1c(%ebp)
   0x00001ecb <+75>:    call   0x1f5a
   0x00001ed0 <+80>:    mov    -0x18(%ebp),%ecx
   0x00001ed3 <+83>:    lea    0xfc(%ecx),%edx
   0x00001ed9 <+89>:    mov    $0x10,%esi
   0x00001ede <+94>:    movswl -0x12(%ebp),%ecx
   0x00001ee2 <+98>:    mov    %edx,(%esp)
   0x00001ee5 <+101>:   mov    %ecx,0x4(%esp)
   0x00001ee9 <+105>:   movl   $0x10,0x8(%esp)
   0x00001ef1 <+113>:   mov    %eax,-0x20(%ebp)
   0x00001ef4 <+116>:   mov    %esi,-0x24(%ebp)
   0x00001ef7 <+119>:   call   0x1f5a
   0x00001efc <+124>:   mov    -0x18(%ebp),%ecx
   0x00001eff <+127>:   lea    0x110(%ecx),%edx
   0x00001f05 <+133>:   mov    $0x8,%esi
   0x00001f0a <+138>:   movsbl -0x13(%ebp),%ecx
   0x00001f0e <+142>:   mov    %edx,(%esp)
   0x00001f11 <+145>:   mov    %ecx,0x4(%esp)
   0x00001f15 <+149>:   movl   $0x8,0x8(%esp)
   0x00001f1d <+157>:   mov    %eax,-0x28(%ebp)
   0x00001f20 <+160>:   mov    %esi,-0x2c(%ebp)
   0x00001f23 <+163>:   call   0x1f5a
   0x00001f28 <+168>:   mov    %eax,-0x30(%ebp)
   0x00001f2b <+171>:   add    $0x3c,%esp
   0x00001f2e <+174>:   pop    %esi
   0x00001f2f <+175>:   pop    %edi
   0x00001f30 <+176>:   pop    %ebx
   0x00001f31 <+177>:   pop    %ebp
   0x00001f32 <+178>:   ret    
End of assembler dump.
(gdb)反汇编f
函数f的汇编程序代码转储:
0x00001e80:推送%ebp
0x00001e81:mov%esp,%ebp
0x00001e83:推送%ebx
0x00001e84:推送%edi
0x00001e85:推送%esi
0x00001e86:子$0x3c,%esp
0x00001e89:调用0x1e8e
0x00001e8e:弹出%eax
0x00001e8f:lea 0xe8(%eax),%ecx
0x00001e95:mov$0x20,%edx
0x00001e9a:movl$0xdeadbeef,-0x10(%ebp)
0x00001ea1:mov-0x10(%ebp),%esi
0x00001ea4:mov%si,%di
0x00001ea7:mov%di,-0x12(%ebp)
0x00001eab:mov-0x10(%ebp),%esi
0x00001AE:mov%esi,%ebx
0x00001eb0:mov%bl,-0x13(%ebp)
0x00001eb3:mov-0x10(%ebp),%esi
0x00001eb6:mov%ecx,(%esp)
0x00001eb9:mov%esi,0x4(%esp)
0x00001ebd:movl$0x20,0x8(%esp)
0x00001ec5:mov%eax,-0x18(%ebp)
0x00001ec8:mov%edx,-0x1c(%ebp)
0x00001ecb:调用0x1f5a
0x00001ed0:mov-0x18(%ebp),%ecx
0x00001ed3:lea 0xfc(%ecx),%edx
0x00001ed9:mov$0x10,%esi
0x00001ede:movswl-0x12(%ebp),%ecx
0x00001ee2:mov%edx,(%esp)
0x00001ee5:mov%ecx,0x4(%esp)
0x00001ee9:movl$0x10,0x8(%esp)
0x00001ef1:mov%eax,-0x20(%ebp)
0x00001ef4:mov%esi,-0x24(%ebp)
0x00001ef7:调用0x1f5a
0x00001efc:mov-0x18(%ebp),%ecx
0x00001eff:lea 0x110(%ecx),%edx
0x00001f05:mov$0x8,%esi
0x00001f0a:movsbl-0x13(%ebp),%ecx
0x00001f0e:mov%edx,(%esp)
0x00001f11:mov%ecx,0x4(%esp)
0x00001f15:movl$0x8,0x8(%esp)
0x00001f1d:mov%eax,-0x28(%ebp)
0x00001f20:mov%esi,-0x2c(%ebp)
0x00001f23:调用0x1f5a
0x00001f28:mov%eax,-0x30(%ebp)
0x00001f2b:添加$0x3c,%esp
0x00001f2e:pop%esi
0x00001f2f:弹出%edi
0x00001f30:弹出%ebx
0x00001f31:弹出%ebp
0x00001f32:ret
汇编程序转储结束。

这是一个生成位置无关代码的技巧。您可以看到下一条指令是
pop%eax
,它将从堆栈中获取返回地址。当然,返回地址是
pop
本身的地址,因此这会得到指令的绝对地址,因此它可以用作访问与代码相关的内容的基础

它立即用于获取第一个
printf
调用的第一个参数,即文本格式字符串。您可以看到,
ecx
是基于
eax
+15
行加载的,然后按照调用约定,
ecx
被写入第一个参数槽中
+54行的堆栈中


参考点也存储在
+69
线上的
-0x18(%ebp)
处。与第一个
printf
一样,它随后被用于后续格式字符串,请参见第
+83行和第
+127行
%eax
加载指令绝对地址=
0x00001e8e
(或
)。地址
0x00001e8e+0xe8
中应该显示什么?i、 e.为什么该地址的内容被加载到
%ecx
?(根据地址
的说明,对不起,我错过了代码如何使用它。请参阅更新的答案。注意,使用
gcc-S
应该会生成更可读的代码,您甚至可以看到引用的格式字符串。