获取“调用‘__bad_copy_to’”声明属性错误:复制目标大小太小”禁用优化后
这是Linux设备驱动程序的一部分。
uint32_t val = 0;
static long axpu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
...
copy_from_user(&val,(int32_t *)arg, sizeof(val));
...
}
我可以编译好的,并进行一些调试。避免某些代码被优化。我像这样更改了代码。
#pragma GCC push_options
#pragma GCC optimize ("O0")
uint32_t val = 0;
static long axpu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
...
copy_from_user(&val,(int32_t *)arg, sizeof(val)); // <-- line 364
...
}
#pragma GCC pop_options
这是我已经使用了一段时间的技巧,而且工作正常。(只是我在Linux内核代码中用于启动调试)。这次,我正在为设备驱动程序做。现在,编译器给了我这个错误。
In file included from ./arch/arm64/include/asm/preempt.h:5,
from ./include/linux/preempt.h:78,
from ./include/linux/spinlock.h:51,
from ./include/linux/seqlock.h:36,
from ./include/linux/time.h:6,
from ./arch/arm64/include/asm/stat.h:12,
from ./include/linux/stat.h:6,
from ./include/linux/module.h:10,
from /home/ckim/testlin540/axpu_ldd_kc.c:8:
In function 'check_copy_size',
inlined from 'copy_from_user' at ./include/linux/uaccess.h:143:6,
inlined from 'axpu_ioctl' at /home/ckim/testlin540/axpu_ldd_kc.c:364:4:
./include/linux/thread_info.h:160:4: error: call to '__bad_copy_to' declared with attribute error: copy destination size is too small
160 | __bad_copy_to();
| ^~~~~~~~~~~~~~~
我尝试将#pragma的内容围绕#include&llt; linux/uaccess.h&gt;
徒劳地。
有些有些说这是GCC问题,但我不确定。这是Linux-5.4.188代码,这是编译器版本。
ckim@ckim-ubuntu:~/testlin540$ aarch64-none-linux-gnu-gcc --version
aarch64-none-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16)) 10.2.1 20201103
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This is part of a linux device driver.
uint32_t val = 0;
static long axpu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
...
copy_from_user(&val,(int32_t *)arg, sizeof(val));
...
}
I can compile this ok and was doing some debug. To keep from some codes from being optimized away. I changed the code like this.
#pragma GCC push_options
#pragma GCC optimize ("O0")
uint32_t val = 0;
static long axpu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
...
copy_from_user(&val,(int32_t *)arg, sizeof(val)); // <-- line 364
...
}
#pragma GCC pop_options
This is a trick I've been using for a while and worked just fine.(just that I used in the linux kernel codes for boot debug). This time, I'm doing it for the device driver. Now the compiler gives me this error.
In file included from ./arch/arm64/include/asm/preempt.h:5,
from ./include/linux/preempt.h:78,
from ./include/linux/spinlock.h:51,
from ./include/linux/seqlock.h:36,
from ./include/linux/time.h:6,
from ./arch/arm64/include/asm/stat.h:12,
from ./include/linux/stat.h:6,
from ./include/linux/module.h:10,
from /home/ckim/testlin540/axpu_ldd_kc.c:8:
In function 'check_copy_size',
inlined from 'copy_from_user' at ./include/linux/uaccess.h:143:6,
inlined from 'axpu_ioctl' at /home/ckim/testlin540/axpu_ldd_kc.c:364:4:
./include/linux/thread_info.h:160:4: error: call to '__bad_copy_to' declared with attribute error: copy destination size is too small
160 | __bad_copy_to();
| ^~~~~~~~~~~~~~~
I tried putting the #pragma thing around #include <linux/uaccess.h>
in vain.
Some say it's gcc problem but I'm not sure. This is linux-5.4.188 code and this is the compiler version.
ckim@ckim-ubuntu:~/testlin540$ aarch64-none-linux-gnu-gcc --version
aarch64-none-linux-gnu-gcc (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16)) 10.2.1 20201103
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论