首页 > 解决方案 > 协助了解linux_start

问题描述

000003b0 <_start>:
 3b0:   31 ed                   xor    %ebp,%ebp
 3b2:   5e                      pop    %esi
 3b3:   89 e1                   mov    %esp,%ecx
 3b5:   83 e4 f0                and    $0xfffffff0,%esp
 3b8:   50                      push   %eax
 3b9:   54                      push   %esp
 3ba:   52                      push   %edx
 3bb:   e8 22 00 00 00          call   3e2 <_start+0x32>
 3c0:   81 c3 1c 1c 00 00       add    $0x1c1c,%ebx
 3c6:   8d 83 94 e5 ff ff       lea    -0x1a6c(%ebx),%eax
 3cc:   50                      push   %eax
 3cd:   8d 83 34 e5 ff ff       lea    -0x1acc(%ebx),%eax
 3d3:   50                      push   %eax
 3d4:   51                      push   %ecx
 3d5:   56                      push   %esi
 3d6:   ff b3 1c 00 00 00       pushl  0x1c(%ebx)
 3dc:   e8 af ff ff ff          call   390 <__libc_start_main@plt>
 3e1:   f4                      hlt    
 3e2:   8b 1c 24                mov    (%esp),%ebx
 3e5:   c3                      ret    
 3e6:   66 90                   xchg   %ax,%ax
 3e8:   66 90                   xchg   %ax,%ax
 3ea:   66 90                   xchg   %ax,%ax
 3ec:   66 90                   xchg   %ax,%ax
 3ee:   66 90                   xchg   %ax,%ax

嘿,伙计们,请帮我理解 addr 3b8 之后的这段代码片段。我可以猜到它在做什么,但不是很具体。

顺便说一句,如果你们有任何线索教我如何在特定代码上弄清楚 Linux 调用系统的实现,请告诉我。谢谢。

在检查了 ABI 文档后,仍然不太明白为什么它会跳转到 3e2,因为他们似乎什么也没做,只是跳了回来。

标签: linuxassemblyx86main

解决方案


查看 i386 System V ABI 文档。(https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI)。它还详细记录了函数调用约定。(它变得很激烈,有时只看 GCC 如何-O2编译参数传递或按值返回结构会更容易。例如在https://godbolt.org/上)

它指定入口的用户空间堆栈布局_start。例如,ESP 指向argc,并且argv[]在其上方(数组内容,而不是指针)。 envp[]以上。另请注意,在动态链接的可执行文件中,_start是从动态链接器自己的启动代码跳转到的。这就是 atexit 指针的来源。

另请注意,这是一个 PIE 可执行文件,因此它将返回地址转换为 EBX,以便使用call 3e2.


推荐阅读