内核文件中函数错误的多重定义

发布于 2024-10-19 16:31:34 字数 1609 浏览 3 评论 0原文

嘿伙计们。 我目前正在尝试做的是将工具 DigSig 移植到 CentOS 内核,该内核似乎缺少一些重要的 DigSig 加密功能。 所以这个端口我只是一个较新的 /linux/crypto.h ,它具有我需要的功能,另外我添加了这个小代码:

void kzfree(const void *p) {
    size_t ks;
    void *mem = (void *)p;

    if (unlikely(ZONP(mem)))
             return;
    ks = ksize(mem);
    memset(mem, 0, ks);
    kfree(mem);

}

因为我正在处理的内核还没有 kzfree 。 现在,当我尝试编译 DigSig 时,这是输出:

/home/Chris/dsTest/dsi_sysfs.o: In function `kzfree':
/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: multiple definition of `kzfree'
/home/Chris/dsTest/digsig.o:/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: first defined here
/home/Chris/dsTest/digsig_cache.o: In function `kzfree':
/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: multiple definition of `kzfree'
/home/Chris/dsTest/digsig.o:/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: first defined here
/home/Chris/dsTest/digsig_revocation.o: In function `kzfree':
/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: multiple definition of `kzfree'
/home/Chris/dsTest/digsig.o:/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: first defined here
/home/Chris/dsTest/dsi_sig_verify.o: In function `kzfree':
/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: multiple definition of `kzfree'
/home/Chris/dsTest/digsig.o:/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: first defined here

当然,所有内容都被 #ifndef-Guards 覆盖,所以我只是不明白为什么他多次定义这个函数...... 有什么想法吗?

Hey guys.
What I'm currently trying to do is to port the tool DigSig to a CentOS-Kernel which seems to lack a few important crypto-functions for DigSig.
So the port this I just a newer /linux/crypto.h which has the functionality I need plus I added this little code:

void kzfree(const void *p) {
    size_t ks;
    void *mem = (void *)p;

    if (unlikely(ZONP(mem)))
             return;
    ks = ksize(mem);
    memset(mem, 0, ks);
    kfree(mem);

}

because my kernel I'm working on does not have kzfree yet.
Now, when I try to compile DigSig, this is the output:

/home/Chris/dsTest/dsi_sysfs.o: In function `kzfree':
/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: multiple definition of `kzfree'
/home/Chris/dsTest/digsig.o:/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: first defined here
/home/Chris/dsTest/digsig_cache.o: In function `kzfree':
/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: multiple definition of `kzfree'
/home/Chris/dsTest/digsig.o:/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: first defined here
/home/Chris/dsTest/digsig_revocation.o: In function `kzfree':
/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: multiple definition of `kzfree'
/home/Chris/dsTest/digsig.o:/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: first defined here
/home/Chris/dsTest/dsi_sig_verify.o: In function `kzfree':
/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: multiple definition of `kzfree'
/home/Chris/dsTest/digsig.o:/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h:114: first defined here

Of course, all is covered by #ifndef-Guards, so I just cannot understand why he is defining this function multiple times...
Any ideas?

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

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

发布评论

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

评论(1

妳是的陽光 2024-10-26 16:31:34

您的包含文件被包含在多个位置。
这不是编译时错误。而是链接的时间错误。
你的每个文件都被编译并生成了以下 .o 文件

/home/Chris/dsTest/dsi_sysfs.o
/home/Chris/dsTest/digsig_cache.o
/home/Chris/dsTest/digsig_revocation.o
/home/Chris/dsTest/dsi_sig_verify.o

现在,当将它们链接在一起时,它会找到 kzfreez 的多个定义,上面的 .o 文件中各有一个,因为它们包含相应的 c 文件

/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h

你已经使用 ifdef 保护了该文件,但这只会阻止包含.h 文件位于同一 c 文件(翻译单元)中,而不是跨不同的 c 文件。

您应该将函数编写在 c 文件中并添加到 make 文件中,以便单独编译和链接。并且仅在 crypto.h 中添加声明。 (为了进行测试,您可以在 crypto.c 中添加定义并在 crypto.h 中添加声明)。

Your include file gets included in multiple places.
This is not compile time error. But rather a linked time error.
Each of your file got compiled and produced following .o files

/home/Chris/dsTest/dsi_sysfs.o
/home/Chris/dsTest/digsig_cache.o
/home/Chris/dsTest/digsig_revocation.o
/home/Chris/dsTest/dsi_sig_verify.o

Now while linking them together it finds multiple definition of kzfreez, one each in above .o files because their corresponding c files included

/usr/src/kernels/2.6.18-194.32.1.el5-i686/include/linux/crypto.h

You have ifdef guarded the file, but that only prevents inclusion of .h file in same c file (translation units) not across different c files.

You should write the function in c file and add in in make files, so that it gets compiled separately and linked. And only add declaration in crypto.h . (For testing you can add definition in crypto.c and declaration in crypto.h).

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