• 什么是ELF,COFF,和PE COFF 朱燚:


    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

  • 相关阅读:
    Java-16 常用包装类
    Java-15 String类
    flask实现web端微信登录
    Flask-excel导出数据
    Java-14 单例模式
    Java-13 接口
    Java-12 抽象类
    结对项目:一个自动生成小学四则运算题目的命令行程序(c++)
    软工作业:第一次个人项目作业
    操作系统笔记一:操作系统引论
  • 原文地址:https://www.cnblogs.com/yizhu2000/p/1420953.html
Copyright © 2020-2023  润新知