有没有办法让 Splint 或类似的静态检查器与 Linux 内核模块一起工作?

发布于 2024-08-08 09:42:07 字数 847 浏览 8 评论 0原文

我从“Linux 内核模块编程指南”,当我尝试 insmod 它时,我收到以下错误:

insmod: error inserting 'hello-5.ko': -1 Unknown symbol in module

我以为我会尝试 splint 看看它是否出现任何明显的错误,但是当我运行我从内核头中收到了一系列警告,直到它在尝试解析 asm/types.h 时失败。

anon@anon:~/kernel-source/lkmpg$ splint -I/lib/modules/$(uname -r)/build/include hello-5.c
Splint 3.1.1 --- 03 Nov 2006

( ... lots of warnings ... )

/lib/modules/2.6.24-24-insp8600/build/include/asm/types.h:13:24: Parse Error:
    Suspect missing struct or union keyword: __signed__ :
    unsigned short int. (For help on parse errors, see splint -help
    parseerrors.)
*** Cannot continue.

所以实际上有两个问题:

  1. 如何修复 insmod 错误?
  2. 如何让夹板与内核头文件配合良好?

I compiled ( no warnings ) the hello-5.c example from "The Linux Kernel Module Programming Guide" and when I tried to insmod it, I received the following error:

insmod: error inserting 'hello-5.ko': -1 Unknown symbol in module

I thought I would try splint to see if it came up with any obvious errors, but when I ran it I got a slew of warnings from the kernel headers until it barfed trying to parse asm/types.h

anon@anon:~/kernel-source/lkmpg$ splint -I/lib/modules/$(uname -r)/build/include hello-5.c
Splint 3.1.1 --- 03 Nov 2006

( ... lots of warnings ... )

/lib/modules/2.6.24-24-insp8600/build/include/asm/types.h:13:24: Parse Error:
    Suspect missing struct or union keyword: __signed__ :
    unsigned short int. (For help on parse errors, see splint -help
    parseerrors.)
*** Cannot continue.

So really there are two questions:

  1. How do I fix the insmod error?
  2. How do I get splint to play nice with the kernel headers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星光不落少年眉 2024-08-15 09:42:07

有趣的。目前,我坐在办公室里,尝试在 Linux 内核驱动程序上运行静态检查器:)

静态检查器很难处理 Linux 内核,因为内核代码中使用的 C 方言比通常理解的“C 语言”更广泛。有时,检查器的 C 前端无法解析代码中使用的不断变化的结构。

据我所知,您只是使用了过时版本的检查器(03 Nov 2006),但您的内核版本也过时了,我不知道哪个版本更旧。可能有帮助的是将检查器更新到当前版本,或者使用最新的 C 前端(如果检查器支持切换)。

此外,如果一个检查器可以处理Linux内核,那么这个事实就会在检查器的主页上大肆吹嘘。因此,选择一个声称拥有该权利的人并进行检查。

Funny. Currently I'm sitting in the office and trying to run a static checker on Linux Kernel drivers :)

Static checkers have a hard time processing linux kernel, because C dialect used in kernel code is broader than the one commonly understood as "C language". It sometimes happens that C front-end of a checker just can't parse ever-changing constructs used in the code.

As I could understand, you simply use an outdated version of the checker (03 Nov 2006), but your kernel version is outdated too, and I don't know which is older. What may help is updating the checker to its current version, or using up-to-date C front-end, if the checker supports switching it.

Moreover, if a checker can process Linux kernel, the fact outright becomes being bragged about on the checker's homepage. So, pick one that claims it and do your checks.

小姐丶请自重 2024-08-15 09:42:07

我不确定,但这可能就是我正在寻找的:

splint-discuss 在 Linux 内核模块上使用 Splint

它提供了一个自定义 make 文件来帮助 splint 通过内核中使用的 gcc 特定扩展。

I'm not sure but this might be what I'm looking for:

splint-discuss Using Splint on Linux kernel modules

It provides a custom make file to help splint get through the gcc specific extensions used in the Kernel.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文