- 论坛徽章:
- 1
|
本帖最后由 mrpre 于 2015-04-30 20:01 编辑
首先是这样的,我在一个文件里面 定义了一个函数指针:
s32 (*test_func_ptr)(void * buf, s32 len, void * session) = dummy_func();
我需要在另外一个文件使用该函数,第一次向下面一样使用(死的稀里哗啦的)
extern s32 test_func_ptr(void * buf, s32 len, void * session);
int test_func()
{
void *ptr1, *ptr2;
int a;
test_func_ptr(ptr1, a, ptr2);
return 0;
}
panic了。我看了一下汇编
0xffffffffc0380198 test_func: daddiu sp,sp,-16
0xffffffffc038019c test_func+0x4: lui v0,0xc045
0xffffffffc03801a0 test_func+0x8: move a0,zero
0xffffffffc03801a4 test_func+0xc: move a1,zero
0xffffffffc03801a8 test_func+0x10: sd ra,8(sp)
0xffffffffc03801ac test_func+0x14: daddiu v0,v0,30544
0xffffffffc03801b0 test_func+0x18: jalr v0 //v0 是 test_func_ptr这个符号
0xffffffffc03801b4 test_func+0x1c: move a2,zero
0xffffffffc03801b8 test_func+0x20: ld ra,8(sp)
0xffffffffc03801bc test_func+0x24: move v0,zero
0xffffffffc03801c0 test_func+0x28: jr ra
0xffffffffc03801c4 test_func+0x2c: daddiu sp,sp,16
[0]kdb> 0xffffffffc0450000+30544
0xffffffffc0450000 = 0xffffffffc0457750 ([modlue_net] test_func_ptr)
然后我把 extern s32 test_func_ptr(void * buf, s32 len, void * session);
变换为 extern s32 (*test_func_ptr)(void * buf, s32 len, void * session);
这下总对了吧,果然,不再panic
但是问题来了,我查看了一下 test_func 对应的汇编代码。。。居然和上面的没区别(基本没区别)。
[0]kdb> id test_func
0xffffffffc037d040 test_func: lui v0,0xc045
0xffffffffc037d044 test_func+0x4: daddiu sp,sp,-16
0xffffffffc037d048 test_func+0x8: move a0,zero
0xffffffffc037d04c test_func+0xc: move a1,zero
0xffffffffc037d050 test_func+0x10: ld v0,30544(v0)
0xffffffffc037d054 test_func+0x14: sd ra,8(sp)
0xffffffffc037d058 test_func+0x18: jalr v0 //v0 还是 test_func_ptr这个符号,我觉得应该jalr dummy_func
0xffffffffc037d05c test_func+0x1c: move a2,zero
0xffffffffc037d060 test_func+0x20: ld ra,8(sp)
0xffffffffc037d064 test_func+0x24: move v0,zero
0xffffffffc037d068 test_func+0x28: jr ra
0xffffffffc037d06c test_func+0x2c: daddiu sp,sp,16
我对底层的东西不太平白,觉得如果和“编译”没关系的话,是不是和“链接”有关系?
望有大神释疑。 |
|