我使用 GCC 编译了以下 C 代码并在 gdb 中反汇编为程序集。我正在使用带有 64 位 Intel i5 处理器的 Macbook pro。在“main()”中,“char* name[2]”有 2 个字符指针,应该让堆栈指针减少 2 个字(16 个字节)?但是,当我在 gdb 中反汇编时,它减少了 20 ......有人可以帮助我理解吗?C代码:
#include <stdio.h>
#include <unistd.h>
int main(void)
{
char* name[2];
name[0] = "/bin/sh";
name[1]= NULL;
execve(name[0],name,NULL);
}
gdb反汇编代码:
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov 3 21:59:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries .. done
(gdb) disassemble main
Dump of assembler code for function main:
0x0000000100000ee0 <main+0>: push %rbp
0x0000000100000ee1 <main+1>: mov %rsp,%rbp
0x0000000100000ee4 <main+4>: sub $0x20,%rsp
0x0000000100000ee8 <main+8>: lea -0x18(%rbp),%rax
0x0000000100000eec <main+12>: lea 0x61(%rip),%rcx # 0x100000f54
0x0000000100000ef3 <main+19>: mov %rcx,-0x18(%rbp)
0x0000000100000ef7 <main+23>: movq $0x0,-0x10(%rbp)
0x0000000100000eff <main+31>: mov -0x18(%rbp),%rcx
0x0000000100000f03 <main+35>: mov $0x0,%rdx
0x0000000100000f0d <main+45>: mov %rcx,%rdi
0x0000000100000f10 <main+48>: mov %rax,%rsi
0x0000000100000f13 <main+51>: callq 0x100000f22 <dyld_stub_execve>
0x0000000100000f18 <main+56>: mov -0x4(%rbp),%eax
0x0000000100000f1b <main+59>: add $0x20,%rsp
0x0000000100000f1f <main+63>: pop %rbp
0x0000000100000f20 <main+64>: retq
End of assembler dump.