Linux
核心本身和核心模組有哪些 ELF 類型?
https://linux-audit.com/elf-binaries-on-linux-understanding-and-analysis/ 說
type 欄位告訴我們文件的用途是什麼。有幾種常見的文件類型。
CORE (value 4) DYN (Shared object file), for libraries (value 3) EXEC (Executable file), for binaries (value 2) REL (Relocatable file), before linked into an executable file (value 1)
…
一個常見的誤解是 ELF 文件僅適用於二進製文件或執行檔。我們已經看到它們可以用於部分片段(目標程式碼)。另一個例子是共享庫甚至核心轉儲(那些核心或 a.out 文件)。ELF 規範也用於 Linux 核心本身和 Linux 核心模組。
核心本身和核心模組有哪些 ELF 類型?
您能否舉一些核心本身和核心模組文件的範例,供我試用
file
?我正在使用 Ubuntu 18.04。謝謝。
您可以自行了解:
對於模組,通過查看
/lib/modules/$(uname -r)/kernel/.../*.ko
:$ file xfs.ko xfs.ko: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), BuildID[sha1]=bcb5e287509cedbb0c5ece383e0b97fb99e4781e, not stripped $ readelf -h xfs.ko ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: REL (Relocatable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file) Start of section headers: 1829088 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 0 (bytes) Number of program headers: 0 Size of section headers: 64 (bytes) Number of section headers: 45 Section header string table index: 44
對於核心,一種簡單的方法是編譯一個並查看 vmlinux:
$ file vmlinux vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=eaf006a7ccfedbc40a6feddb04088bdb2ef0112f, with debug_info, not stripped $ readelf -h vmlinux ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x1000000 Start of program headers: 64 (bytes into file) Start of section headers: 171602920 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 5 Size of section headers: 64 (bytes) Number of section headers: 43 Section header string table index: 42