07-24-2023, 07:13 AM
**Suppose I have a function like below:**
# cat 003.c
int foo(int a, int b)
{
return a+b;
}
**And compile it like this:**
gcc -S 003.c
**The gets the following assembly result:**
.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?*/
The last line above do get the size of the function. Where does the compiler store the size? Can I get the function's size in some way in my origin C program using <b>C or inline asm</b>?
# cat 003.c
int foo(int a, int b)
{
return a+b;
}
**And compile it like this:**
gcc -S 003.c
**The gets the following assembly result:**
.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?*/
The last line above do get the size of the function. Where does the compiler store the size? Can I get the function's size in some way in my origin C program using <b>C or inline asm</b>?