什麼是ELF,COFF,和PE COFF

來源:互聯網
上載者:User
When your compiler compiles your C code, it generates an object file, which is consequently linked into a program. These "object" files and "executable" files have a specific format.

當你的編譯器編譯C代碼時,會產生一個object檔案,這個檔案接下來會被連結到程式中,object檔案和可執行檔都有固定的格式

Under Windows, Visual C++ (and every Windows compiler) generates PE COFF files. Under Linux, GCC generates ELF files (or others depending on your configurations).

在Windows下Visual C++(所有的windows編譯器都一樣)會產生呢個PE COFF格式的檔案,在Linux下GCC產生ELF格式的檔案(格式可以根據你的配置進行變化)

ELF stands for Executable and Linking Format. COFF for Common Object File Format.

ELF是Executable and Linking Format的縮寫,而COFF是Common Object File Format的縮寫

Microsoft took the COFF file and created their own Windows specific version called PE COFF or Microsoft Portable Executable COFF. They call it portable because the executable itself has the same format no matter what type of code it contains (it can contain code for 64 bit chips, or 32 bit chips, etc., the format is still the same). This doesn't imply that you can run the executable files anywhere; it just means it has a defined format even for code types you never use. (i.e.: executables files for Pocket PC are PE COFF, but you can't run them on your computer and vice versa).

微軟在COF檔案的格式基礎上發展了專屬於Windows的PE COFF檔案格式,PE中的portable(可移植)是指無論裡麵包含什麼代碼(64位代碼,32位代碼等等,檔案格式都會相同),並不是說代碼可以在任何系統上運行.所謂可移植只是說這個檔案格式為各種代碼類型提供支援.(比如:在Pocket PC上的可執行檔格式也為PE COFF,但是他並不能在你的PC機器上運行,反之亦然)

ELF and COFF formats are very similar, and allow for mostly the same functionality. They both can specify object code (files which are generated by the compiler), and executables (files produced by the linker).

ELF 和 COFF 格式非常近似,所以他們所支援的功能也也幾乎相同,他們都能指定被產生為object代碼(由編譯器產生)以及可執行檔(由linker產生)

There is also an a.out format, which was used a while ago, and is supposedly now replaced by ELF. (a.out was a fairly primitive format, lacking some key features to enable easy shared libraries, etc.)

Linux的可執行檔還有一種的格式,a.out,這是一個遺留格式,一般認為會被ELF取代(a.out 是一種很原始的格式,缺乏支援共用庫的準系統) 

The link between these formats is that they contain sections. The usual sections you'd find in object and executable files are: .text, which contains actual binary executable code, .data which contains initialized data (if you say "int a = 7;" that's where that integer is stored as initialized to 7), and .bss (blow stack segment) section, which stores un-initialized data (when you declare "int arr[100000];" the executable file will not be increased by that size; this section just has the sizes, etc., and is allocated at load time).

這幾種檔案格式的聯絡在於他們都包含section[段],在object檔案中和可執行檔中比較常見的段有下面幾種:.text,這個段包含實際的可執行代碼,.data,這個段包含已經被初始化的資料(比如"int a=7;"這個整型變數的將會被存放在這個段).bss段:存放沒有初始化的資料,(比如當你定義"int arr[100000];" ,可執行檔不會真的增大到如此大小,這些空間將會在載入時被分配)

Part of writing an operating is deciding on what object/executable format it will support or whether it defines it's own. It's also important to understand and know these formats to be able to build your operating system.

編寫作業系統時會判斷是否支援已有的檔案格式,或者定義自己的檔案格式,所以瞭解這些檔案系統對建立作業系統是十分重要

ELF格式說明書http://www.muppetlabs.com/~breadbox/software/ELF.txt

PE檔案格式詳解http://bbs.pediy.com/showthread.php?t=21932

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.