Linux kernel CONFIG_DEBUG_SECTION_MISMATCH make errors

后端 未结 1 918
鱼传尺愫
鱼传尺愫 2021-02-05 13:56

During the \"make\" step of the Linux kernel compilation I get lots of these errors:

Building modules, stage 2.
MODPOST 2283 modules
WARNING: modpost: Found 1 se         


        
相关标签:
1条回答
  • 2021-02-05 14:13

    This is just a warning. The kernel build systems did a sanity check and found out something that might be an error. The warning message says somewhere in kernel code there is code that might do inappropriate cross section access. Note that your kernel did build!

    To understand what the warning means, consider the following example:

    Some kernel code in the kernel text section might be trying to call a function marked with the __init data macro, which the linker puts in the kernel init section that gets de-allocated after boot or module loading.

    This might be a run time error since if the code in the text section calls the code in the init section after the initialization code has finished, it is basically calling a stale pointer.

    Having said that, that call may be perfectly fine - it is possible that the calls in the kernel text section has some good reason to know that it only calls the function in the init section when it is guaranteed to be there.

    This, of course, is just an example. Similar other scenarios also exists.

    The solution is to compile with CONFIG_DEBUG_SECTION_MISMATCH=y which will give you output of what function is trying to access which data or function and which section they belong to. You can then try to figure out if the build time warning is warranted and if so hopefully fix.

    The init.h macros __ref and __refdata can be used to allow such init references without warnings. For example,

    char * __init_refok bar(void) 
    {
      static int flag = 0;
      static char* rval = NULL;
      if(!flag) {
         flag = 1;
         rval = init_fn(); /* a function discarded after init */
      }
      return rval;
    }
    

    __init_refok, etc can fix "valid" instances, so the fact they exist may not inspire confidence.

    0 讨论(0)
提交回复
热议问题