I have 4 sample function:
void test_func1(void)
{
return;
}
void test_func2(int a)
{
return;
}
int test_func3(void)
{
return 0;
}
void test_func4(void)
{
int a;
a = a + 1;
return;
}
I compiled them with powerpc cross-compiler tools in vxworks, and get the following assembly code with generated elf file and "objdump -d" command.
00000f2c <test_func1>:
f2c: 94 21 ff f0 stwu r1,-16(r1)
f30: 93 e1 00 0c stw r31,12(r1)
f34: 7c 3f 0b 78 mr r31,r1
f38: 81 61 00 00 lwz r11,0(r1)
f3c: 83 eb ff fc lwz r31,-4(r11)
f40: 7d 61 5b 78 mr r1,r11
f44: 4e 80 00 20 blr
00000f48 <test_func2>:
f48: 94 21 ff e0 stwu r1,-32(r1)
f4c: 93 e1 00 1c stw r31,28(r1)
f50: 7c 3f 0b 78 mr r31,r1
f54: 90 7f 00 08 stw r3,8(r31)
f58: 81 61 00 00 lwz r11,0(r1)
f5c: 83 eb ff fc lwz r31,-4(r11)
f60: 7d 61 5b 78 mr r1,r11
f64: 4e 80 00 20 blr
00000f68 <test_func3>:
f68: 94 21 ff f0 stwu r1,-16(r1)
f6c: 93 e1 00 0c stw r31,12(r1)
f70: 7c 3f 0b 78 mr r31,r1
f74: 38 00 00 00 li r0,0
f78: 7c 03 03 78 mr r3,r0
f7c: 81 61 00 00 lwz r11,0(r1)
f80: 83 eb ff fc lwz r31,-4(r11)
f84: 7d 61 5b 78 mr r1,r11
f88: 4e 80 00 20 blr
00000f8c <test_func4>:
f8c: 94 21 ff d0 stwu r1,-48(r1)
f90: 93 e1 00 2c stw r31,44(r1)
f94: 7c 3f 0b 78 mr r31,r1
f98: 81 3f 00 08 lwz r9,8(r31)
f9c: 38 09 00 01 addi r0,r9,1
fa0: 90 1f 00 08 stw r0,8(r31)
fa4: 81 61 00 00 lwz r11,0(r1)
fa8: 83 eb ff fc lwz r31,-4(r11)
fac: 7d 61 5b 78 mr r1,r11
fb0: 4e 80 00 20 blr
At last, I use a stack check tools in linux kernel script dircetory checkstack.pl, and get them stack useage:
0x0f8c test_func4 [filecheck2.o]: 48
0x0f48 test_func2 [filecheck2.o]: 32
0x0f2c test_func1 [filecheck2.o]: 16
0x0f68 test_func3 [filecheck2.o]: 16
The stack size is result of assembly code to first statement
f2c: 94 21 ff f0 stwu r1,-16(r1)
f48: 94 21 ff e0 stwu r1,-32(r1)
f68: 94 21 ff f0 stwu r1,-16(r1)
f8c: 94 21 ff d0 stwu r1,-48(r1)
My question is why the stack useage is different? especailly the function "test_func2" and "test_func4"?
My question is why the stack useage is different? especailly the function "test_func2" and "test_func4"?
Hint: test_func2 accpets one argument test_func4 has a local variable in it.