辅助理解linux_start

Assist to understand 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    [=11=]xfffffff0,%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    [=11=]x1c1c,%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 doc,还是不太明白为什么会跳到3e2,因为好像除了跳回去什么都没做。

查看 i386 System V ABI 文档。 (https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI). It also documents the function-calling convention in complete detail. (It gets intense, sometimes it's easier to just look at how GCC -O2 compiles arg-passing or return of a struct by value. e.g. on https://godbolt.org/)

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

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

进行 PC 相对寻址