- 論壇徽章:
- 1
|
本帖最后由 mrpre 于 2015-04-30 20:01 編輯
首先是這樣的,我在一個(gè)文件里面 定義了一個(gè)函數(shù)指針:
s32 (*test_func_ptr)(void * buf, s32 len, void * session) = dummy_func();
我需要在另外一個(gè)文件使用該函數(shù),第一次向下面一樣使用(死的稀里嘩啦的)
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這個(gè)符號(hào)
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);
這下總對(duì)了吧,果然,不再panic
但是問題來了,我查看了一下 test_func 對(duì)應(yīng)的匯編代碼。。。居然和上面的沒區(qū)別(基本沒區(qū)別)。
[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這個(gè)符號(hào),我覺得應(yīng)該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
我對(duì)底層的東西不太平白,覺得如果和“編譯”沒關(guān)系的話,是不是和“鏈接”有關(guān)系?
望有大神釋疑。 |
|