在编译内核时,有一个链接错误:
[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))
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索编译
, 移植
, 内核
, size
, bad
void
,以便于您获取更多的相关知识。