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

 
快乐虾
http://blog.csdn.net/lights_joy/
 
 
本文适用于
ADI bf561 DSP
uclinux-2008r1-rc8 (移植到vdsp5)
Visual DSP++ 5.0
 
 
欢迎转载,但请保留作者信息
 
在编译内核时,有一个链接错误:
[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))

你可能感兴趣的:(uclinux-2008R1-RC8(bf561)到VDSP5的移植(42):__bad_size的问题)