歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> uclinux-2008R1-RC8(bf561)到VDSP5的移植(42):__bad_size的問題

uclinux-2008R1-RC8(bf561)到VDSP5的移植(42):__bad_size的問題

日期:2017/3/3 16:43:29   编辑:關於Linux

在編譯內核時,有一個鏈接錯誤:

[Error li1021] The following symbols referenced in processor 'p0' could not be resolved:
        '__bad_size [___bad_size]' referenced from 'mm.dlb[slab.doj]'

引用__bad_size函數的是:

/*
* This function must be completely optimized away if a constant is passed to
* it. Mostly the same as what is in linux/slab.h except it returns an index.
*/
static __always_inline int index_of(const size_t size)
{
extern void __bad_size(void);
if (__builtin_constant_p(size)) {
int i = 0;
#define CACHE(x) /
if (size <=x) /
return i; /
else /
i++;
#include "linux/kmalloc_sizes.h"
#undef CACHE
__bad_size();
} else {
__bad_size();
}
return 0;
}

但是在整個內核源代碼中搜索,完全沒有__bad_size函數的實現,這是怎麼回事?

查一下引用這個函數的地方:

#define INDEX_AC index_of(sizeof(struct arraycache_init))
#define INDEX_L3 index_of(sizeof(struct kmem_list3))

除此以外沒有其它地方用到。

我們知道sizeof(struct arraycache_init)和sizeof(struct kmem_list3)是在編譯時就可以確定的常數,當這兩個參數傳遞到index_of之後,由於__builtin_constant_p的關系,它將執行if裡面的內容。

把這裡面的宏展開,就變成了:

if (size <=32)
         return i;
     else
         i++;
     if (size <=64)
         return i;
     else
         i++;
     if (size <=96)
         return i;
     else
         i++;

因而,在打開GCC優化的時候,這個函數實際就變成了一個常數,最後的__bad_size或者if判斷都將被優化掉!

在沒有打開優化的時候,__bad_size仍將做為一個函數調用保留,此時鏈接必然出錯!

這也是在這個函數頭注釋的意思!

回到VDSP5上來,我們希望用VDSP5來調試內核,因此自然不可能打開優化,況且VDSP5也不支持__builtin_constant_p。因此直接修改這兩個宏定義:

#define INDEX_AC 0 //index_of(sizeof(struct arraycache_init))
#define INDEX_L3 1 //index_of(sizeof(struct kmem_list3))

Copyright © Linux教程網 All Rights Reserved