Linux 内核头中的错误

发布于 2024-11-08 14:50:32 字数 1469 浏览 4 评论 0原文

我正在尝试编译一个库,其中包含 kernel-devel 包中的一些标头。我链接了适当的头文件,但现在这些头文件中出现编译错误。

/usr/include/asm-generic/bitops/fls64.h: In function ‘int fls64(__u64)’:
/usr/include/asm-generic/bitops/fls64.h:10: error: ‘fls’ was not declared in this scope
/usr/include/asm-generic/bitops/fls64.h:11: error: ‘fls’ was not declared in this scope

而且,这里是来自 asm-generic/bitops/fls64.h 的代码

#ifndef _ASM_GENERIC_BITOPS_FLS64_H_
#define _ASM_GENERIC_BITOPS_FLS64_H_

#include <asm/types.h>

static inline int fls64(__u64 x)
{
        __u32 h = x >> 32;
        if (h)
                return fls(h) + 32;
        return fls(x);
}

#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */

,您可以注意到“return fls(h)”,没有 fls() 的定义。我可以通过包含“fls.h”来解决这个问题,但是我是否应该修复标准内核头中的此类错误?

有任何指针可以解释为什么会这样以及我能做些什么来解决这些问题吗?顺便说一句,我在这里提到的错误只是冰山一角。在多个此类标头中存在很多此类(声明缺失)错误。

帮助将不胜感激。谢谢!

rgds/R。

PS:一些系统详细信息:

Linux发行版:CentOS(5.5)

[raj@localhost common]$ uname -a
Linux localhost.localdomain 2.6.18-238.9.1.el5 #1 SMP Tue Apr 12 18:10:56 EDT 2011 i686 i686 i386 GNU/Linux

[raj@localhost common]$ cat /proc/version 
Linux version 2.6.18-238.9.1.el5 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Tue Apr 12 18:10:56 EDT 2011

I'm trying to compile a library which includes some headers from kernel-devel package. I linked the appropriate headers, but now I get compilation errors in those header files.

/usr/include/asm-generic/bitops/fls64.h: In function ‘int fls64(__u64)’:
/usr/include/asm-generic/bitops/fls64.h:10: error: ‘fls’ was not declared in this scope
/usr/include/asm-generic/bitops/fls64.h:11: error: ‘fls’ was not declared in this scope

And, here are the code from asm-generic/bitops/fls64.h

#ifndef _ASM_GENERIC_BITOPS_FLS64_H_
#define _ASM_GENERIC_BITOPS_FLS64_H_

#include <asm/types.h>

static inline int fls64(__u64 x)
{
        __u32 h = x >> 32;
        if (h)
                return fls(h) + 32;
        return fls(x);
}

#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */

As you can notice "return fls(h)", there's no definition of fls(). I can resolve this by including "fls.h", but am I suppose to fix such errors in standard Kernel headers??

Any pointers which could explain why is it this way and what can I do to get around such issues?? Btw, the errors I mentioned here are just the tip of the iceberg. There are a lot of such (delcaration missing) errors in multiple such headers.

Help would be greatly appreciated. Thanks!

rgds/R.

PS: some system details:

Linux Distribution: CentOS (5.5)

[raj@localhost common]$ uname -a
Linux localhost.localdomain 2.6.18-238.9.1.el5 #1 SMP Tue Apr 12 18:10:56 EDT 2011 i686 i686 i386 GNU/Linux

[raj@localhost common]$ cat /proc/version 
Linux version 2.6.18-238.9.1.el5 ([email protected]) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Tue Apr 12 18:10:56 EDT 2011

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

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

发布评论

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

评论(1

一笔一画续写前缘 2024-11-15 14:50:32

问题的根源在于您使用的头文件 是内部内核实现的一部分,根本不打算由用户空间使用。事实上,即使在内核中,这个头文件也应该包含在像 arch/XXX/include/bitops.h 这样的头文件中,以提供 fls64() 的通用实现基于特定于架构的代码中定义的 fls()

换句话说,该库存在一个问题,即它依赖于内核内部结构,而这些内核内部结构并未真正导出到用户空间以供使用,因此可能会因各种内核版本而中断;该库很可能已经针对某些较旧的内核构建得很好,但这只是运气。

正确的修复实际上是让库提供自己的 fls64 定义,而不是依赖于幸运地碰巧偶然定义了某些随机版本的内核头文件。

The root of the problem is that you are using a header file <asm-generic/fls64.h> that is part of the internal kernel implementation and not intended to be used by userspace at all. In fact even in the kernel this header file is just supposed to be included by headers like arch/XXX/include/bitops.h to provide a generic implementation of fls64() based on the fls() defined in architecture-specific code.

In other words the library has a problem in that it is depending on kernel internals that are not really exported to userspace for use and therefore may break for various kernel versions; the library may well have built OK against some older kernel but this was just by luck.

The correct fix is really for the library to provide its own fls64 definition rather than relying on getting lucky about what some random version of kernel headers happens to define by accident.

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