gpt4 book ai didi

linux - 什么是内核部分不匹配?

转载 作者:IT王子 更新时间:2023-10-29 00:13:18 24 4
gpt4 key购买 nike

在编译内核模块时,我收到一条警告,其中包含添加编译选项的注释,CONFIG_DEBUG_SECTION_MISMATCH=y。它为我提供了有关问题的更多详细信息:

WARNING: \**\*path to module\***(.text+0x8d2): Section mismatch in reference from the function Pch_Spi_Enable_Bios_Wr() to the variable .devinit.data:ich9_pci_tbl.22939
The function Pch_Spi_Enable_Bios_Wr() references
the variable __devinitdata ich9_pci_tbl.22939.
This is often because Pch_Spi_Enable_Bios_Wr lacks a __devinitdata
annotation or the annotation of ich9_pci_tbl.22939 is wrong.

我找不到内核部分不匹配到底是什么,更不用说如何修复了。

最佳答案

这意味着具有给定生命周期的部分中的函数引用了具有不同生命周期的部分中的某些东西。

链接内核二进制文件时,代码和数据的不同部分被分成不同的部分。其中一些部分始终保持加载状态,但其他一些部分在不再需要时会被删除(例如,仅在启动期间需要的内容可以在启动完成后释放 - 这样可以节省内存)。

如果持久部分中的函数引用其中一个可丢弃部分中的数据,则会出现问题 - 它可能会在数据已被释放时尝试访问该数据,从而导致各种运行时问题.

这不是您可以自己修复的警告,除非您编写了该代码或非常熟悉它。通过正确注释函数(或它引用的数据)使其进入正确的部分来修复它。只有详细了解内核的那一部分才能确定正确的修复。


有关这些部分和注释的列表,请参阅内核源代码树中的 include/linux/init.h header :

/* These macros are used to mark some functions or 
* initialized data (doesn't apply to uninitialized data)
* as `initialization' functions. The kernel can take this
* as hint that the function is used only during the initialization
* phase and free up used memory resources after
*
* Usage:
* For functions:
*
* You should add __init immediately before the function name, like:
*
* static void __init initme(int x, int y)
* {
* extern int z; z = x * y;
* }
*
* If the function has a prototype somewhere, you can also add
* __init between closing brace of the prototype and semicolon:
*
* extern int initialize_foobar_device(int, int, int) __init;
*
* For initialized data:
* You should insert __initdata between the variable name and equal
* sign followed by value, e.g.:
*
* static int init_variable __initdata = 0;
* static const char linux_logo[] __initconst = { 0x32, 0x36, ... };
*
* Don't forget to initialize data not at file scope, i.e. within a function,
* as gcc otherwise puts the data into the bss section and not into the init
* section.
*
* Also note, that this data cannot be "const".
*/

/* These are for everybody (although not all archs will actually
discard it in modules) */
#define __init __section(.init.text) __cold notrace
#define __initdata __section(.init.data)
#define __initconst __section(.init.rodata)
#define __exitdata __section(.exit.data)
#define __exit_call __used __section(.exitcall.exit)

其他人紧随其后,并提供更多评论和解释。

另请参阅CONFIG_DEBUG_SECTION_MISMATCH Kconfig 符号的帮助文本:

The section mismatch analysis checks if there are illegal
references from one section to another section.
Linux will during link or during runtime drop some sections
and any use of code/data previously in these sections will
most likely result in an oops.
In the code functions and variables are annotated with
__init, __devinit etc. (see full list in include/linux/init.h)
which results in the code/data being placed in specific sections.
The section mismatch analysis is always done after a full
kernel build but enabling this option will in addition
do the following:

  • Add the option -fno-inline-functions-called-once to gcc
    When inlining a function annotated __init in a non-init
    function we would lose the section information and thus
    the analysis would not catch the illegal reference.
    This option tells gcc to inline less but will also
    result in a larger kernel.
  • Run the section mismatch analysis for each module/built-in.o
    When we run the section mismatch analysis on vmlinux.o we
    lose valueble information about where the mismatch was
    introduced.
    Running the analysis for each module/built-in.o file
    will tell where the mismatch happens much closer to the
    source. The drawback is that we will report the same
    mismatch at least twice.
  • Enable verbose reporting from modpost to help solving
    the section mismatches reported.

关于linux - 什么是内核部分不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8563978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com