ELF(Executable and Linking Format)是一個定義了目標文件內部信息如何組成和組織的文件格式。內核會根據這些信息加載可執行文件,內核根據這些信息能夠知道從文件哪裏獲取代碼,從哪裏獲取初始化數據,在哪裏應該加載共享庫,等信息。linux
ELF文件主要三種文件類型,具體參考(https://blog.csdn.net/zl6481033/article/details/84990262)。bash
那麼從ELF文件上能夠獲得什麼信息,在linux上有一個GNU軟件,能夠查看目標文件內容。咱們獲得一個可執行文件,能夠採用指令 readelf -h a.out 來查看其信息。ide
有關readelf指令使用以下:函數
NAME readelf - Displays information about ELF files. SYNOPSIS readelf [-a|--all] [-h|--file-header] [-l|--program-headers|--segments] [-S|--section-headers|--sections] [-g|--section-groups] [-t|--section-details] [-e|--headers] [-s|--syms|--symbols] [--dyn-syms] [-n|--notes] [-r|--relocs] [-u|--unwind] [-d|--dynamic] [-V|--version-info] [-A|--arch-specific] [-D|--use-dynamic] [-x <number or name>|--hex-dump=<number or name>] [-p <number or name>|--string-dump=<number or name>] [-R <number or name>|--relocated-dump=<number or name>] [-z|--decompress] [-c|--archive-index] [-w[lLiaprmfFsoRt]| --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=frames-interp,=str,=loc,=Ranges,=pubtypes,=trace_info,=trace_abbrev,=trace_aranges,=gdb_index]] [--dwarf-depth=n] [--dwarf-start=n] [-I|--histogram] [-v|--version] [-W|--wide] [-H|--help]
可執行文件分析以下:.net
從上圖中頭部信息能夠獲得不少信息,根據Class、Machine、Type能夠知道這個文件是在x86-64位機器上可執行文件,根據Entry point address 知道程序啓動是從虛擬地址0x4003e0開始運行,這個地址並非main的地址,而是_start函數地址,_start函數是連接器建立的,爲了初始化程序。number of program header 程序有9個段, Number of section headers 程序有31個區,區中的信息是用來將連接使用的,主要包括程序代碼、程序數據、重定向信息等。、debug
查看區的信息能夠使用:readelf -S a.out。code
更多內容參考(https://blog.csdn.net/linux_ever/article/details/78210089)。orm