[英]What is kernel section mismatch?
在編譯內核模塊時,我得到了一個WARNING,其中包含一個添加編譯選項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
頭:
/* 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符號的幫助文本:
部分不匹配分析檢查是否存在違法行為
從一個部分到另一個部分的引用。
Linux將在鏈接期間或運行時刪除某些部分
以前在這些部分中對代碼/數據的任何使用都將是
最有可能導致哎呀。
在代碼中,函數和變量都帶有注釋
__init,__ devinit等(參見include / linux / init.h中的完整列表)
這導致代碼/數據被放置在特定的部分中。
部分不匹配分析總是在完整之后完成
內核構建,但另外啟用此選項
請執行下列操作:
- 將選項-fno-inline-functions-called-once添加到gcc
在非init中內聯函數注釋__init時
功能我們會失去部分信息,因此
分析不會抓到非法參考。
此選項告訴gcc內聯較少,但也會
導致更大的內核。- 對每個模塊/ built-in.o運行部分不匹配分析
當我們在vmlinux.o上運行部分不匹配分析時,我們
丟失關於錯配位置的有價值的信息
介紹。
為每個模塊/ built-in.o文件運行分析
將告訴錯配發生在哪里更接近於
資源。 缺點是我們會報告相同的情況
不匹配至少兩次。- 從modpost啟用詳細報告以幫助解決問題
報告的部分不匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.