https://www.cnblogs.com/xiaojianliu/articles/8733560.html

文章目录

  • `vi test.c`
  • `gcc test.c -g`
  • `objdump -dS a.out`
  • 查看关键部分:
  • esp 与 ebp

vi test.c

int bar(int c, int d)
{ int e = c + d;return e;
}int foo(int a, int b)
{return bar(a, b);
}int main(void)
{foo(2, 3);return 0;
}

gcc test.c -g

objdump -dS a.out

注意大小写

dontla@dontla-virtual-machine:~/桌面/test$ objdump -dS a.outa.out:     文件格式 elf64-x86-64Disassembly of section .init:0000000000001000 <_init>:1000:  f3 0f 1e fa             endbr64 1004:   48 83 ec 08             sub    $0x8,%rsp1008:   48 8b 05 d9 2f 00 00    mov    0x2fd9(%rip),%rax        # 3fe8 <__gmon_start__>100f:  48 85 c0                test   %rax,%rax1012:   74 02                   je     1016 <_init+0x16>1014:    ff d0                   callq  *%rax1016:   48 83 c4 08             add    $0x8,%rsp101a:   c3                      retq   Disassembly of section .plt:0000000000001020 <.plt>:1020:  ff 35 a2 2f 00 00       pushq  0x2fa2(%rip)        # 3fc8 <_GLOBAL_OFFSET_TABLE_+0x8>1026:   f2 ff 25 a3 2f 00 00    bnd jmpq *0x2fa3(%rip)        # 3fd0 <_GLOBAL_OFFSET_TABLE_+0x10>102d:   0f 1f 00                nopl   (%rax)Disassembly of section .plt.got:0000000000001030 <__cxa_finalize@plt>:1030: f3 0f 1e fa             endbr64 1034:   f2 ff 25 bd 2f 00 00    bnd jmpq *0x2fbd(%rip)        # 3ff8 <__cxa_finalize@GLIBC_2.2.5>103b:   0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)Disassembly of section .text:0000000000001040 <_start>:1040:   f3 0f 1e fa             endbr64 1044:   31 ed                   xor    %ebp,%ebp1046:   49 89 d1                mov    %rdx,%r91049:    5e                      pop    %rsi104a:    48 89 e2                mov    %rsp,%rdx104d:   48 83 e4 f0             and    $0xfffffffffffffff0,%rsp1051:    50                      push   %rax1052:    54                      push   %rsp1053:    4c 8d 05 a6 01 00 00    lea    0x1a6(%rip),%r8        # 1200 <__libc_csu_fini>105a:   48 8d 0d 2f 01 00 00    lea    0x12f(%rip),%rcx        # 1190 <__libc_csu_init>1061:  48 8d 3d 02 01 00 00    lea    0x102(%rip),%rdi        # 116a <main>1068: ff 15 72 2f 00 00       callq  *0x2f72(%rip)        # 3fe0 <__libc_start_main@GLIBC_2.2.5>106e:  f4                      hlt    106f:    90                      nop0000000000001070 <deregister_tm_clones>:1070:  48 8d 3d 99 2f 00 00    lea    0x2f99(%rip),%rdi        # 4010 <__TMC_END__>1077: 48 8d 05 92 2f 00 00    lea    0x2f92(%rip),%rax        # 4010 <__TMC_END__>107e: 48 39 f8                cmp    %rdi,%rax1081:   74 15                   je     1098 <deregister_tm_clones+0x28>1083: 48 8b 05 4e 2f 00 00    mov    0x2f4e(%rip),%rax        # 3fd8 <_ITM_deregisterTMCloneTable>108a: 48 85 c0                test   %rax,%rax108d:   74 09                   je     1098 <deregister_tm_clones+0x28>108f: ff e0                   jmpq   *%rax1091:   0f 1f 80 00 00 00 00    nopl   0x0(%rax)1098:   c3                      retq   1099:    0f 1f 80 00 00 00 00    nopl   0x0(%rax)00000000000010a0 <register_tm_clones>:10a0:   48 8d 3d 69 2f 00 00    lea    0x2f69(%rip),%rdi        # 4010 <__TMC_END__>10a7: 48 8d 35 62 2f 00 00    lea    0x2f62(%rip),%rsi        # 4010 <__TMC_END__>10ae: 48 29 fe                sub    %rdi,%rsi10b1:   48 89 f0                mov    %rsi,%rax10b4:   48 c1 ee 3f             shr    $0x3f,%rsi10b8:  48 c1 f8 03             sar    $0x3,%rax10bc:   48 01 c6                add    %rax,%rsi10bf:   48 d1 fe                sar    %rsi10c2:    74 14                   je     10d8 <register_tm_clones+0x38>10c4:   48 8b 05 25 2f 00 00    mov    0x2f25(%rip),%rax        # 3ff0 <_ITM_registerTMCloneTable>10cb:   48 85 c0                test   %rax,%rax10ce:   74 08                   je     10d8 <register_tm_clones+0x38>10d0:   ff e0                   jmpq   *%rax10d2:   66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)10d8:    c3                      retq   10d9:    0f 1f 80 00 00 00 00    nopl   0x0(%rax)00000000000010e0 <__do_global_dtors_aux>:10e0:    f3 0f 1e fa             endbr64 10e4:   80 3d 25 2f 00 00 00    cmpb   $0x0,0x2f25(%rip)        # 4010 <__TMC_END__>10eb: 75 2b                   jne    1118 <__do_global_dtors_aux+0x38>10ed:    55                      push   %rbp10ee:    48 83 3d 02 2f 00 00    cmpq   $0x0,0x2f02(%rip)        # 3ff8 <__cxa_finalize@GLIBC_2.2.5>10f5: 00 10f6:    48 89 e5                mov    %rsp,%rbp10f9:   74 0c                   je     1107 <__do_global_dtors_aux+0x27>10fb:    48 8b 3d 06 2f 00 00    mov    0x2f06(%rip),%rdi        # 4008 <__dso_handle>1102:    e8 29 ff ff ff          callq  1030 <__cxa_finalize@plt>1107:    e8 64 ff ff ff          callq  1070 <deregister_tm_clones>110c:   c6 05 fd 2e 00 00 01    movb   $0x1,0x2efd(%rip)        # 4010 <__TMC_END__>1113: 5d                      pop    %rbp1114:    c3                      retq   1115:    0f 1f 00                nopl   (%rax)1118:  c3                      retq   1119:    0f 1f 80 00 00 00 00    nopl   0x0(%rax)0000000000001120 <frame_dummy>:1120:  f3 0f 1e fa             endbr64 1124:   e9 77 ff ff ff          jmpq   10a0 <register_tm_clones>0000000000001129 <bar>:
int bar(int c, int d)
{1129:  f3 0f 1e fa             endbr64 112d:   55                      push   %rbp112e:    48 89 e5                mov    %rsp,%rbp1131:   89 7d ec                mov    %edi,-0x14(%rbp)1134:    89 75 e8                mov    %esi,-0x18(%rbp)int e = c + d;1137:    8b 55 ec                mov    -0x14(%rbp),%edx113a:    8b 45 e8                mov    -0x18(%rbp),%eax113d:    01 d0                   add    %edx,%eax113f:   89 45 fc                mov    %eax,-0x4(%rbp)return e;1142:    8b 45 fc                mov    -0x4(%rbp),%eax
}1145:  5d                      pop    %rbp1146:    c3                      retq   0000000000001147 <foo>:int foo(int a, int b)
{1147:  f3 0f 1e fa             endbr64 114b:   55                      push   %rbp114c:    48 89 e5                mov    %rsp,%rbp114f:   48 83 ec 08             sub    $0x8,%rsp1153:   89 7d fc                mov    %edi,-0x4(%rbp)1156: 89 75 f8                mov    %esi,-0x8(%rbp)return bar(a, b);1159:    8b 55 f8                mov    -0x8(%rbp),%edx115c: 8b 45 fc                mov    -0x4(%rbp),%eax115f: 89 d6                   mov    %edx,%esi1161:   89 c7                   mov    %eax,%edi1163:   e8 c1 ff ff ff          callq  1129 <bar>
}1168:  c9                      leaveq 1169:    c3                      retq   000000000000116a <main>:int main(void)
{116a:  f3 0f 1e fa             endbr64 116e:   55                      push   %rbp116f:    48 89 e5                mov    %rsp,%rbpfoo(2, 3);1172: be 03 00 00 00          mov    $0x3,%esi1177:   bf 02 00 00 00          mov    $0x2,%edi117c:   e8 c6 ff ff ff          callq  1147 <foo>return 0;1181:   b8 00 00 00 00          mov    $0x0,%eax
}1186:  5d                      pop    %rbp1187:    c3                      retq   1188:    0f 1f 84 00 00 00 00    nopl   0x0(%rax,%rax,1)118f:    00 0000000000001190 <__libc_csu_init>:1190:   f3 0f 1e fa             endbr64 1194:   41 57                   push   %r151196:    4c 8d 3d 53 2c 00 00    lea    0x2c53(%rip),%r15        # 3df0 <__frame_dummy_init_array_entry>119d:  41 56                   push   %r14119f:    49 89 d6                mov    %rdx,%r1411a2:   41 55                   push   %r1311a4:    49 89 f5                mov    %rsi,%r1311a7:   41 54                   push   %r1211a9:    41 89 fc                mov    %edi,%r12d11ac:  55                      push   %rbp11ad:    48 8d 2d 44 2c 00 00    lea    0x2c44(%rip),%rbp        # 3df8 <__do_global_dtors_aux_fini_array_entry>11b4:  53                      push   %rbx11b5:    4c 29 fd                sub    %r15,%rbp11b8:   48 83 ec 08             sub    $0x8,%rsp11bc:   e8 3f fe ff ff          callq  1000 <_init>11c1:  48 c1 fd 03             sar    $0x3,%rbp11c5:   74 1f                   je     11e6 <__libc_csu_init+0x56>11c7:  31 db                   xor    %ebx,%ebx11c9:   0f 1f 80 00 00 00 00    nopl   0x0(%rax)11d0:   4c 89 f2                mov    %r14,%rdx11d3:   4c 89 ee                mov    %r13,%rsi11d6:   44 89 e7                mov    %r12d,%edi11d9:  41 ff 14 df             callq  *(%r15,%rbx,8)11dd:  48 83 c3 01             add    $0x1,%rbx11e1:   48 39 dd                cmp    %rbx,%rbp11e4:   75 ea                   jne    11d0 <__libc_csu_init+0x40>11e6:  48 83 c4 08             add    $0x8,%rsp11ea:   5b                      pop    %rbx11eb:    5d                      pop    %rbp11ec:    41 5c                   pop    %r1211ee:    41 5d                   pop    %r1311f0:    41 5e                   pop    %r1411f2:    41 5f                   pop    %r1511f4:    c3                      retq   11f5:    66 66 2e 0f 1f 84 00    data16 nopw %cs:0x0(%rax,%rax,1)11fc:   00 00 00 00 0000000000001200 <__libc_csu_fini>:1200:  f3 0f 1e fa             endbr64 1204:   c3                      retq   Disassembly of section .fini:0000000000001208 <_fini>:1208:    f3 0f 1e fa             endbr64 120c:   48 83 ec 08             sub    $0x8,%rsp1210:   48 83 c4 08             add    $0x8,%rsp1214:   c3                      retq   

