ELF文件之六——使用链接脚本-2个函数-data-bss-temp

main.c

int enable;
int test = 1;

int main()
{
    int temp;
    
    return 0;
}

int add()
{
    return 0;
}
View Code

elf反汇编结果如下,可以看出main函数中的栈多开了8字节,虽然局部变量只是int,占4字节

这是因为堆栈是要求8字节对齐的,为了能够使用更高效的LDD,STD指令,v8 manual,p191.

The stack pointer %sp must always be doubleword-aligned. This allows window
overflow and underflow trap handlers to use the more efficient STD and LDD
instructions to store and reload register windows.
View Code

原文地址:https://www.cnblogs.com/yanhc/p/12288420.html