假设我有如下函数:
# cat 003.c
int foo(int a, int b)
{
return a+b;
}
Run Code Online (Sandbox Code Playgroud)
并像这样编译它:
gcc -S 003.c
Run Code Online (Sandbox Code Playgroud)
得到以下汇编结果:
.file "003.c"
.text
.globl foo
.type foo, @function
foo:
.LFB2:
pushq %rbp
.LCFI0:
movq %rsp, %rbp
.LCFI1:
movl %edi, -4(%rbp)
movl %esi, -8(%rbp)
movl -8(%rbp), %edx
movl -4(%rbp), %eax
addl %edx, %eax
leave
ret
.LFE2:
.size foo, .-foo /* size of the function foo, how to get it?*/
Run Code Online (Sandbox Code Playgroud)
上面的最后一行确实得到了函数的大小.编译器在哪里存储大小?我可以使用C或内联asm在我的原始C程序中以某种方式获取函数的大小吗?