查看关键部分:

0000000000001129 <bar>:
int bar(int c, int d)
{1129:  f3 0f 1e fa             endbr64 112d:   55                      push   %rbp112e:    48 89 e5                mov    %rsp,%rbp1131:   89 7d ec                mov    %edi,-0x14(%rbp)1134:    89 75 e8                mov    %esi,-0x18(%rbp)int e = c + d;1137:    8b 55 ec                mov    -0x14(%rbp),%edx113a:    8b 45 e8                mov    -0x18(%rbp),%eax113d:    01 d0                   add    %edx,%eax113f:   89 45 fc                mov    %eax,-0x4(%rbp)return e;1142:    8b 45 fc                mov    -0x4(%rbp),%eax
}1145:  5d                      pop    %rbp1146:    c3                      retq   0000000000001147 <foo>:int foo(int a, int b)
{1147:  f3 0f 1e fa             endbr64 114b:   55                      push   %rbp114c:    48 89 e5                mov    %rsp,%rbp114f:   48 83 ec 08             sub    $0x8,%rsp1153:   89 7d fc                mov    %edi,-0x4(%rbp)1156: 89 75 f8                mov    %esi,-0x8(%rbp)return bar(a, b);1159:    8b 55 f8                mov    -0x8(%rbp),%edx115c: 8b 45 fc                mov    -0x4(%rbp),%eax115f: 89 d6                   mov    %edx,%esi1161:   89 c7                   mov    %eax,%edi1163:   e8 c1 ff ff ff          callq  1129 <bar>
}1168:  c9                      leaveq 1169:    c3                      retq   000000000000116a <main>:int main(void)
{116a:  f3 0f 1e fa             endbr64 116e:   55                      push   %rbp116f:    48 89 e5                mov    %rsp,%rbpfoo(2, 3);1172: be 03 00 00 00          mov    $0x3,%esi1177:   bf 02 00 00 00          mov    $0x2,%edi117c:   e8 c6 ff ff ff          callq  1147 <foo>return 0;1181:   b8 00 00 00 00          mov    $0x0,%eax
}1186:  5d                      pop    %rbp1187:    c3                      retq   1188:    0f 1f 84 00 00 00 00    nopl   0x0(%rax,%rax,1)118f:    00 

esp 与 ebp

esp是堆栈指针 
ebp是基址指针

esp和ebp详解

C语言函数调用过程的汇编分析(停更)相关推荐

  1. c语言函数调用过程中栈的工作原理理解

    差不多每个程序员都知道,函数调用过程,就是层层入栈出栈的过程. 那么这个过程中的详细的细节是什么样子的呢? 阅读了以下几篇文章之后,对整个过程基本理解了: C函数调用过程原理及函数栈帧分析 阅读经典- ...

  2. [读书笔记]C语言函数调用过程

    *** 本文是<老码识途>第一章的读书笔记 *** 函数调用 例子代码如下所示: int Add(int x, int y) {int sum;sum = x + y;return sum ...

  3. C语言高级编程:汇编分析i++和++i

    测试环境: Ubuntu 14.04 1. 代码 #include <stdio.h>int main() {int a;int b;int c;a = 1;b = a++;c = ++a ...

  4. C语言函数调用时候内存中栈的动态变化详细分析

    先了解如下几点知识和过程: * 冯诺伊曼体系计算机程序指令代码都是提前从硬盘加载进入内存从而执行的(如果是哈佛体系结构的计算机指令代码是直接在外存里面执行的,具体可以看我这篇文章,计算机冯诺伊曼体系结 ...

  5. 从汇编的角度分析函数调用过程(1)

    一. 函数参数传递形式 函数的参数传递有2种方式:堆栈方式.寄存器方式. 如果是堆栈方式传递的,就需要定义函数参数在堆栈中的传递顺序,并约定函数被调用之后,由谁来平衡堆栈: 如果是寄存器方式传递的,就 ...

  6. 函数调用过程简单分析

    C/C++函数调用过程分析 这里以一个简单的C语言代码为例,来分析函数调用过程 代码: 1 #include <stdio.h> 2 3 int func(int param1 ,int ...

  7. C函数调用过程原理及函数栈帧分析

    在x86的计算机系统中,内存空间中的栈主要用于保存函数的参数,返回值,返回地址,本地变量等.一切的函数调用都要将不同的数据.地址压入或者弹出栈.因此,为了更好地理解函数的调用,我们需要先来看看栈是怎么 ...

  8. C语言的函数调用过程(栈帧的创建与销毁)

    从汇编的角度解析函数调用过程 看看下面这个简单函数的调用过程: 1 int Add(int x,int y)2 {3 int sum = 0;4 sum = x + y;5 return sum;6 ...

  9. 深入理解C语言的函数调用过程

    深入理解C语言的函数调用过程 本文主要从进程栈空间的层面复习一下C语言中函数调用的具体过程,以加深对一些基础知识的理解.     先看一个最简单的程序: 点击(此处)折叠或打开 /*test.c*/ ...

最新文章

  1. MATLAB_10-模式识别_
  2. android handler,Android中Handler原理
  3. 蓝桥杯 Java B组 省赛决赛模拟赛 详解及小结汇总+题目下载【2013年(第4届)~2021年(第12届)】
  4. 9050 端口 linux 进程,Linux中查看某个端口占用情况
  5. python asyncio tcp server_asyncio异步IO——Streams详解
  6. [原]openstack-kilo--issue(十八) Error parsing template file: Template format version not found.
  7. wepy小程序踩坑-未发现相关 sass/less 编译器配置,请检查wepy.config.js文件
  8. BitmapFactory.decodeResource(res, id); 第一个参数跟第二个参数有什么关系?
  9. 我中的第一标:4000人中脱颖而出的威客
  10. MCGS触摸屏通过MODBUS通讯速度控制台达B2伺服参数,有触摸屏源程序和伺服设定参数,实际的项目应用的。
  11. 我们常用的软件测试工具有哪些?
  12. bat文件批量创建文件夹
  13. DCDC芯片内部模块原理
  14. GitHub怎么搜索项目
  15. vps没有mysql怎么用商店_买了vps能干什么,何不用它搭建一个5T私人网盘?
  16. 八字易经算法之用JAVA实现最简单的称骨算命法
  17. 声明$(function(){})的含义
  18. 港科夜闻|全国政协副主席梁振英一行到访香港科技大学(广州)
  19. sw转cad映射文件_SW转CAD图层映射
  20. 什么是android应用程序未安装,显示“应用程序未安装”是怎么回事?程序未安装的解决图文步骤...

热门文章

  1. CCNA Discovery第二学期 (版本 4.1)
  2. NAP客户端计算机隔离测试之五
  3. 教你获取WindowsNT的Admin权限的方法
  4. 【增强】批次特性增强案例
  5. 【温故知新】CSS学习笔记(背景)
  6. 定义定价用途的条件类型(Condition Types)
  7. SAP保存操作记录CDHDR和CDPOS表
  8. SAP Client Copy 过程
  9. MIGO时没发料不允许入库
  10. Oracle的一点注意点